From 6b5f83f76291362a510bc99e35139bdd175cc9bf Mon Sep 17 00:00:00 2001 From: ccremers Date: Mon, 7 Aug 2006 12:59:22 +0000 Subject: [PATCH] - Added parameters for automatic starts. (try filename --verify) - Splash screen can now be disabled. --- gui/Mainwindow.py | 32 ++++++++++++++++++++++++------ gui/Scytherthread.py | 14 ++++++------- gui/scyther-gui.py | 47 ++++++++++++++++++++++++++++---------------- 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/gui/Mainwindow.py b/gui/Mainwindow.py index 859f082..bf31211 100644 --- a/gui/Mainwindow.py +++ b/gui/Mainwindow.py @@ -28,16 +28,28 @@ ID_CHECK = 103 class MainWindow(wx.Frame): - def __init__(self, filename=''): + def __init__(self, opts, args): super(MainWindow, self).__init__(None, size=(600,800)) + + self.opts = opts + self.args = args + self.dirname = '.' - if filename != '' and os.path.isfile(filename): - self.filename = filename + self.filename = 'noname.spdl' + self.load = False + + # test + if opts.test: + self.filename = 'scythergui-default.spdl' self.load = True - else: - self.filename = 'noname.spdl' - self.load = False + + # if there is an argument (file), we load it + if len(args) > 0: + filename = args[0] + if filename != '' and os.path.isfile(filename): + self.filename = filename + self.load = True Icon.ScytherIcon(self) @@ -63,6 +75,8 @@ class MainWindow(wx.Frame): #self.SetTitle(self.title) + self.firstCommand() + def CreateInteriorWindowComponents(self): ''' Create "interior" window components. In this case it is just a simple multiline text control. ''' @@ -237,6 +251,12 @@ class MainWindow(wx.Frame): def OnCheck(self, event): self.RunScyther("check") + def firstCommand(self): + if self.opts.command: + # Trigger a command automatically + self.RunScyther(self.opts.command) + + #--------------------------------------------------------------------------- class SettingsWindow(wx.Panel): diff --git a/gui/Scytherthread.py b/gui/Scytherthread.py index a4bd9e0..82e6539 100644 --- a/gui/Scytherthread.py +++ b/gui/Scytherthread.py @@ -366,7 +366,7 @@ class ScytherRun(object): # Verification window self.verifywin = verifywin = VerificationWindow(mainwin,"Running Scyther %s process" % mode) - verifywin.CenterOnScreen() + verifywin.Center() verifywin.Show(True) # start the thread @@ -381,12 +381,8 @@ class ScytherRun(object): # start the window and show until something happens # if it terminates, this is a cancel, and should also kill the thread. (what happens to a spawned Scyther in that case?) # if the thread terminames, it should close the window normally, and we end up here as well. - val = verifywin.ShowModal() - # Cursor back to normal - verifywin.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) - if self.verified: # Scyther program is done (the alternative is that it was # cancelled) @@ -402,23 +398,25 @@ class ScytherRun(object): else: txt = "Done." resultwin.SetStatusText(txt) + resultwin.Refresh() def claimDone(claim): if claim.button and len(claim.attacks) > 0: claim.button.Enable() + resultwin.Refresh() t = AttackThread(self,resultwin,claimDone,attackDone) t.start() resultwin.thread = t - resultwin.CenterOnScreen() + resultwin.Center() resultwin.Show(True) + else: # Darn, some errors. report. title = "Scyther errors : %s" % mode errorwin = ErrorWindow(mainwin,title,errors=self.scyther.errors) - errorwin.Show(True) - errorwin.CenterOnScreen() + errorwin.Center() val = errorwin.ShowModal() diff --git a/gui/scyther-gui.py b/gui/scyther-gui.py index 09071ca..9bc6696 100755 --- a/gui/scyther-gui.py +++ b/gui/scyther-gui.py @@ -5,6 +5,7 @@ """ Import externals """ import wx import sys +from optparse import OptionParser #--------------------------------------------------------------------------- @@ -15,6 +16,23 @@ import Misc #--------------------------------------------------------------------------- +def parseArgs(): + usage = "usage: %s [optional initial settings]" % sys.argv[0] + parser = OptionParser(usage=usage) + + # command + parser.add_option("-V","--verify",dest="command",default=None,action="store_const",const="verify") + parser.add_option("-s","--state-space",dest="command",default=None,action="store_const",const="statespace") + parser.add_option("-a","--auto-claims",dest="command",default=None,action="store_const",const="autoverify") + parser.add_option("-c","--check",dest="command",default=None,action="store_const",const="check") + + # misc debug etc + parser.add_option("","--test",dest="test",default=False,action="store_true") + + return parser.parse_args() + +#--------------------------------------------------------------------------- + class MySplashScreen(wx.SplashScreen): def __init__(self): bmp = wx.Image(Misc.mypath("images/scyther-splash.png")).ConvertToBitmap() @@ -42,37 +60,32 @@ class MySplashScreen(wx.SplashScreen): self.Raise() +#--------------------------------------------------------------------------- class ScytherApp(wx.App): def OnInit(self): wx.GetApp().SetAppName("Scyther-gui") - """ - Load preferences file - """ + # Parse arguments + (opts,args) = parseArgs() + # Load preferences file Preference.init() """ Create and show the splash screen. It will then create and show the main frame when it is time to do so. + + The splash screen is disabled for automatic commands, and also + by a setting in the preferences file. """ + if not opts.command: + if not (Preference.get('splashscreen') in ['false','off','disable','0']): + splash = MySplashScreen() + splash.Show() - - splash = MySplashScreen() - splash.Show() - - """ Build up """ - infile = '' - args = sys.argv[1:] - if len(args) > 0: - if args[0] == 'test': - infile = 'scythergui-default.spdl' - else: - infile = args[0] - - self.mainWindow = Mainwindow.MainWindow(infile) + self.mainWindow = Mainwindow.MainWindow(opts,args) self.SetTopWindow(self.mainWindow) self.mainWindow.Show()