def RefreshControlBar(self): """Refresh the state of the control bar based on the current config""" handler = handlers.GetHandlerById(self._config['lang']) cmds = handler.GetAliases() # Get the controls exe_ch = self.FindWindowById(ID_EXECUTABLE) args_txt = self.FindWindowById(ID_ARGS) run_btn = self.FindWindowById(ID_RUN) # Set control states csel = exe_ch.GetStringSelection() exe_ch.SetItems(cmds) util.Log("[Launch][info] Found commands %s" % str(cmds)) if handler.GetName() != handlers.DEFAULT_HANDLER and len( self.GetFile()): for ctrl in (exe_ch, args_txt, run_btn, self._chFiles): ctrl.Enable() self._isready = True if self._config['lang'] == self._config['prelang'] and len(csel): exe_ch.SetStringSelection(csel) else: exe_ch.SetStringSelection(handler.GetDefault()) self.GetControlBar().Layout() else: self._isready = False for ctrl in (exe_ch, args_txt, run_btn, self._chFiles): ctrl.Disable()
def Run(self, fname, cmd, args, ftype): """Run the given file @param fname: File path @param cmd: Command to run on file @param args: Executable arguments @param ftype: File type id """ # Find and save the file if it is modified nb = self._mw.GetNotebook() for ctrl in nb.GetTextControls(): tname = ctrl.GetFileName() if fname == tname: if ctrl.GetModify(): ctrl.SaveFile(tname) break handler = handlers.GetHandlerById(ftype) path, fname = os.path.split(fname) if wx.Platform == '__WXMSW__': fname = u"\"" + fname + u"\"" else: fname = fname.replace(u' ', u'\\ ') self._worker = eclib.ProcessThread(self._buffer, cmd, fname, args, path, handler.GetEnvironment()) self._worker.start()
def StartStopProcess(self): """Run or abort the context of the current process if possible""" if self.Preferences.get('autoclear', False): self._buffer.Clear() # Check Auto-save preferences if not self._busy: if self.Preferences.get('autosaveall', False): self.MainWindow.SaveAllBuffers() elif self.Preferences.get('autosave', False): self.MainWindow.SaveCurrentBuffer() # Start or stop the process self.SetProcessRunning(not self._busy) if self._busy: util.Log("[Launch][info] Starting process") handler = handlers.GetHandlerById(self.State['lang']) cmd = self.FindWindowById(ID_EXECUTABLE).GetStringSelection() self.State['lcmd'] = cmd cmd = handler.GetCommand(cmd) args = self.FindWindowById(ID_ARGS).GetValue().split() self.State['largs'] = args self.Run(self.State['file'], cmd, args, self.State['lang']) else: util.Log("[Launch][info] Aborting process") self._worker.Abort() self._worker = None
def OnButton(self, evt): """Handle events from the buttons on the control bar""" e_id = evt.GetId() if e_id == ID_SETTINGS: app = wx.GetApp() win = app.GetWindowInstance(cfgdlg.ConfigDialog) if win is None: config = cfgdlg.ConfigDialog(self._mw, ftype=self._config['lang']) config.CentreOnParent() config.Show() else: win.Raise() elif e_id == ID_RUN: self.SetProcessRunning(not self._busy) if self._busy: util.Log("[Launch][info] Starting process") handler = handlers.GetHandlerById(self._config['lang']) cmd = self.FindWindowById(ID_EXECUTABLE).GetStringSelection() cmd = handler.GetCommand(cmd) path, fname = os.path.split(self._config['file']) args = self.FindWindowById(ID_ARGS).GetValue().split() self._worker = outbuff.ProcessThread(self._buffer, cmd, fname, args, path, handler.GetEnvironment()) self._worker.start() else: self._worker.Abort() self._worker = None elif e_id == wx.ID_CLEAR: self._buffer.Clear() else: evt.Skip()
def GetCurrentHandler(self): """Get the current filetype handler @return: L{handlers.FileTypeHandler} instance """ lang_id = self.GetParent().GetLastRun()[1] handler = handlers.GetHandlerById(lang_id) return handler
def DoHotSpotClicked(self, pos, line): """Pass hotspot click to the filetype handler for processing @param pos: click position @param line: line the click happened on @note: overridden from L{eclib.OutputBuffer} """ fname, lang_id = self.GetParent().GetLastRun() handler = handlers.GetHandlerById(lang_id) handler.HandleHotSpot(self._mw, self, line, fname)
def OnChoice(self, evt): """Handle events from the Choice controls @param evt: wx.CommandEvent """ e_id = evt.GetId() e_sel = evt.GetSelection() if e_id == self._chFiles.GetId(): fname = self._fnames[e_sel] self.SetFile(fname) self._chFiles.SetToolTipString(fname) elif e_id == ID_EXECUTABLE: e_obj = evt.GetEventObject() handler = handlers.GetHandlerById(self._config['lang']) cmd = e_obj.GetStringSelection() e_obj.SetToolTipString(handler.GetCommand(cmd)) else: evt.Skip()
def StartStopProcess(self): """Run or abort the context of the current process if possible""" if self._prefs.get('autoclear'): self._buffer.Clear() self.SetProcessRunning(not self._busy) if self._busy: util.Log("[Launch][info] Starting process") handler = handlers.GetHandlerById(self._config['lang']) cmd = self.FindWindowById(ID_EXECUTABLE).GetStringSelection() self._config['lcmd'] = cmd cmd = handler.GetCommand(cmd) args = self.FindWindowById(ID_ARGS).GetValue().split() self._config['largs'] = args self.Run(self._config['file'], cmd, args, self._config['lang']) else: util.Log("[Launch][info] Aborting process") self._worker.Abort() self._worker = None
def StartStopProcess(self): """Run or abort the context of the current process if possible""" if self._prefs.get('autoclear'): self._buffer.Clear() self.SetProcessRunning(not self._busy) if self._busy: util.Log("[Launch][info] Starting process") handler = handlers.GetHandlerById(self._config['lang']) cmd = self.FindWindowById(ID_EXECUTABLE).GetStringSelection() cmd = handler.GetCommand(cmd) path, fname = os.path.split(self._config['file']) args = self.FindWindowById(ID_ARGS).GetValue().split() self._worker = outbuff.ProcessThread(self._buffer, cmd, fname, args, path, handler.GetEnvironment()) self._worker.start() else: util.Log("[Launch][info] Aborting process") self._worker.Abort() self._worker = None
def RefreshControlBar(self): """Refresh the state of the control bar based on the current config""" handler = handlers.GetHandlerById(self.State['lang']) cmds = handler.GetAliases() # Get the controls exe_ch = self.FindWindowById(ID_EXECUTABLE) args_txt = self.FindWindowById(ID_ARGS) csel = exe_ch.GetStringSelection() exe_ch.SetItems(cmds) ncmds = len(cmds) if ncmds > 0: exe_ch.SetToolTipString(handler.GetCommand(cmds[0])) util.Log("[Launch][info] Found commands %s" % repr(cmds)) if handler.GetName() != handlers.DEFAULT_HANDLER and \ ncmds > 0 and len(self.GetFile()): for ctrl in (exe_ch, args_txt, self._run, self._chFiles, self._lockFile): ctrl.Enable() self._isready = True if self.Locked: self._chFiles.Enable(False) if self.State['lang'] == self.State['prelang'] and len(csel): exe_ch.SetStringSelection(csel) else: csel = handler.GetDefault() exe_ch.SetStringSelection(csel) exe_ch.SetToolTipString(handler.GetCommand(csel)) self.GetControlBar().Layout() else: self._isready = False for ctrl in (exe_ch, args_txt, self._run, self._chFiles, self._lockFile): ctrl.Disable()
def __DoLayout(self): """Layout the controls""" msizer = wx.BoxSizer(wx.VERTICAL) lsizer = wx.BoxSizer(wx.HORIZONTAL) ftype = wx.GetApp().GetCurrentBuffer().GetLangId() ftype = handlers.GetHandlerById(ftype) hname = ftype.GetName() util.Log("[Launch][info] ConfigPanel: %s" % hname) htypes = sorted(syntax.SyntaxNames()) lang_ch = wx.Choice(self, ID_LANGUAGE, choices=htypes) if ftype != handlers.DEFAULT_HANDLER: lang_ch.SetStringSelection(hname) else: lang_ch.SetStringSelection(htypes[0]) lsizer.AddMany([(wx.StaticText(self, label=_("File Type") + u":"), 0, wx.ALIGN_CENTER_VERTICAL), ((5, 5), 0), (lang_ch, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)]) # Main area sbox = wx.StaticBox(self, label=_("Executables")) boxsz = wx.StaticBoxSizer(sbox, wx.VERTICAL) # Default exe dsizer = wx.BoxSizer(wx.HORIZONTAL) chandler = handlers.GetHandlerByName(lang_ch.GetStringSelection()) cmds = chandler.GetAliases() def_ch = wx.Choice(self, wx.ID_DEFAULT, choices=cmds) if chandler.GetName() != handlers.DEFAULT_HANDLER: def_ch.SetStringSelection(chandler.GetDefault()) elif len(cmds): def_ch.SetStringSelection(cmds[0]) else: pass dsizer.AddMany([(wx.StaticText(self, label=_("Default") + u":"), 0, wx.ALIGN_CENTER_VERTICAL), ((5, 5), 0), (def_ch, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL)]) # Executables List exelist = CommandListCtrl(self, ID_EXECUTABLES, style=wx.LC_EDIT_LABELS|\ wx.BORDER|wx.LC_REPORT|\ wx.LC_SINGLE_SEL) self.SetListItems(chandler.GetCommands()) bmp = wx.ArtProvider.GetBitmap(str(ed_glob.ID_ADD), wx.ART_MENU) self.addbtn = wx.BitmapButton(self, wx.ID_ADD, bmp) self.addbtn.SetToolTipString(_("Add a new executable")) bmp = wx.ArtProvider.GetBitmap(str(ed_glob.ID_REMOVE), wx.ART_MENU) self.delbtn = wx.BitmapButton(self, wx.ID_REMOVE, bmp) self.delbtn.SetToolTipString(_("Remove selection from list")) btnsz = wx.BoxSizer(wx.HORIZONTAL) self.infotxt = wx.StaticText(self, label=_("Transient XML Handler")) self.infotxt.Hide() btnsz.AddMany([(self.addbtn, 0), ((2, 2), 0), (self.delbtn, 0), ((5, 2), 0), (self.infotxt, 0, wx.ALIGN_CENTER_VERTICAL)]) # Box Sizer Layout boxsz.AddMany([((5, 5), 0), (dsizer, 0, wx.ALIGN_CENTER | wx.EXPAND), ((5, 5), 0), (wx.StaticLine(self), 0, wx.EXPAND), ((8, 8), 0), (exelist, 1, wx.EXPAND), ((5, 5), 0), (btnsz, 0, wx.ALIGN_LEFT)]) # Setup the main sizer msizer.AddMany([((10, 10), 0), (lsizer, 0, wx.EXPAND), ((10, 10), 0), (wx.StaticLine(self), 0, wx.EXPAND), ((10, 10), 0), (boxsz, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL), ((10, 10), 0)]) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.AddMany([((8, 8), 0), (msizer, 1, wx.EXPAND), ((8, 8), 0)]) self.SetSizer(hsizer) self.UpdateForHandler()
def __DoLayout(self): """Layout the controls""" msizer = wx.BoxSizer(wx.VERTICAL) lsizer = wx.BoxSizer(wx.HORIZONTAL) ftype = wx.GetApp().GetCurrentBuffer().GetLangId() ftype = handlers.GetHandlerById(ftype).GetName() htypes = GetHandlerTypes() lang_ch = wx.Choice(self, ID_LANGUAGE, choices=htypes) if ftype != handlers.DEFAULT_HANDLER: lang_ch.SetStringSelection(ftype) else: lang_ch.SetStringSelection(htypes[0]) lsizer.AddMany([(wx.StaticText(self, label=_("File Type") + ":"), 0, wx.ALIGN_CENTER_VERTICAL), ((5, 5), 0), (lang_ch, 1, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)]) # Main area sbox = wx.StaticBox(self, label=_("Executables")) boxsz = wx.StaticBoxSizer(sbox, wx.VERTICAL) # Default exe dsizer = wx.BoxSizer(wx.HORIZONTAL) chandler = handlers.GetHandlerByName(lang_ch.GetStringSelection()) cmds = chandler.GetAliases() def_ch = wx.Choice(self, wx.ID_DEFAULT, choices=cmds) if chandler.GetName() != handlers.DEFAULT_HANDLER: def_ch.SetStringSelection(chandler.GetDefault()) elif len(cmds): def_ch.SetStringSelection(cmds[0]) else: pass dsizer.AddMany([(wx.StaticText(self, label=_("Default") + ":"), 0, wx.ALIGN_CENTER_VERTICAL), ((5, 5), 0), (def_ch, 1, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL)]) # Executables List exelist = CommandListCtrl(self, ID_EXECUTABLES, style=wx.LC_EDIT_LABELS|\ wx.BORDER|wx.LC_REPORT|\ wx.LC_SINGLE_SEL) # exelist.SetToolTipString(_("Click on an item to edit")) # exelist.InsertColumn(0, _("Alias")) # exelist.InsertColumn(1, _("Executable Commands")) self.SetListItems(chandler.GetCommands()) addbtn = wx.BitmapButton(self, wx.ID_ADD, GetPlusBitmap()) addbtn.SetToolTipString(_("Add a new executable")) delbtn = wx.BitmapButton(self, wx.ID_REMOVE, GetMinusBitmap()) delbtn.SetToolTipString(_("Remove selection from list")) btnsz = wx.BoxSizer(wx.HORIZONTAL) btnsz.AddMany([(addbtn, 0), ((2, 2), 0), (delbtn, 0)]) # Box Sizer Layout boxsz.AddMany([((5, 5), 0), (dsizer, 0, wx.ALIGN_CENTER|wx.EXPAND), ((5, 5), 0), (wx.StaticLine(self), 0, wx.EXPAND), ((8, 8), 0), (exelist, 1, wx.EXPAND), ((5, 5), 0), (btnsz, 0, wx.ALIGN_LEFT)]) # Setup the main sizer msizer.AddMany([((10, 10), 0), (lsizer, 0, wx.EXPAND), ((10, 10), 0), (wx.StaticLine(self), 0, wx.EXPAND), ((10, 10), 0), (boxsz, 1, wx.EXPAND|wx.ALIGN_CENTER_VERTICAL), ((10, 10), 0)]) hsizer = wx.BoxSizer(wx.HORIZONTAL) hsizer.AddMany([((8, 8), 0), (msizer, 1, wx.EXPAND), ((8, 8), 0)]) self.SetSizer(hsizer) self.SetAutoLayout(True)