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, 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 __init__(self, parent, giface, controller, toolSwitcher): """RDigit toolbar constructor """ BaseToolbar.__init__(self, parent, toolSwitcher) self._controller = controller self._giface = giface self.InitToolbar(self._toolbarData()) self._mapSelectionComboId = wx.NewId() self._mapSelectionCombo = wx.ComboBox(self, id=self._mapSelectionComboId, value=_("Select raster map"), choices=[], size=(120, -1)) self._mapSelectionCombo.Bind(wx.EVT_COMBOBOX, self.OnMapSelection) self._mapSelectionCombo.SetEditable(False) self.InsertControl(0, self._mapSelectionCombo) self._previousMap = self._mapSelectionCombo.GetValue() self._colorId = wx.NewId() self._color = csel.ColourSelect(parent=self, colour=wx.GREEN, size=(30, 30)) self._color.Bind(csel.EVT_COLOURSELECT, lambda evt: self._changeDrawColor()) self._color.SetToolTipString( _("Set drawing color (not raster cell color)")) self.InsertControl(4, self._color) self._cellValues = set(['1']) self._valueComboId = wx.NewId() # validator does not work with combobox, SetBackgroundColor is not # working self._valueCombo = wx.ComboBox(self, id=self._valueComboId, choices=list(self._cellValues), size=(80, -1), validator=FloatValidator()) self._valueCombo.Bind(wx.EVT_COMBOBOX, lambda evt: self._cellValueChanged()) self._valueCombo.Bind(wx.EVT_TEXT, lambda evt: self._cellValueChanged()) self._valueCombo.SetSelection(0) self._cellValueChanged() self.InsertControl(6, wx.StaticText(self, label=" %s" % _("Cell value:"))) self.InsertControl(7, self._valueCombo) self._widthValueId = wx.NewId() # validator does not work with combobox, SetBackgroundColor is not # working self._widthValue = wx.TextCtrl(self, id=self._widthValueId, value='0', size=(80, -1), validator=FloatValidator()) self._widthValue.Bind(wx.EVT_TEXT, lambda evt: self._widthValueChanged()) self._widthValueChanged() self._widthValue.SetToolTipString( _("Width of currently digitized line or diameter of a digitized point in map units." )) self.InsertControl(8, wx.StaticText(self, label=" %s" % _("Width:"))) self.InsertControl(9, self._widthValue) for tool in (self.area, self.line, self.point): self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool) self.toolSwitcher.toggleToolChanged.connect(self.CheckSelectedTool) self._default = self.area # realize the toolbar self.Realize()
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)