def OnLeftDownEditLine(self, event): """Left mouse button pressed - edit linear feature - add new vertex. """ self.polycoords.append(self.Pixel2Cell(self.mouse["begin"])) self.moveInfo["id"].append(NewId()) self.DrawLines(pdc=self.pdcTmp)
def CreateTool(self, label, bitmap, kind, shortHelp, longHelp, handler, pos=-1): """Add tool to the toolbar :param pos: if -1 add tool, if > 0 insert at given pos :return: id of tool """ bmpDisabled = wx.NullBitmap tool = -1 if label: tool = vars(self)[label] = NewId() Debug.msg( 3, "CreateTool(): tool=%d, label=%s bitmap=%s" % (tool, label, bitmap)) if pos < 0: toolWin = self.AddLabelTool(tool, label, bitmap, bmpDisabled, kind, shortHelp, longHelp) else: toolWin = self.InsertLabelTool(pos, tool, label, bitmap, bmpDisabled, kind, shortHelp, longHelp) self.handlers[tool] = handler self.Bind(wx.EVT_TOOL, handler, toolWin) self.Bind(wx.EVT_TOOL, self.OnTool, toolWin) else: # separator self.AddSeparator() return tool
def OnContextMenu(self, event): """Popup context menu enabling to choose a widget that will be shown in statusbar.""" def setSbItemProperty(idx): self.mapFrame.mapWindowProperties.sbItem = idx def getSbItemProperty(): return self.mapFrame.mapWindowProperties.sbItem menu = Menu() for i, label in enumerate(self.GetItemLabels()): wxid = NewId() self.statusbar.Bind( wx.EVT_MENU, lambda evt, idx=i: setSbItemProperty(idx), id=wxid, ) menu.Append(wxid, label, kind=wx.ITEM_RADIO) item = menu.FindItem(wxid)[0] if i == getSbItemProperty(): item.Check(item.IsChecked() is False) if label in (self.GetDisabledItemLabels()): item.Enable(enable=False) # show the popup menu self.statusbar.PopupMenu(menu) menu.Destroy() event.Skip()
def OnContextMenu(self, event): """Show context menu. So far offers only copying layer list to clipboard """ if len(self._layerList) < 1: event.Skip() return menu = Menu() llist = [layer.name for layer in self._layerList] texts = [",".join(llist), ",".join(reversed(llist))] labels = [ _("Copy map names to clipboard (top to bottom)"), _("Copy map names to clipboard (bottom to top)"), ] for label, text in zip(labels, texts): id = NewId() self.Bind(wx.EVT_MENU, lambda evt, t=text, id=id: self._copyText(t), id=id) menu.Append(id, label) # show the popup menu self.PopupMenu(menu) menu.Destroy() event.Skip()
def __init__(self, coords, penName=None, brushName=None, label=None, hide=False): """Could be point or line according to graphicsType in GraphicsSet class :param coords: list of coordinates (double) of item Example: point: [1023, 122] line: [[10, 12],[20,40],[23, 2334]] rectangle: [[10, 12], [33, 45]] :param penName: if it is not defined 'default' pen is used :type penName: str :param brushName: if it is not defined 'default' brush is used :type brushName: str :param label: label, which will be drawn with point. It is relevant just for 'point' type :type label: str :param hide: if it is True, item is not drawn Hidden items are also counted in drawing order in GraphicsSet class. :type hide: bool """ self.coords = coords self.properties = { "penName": penName, "brushName": brushName, "hide": hide, "label": label } self.id = NewId()
def _initShortcuts(self): """init shortcuts to acceleration table""" accelTable = [] for handler, entry, kdb in self.shortcuts_table: wxId = NewId() self.Bind(wx.EVT_MENU, handler, id=wxId) accelTable.append((entry, kdb, wxId)) self.SetAcceleratorTable(wx.AcceleratorTable(accelTable))
def ShowContextMenu(self, node): """Show context menu. Menu for copying distinguishes single and multiple selection. """ nodes = self.tree.GetSelected() if not nodes: return menu = Menu() texts = [] if len(nodes) > 1: values = [] for node in nodes: values.append( (node.label, node.data[ self._colNames[1]] if node.data else '')) col1 = '\n'.join([val[1] for val in values if val[1]]) col2 = '\n'.join([val[0] for val in values if val[0]]) table = '\n'.join([val[0] + ': ' + val[1] for val in values]) texts.append( (_("Copy from '%s' column") % self._colNames[1], col1)) texts.append( (_("Copy from '%s' column") % self._colNames[0], col2)) texts.append((_("Copy selected lines"), table)) else: label1 = nodes[0].label texts.append((_("Copy '%s'" % self._cutLabel(label1)), label1)) if nodes[0].data and nodes[0].data[self._colNames[1]]: label2 = nodes[0].data[self._colNames[1]] texts.insert( 0, (_( "Copy '%s'" % self._cutLabel(label2)), label2)) texts.append((_("Copy line"), label1 + ': ' + label2)) ids = [] for text in texts: id = NewId() ids.append(id) self.Bind( wx.EVT_MENU, lambda evt, t=text[1], id=id: self._copyText(t), id=id) menu.Append(id, text[0]) # show the popup menu self.PopupMenu(menu) menu.Destroy() for id in ids: self.Unbind(wx.EVT_MENU, id=id)
def OnRightUp(self, event): """Mouse right button up""" if self.disablePopup: return if not hasattr(self, "popupId"): self.popupID = dict() self.popupID['remove'] = NewId() self.popupID['reload'] = NewId() self.Bind(wx.EVT_MENU, self.OnRemove, id=self.popupID['remove']) self.Bind(wx.EVT_MENU, self.OnReload, id=self.popupID['reload']) # generate popup-menu menu = Menu() menu.Append(self.popupID['remove'], _("Delete selected")) if self.GetFirstSelected() == -1: menu.Enable(self.popupID['remove'], False) menu.AppendSeparator() menu.Append(self.popupID['reload'], _("Reload")) self.PopupMenu(menu) menu.Destroy()
def OnRightUp(self, event): """Mouse right button up""" if not hasattr(self, "popupID1"): self.popupID1 = NewId() self.popupID2 = NewId() self.popupID3 = NewId() self.Bind(wx.EVT_MENU, self.OnItemDelete, id=self.popupID1) self.Bind(wx.EVT_MENU, self.OnItemDeleteAll, id=self.popupID2) self.Bind(wx.EVT_MENU, self.OnReload, id=self.popupID3) # generate popup-menu menu = Menu() menu.Append(self.popupID1, _("Delete selected")) if self.list.GetFirstSelected() == -1: menu.Enable(self.popupID1, False) menu.Append(self.popupID2, _("Delete all")) menu.AppendSeparator() menu.Append(self.popupID3, _("Reload")) self.PopupMenu(menu) menu.Destroy()
def __init__(self, parent, giface, Map, properties, **kwargs): BufferedMapWindow.__init__(self, parent=parent, giface=giface, Map=Map, properties=properties, **kwargs) Debug.msg(2, "SwipeBufferedWindow.__init__()") self.specialSize = super(SwipeBufferedWindow, self).GetClientSize() self.specialCoords = [0, 0] self.imageId = 99 self.movingSash = False self._mode = 'swipe' self.lineid = NewId()
def _initShortcuts(self): # set accelerator table (fullscreen, close window) shortcuts_table = ( (self.OnFullScreen, wx.ACCEL_NORMAL, wx.WXK_F11), (self.OnCloseWindow, wx.ACCEL_CTRL, ord("W")), (self.OnRender, wx.ACCEL_CTRL, ord("R")), (self.OnRender, wx.ACCEL_NORMAL, wx.WXK_F5), ) accelTable = [] for handler, entry, kdb in shortcuts_table: wxId = NewId() self.Bind(wx.EVT_MENU, handler, id=wxId) accelTable.append((entry, kdb, wxId)) self.SetAcceleratorTable(wx.AcceleratorTable(accelTable))
def __init__(self, renderer, giface): self._giface = giface self._renderer = renderer self._overlay = None self._coords = None self._pdcType = 'image' self._propwin = None self._defaultAt = '' self._cmd = None # to be set by user self._name = None # to be defined by subclass self._removeLabel = None # to be defined by subclass self._id = NewId() self._dialog = None # signals that overlay or its visibility changed self.overlayChanged = Signal('OverlayController::overlayChanged')
def OnContextMenu(self, node): if not hasattr(self, "popupID"): self.popupID = dict() for key in ("install", "help"): self.popupID[key] = NewId() data = node.data if data and "command" in data: self.popupMenu = Menu() self.popupMenu.Append(self.popupID["install"], _("Install")) self.Bind(wx.EVT_MENU, self.OnInstall, id=self.popupID["install"]) self.popupMenu.AppendSeparator() self.popupMenu.Append(self.popupID["help"], _("Show manual page")) self.Bind(wx.EVT_MENU, self.OnItemHelp, id=self.popupID["help"]) self.PopupMenu(self.popupMenu) self.popupMenu.Destroy()
def ContexMenu(self, event): if not event.inaxes: return if event.button == 3: menu = Menu() menu_items = [[ "zoom_to_extend", _("Zoom to scatter plot extend"), lambda event: self.plot.ZoomToExtend() ]] for item in menu_items: item_id = NewId() menu.Append(item_id, item[1]) menu.Bind(wx.EVT_MENU, item[2], id=item_id) wx.CallAfter(self.ShowMenu, menu)
def OnClassRightUp(self, event): """Show context menu on right click""" item, flags = self.HitTest((event.GetX(), event.GetY())) if item != wx.NOT_FOUND and flags & wx.LIST_HITTEST_ONITEM: self.rightClickedItemIdx = item if not hasattr(self, "popupZoomtoAreas"): self.popupZoomtoAreas = NewId() self.Bind(wx.EVT_MENU, self.OnZoomToAreasByCat, id=self.popupZoomtoAreas) # generate popup-menu menu = Menu() menu.Append( self.popupZoomtoAreas, _("Zoom to training areas of selected class") ) self.PopupMenu(menu) menu.Destroy()
def Draw(self, pdc, img=None, drawid=None, pdctype="image", coords=[0, 0, 0, 0]): """Draws histogram or clears window""" if drawid is None: if pdctype == "image": drawid = self.imagedict[img] elif pdctype == "clear": drawid is None else: drawid = NewId() else: pdc.SetId(drawid) pdc.BeginDrawing() Debug.msg( 3, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % (drawid, pdctype, coords), ) if pdctype == "clear": # erase the display bg = wx.WHITE_BRUSH pdc.SetBackground(bg) pdc.Clear() self.Refresh() pdc.EndDrawing() return if pdctype == "image": bg = wx.TRANSPARENT_BRUSH pdc.SetBackground(bg) bitmap = BitmapFromImage(img) w, h = bitmap.GetSize() pdc.DrawBitmap(bitmap, coords[0], coords[1], True) # draw the composite map pdc.SetIdBounds(drawid, (coords[0], coords[1], w, h)) pdc.EndDrawing() self.Refresh()