def _widgets(self): if self.etype == 'raster': self.resolution = TextCtrl(self.panel, validator=FloatValidator()) self.resampling = wx.Choice(self.panel, size=(200, -1), choices=[ 'nearest', 'bilinear', 'bicubic', 'lanczos', 'bilinear_f', 'bicubic_f', 'lanczos_f' ]) else: self.vsplit = TextCtrl(self.panel, validator=IntegerValidator()) self.vsplit.SetValue('10000') # # buttons # self.btn_close = Button(parent=self.panel, id=wx.ID_CLOSE) self.SetEscapeId(self.btn_close.GetId()) # run self.btn_run = Button(parent=self.panel, id=wx.ID_OK, label=_("Reproject")) if self.etype == 'raster': self.btn_run.SetToolTip(_("Reproject raster")) elif self.etype == 'vector': self.btn_run.SetToolTip(_("Reproject vector")) self.btn_run.SetDefault() self.btn_run.Bind(wx.EVT_BUTTON, self.OnReproject)
def __init__(self, parent): wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY) self.label1 = StaticText(self, id=wx.ID_ANY) self.slider = wx.Slider(self, id=wx.ID_ANY, style=wx.SL_HORIZONTAL) self.indexField = TextCtrl(self, id=wx.ID_ANY, size=(40, -1), style=wx.TE_PROCESS_ENTER | wx.TE_RIGHT, validator=IntegerValidator()) self.callbackSliderChanging = None self.callbackSliderChanged = None self.callbackFrameIndexChanged = None self.framesCount = 0 self.enable = True self.slider.Bind(wx.EVT_SPIN, self.OnSliderChanging) self.slider.Bind(wx.EVT_SCROLL_THUMBRELEASE, self.OnSliderChanged) self.indexField.Bind(wx.EVT_TEXT_ENTER, self.OnFrameIndexChanged)
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( , )', 'not(x)': 'not()', 'pow(x,y)': 'pow( , )', 'rand(a,b)': 'rand( , )', 'round(x)': 'round()', 'sin(x)': 'sin()', 'sqrt(x)': 'sqrt()', 'tan(x)': 'tan()', 'xor(x,y)': 'xor( , )', 'row()': 'row()', 'col()': 'col()', 'x()': 'x()', 'y()': 'y()', 'ewres()': 'ewres()', 'nsres()': 'nsres()', '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 = wx.StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Operators')) self.outputBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Output')) self.operandBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Operands')) self.expressBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY, label=" %s " % _('Expression')) # # Buttons # self.btn_clear = wx.Button(parent=self.panel, id=wx.ID_CLEAR) self.btn_help = wx.Button(parent=self.panel, id=wx.ID_HELP) self.btn_run = wx.Button(parent=self.panel, id=wx.ID_ANY, label=_("&Run")) self.btn_run.SetForegroundColour(wx.Colour(35, 142, 35)) self.btn_run.SetDefault() self.btn_close = wx.Button(parent=self.panel, id=wx.ID_CLOSE) self.btn_save = wx.Button(parent=self.panel, id=wx.ID_SAVE) self.btn_save.SetToolTipString(_('Save expression to file')) self.btn_load = wx.Button(parent=self.panel, id=wx.ID_ANY, label=_("&Load")) self.btn_load.SetToolTipString(_('Load expression from file')) self.btn_copy = wx.Button(parent=self.panel, id=wx.ID_COPY) self.btn_copy.SetToolTipString( _("Copy the current command string to the clipboard")) self.btn = dict() self.btn['pow'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="^") self.btn['pow'].SetToolTipString(_('exponent')) self.btn['div'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="/") self.btn['div'].SetToolTipString(_('divide')) self.btn['add'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="+") self.btn['add'].SetToolTipString(_('add')) self.btn['minus'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="-") self.btn['minus'].SetToolTipString(_('subtract')) self.btn['mod'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="%") self.btn['mod'].SetToolTipString(_('modulus')) self.btn['mult'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="*") self.btn['mult'].SetToolTipString(_('multiply')) self.btn['parenl'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="(") self.btn['parenr'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label=")") self.btn['lshift'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="<<") self.btn['lshift'].SetToolTipString(_('left shift')) self.btn['rshift'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label=">>") self.btn['rshift'].SetToolTipString(_('right shift')) self.btn['rshiftu'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label=">>>") self.btn['rshiftu'].SetToolTipString(_('right shift (unsigned)')) self.btn['gt'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label=">") self.btn['gt'].SetToolTipString(_('greater than')) self.btn['gteq'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label=">=") self.btn['gteq'].SetToolTipString(_('greater than or equal to')) self.btn['lt'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="<") self.btn['lt'].SetToolTipString(_('less than')) self.btn['lteq'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="<=") self.btn['lteq'].SetToolTipString(_('less than or equal to')) self.btn['eq'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="==") self.btn['eq'].SetToolTipString(_('equal to')) self.btn['noteq'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="!=") self.btn['noteq'].SetToolTipString(_('not equal to')) self.btn['compl'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="~") self.btn['compl'].SetToolTipString(_('one\'s complement')) self.btn['not'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="!") self.btn['not'].SetToolTipString(_('NOT')) self.btn['andbit'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label='&&') self.btn['andbit'].SetToolTipString(_('bitwise AND')) self.btn['orbit'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="|") self.btn['orbit'].SetToolTipString(_('bitwise OR')) self.btn['and'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="&&&&") self.btn['and'].SetToolTipString(_('logical AND')) self.btn['andnull'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="&&&&&&") self.btn['andnull'].SetToolTipString(_('logical AND (ignores NULLs)')) self.btn['or'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="||") self.btn['or'].SetToolTipString(_('logical OR')) self.btn['ornull'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="|||") self.btn['ornull'].SetToolTipString(_('logical OR (ignores NULLs)')) self.btn['cond'] = wx.Button(parent=self.panel, id=wx.ID_ANY, label="a ? b : c") self.btn['cond'].SetToolTipString(_('conditional')) # # Text area # self.text_mcalc = wx.TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(-1, 75), style=wx.TE_MULTILINE) wx.CallAfter(self.text_mcalc.SetFocus) # # Map and function insertion text and ComboBoxes self.newmaplabel = wx.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')) self.newmaptxt = wx.TextCtrl(parent=self.panel, id=wx.ID_ANY, size=(250, -1)) self.mapsellabel = wx.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 = wx.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 = wx.StaticText(parent=self.panel, label=_("Seed:")) self.randomSeedText = wx.TextCtrl(parent=self.panel, size=(100, -1), validator=IntegerValidator()) self.randomSeedText.SetToolTipString( _("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.OnCopy) # self.mapselect.Bind(wx.EVT_TEXT, self.OnSelectTextEvt) 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) self._layout() self.SetMinSize(self.GetBestSize()) # workaround for http://trac.wxwidgets.org/ticket/13628 self.SetSize(self.GetBestSize())
def __init__(self, parent, title, data, keyEditable=(-1, True), id=wx.ID_ANY, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER): """Dialog for inserting/updating table record :param data: a list: [(column, value)] :param keyEditable: (id, editable?) indicates if textarea for key column is editable(True) or not """ # parent -> VDigitWindow wx.Dialog.__init__(self, parent, id, title, style=style) self.CenterOnParent() self.keyId = keyEditable[0] box = StaticBox(parent=self, id=wx.ID_ANY) box.Hide() self.dataPanel = scrolled.ScrolledPanel(parent=self, id=wx.ID_ANY, style=wx.TAB_TRAVERSAL) self.dataPanel.SetupScrolling(scroll_x=False) # buttons self.btnCancel = Button(self, wx.ID_CANCEL) self.btnSubmit = Button(self, wx.ID_OK, _("&Submit")) self.btnSubmit.SetDefault() # data area self.widgets = [] cId = 0 self.usebox = False self.cat = None winFocus = False for column, ctype, ctypeStr, value in data: if self.keyId == cId: self.cat = int(value) if not keyEditable[1]: self.usebox = True box.SetLabel(" %s %d " % (_("Category"), self.cat)) box.Show() self.boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) cId += 1 continue else: valueWin = SpinCtrl(parent=self.dataPanel, id=wx.ID_ANY, value=value, min=-1e9, max=1e9, size=(250, -1)) else: valueWin = TextCtrl(parent=self.dataPanel, id=wx.ID_ANY, value=value, size=(250, -1)) if ctype == int: valueWin.SetValidator(IntegerValidator()) elif ctype == float: valueWin.SetValidator(FloatValidator()) if not winFocus: wx.CallAfter(valueWin.SetFocus) winFocus = True label = StaticText(parent=self.dataPanel, id=wx.ID_ANY, label=column) ctype = StaticText(parent=self.dataPanel, id=wx.ID_ANY, label="[%s]:" % ctypeStr.lower()) self.widgets.append( (label.GetId(), ctype.GetId(), valueWin.GetId())) cId += 1 self._layout()
def UpdateDialog(self, map=None, query=None, cats=None, fid=-1, action=None): """Update dialog :param map: name of vector map :param query: :param cats: :param fid: feature id :param action: add, update, display or None :return: True if updated :return: False """ if action: self.action = action if action == 'display': enabled = False else: enabled = True self.closeDialog.Enable(enabled) self.FindWindowById(wx.ID_OK).Enable(enabled) if map: self.map = map # get layer/table/column information self.mapDBInfo = VectorDBInfo(self.map) if not self.mapDBInfo: return False self.mapDBInfo.Reset() layers = self.mapDBInfo.layers.keys() # get available layers # id of selected line if query: # select by position data = self.mapDBInfo.SelectByPoint(query[0], query[1]) self.cats = {} if data and 'Layer' in data: idx = 0 for layer in data['Layer']: layer = int(layer) if data['Id'][idx] is not None: tfid = int(data['Id'][idx]) else: tfid = 0 # Area / Volume if tfid not in self.cats: self.cats[tfid] = {} if layer not in self.cats[tfid]: self.cats[tfid][layer] = [] cat = int(data['Category'][idx]) self.cats[tfid][layer].append(cat) idx += 1 else: self.cats = cats if fid > 0: self.fid = fid elif len(self.cats.keys()) > 0: self.fid = list(self.cats.keys())[0] else: self.fid = -1 if len(self.cats.keys()) == 1: self.fidMulti.Show(False) self.fidText.Show(True) if self.fid > 0: self.fidText.SetLabel("%d" % self.fid) else: self.fidText.SetLabel(_("Unknown")) else: self.fidMulti.Show(True) self.fidText.Show(False) choices = [] for tfid in self.cats.keys(): choices.append(str(tfid)) self.fidMulti.SetItems(choices) self.fidMulti.SetStringSelection(str(self.fid)) # reset notebook self.notebook.DeleteAllPages() for layer in layers: # for each layer if not query: # select by layer/cat if self.fid > 0 and layer in self.cats[self.fid]: for cat in self.cats[self.fid][layer]: nselected = self.mapDBInfo.SelectFromTable( layer, where="%s=%d" % (self.mapDBInfo.layers[layer]['key'], cat)) else: nselected = 0 # if nselected <= 0 and self.action != "add": # continue # nothing selected ... if self.action == "add": if nselected <= 0: if layer in self.cats[self.fid]: table = self.mapDBInfo.layers[layer]["table"] key = self.mapDBInfo.layers[layer]["key"] columns = self.mapDBInfo.tables[table] for name in columns.keys(): if name == key: for cat in self.cats[self.fid][layer]: self.mapDBInfo.tables[table][name][ 'values'].append(cat) else: self.mapDBInfo.tables[table][name][ 'values'].append(None) else: # change status 'add' -> 'update' self.action = "update" table = self.mapDBInfo.layers[layer]["table"] key = self.mapDBInfo.layers[layer]["key"] columns = self.mapDBInfo.tables[table] for idx in range(len(columns[key]['values'])): for name in columns.keys(): if name == key: cat = int(columns[name]['values'][idx]) break # use scrolled panel instead (and fix initial max height of the # window to 480px) panel = scrolled.ScrolledPanel(parent=self.notebook, id=wx.ID_ANY, size=(-1, 150)) panel.SetupScrolling(scroll_x=False) self.notebook.AddPage(page=panel, text=" %s %d / %s %d" % (_("Layer"), layer, _("Category"), cat)) # notebook body border = wx.BoxSizer(wx.VERTICAL) flexSizer = wx.FlexGridSizer(cols=3, hgap=3, vgap=3) flexSizer.AddGrowableCol(2) # columns (sorted by index) names = [''] * len(columns.keys()) for name in columns.keys(): names[columns[name]['index']] = name for name in names: if name == key: # skip key column (category) continue vtype = columns[name]['type'].lower() ctype = columns[name]['ctype'] if columns[name]['values'][idx] is not None: if not isinstance(columns[name]['ctype'], six.string_types): value = str(columns[name]['values'][idx]) else: value = columns[name]['values'][idx] else: value = '' colName = StaticText(parent=panel, id=wx.ID_ANY, label=name) colType = StaticText(parent=panel, id=wx.ID_ANY, label="[%s]:" % vtype) colValue = TextCtrl(parent=panel, id=wx.ID_ANY, value=value) colValue.SetName(name) if ctype == int: colValue.SetValidator(IntegerValidator()) elif ctype == float: colValue.SetValidator(FloatValidator()) self.Bind(wx.EVT_TEXT, self.OnSQLStatement, colValue) if self.action == 'display': colValue.SetWindowStyle(wx.TE_READONLY) flexSizer.Add(colName, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) flexSizer.Add(colType, proportion=0, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALIGN_RIGHT) flexSizer.Add(colValue, proportion=1, flag=wx.EXPAND | wx.ALIGN_CENTER_VERTICAL) # add widget reference to self.columns columns[name]['ids'].append( colValue.GetId()) # name, type, values, id # for each attribute (including category) END border.Add(flexSizer, proportion=1, flag=wx.ALL | wx.EXPAND, border=5) panel.SetSizer(border) # for each category END # for each layer END if self.notebook.GetPageCount() == 0: self.noFoundMsg.Show(True) else: self.noFoundMsg.Show(False) self.Layout() return True
def __init__(self, parent, data, pointNo, itemCap="Point No.", id=wx.ID_ANY, title=_("Edit point"), style=wx.DEFAULT_DIALOG_STYLE): """Dialog for editing item cells in list""" wx.Dialog.__init__(self, parent, id, title=_(title), style=style) self.parent = parent panel = Panel(parent=self) sizer = wx.BoxSizer(wx.VERTICAL) box = StaticBox(parent=panel, id=wx.ID_ANY, label=" %s %s " % (_(itemCap), str(pointNo + 1))) boxSizer = wx.StaticBoxSizer(box, wx.VERTICAL) # source coordinates gridSizer = wx.GridBagSizer(vgap=5, hgap=5) self.fields = [] self.data = deepcopy(data) col = 0 row = 0 iField = 0 for cell in self.data: # Select if type(cell[2]).__name__ == "list": self.fields.append( ComboBox(parent=panel, id=wx.ID_ANY, choices=cell[2], style=wx.CB_READONLY, size=(110, -1))) # Text field else: if cell[2] == float: validator = FloatValidator() elif cell[2] == int: validator = IntegerValidator() else: validator = None if validator: self.fields.append( TextCtrl(parent=panel, id=wx.ID_ANY, validator=validator, size=(150, -1))) else: self.fields.append( TextCtrl(parent=panel, id=wx.ID_ANY, size=(150, -1))) value = cell[1] if not isinstance(cell[1], basestring): value = str(cell[1]) self.fields[iField].SetValue(value) label = StaticText(parent=panel, id=wx.ID_ANY, label=_(parent.GetColumn(cell[0]).GetText()) + ":") # name of column) gridSizer.Add(label, flag=wx.ALIGN_CENTER_VERTICAL, pos=(row, col)) col += 1 gridSizer.Add(self.fields[iField], pos=(row, col)) if col % 3 == 0: col = 0 row += 1 else: col += 1 iField += 1 boxSizer.Add(gridSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) sizer.Add(boxSizer, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) # # buttons # self.btnCancel = Button(panel, wx.ID_CANCEL) self.btnOk = Button(panel, wx.ID_OK) self.btnOk.SetDefault() btnSizer = wx.StdDialogButtonSizer() btnSizer.AddButton(self.btnCancel) btnSizer.AddButton(self.btnOk) btnSizer.Realize() sizer.Add(btnSizer, proportion=0, flag=wx.ALIGN_RIGHT | wx.ALL, border=5) panel.SetSizer(sizer) sizer.Fit(self)
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())