def onBrowseScriptEvent (self, event): dialog = wx.FileDialog (None, message = "Choose script", defaultDir = run_recorded.recorded_scripts_dir(), defaultFile = "", wildcard = "*.py", style = wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR) if dialog.ShowModal() == wx.ID_OK: paths = dialog.GetPaths() for path in paths: (path, extension) = os.path.splitext (path) #split the filename out of the path (path, filename) = os.path.split(path) #run the recorded script runScript (filename) dialog.Destroy()
def onToggleRecordingEvent (self, event): theApp = wx.GetApp() if self.FilterEvent not in theApp.filterEventCallables: self.commands = "" self.comments = "" self.typingSequence = None if hasattr (self, "lastFocus"): del self.lastFocus self.lineNumber = 0 self.lastOffset = len(self.commands) self.lastEventWasSetFocus = False theApp.filterEventCallables.add (self.FilterEvent) theApp.SetCallFilterEvent() else: theApp.filterEventCallables.remove (self.FilterEvent) theApp.SetCallFilterEvent (False) dialog = wx.FileDialog (None, message = _(u"Save Script"), defaultDir = run_recorded.recorded_scripts_dir(), defaultFile = u"", wildcard = u"*.py", style = wx.SAVE|wx.CHANGE_DIR) if dialog.ShowModal () == wx.ID_OK: # Finish the script if self.typingSequence is not None: self.comments += " Type %s (%d)%s" % \ (self.valueToString (self.typingSequence), self.startTypingLineNumber, os.linesep) # Change the working directory so the next time you save a script #you will be where you saved the last one. path = dialog.GetPath() # Save the script (root, ext) = os.path.splitext (path) if len (ext) == 0: path += ".py" theFile = file (path, 'wb') self.script = "import wx, osaf, application" + os.linesep self.script += "def run():" + os.linesep if len (self.comments) > 0: self.script += ' """' + os.linesep self.script += self.comments self.script += ' """' + os.linesep + os.linesep self.script += " wx.GetApp().RunRecordedScript ([" + os.linesep if len (self.commands) > 0: self.script += self.commands self.script += " ])" + os.linesep theFile.write (self.script) theFile.close() # dealocate memory used for script del self.script del self.comments del self.commands dialog.Destroy()