def __init__(self, parent, giface, id=wx.ID_ANY, simpleEditorHandler=None, **kwargs): self.parent = parent self.giface = giface wx.Panel.__init__(self, parent=parent, id=id, **kwargs) self.intro = ( _("Welcome to wxGUI Interactive Python Shell %s") % VERSION + "\n\n" + _("Type %s for more GRASS scripting related information.") % '"help(gs)"' + "\n" + _("Type %s to add raster or vector to the layer tree.") % "\"AddLayer('map_name')\"" + "\n\n") shellargs = dict( parent=self, id=wx.ID_ANY, introText=self.intro, locals={ "gs": grass, "AddLayer": self.AddLayer, "help": self.Help }, ) # useStockId (available since wxPython 4.0.2) should be False on macOS if sys.platform == "darwin" and CheckWxVersion([4, 0, 2]): shellargs["useStockId"] = False self.shell = PyShell(**shellargs) if IsDark(): SetDarkMode(self.shell) sys.displayhook = self._displayhook self.btnClear = ClearButton(self) self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear) self.btnClear.SetToolTip(_("Delete all text from the shell")) self.simpleEditorHandler = simpleEditorHandler if simpleEditorHandler: self.btnSimpleEditor = Button(self, id=wx.ID_ANY, label=_("Simple &editor")) self.btnSimpleEditor.Bind(wx.EVT_BUTTON, simpleEditorHandler) self.btnSimpleEditor.SetToolTip( _("Open a simple Python code editor")) self._layout()
def __init__(self, parent, giface, id=wx.ID_ANY, simpleEditorHandler=None, **kwargs): self.parent = parent self.giface = giface wx.Panel.__init__(self, parent=parent, id=id, **kwargs) self.intro = _("Welcome to wxGUI Interactive Python Shell %s") % VERSION + "\n\n" + \ _("Type %s for more GRASS scripting related information.") % "\"help(gs)\"" + "\n" + \ _("Type %s to add raster or vector to the layer tree.") % "\"AddLayer()\"" + "\n\n" # useStockId should be False on macOS self.shell = PyShell(parent=self, id=wx.ID_ANY, introText=self.intro, locals={ 'gs': grass, 'AddLayer': self.AddLayer }, useStockId=(sys.platform != "darwin")) sys.displayhook = self._displayhook self.btnClear = ClearButton(self) self.btnClear.Bind(wx.EVT_BUTTON, self.OnClear) self.btnClear.SetToolTip(_("Delete all text from the shell")) self.simpleEditorHandler = simpleEditorHandler if simpleEditorHandler: self.btnSimpleEditor = Button(self, id=wx.ID_ANY, label=_("Simple &editor")) self.btnSimpleEditor.Bind(wx.EVT_BUTTON, simpleEditorHandler) self.btnSimpleEditor.SetToolTip( _("Open a simple Python code editor")) self._layout()
def __init__( self, parent, giface, gconsole, menuModel=None, margin=False, style=wx.TAB_TRAVERSAL | wx.FULL_REPAINT_ON_RESIZE, gcstyle=GC_EMPTY, **kwargs, ): """ :param parent: gui parent :param gconsole: console logic :param menuModel: tree model of modules (from menu) :param margin: use margin in output pane (GStc) :param style: wx.SplitterWindow style :param gcstyle: GConsole style (GC_EMPTY, GC_PROMPT to show command prompt) """ wx.SplitterWindow.__init__(self, parent, id=wx.ID_ANY, style=style, **kwargs) self.SetName("GConsole") self.panelOutput = wx.Panel(parent=self, id=wx.ID_ANY) self.panelProgress = wx.Panel( parent=self.panelOutput, id=wx.ID_ANY, name="progressPanel" ) self.panelPrompt = wx.Panel(parent=self, id=wx.ID_ANY) # initialize variables self.parent = parent # GMFrame | CmdPanel | ? self._gconsole = gconsole self._menuModel = menuModel self._gcstyle = gcstyle self.lineWidth = 80 # signal which requests showing of a notification self.showNotification = Signal("GConsoleWindow.showNotification") # signal emitted when text appears in the console # parameter 'notification' suggests form of notification (according to # core.giface.Notification) self.contentChanged = Signal("GConsoleWindow.contentChanged") # progress bar self.progressbar = wx.Gauge( parent=self.panelProgress, id=wx.ID_ANY, range=100, pos=(110, 50), size=(-1, 25), style=wx.GA_HORIZONTAL, ) self._gconsole.Bind(EVT_CMD_PROGRESS, self.OnCmdProgress) self._gconsole.Bind(EVT_CMD_OUTPUT, self.OnCmdOutput) self._gconsole.Bind(EVT_CMD_RUN, self.OnCmdRun) self._gconsole.Bind(EVT_CMD_DONE, self.OnCmdDone) self._gconsole.writeLog.connect(self.WriteLog) self._gconsole.writeCmdLog.connect(self.WriteCmdLog) self._gconsole.writeWarning.connect(self.WriteWarning) self._gconsole.writeError.connect(self.WriteError) # text control for command output self.cmdOutput = GStc( parent=self.panelOutput, id=wx.ID_ANY, margin=margin, wrap=None ) # command prompt # move to the if below # search depends on cmd prompt self.cmdPrompt = GPromptSTC( parent=self, giface=giface, menuModel=self._menuModel ) self.cmdPrompt.promptRunCmd.connect( lambda cmd: self._gconsole.RunCmd(command=cmd) ) self.cmdPrompt.showNotification.connect(self.showNotification) if not self._gcstyle & GC_PROMPT: self.cmdPrompt.Hide() if self._gcstyle & GC_PROMPT: cmdLabel = _("Command prompt") self.outputBox = StaticBox( parent=self.panelOutput, id=wx.ID_ANY, label=" %s " % _("Output window") ) self.cmdBox = StaticBox( parent=self.panelOutput, id=wx.ID_ANY, label=" %s " % cmdLabel ) # buttons self.btnOutputClear = ClearButton(parent=self.panelOutput) self.btnOutputClear.SetToolTip(_("Clear output window content")) self.btnCmdClear = ClearButton(parent=self.panelOutput) self.btnCmdClear.SetToolTip(_("Clear command prompt content")) self.btnOutputSave = Button(parent=self.panelOutput, id=wx.ID_SAVE) self.btnOutputSave.SetToolTip(_("Save output window content to the file")) self.btnCmdAbort = Button(parent=self.panelProgress, id=wx.ID_STOP) self.btnCmdAbort.SetToolTip(_("Abort running command")) self.btnCmdProtocol = ToggleButton( parent=self.panelOutput, id=wx.ID_ANY, label=_("&Log file"), size=self.btnCmdClear.GetSize(), ) self.btnCmdProtocol.SetToolTip( _( "Toggle to save list of executed commands into " "a file; content saved when switching off." ) ) self.cmdFileProtocol = None if not self._gcstyle & GC_PROMPT: self.btnCmdClear.Hide() self.btnCmdProtocol.Hide() self.btnCmdClear.Bind(wx.EVT_BUTTON, self.cmdPrompt.OnCmdErase) self.btnOutputClear.Bind(wx.EVT_BUTTON, self.OnOutputClear) self.btnOutputSave.Bind(wx.EVT_BUTTON, self.OnOutputSave) self.btnCmdAbort.Bind(wx.EVT_BUTTON, self._gconsole.OnCmdAbort) self.btnCmdProtocol.Bind(wx.EVT_TOGGLEBUTTON, self.OnCmdProtocol) self._layout()
def __init__(self, parent, id=wx.ID_ANY, title=None, vectorName=None, item=None, log=None, selection=None, **kwargs): """GRASS Attribute Table Manager window :param parent: parent window :param id: window id :param title: window title or None for default title :param vectorName: name of vector map :param item: item from Layer Tree :param log: log window :param selection: name of page to be selected :param kwagrs: other wx.Frame's arguments """ self.parent = parent try: mapdisplay = self.parent.GetMapDisplay() except: mapdisplay = None DbMgrBase.__init__(self, id=id, mapdisplay=mapdisplay, vectorName=vectorName, item=item, log=log, statusbar=self, **kwargs) wx.Frame.__init__(self, parent, id, *kwargs) # title if not title: title = "%s" % _("GRASS GIS Attribute Table Manager - ") if not self.dbMgrData['editable']: title += _("READONLY - ") title += "<%s>" % (self.dbMgrData['vectName']) self.SetTitle(title) # icon self.SetIcon( wx.Icon(os.path.join(globalvar.ICONDIR, 'grass_sql.ico'), wx.BITMAP_TYPE_ICO)) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) if len(self.dbMgrData['mapDBInfo'].layers.keys()) == 0: GMessage(parent=self.parent, message=_("Database connection for vector map <%s> " "is not defined in DB file. " "You can define new connection in " "'Manage layers' tab.") % self.dbMgrData['vectName']) busy = wx.BusyInfo(_("Please wait, loading attribute data..."), parent=self.parent) wx.SafeYield() self.CreateStatusBar(number=1) self.notebook = GNotebook(self.panel, style=globalvar.FNPageDStyle) self.CreateDbMgrPage(parent=self, pageName='browse') self.notebook.AddPage(page=self.pages['browse'], text=_("Browse data"), name='browse') self.pages['browse'].SetTabAreaColour(globalvar.FNPageColor) self.CreateDbMgrPage(parent=self, pageName='manageTable') self.notebook.AddPage(page=self.pages['manageTable'], text=_("Manage tables"), name='table') self.pages['manageTable'].SetTabAreaColour(globalvar.FNPageColor) self.CreateDbMgrPage(parent=self, pageName='manageLayer') self.notebook.AddPage(page=self.pages['manageLayer'], text=_("Manage layers"), name='layers') del busy if selection: wx.CallAfter(self.notebook.SetSelectionByName, selection) else: wx.CallAfter(self.notebook.SetSelection, 0) # select browse tab # buttons self.btnClose = CloseButton(parent=self.panel) self.btnClose.SetToolTip(_("Close Attribute Table Manager")) self.btnReload = Button(parent=self.panel, id=wx.ID_REFRESH) self.btnReload.SetToolTip( _("Reload currently selected attribute data")) self.btnReset = ClearButton(parent=self.panel) self.btnReset.SetToolTip( _("Reload all attribute data (drop current selection)")) # bind closing to ESC self.Bind(wx.EVT_MENU, self.OnCloseWindow, id=wx.ID_CANCEL) accelTableList = [(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_CANCEL)] accelTable = wx.AcceleratorTable(accelTableList) self.SetAcceleratorTable(accelTable) # events self.btnClose.Bind(wx.EVT_BUTTON, self.OnCloseWindow) self.btnReload.Bind(wx.EVT_BUTTON, self.OnReloadData) self.btnReset.Bind(wx.EVT_BUTTON, self.OnReloadDataAll) self.notebook.Bind(FN.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.OnPageChanged) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) # do layout self._layout() # self.SetMinSize(self.GetBestSize()) self.SetSize((700, 550)) # FIXME hard-coded size self.SetMinSize(self.GetSize())
def __init__(self, parent, giface, cmd, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs): self.parent = parent self._giface = giface if self.parent: self.log = self.parent.GetLogWindow() else: self.log = None # grass command self.cmd = cmd if self.cmd == 'r.mapcalc': self.rast3d = False title = _('GRASS GIS Raster Map Calculator') if self.cmd == 'r3.mapcalc': self.rast3d = True title = _('GRASS GIS 3D Raster Map Calculator') wx.Frame.__init__(self, parent, id=id, title=title, **kwargs) self.SetIcon( wx.Icon(os.path.join(globalvar.ICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO)) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.CreateStatusBar() # # variables # self.heading = _('mapcalc statement') self.funct_dict = { 'abs(x)': 'abs()', 'acos(x)': 'acos()', 'asin(x)': 'asin()', 'atan(x)': 'atan()', 'atan(x,y)': 'atan( , )', 'cos(x)': 'cos()', 'double(x)': 'double()', 'eval([x,y,...,]z)': 'eval()', 'exp(x)': 'exp()', 'exp(x,y)': 'exp( , )', 'float(x)': 'float()', 'graph(x,x1,y1[x2,y2..])': 'graph( , , )', 'if(x)': 'if()', 'if(x,a)': 'if( , )', 'if(x,a,b)': 'if( , , )', 'if(x,a,b,c)': 'if( , , , )', 'int(x)': 'int()', 'isnull(x)': 'isnull()', 'log(x)': 'log(', 'log(x,b)': 'log( , )', 'max(x,y[,z...])': 'max( , )', 'median(x,y[,z...])': 'median( , )', 'min(x,y[,z...])': 'min( , )', 'mode(x,y[,z...])': 'mode( , )', 'nmax(x,y[,z...])': 'nmax( , )', 'nmedian(x,y[,z...])': 'nmedian( , )', 'nmin(x,y[,z...])': 'nmin( , )', 'nmode(x,y[,z...])': 'nmode( , )', 'not(x)': 'not()', 'pow(x,y)': 'pow( , )', 'rand(a,b)': 'rand( , )', 'round(x)': 'round()', 'round(x,y)': 'round( , )', 'round(x,y,z)': 'round( , , )', 'sin(x)': 'sin()', 'sqrt(x)': 'sqrt()', 'tan(x)': 'tan()', 'xor(x,y)': 'xor( , )', 'row()': 'row()', 'col()': 'col()', 'nrows()': 'nrows()', 'ncols()': 'ncols()', 'x()': 'x()', 'y()': 'y()', 'ewres()': 'ewres()', 'nsres()': 'nsres()', 'area()': 'area()', 'null()': 'null()' } if self.rast3d: self.funct_dict['z()'] = 'z()' self.funct_dict['tbres()'] = 'tbres()' element = 'raster_3d' else: element = 'cell' # characters which can be in raster map name but the map name must be # then quoted self.charactersToQuote = '+-&!<>%~?^|' # stores last typed map name in Select widget to distinguish typing # from selection self.lastMapName = '' self.operatorBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Operators')) self.outputBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Output')) self.operandBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Operands')) self.expressBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Expression')) # # Buttons # self.btn_clear = ClearButton(parent=self.panel) self.btn_help = Button(parent=self.panel, id=wx.ID_HELP) self.btn_run = Button(parent=self.panel, id=wx.ID_ANY, label=_("&Run")) self.btn_run.SetDefault() self.btn_close = CloseButton(parent=self.panel) self.btn_save = Button(parent=self.panel, id=wx.ID_SAVE) self.btn_save.SetToolTip(_('Save expression to file')) self.btn_load = Button(parent=self.panel, id=wx.ID_ANY, label=_("&Load")) self.btn_load.SetToolTip(_('Load expression from file')) self.btn_copy = Button(parent=self.panel, id=wx.ID_ANY, label=_("Copy")) self.btn_copy.SetToolTip( _("Copy the current command string to the clipboard")) self.btn = dict() self.btn['pow'] = Button(parent=self.panel, id=wx.ID_ANY, label="^") self.btn['pow'].SetToolTip(_('exponent')) self.btn['div'] = Button(parent=self.panel, id=wx.ID_ANY, label="/") self.btn['div'].SetToolTip(_('divide')) self.btn['add'] = Button(parent=self.panel, id=wx.ID_ANY, label="+") self.btn['add'].SetToolTip(_('add')) self.btn['minus'] = Button(parent=self.panel, id=wx.ID_ANY, label="-") self.btn['minus'].SetToolTip(_('subtract')) self.btn['mod'] = Button(parent=self.panel, id=wx.ID_ANY, label="%") self.btn['mod'].SetToolTip(_('modulus')) self.btn['mult'] = Button(parent=self.panel, id=wx.ID_ANY, label="*") self.btn['mult'].SetToolTip(_('multiply')) self.btn['parenl'] = Button(parent=self.panel, id=wx.ID_ANY, label="(") self.btn['parenr'] = Button(parent=self.panel, id=wx.ID_ANY, label=")") self.btn['lshift'] = Button(parent=self.panel, id=wx.ID_ANY, label="<<") self.btn['lshift'].SetToolTip(_('left shift')) self.btn['rshift'] = Button(parent=self.panel, id=wx.ID_ANY, label=">>") self.btn['rshift'].SetToolTip(_('right shift')) self.btn['rshiftu'] = Button(parent=self.panel, id=wx.ID_ANY, label=">>>") self.btn['rshiftu'].SetToolTip(_('right shift (unsigned)')) self.btn['gt'] = Button(parent=self.panel, id=wx.ID_ANY, label=">") self.btn['gt'].SetToolTip(_('greater than')) self.btn['gteq'] = Button(parent=self.panel, id=wx.ID_ANY, label=">=") self.btn['gteq'].SetToolTip(_('greater than or equal to')) self.btn['lt'] = Button(parent=self.panel, id=wx.ID_ANY, label="<") self.btn['lt'].SetToolTip(_('less than')) self.btn['lteq'] = Button(parent=self.panel, id=wx.ID_ANY, label="<=") self.btn['lteq'].SetToolTip(_('less than or equal to')) self.btn['eq'] = Button(parent=self.panel, id=wx.ID_ANY, label="==") self.btn['eq'].SetToolTip(_('equal to')) self.btn['noteq'] = Button(parent=self.panel, id=wx.ID_ANY, label="!=") self.btn['noteq'].SetToolTip(_('not equal to')) self.btn['compl'] = Button(parent=self.panel, id=wx.ID_ANY, label="~") self.btn['compl'].SetToolTip(_('one\'s complement')) self.btn['not'] = Button(parent=self.panel, id=wx.ID_ANY, label="!") self.btn['not'].SetToolTip(_('NOT')) self.btn['andbit'] = Button(parent=self.panel, id=wx.ID_ANY, label='&&') self.btn['andbit'].SetToolTip(_('bitwise AND')) self.btn['orbit'] = Button(parent=self.panel, id=wx.ID_ANY, label="|") self.btn['orbit'].SetToolTip(_('bitwise OR')) self.btn['and'] = Button(parent=self.panel, id=wx.ID_ANY, label="&&&&") self.btn['and'].SetToolTip(_('logical AND')) self.btn['andnull'] = Button(parent=self.panel, id=wx.ID_ANY, label="&&&&&&") self.btn['andnull'].SetToolTip(_('logical AND (ignores NULLs)')) self.btn['or'] = Button(parent=self.panel, id=wx.ID_ANY, label="||") self.btn['or'].SetToolTip(_('logical OR')) self.btn['ornull'] = Button(parent=self.panel, id=wx.ID_ANY, label="|||") self.btn['ornull'].SetToolTip(_('logical OR (ignores NULLs)')) self.btn['cond'] = Button(parent=self.panel, id=wx.ID_ANY, label="a ? b : c") self.btn['cond'].SetToolTip(_('conditional')) # # Text area # self.text_mcalc = TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(-1, 100), style=wx.TE_MULTILINE) wx.CallAfter(self.text_mcalc.SetFocus) # # Map and function insertion text and ComboBoxes self.newmaplabel = StaticText(parent=self.panel, id=wx.ID_ANY) if self.rast3d: self.newmaplabel.SetLabel( _('Name for new 3D raster map to create')) else: self.newmaplabel.SetLabel(_('Name for new raster map to create')) # As we can write only to current mapset, names should not be fully qualified # to not confuse end user about writing in other mapset self.newmaptxt = Select(parent=self.panel, id=wx.ID_ANY, size=(250, -1), type=element, multiple=False, fullyQualified=False) self.mapsellabel = StaticText(parent=self.panel, id=wx.ID_ANY) if self.rast3d: self.mapsellabel.SetLabel(_('Insert existing 3D raster map')) else: self.mapsellabel.SetLabel(_('Insert existing raster map')) self.mapselect = Select(parent=self.panel, id=wx.ID_ANY, size=(250, -1), type=element, multiple=False) self.functlabel = StaticText(parent=self.panel, id=wx.ID_ANY, label=_('Insert mapcalc function')) self.function = wx.ComboBox(parent=self.panel, id=wx.ID_ANY, size=(250, -1), choices=sorted(self.funct_dict.keys()), style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.TE_PROCESS_ENTER) self.overwrite = wx.CheckBox( parent=self.panel, id=wx.ID_ANY, label=_("Allow output files to overwrite existing files")) self.overwrite.SetValue( UserSettings.Get(group='cmd', key='overwrite', subkey='enabled')) self.randomSeed = wx.CheckBox( parent=self.panel, label=_("Generate random seed for rand()")) self.randomSeedStaticText = StaticText(parent=self.panel, label=_("Seed:")) self.randomSeedText = TextCtrl(parent=self.panel, size=(100, -1), validator=IntegerValidator()) self.randomSeedText.SetToolTip(_("Integer seed for rand() function")) self.randomSeed.SetValue(True) self.randomSeedStaticText.Disable() self.randomSeedText.Disable() self.addbox = wx.CheckBox( parent=self.panel, label=_('Add created raster map into layer tree'), style=wx.NO_BORDER) self.addbox.SetValue( UserSettings.Get(group='cmd', key='addNewLayer', subkey='enabled')) if not self.parent or self.parent.GetName() != 'LayerManager': self.addbox.Hide() # # Bindings # for btn in self.btn.keys(): self.btn[btn].Bind(wx.EVT_BUTTON, self.AddMark) self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.btn_clear.Bind(wx.EVT_BUTTON, self.OnClear) self.btn_run.Bind(wx.EVT_BUTTON, self.OnMCalcRun) self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp) self.btn_save.Bind(wx.EVT_BUTTON, self.OnSaveExpression) self.btn_load.Bind(wx.EVT_BUTTON, self.OnLoadExpression) self.btn_copy.Bind(wx.EVT_BUTTON, self.OnCopyCommand) self.mapselect.Bind(wx.EVT_TEXT, self.OnSelect) self.function.Bind(wx.EVT_COMBOBOX, self._return_funct) self.function.Bind(wx.EVT_TEXT_ENTER, self.OnSelect) self.newmaptxt.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar) self.text_mcalc.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar) self.overwrite.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar) self.randomSeed.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar) self.randomSeed.Bind(wx.EVT_CHECKBOX, self.OnSeedFlag) self.randomSeedText.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar) # bind closing to ESC self.Bind(wx.EVT_MENU, self.OnClose, id=wx.ID_CANCEL) accelTableList = [(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_CANCEL)] accelTable = wx.AcceleratorTable(accelTableList) self.SetAcceleratorTable(accelTable) self._layout() self.SetMinSize(self.panel.GetBestSize()) # workaround for http://trac.wxwidgets.org/ticket/13628 self.SetSize(self.panel.GetBestSize())
def _doLayout(self, modeChoices, showDbInfo=False): """Do dialog layout""" self.pagesizer = wx.BoxSizer(wx.VERTICAL) # dbInfo if showDbInfo: databasebox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Database connection")) databaseboxsizer = wx.StaticBoxSizer(databasebox, wx.VERTICAL) databaseboxsizer.Add( CreateDbInfoDesc(self.panel, self.dbInfo, layer=self.layer), proportion=1, flag=wx.EXPAND | wx.ALL, border=3, ) # # text areas # # sql box sqlbox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Query")) sqlboxsizer = wx.StaticBoxSizer(sqlbox, wx.VERTICAL) self.text_sql = TextCtrl( parent=self.panel, id=wx.ID_ANY, value="", size=(-1, 50), style=wx.TE_MULTILINE, ) self.text_sql.SetInsertionPointEnd() wx.CallAfter(self.text_sql.SetFocus) sqlboxsizer.Add(self.text_sql, flag=wx.EXPAND) # # buttons # self.btn_clear = ClearButton(parent=self.panel) self.btn_clear.SetToolTip(_("Set SQL statement to default")) self.btn_apply = ApplyButton(parent=self.panel) self.btn_apply.SetToolTip(_("Apply SQL statement")) self.btn_close = CloseButton(parent=self.panel) self.btn_close.SetToolTip(_("Close the dialog")) self.btn_logic = { "is": [ "=", ], "isnot": [ "!=", ], "like": [ "LIKE", ], "gt": [ ">", ], "ge": [ ">=", ], "lt": [ "<", ], "le": [ "<=", ], "or": [ "OR", ], "not": [ "NOT", ], "and": [ "AND", ], "brac": [ "()", ], "prc": [ "%", ], } self.btn_logicpanel = wx.Panel(parent=self.panel, id=wx.ID_ANY) for key, value in six.iteritems(self.btn_logic): btn = Button(parent=self.btn_logicpanel, id=wx.ID_ANY, label=value[0]) self.btn_logic[key].append(btn.GetId()) self.buttonsizer = wx.FlexGridSizer(cols=4, hgap=5, vgap=5) self.buttonsizer.Add(self.btn_clear) self.buttonsizer.Add(self.btn_apply) self.buttonsizer.Add(self.btn_close) btn_logicsizer = wx.GridBagSizer(5, 5) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["is"][1]), pos=(0, 0)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["isnot"][1]), pos=(1, 0)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["like"][1]), pos=(2, 0)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["gt"][1]), pos=(0, 1)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["ge"][1]), pos=(1, 1)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["or"][1]), pos=(2, 1)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["lt"][1]), pos=(0, 2)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["le"][1]), pos=(1, 2)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["not"][1]), pos=(2, 2)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["brac"][1]), pos=(0, 3)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["prc"][1]), pos=(1, 3)) btn_logicsizer.Add(self.FindWindowById(self.btn_logic["and"][1]), pos=(2, 3)) self.btn_logicpanel.SetSizer(btn_logicsizer) # # list boxes (columns, values) # self.hsizer = wx.BoxSizer(wx.HORIZONTAL) columnsbox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Columns")) columnsizer = wx.StaticBoxSizer(columnsbox, wx.VERTICAL) self.list_columns = wx.ListBox( parent=self.panel, id=wx.ID_ANY, choices=self.dbInfo.GetColumns(self.tablename), style=wx.LB_MULTIPLE, ) columnsizer.Add(self.list_columns, proportion=1, flag=wx.EXPAND) if modeChoices: modesizer = wx.BoxSizer(wx.VERTICAL) self.mode = wx.RadioBox( parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Interactive insertion"), choices=modeChoices, style=wx.RA_SPECIFY_COLS, majorDimension=1, ) self.mode.SetSelection(1) # default 'values' modesizer.Add(self.mode, proportion=1, flag=wx.EXPAND, border=5) # self.list_columns.SetMinSize((-1,130)) # self.list_values.SetMinSize((-1,100)) self.valuespanel = wx.Panel(parent=self.panel, id=wx.ID_ANY) valuesbox = StaticBox(parent=self.valuespanel, id=wx.ID_ANY, label=" %s " % _("Values")) valuesizer = wx.StaticBoxSizer(valuesbox, wx.VERTICAL) self.list_values = wx.ListBox( parent=self.valuespanel, id=wx.ID_ANY, choices=self.colvalues, style=wx.LB_MULTIPLE, ) valuesizer.Add(self.list_values, proportion=1, flag=wx.EXPAND) self.valuespanel.SetSizer(valuesizer) self.btn_unique = Button(parent=self.valuespanel, id=wx.ID_ANY, label=_("Get all values")) self.btn_unique.Enable(False) self.btn_uniquesample = Button(parent=self.valuespanel, id=wx.ID_ANY, label=_("Get sample")) self.btn_uniquesample.SetToolTip( _("Get first 256 unique values as sample")) self.btn_uniquesample.Enable(False) buttonsizer3 = wx.BoxSizer(wx.HORIZONTAL) buttonsizer3.Add(self.btn_uniquesample, proportion=0, flag=wx.RIGHT, border=5) buttonsizer3.Add(self.btn_unique, proportion=0) valuesizer.Add(buttonsizer3, proportion=0, flag=wx.TOP, border=5) # go to gotosizer = wx.BoxSizer(wx.HORIZONTAL) self.goto = TextCtrl(parent=self.valuespanel, id=wx.ID_ANY, style=wx.TE_PROCESS_ENTER) gotosizer.Add( StaticText(parent=self.valuespanel, id=wx.ID_ANY, label=_("Go to:")), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=5, ) gotosizer.Add(self.goto, proportion=1, flag=wx.EXPAND) valuesizer.Add(gotosizer, proportion=0, flag=wx.ALL | wx.EXPAND, border=5) self.hsizer.Add(columnsizer, proportion=1, flag=wx.EXPAND) self.hsizer.Add(self.valuespanel, proportion=1, flag=wx.EXPAND) self.close_onapply = wx.CheckBox(parent=self.panel, id=wx.ID_ANY, label=_("Close dialog on apply")) self.close_onapply.SetValue(True) if showDbInfo: self.pagesizer.Add(databaseboxsizer, flag=wx.ALL | wx.EXPAND, border=5) if modeChoices: self.pagesizer.Add( modesizer, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5, ) self.pagesizer.Add( self.hsizer, proportion=1, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5, ) # self.pagesizer.Add(self.btn_uniqe,0,wx.ALIGN_LEFT|wx.TOP,border=5) # self.pagesizer.Add(self.btn_uniqesample,0,wx.ALIGN_LEFT|wx.TOP,border=5) self.pagesizer.Add(self.btn_logicpanel, proportion=0, flag=wx.ALIGN_CENTER_HORIZONTAL) self.pagesizer.Add(sqlboxsizer, proportion=0, flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=5) self.pagesizer.Add(self.buttonsizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5) self.pagesizer.Add( self.close_onapply, proportion=0, flag=wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, border=5, ) # # bindings # if modeChoices: self.mode.Bind(wx.EVT_RADIOBOX, self.OnMode) # self.text_sql.Bind(wx.EVT_ACTIVATE, self.OnTextSqlActivate)TODO self.btn_unique.Bind(wx.EVT_BUTTON, self.OnUniqueValues) self.btn_uniquesample.Bind(wx.EVT_BUTTON, self.OnSampleValues) for key, value in six.iteritems(self.btn_logic): self.FindWindowById(value[1]).Bind(wx.EVT_BUTTON, self.OnAddMark) self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.btn_clear.Bind(wx.EVT_BUTTON, self.OnClear) self.btn_apply.Bind(wx.EVT_BUTTON, self.OnApply) self.list_columns.Bind(wx.EVT_LISTBOX, self.OnAddColumn) self.list_values.Bind(wx.EVT_LISTBOX, self.OnAddValue) self.goto.Bind(wx.EVT_TEXT, self.OnGoTo) self.goto.Bind(wx.EVT_TEXT_ENTER, self.OnAddValue)
def __init__( self, parent, giface, cmd, id=wx.ID_ANY, style=wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs, ): self.parent = parent self._giface = giface if self.parent: self.log = self.parent.GetLogWindow() else: self.log = None # grass command self.cmd = cmd if self.cmd == "r.mapcalc": self.rast3d = False title = _("Raster Map Calculator") if self.cmd == "r3.mapcalc": self.rast3d = True title = _("3D Raster Map Calculator") wx.Frame.__init__(self, parent, id=id, title=title, **kwargs) self.SetIcon( wx.Icon(os.path.join(globalvar.ICONDIR, "grass.ico"), wx.BITMAP_TYPE_ICO)) self.panel = wx.Panel(parent=self, id=wx.ID_ANY) self.CreateStatusBar() # # variables # self.heading = _("mapcalc statement") self.funct_dict = { "abs(x)": "abs()", "acos(x)": "acos()", "asin(x)": "asin()", "atan(x)": "atan()", "atan(x,y)": "atan( , )", "cos(x)": "cos()", "double(x)": "double()", "eval([x,y,...,]z)": "eval()", "exp(x)": "exp()", "exp(x,y)": "exp( , )", "float(x)": "float()", "graph(x,x1,y1[x2,y2..])": "graph( , , )", "if(x)": "if()", "if(x,a)": "if( , )", "if(x,a,b)": "if( , , )", "if(x,a,b,c)": "if( , , , )", "int(x)": "int()", "isnull(x)": "isnull()", "log(x)": "log(", "log(x,b)": "log( , )", "max(x,y[,z...])": "max( , )", "median(x,y[,z...])": "median( , )", "min(x,y[,z...])": "min( , )", "mode(x,y[,z...])": "mode( , )", "nmax(x,y[,z...])": "nmax( , )", "nmedian(x,y[,z...])": "nmedian( , )", "nmin(x,y[,z...])": "nmin( , )", "nmode(x,y[,z...])": "nmode( , )", "not(x)": "not()", "pow(x,y)": "pow( , )", "rand(a,b)": "rand( , )", "round(x)": "round()", "round(x,y)": "round( , )", "round(x,y,z)": "round( , , )", "sin(x)": "sin()", "sqrt(x)": "sqrt()", "tan(x)": "tan()", "xor(x,y)": "xor( , )", "row()": "row()", "col()": "col()", "nrows()": "nrows()", "ncols()": "ncols()", "x()": "x()", "y()": "y()", "ewres()": "ewres()", "nsres()": "nsres()", "area()": "area()", "null()": "null()", } if self.rast3d: self.funct_dict["z()"] = "z()" self.funct_dict["tbres()"] = "tbres()" element = "raster_3d" else: element = "cell" # characters which can be in raster map name but the map name must be # then quoted self.charactersToQuote = "+-&!<>%~?^|" # stores last typed map name in Select widget to distinguish typing # from selection self.lastMapName = "" self.operatorBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Operators")) self.outputBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Output")) self.operandBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Operands")) self.expressBox = StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _("Expression")) # # Buttons # self.btn_clear = ClearButton(parent=self.panel) self.btn_help = Button(parent=self.panel, id=wx.ID_HELP) self.btn_run = Button(parent=self.panel, id=wx.ID_ANY, label=_("&Run")) self.btn_run.SetDefault() self.btn_close = CloseButton(parent=self.panel) self.btn_save = Button(parent=self.panel, id=wx.ID_SAVE) self.btn_save.SetToolTip(_("Save expression to file")) self.btn_load = Button(parent=self.panel, id=wx.ID_ANY, label=_("&Load")) self.btn_load.SetToolTip(_("Load expression from file")) self.btn_copy = Button(parent=self.panel, id=wx.ID_ANY, label=_("Copy")) self.btn_copy.SetToolTip( _("Copy the current command string to the clipboard")) self.btn = dict() self.btn["pow"] = Button(parent=self.panel, id=wx.ID_ANY, label="^") self.btn["pow"].SetToolTip(_("exponent")) self.btn["div"] = Button(parent=self.panel, id=wx.ID_ANY, label="/") self.btn["div"].SetToolTip(_("divide")) self.btn["add"] = Button(parent=self.panel, id=wx.ID_ANY, label="+") self.btn["add"].SetToolTip(_("add")) self.btn["minus"] = Button(parent=self.panel, id=wx.ID_ANY, label="-") self.btn["minus"].SetToolTip(_("subtract")) self.btn["mod"] = Button(parent=self.panel, id=wx.ID_ANY, label="%") self.btn["mod"].SetToolTip(_("modulus")) self.btn["mult"] = Button(parent=self.panel, id=wx.ID_ANY, label="*") self.btn["mult"].SetToolTip(_("multiply")) self.btn["parenl"] = Button(parent=self.panel, id=wx.ID_ANY, label="(") self.btn["parenr"] = Button(parent=self.panel, id=wx.ID_ANY, label=")") self.btn["lshift"] = Button(parent=self.panel, id=wx.ID_ANY, label="<<") self.btn["lshift"].SetToolTip(_("left shift")) self.btn["rshift"] = Button(parent=self.panel, id=wx.ID_ANY, label=">>") self.btn["rshift"].SetToolTip(_("right shift")) self.btn["rshiftu"] = Button(parent=self.panel, id=wx.ID_ANY, label=">>>") self.btn["rshiftu"].SetToolTip(_("right shift (unsigned)")) self.btn["gt"] = Button(parent=self.panel, id=wx.ID_ANY, label=">") self.btn["gt"].SetToolTip(_("greater than")) self.btn["gteq"] = Button(parent=self.panel, id=wx.ID_ANY, label=">=") self.btn["gteq"].SetToolTip(_("greater than or equal to")) self.btn["lt"] = Button(parent=self.panel, id=wx.ID_ANY, label="<") self.btn["lt"].SetToolTip(_("less than")) self.btn["lteq"] = Button(parent=self.panel, id=wx.ID_ANY, label="<=") self.btn["lteq"].SetToolTip(_("less than or equal to")) self.btn["eq"] = Button(parent=self.panel, id=wx.ID_ANY, label="==") self.btn["eq"].SetToolTip(_("equal to")) self.btn["noteq"] = Button(parent=self.panel, id=wx.ID_ANY, label="!=") self.btn["noteq"].SetToolTip(_("not equal to")) self.btn["compl"] = Button(parent=self.panel, id=wx.ID_ANY, label="~") self.btn["compl"].SetToolTip(_("one's complement")) self.btn["not"] = Button(parent=self.panel, id=wx.ID_ANY, label="!") self.btn["not"].SetToolTip(_("NOT")) self.btn["andbit"] = Button(parent=self.panel, id=wx.ID_ANY, label="&&") self.btn["andbit"].SetToolTip(_("bitwise AND")) self.btn["orbit"] = Button(parent=self.panel, id=wx.ID_ANY, label="|") self.btn["orbit"].SetToolTip(_("bitwise OR")) self.btn["and"] = Button(parent=self.panel, id=wx.ID_ANY, label="&&&&") self.btn["and"].SetToolTip(_("logical AND")) self.btn["andnull"] = Button(parent=self.panel, id=wx.ID_ANY, label="&&&&&&") self.btn["andnull"].SetToolTip(_("logical AND (ignores NULLs)")) self.btn["or"] = Button(parent=self.panel, id=wx.ID_ANY, label="||") self.btn["or"].SetToolTip(_("logical OR")) self.btn["ornull"] = Button(parent=self.panel, id=wx.ID_ANY, label="|||") self.btn["ornull"].SetToolTip(_("logical OR (ignores NULLs)")) self.btn["cond"] = Button(parent=self.panel, id=wx.ID_ANY, label="a ? b : c") self.btn["cond"].SetToolTip(_("conditional")) # # Text area # self.text_mcalc = TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(-1, 100), style=wx.TE_MULTILINE) wx.CallAfter(self.text_mcalc.SetFocus) # # Map and function insertion text and ComboBoxes self.newmaplabel = StaticText(parent=self.panel, id=wx.ID_ANY) if self.rast3d: self.newmaplabel.SetLabel( _("Name for new 3D raster map to create")) else: self.newmaplabel.SetLabel(_("Name for new raster map to create")) # As we can write only to current mapset, names should not be fully qualified # to not confuse end user about writing in other mapset self.newmaptxt = Select( parent=self.panel, id=wx.ID_ANY, size=(250, -1), type=element, multiple=False, fullyQualified=False, ) self.mapsellabel = StaticText(parent=self.panel, id=wx.ID_ANY) if self.rast3d: self.mapsellabel.SetLabel(_("Insert existing 3D raster map")) else: self.mapsellabel.SetLabel(_("Insert existing raster map")) self.mapselect = Select( parent=self.panel, id=wx.ID_ANY, size=(250, -1), type=element, multiple=False, ) self.functlabel = StaticText(parent=self.panel, id=wx.ID_ANY, label=_("Insert mapcalc function")) self.function = wx.ComboBox( parent=self.panel, id=wx.ID_ANY, size=(250, -1), choices=sorted(self.funct_dict.keys()), style=wx.CB_DROPDOWN | wx.CB_READONLY | wx.TE_PROCESS_ENTER, ) self.overwrite = wx.CheckBox( parent=self.panel, id=wx.ID_ANY, label=_("Allow output files to overwrite existing files"), ) self.overwrite.SetValue( UserSettings.Get(group="cmd", key="overwrite", subkey="enabled")) self.randomSeed = wx.CheckBox( parent=self.panel, label=_("Generate random seed for rand()")) self.randomSeedStaticText = StaticText(parent=self.panel, label=_("Seed:")) self.randomSeedText = TextCtrl(parent=self.panel, size=(100, -1), validator=IntegerValidator()) self.randomSeedText.SetToolTip(_("Integer seed for rand() function")) self.randomSeed.SetValue(True) self.randomSeedStaticText.Disable() self.randomSeedText.Disable() self.addbox = wx.CheckBox( parent=self.panel, label=_("Add created raster map into layer tree"), style=wx.NO_BORDER, ) self.addbox.SetValue( UserSettings.Get(group="cmd", key="addNewLayer", subkey="enabled")) if not self.parent or self.parent.GetName() != "LayerManager": self.addbox.Hide() # # Bindings # for btn in self.btn.keys(): self.btn[btn].Bind(wx.EVT_BUTTON, self.AddMark) self.btn_close.Bind(wx.EVT_BUTTON, self.OnClose) self.btn_clear.Bind(wx.EVT_BUTTON, self.OnClear) self.btn_run.Bind(wx.EVT_BUTTON, self.OnMCalcRun) self.btn_help.Bind(wx.EVT_BUTTON, self.OnHelp) self.btn_save.Bind(wx.EVT_BUTTON, self.OnSaveExpression) self.btn_load.Bind(wx.EVT_BUTTON, self.OnLoadExpression) self.btn_copy.Bind(wx.EVT_BUTTON, self.OnCopyCommand) self.mapselect.Bind(wx.EVT_TEXT, self.OnSelect) self.function.Bind(wx.EVT_COMBOBOX, self._return_funct) self.function.Bind(wx.EVT_TEXT_ENTER, self.OnSelect) self.newmaptxt.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar) self.text_mcalc.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar) self.overwrite.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar) self.randomSeed.Bind(wx.EVT_CHECKBOX, self.OnUpdateStatusBar) self.randomSeed.Bind(wx.EVT_CHECKBOX, self.OnSeedFlag) self.randomSeedText.Bind(wx.EVT_TEXT, self.OnUpdateStatusBar) # bind closing to ESC self.Bind(wx.EVT_MENU, self.OnClose, id=wx.ID_CANCEL) accelTableList = [(wx.ACCEL_NORMAL, wx.WXK_ESCAPE, wx.ID_CANCEL)] accelTable = wx.AcceleratorTable(accelTableList) self.SetAcceleratorTable(accelTable) self._layout() self.SetMinSize(self.panel.GetBestSize()) # workaround for http://trac.wxwidgets.org/ticket/13628 self.SetSize(self.panel.GetBestSize())