如果没有包或对象引用,则无法调用方法“geometry”

时间:2011-10-06 13:01:31

标签: linux perl

我正在尝试将getSaveFile对话框放在选定的(通过xwininfo)窗口中心,我有所选窗口的位置,宽度和高度,但需要帮助移动getSaveFile对话框(当它出现/显示时可能是键),以及所选窗口的中心......

我对所选窗口的变量是$ window_width,$ window_height,$ abs_x,$ abs_y

我相信正确定位GetSaveFile对话框,我需要类似的东西:

$ sfile - > geometry(“originalWidth”。“x”。“orighnalHeight +($ abs_x +($ window_width / 2 - originalWidth / 2))+($ abs_y +($ window_height / 2 -orighnalHeight / 2)”) ;

上面的问题不是那么多,但有些帮助也会很好, 这是用来将那些数字插入我之后的代码......

在哪里以及如何使用“$ sfile - >几何(widthxheight + x + y);”输入比特,因为我在下面遇到错误:

# save dialog
 my $types = [
['All Files',        '*',             ],
['mpg files',        '.mpg',          ],        
['avi files',        '.avi',          ],              
['mov files',        '.mov',          ],         
];


my $sfile = $mw->getSaveFile( 
                                          -defaultextension => ".mov",
                                          -initialdir => "/home/frank/Perl/screencaps", # standardise...
                                          -initialfile => "ScreenCast01",
                                          -title => "ScreenCast Capture file",
                                          -filetypes => $types,
                                          # position/geometry
                                          ); 

 # $sfile ->geometry('100x100+100+100');   # can't call method "geometry" without a package or object reference...   
 &do_saveFileWithType($sfile) if defined $sfile;

sub do_saveFileWithType {

 my @InboundParameters = @_;
   print "This is what was passed:\t$InboundParameters[0]\n";

#   $sfile ->geometry('100x100+100+100');   # can't call method "geometry" without a package or object reference...   
 }

我现在有了这个:

# to centre the save dialog(for when it's up): 
 my $title = "ScreenCast Capture file";
 my $x = ($abs_x+($window_width/2)-207); # 207 =  SaveDialogWidth/2
 my $y = ($abs_y+($window_height/2)-134); # 134 =  SaveDialogHeight/2

my $checking4win2move;
  $checking4win2move = "on";
  my $pid = fork(); # ??
  if ($pid == 0){ # ??

    while ($checking4win2move eq "on"){
       my  @runwmctrl = wmctrl ("-l"); 
       for( @runwmctrl ) { 
             my $linesOf_wmctrl=$_;  
             chomp ($linesOf_wmctrl);           # Get rid of the trailling \n   ??

            if($linesOf_wmctrl =~ m/ScreenCast Capture file/) { 
               #print "The \"ScreenCast Capture file\" dialog is mentioned and so is up, I can now move it to the centre of the selected window.\n";
                   my $windowMove = wmctrl ("-r $title", "-e 0,$x,$y,-1,-1"); 

                 # and stop checking:
                # $checking4win2move = "off"; # unfork?? # X Error of failed request: BadIDChoice (invalid resource ID chosen for this connection)
                exit(); #??
                  }else{ # print "The dialog is not mentioned in this line of wmctrl\'s output\n";
                   }
     }
      sleep .02; # then check again or...
    }
 } 

1 个答案:

答案 0 :(得分:2)

getSaveFile方法返回文件名(如果取消则返回undef),而不是窗口小部件引用。关于定位窗口,我没有看到任何its documentation