[opendemo-cvs] CVS: opendemo/tools/odcut OdGui.pm,1.1,1.2
Status: Beta
Brought to you by:
girlich
From: Uwe G. <gi...@us...> - 2005-02-08 19:12:16
|
Update of /cvsroot/opendemo/opendemo/tools/odcut In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17132 Modified Files: OdGui.pm Log Message: Implement file open and close (from menu and in file list). Problematic is the mandatory one open file Index: OdGui.pm =================================================================== RCS file: /cvsroot/opendemo/opendemo/tools/odcut/OdGui.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OdGui.pm 7 Feb 2005 21:04:00 -0000 1.1 --- OdGui.pm 8 Feb 2005 19:11:45 -0000 1.2 *************** *** 8,27 **** use OdGuiGlade; use base qw(OdGuiFrame); use Wx::Event qw(EVT_BUTTON EVT_CLOSE EVT_MENU); sub new { my $classname = shift; my $self = $classname->SUPER::new(@_); ! $self->_init(@_); return $self; } ! sub _init($@) { my $self = shift; my $result = 0; # Connect objects. EVT_MENU($self,5,\&OnExit); EVT_MENU($self,21,\&OnAboutStart); --- 8,39 ---- use OdGuiGlade; use base qw(OdGuiFrame); + use Wx qw(wxOPEN wxMULTIPLE wxID_CANCEL); use Wx::Event qw(EVT_BUTTON EVT_CLOSE EVT_MENU); + use Cwd qw(getcwd); + use File::Basename qw(fileparse); sub new { my $classname = shift; + my $output = shift; + my $config = shift; my $self = $classname->SUPER::new(@_); ! $self->_init( ( output=>$output, config=>$config, @_ ) ); return $self; } ! ! sub _init($%) { my $self = shift; + if (@_) { + my %extra = @_; + @$self{keys %extra} = values %extra; + } my $result = 0; # Connect objects. + EVT_MENU($self,1,\&OnFileOpen); + EVT_MENU($self,2,\&OnFileClose); EVT_MENU($self,5,\&OnExit); EVT_MENU($self,21,\&OnAboutStart); *************** *** 29,32 **** --- 41,46 ---- EVT_CLOSE($self,\&OnClose); + EVT_BUTTON($self,$self->{fileClose},\&OnFileClose); + # Give a positive result. $result = 1; *************** *** 35,38 **** --- 49,184 ---- } + + { + my $prevdir; + my $prevfile; + + sub OnFileOpen($) + { + my $self = shift; + print STDERR "add new file\n"; + if (!defined $prevfile) { + $prevfile=""; + } + if (!defined $prevdir) { + $prevdir=Cwd::getcwd; + } + print STDERR "prevdir=$prevdir, prevfile=$prevfile\n"; + my $dialog = Wx::FileDialog->new( + $self, "Select an OpenDemo file", $prevdir, $prevfile, + "OpenDemo files (*.od*)|*.od*|All files (*)|*", + wxOPEN|wxMULTIPLE); + if( $dialog->ShowModal == wxID_CANCEL ) { + print STDERR "cancel\n"; + } else { + my @paths = $dialog->GetPaths; + if( @paths > 0 ) { + for my $filename ( @paths ) { + print "new file $filename\n"; + # remember the last directory / file + ($prevfile,$prevdir) = fileparse($filename); + $self->OnFileAdd($filename); + } + } else { + printf STDERR "no files\n"; + } + } + + $dialog->Destroy; + } + + } + + + sub OnFileAdd($$) + { + my ($self, $filename) = @_; + + # activate desired file + $self->do_command(odcommand->new("d $filename")); + + $self->UpdateGUI(); + } + + + sub OnFileClose($) + { + my ($self) = @_; + my $grid = $self->{gridFiles}; + my @rows = $grid->GetSelectedRows(); + if (@rows) { + my @files; + foreach my $row (@rows) { + printf STDERR "row %d\n", $row; + push @files, $grid->GetCellValue($row,0); + } + foreach my $file (@files) { + printf STDERR "close file: %s\n", $file; + + # close the desired file + $self->do_command(odcommand->new("c " . $file)); + } + $self->UpdateGUI(); + } + else { + printf STDERR "nothing selected\n"; + } + } + + + sub do_command($$) + { + my ($self, $command) = @_; + # memorize the command in a log window + my $text = $command->get_code()." ".join(" ",$command->get_args())."\n"; + # $self->{TEXT}->AppendText($text); + $self->{"output"}->do_command($command); + } + + + sub UpdateGUI() + { + my $self = shift; + + print STDERR "UpdateGUI stub\n"; + + my $grid = $self->{gridFiles}; + my $output = $self->{output}; + + # Remove rows with not open files. + my $remove; + for (my $row=0;$row<$grid->GetNumberRows();$row++) { + my $found = 0; + foreach my $file ($output->get_files()) { + if ($grid->GetCellValue($row,0) eq $file->name()) { + $found = 1; + last; + } + if (!$found) { + $grid->DeleteRows($row,1,1); + } + } + } + + # Add rows with not yet displayed files. + foreach my $file ($output->get_files()) { + my $found = 0; + for (my $row=0;$row<$grid->GetNumberRows();$row++) { + if ($grid->GetCellValue($row,0) eq $file->name()) { + $found = 1; + last; + } + } + if (!$found) { + # add this file. + $grid->AppendRows(1, 1); + $grid->SetCellValue($grid->GetNumberRows()-1,0,$file->name()); + $grid->SetCellValue($grid->GetNumberRows()-1,1,0); + $grid->SetCellValue($grid->GetNumberRows()-1,2,$file->snapshotc()-1); + } + } + } + + sub OnExit($) { *************** *** 72,76 **** Wx::InitAllImageHandlers(); ! my $frame = odframe->new(); $self->SetTopWindow($frame); --- 218,228 ---- Wx::InitAllImageHandlers(); ! my $output = main::get_output(); ! my $config = main::get_config(); ! ! my $frame = odframe->new($output, $config); ! foreach my $file ($output->get_files()) { ! $frame->OnFileAdd( $file->name() ); ! } $self->SetTopWindow($frame); |