class ConsoleDlg(wx.Frame): def __init__(self, parent): self.__layout_frame = parent self.__context = parent.GetContext() # create GUI wx.Frame.__init__(self, parent, -1, 'Python Console', size=(500, 300), style=wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.CAPTION | wx.CLOSE_BOX | wx.SYSTEM_MENU) menu_bar = wx.MenuBar() menu = wx.Menu() menu_run_script = menu.Append(wx.NewId(), '&Run Script\tAlt-R', 'Run a script in the console.') menu_bar.Append(menu, '&Shell') self.SetMenuBar(menu_bar) self.__shell = Shell(self) # set up what user is given to work with self.__shell.interp.locals = {'context': self.__context} self.Bind(wx.EVT_CLOSE, lambda evt: self.Hide()) # Hide instead of closing self.Bind(wx.EVT_MENU, self.OnRunScript) def OnRunScript(self, evt): # Loop until user saves or cancels dlg = wx.FileDialog(self, 'Run Python Script', wildcard='Python Scripts (*.py)|*.py', style=wx.FD_OPEN | wx.FD_CHANGE_DIR) dlg.ShowModal() ret = dlg.GetReturnCode() fp = dlg.GetPath() dlg.Destroy() if ret == wx.ID_CANCEL: return self.__shell.write('Running Script... ' + fp) self.__shell.run('execfile(\'%s\')' % fp)
def __init__(self, parent): wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition, size=wx.Size(500, 300), style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) cmds['app'] = parent cmds['get_img'] = lambda name=None, app=self: self.app.get_img() cmds['update'] = lambda app=self: self.app.get_img().update() shell = Shell(self, locals=cmds) bSizer = wx.BoxSizer(wx.VERTICAL) bSizer.Add(shell, 1, wx.EXPAND | wx.ALL, 5) self.SetSizer(bSizer) cmds['plgs'] = Macros() shell.run('# plgs.run_name() to call a ImagePy plugin.\n') shell.run( '# app is avalible here, and get_img() to get the current ImagePlus, update() to redraw.\n' )
def __init__(self, parent): wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 500,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL ) shell = Shell(self, locals=cmds) bSizer = wx.BoxSizer( wx.VERTICAL ) bSizer.Add( shell, 1, wx.EXPAND|wx.ALL, 5 ) self.SetSizer(bSizer) cmds['plgs'] = Macros() shell.run('# numpy(np) and scipy.ndimage(ndimg) has been imported!\n') shell.run('# plgs.run_name() to call a ImagePy plugin.\n') shell.run('# IPy is avalible here, and curips() to get the current ImagePlus, update() to redraw.\n')