def __init__(self, parent, mainframe): self.initmixin() wx.Panel.__init__(self, parent, -1) self.parent = parent self.mainframe = mainframe self.pref = mainframe.pref if not hasattr(self.pref, 'share_nodes'): self.pref.share_nodes = [] self.processors = {} # self.callplugin('add_process_class', self, self.processors) self.sizer = wx.BoxSizer(wx.VERTICAL) self.shareimagelist = imagelist = wx.ImageList(16, 16) #add share image list self.imagefiles = {} self.imageids = {} self.callplugin('add_images', self.imagefiles) for name, imagefile in self.imagefiles.items(): self.add_image(name, imagefile) self.tree = wx.TreeCtrl(self, -1, style = wx.TR_EDIT_LABELS|wx.TR_SINGLE|wx.TR_TWIST_BUTTONS|wx.TR_HAS_BUTTONS|wx.TR_ROW_LINES|wx.TR_HIDE_ROOT) self.tree.SetImageList(self.shareimagelist) self.sizer.Add(self.tree, 1, wx.EXPAND) self.root = self.tree.AddRoot('Share') self.nodes = {} self.ID = 1 self.read() wx.EVT_TREE_SEL_CHANGING(self.tree, self.tree.GetId(), self.OnChanging) wx.EVT_TREE_SEL_CHANGED(self.tree, self.tree.GetId(), self.OnChanged) wx.EVT_TREE_BEGIN_LABEL_EDIT(self.tree, self.tree.GetId(), self.OnBeginChangeLabel) wx.EVT_TREE_END_LABEL_EDIT(self.tree, self.tree.GetId(), self.OnChangeLabel) wx.EVT_TREE_ITEM_ACTIVATED(self.tree, self.tree.GetId(), self.OnSelected) wx.EVT_TREE_ITEM_RIGHT_CLICK(self.tree, self.tree.GetId(), self.OnRClick) wx.EVT_RIGHT_UP(self.tree, self.OnRClick) wx.EVT_TREE_DELETE_ITEM(self.tree, self.tree.GetId(), self.OnDeleteItem) wx.EVT_LEFT_DCLICK(self.tree, self.OnDoubleClick) wx.EVT_TREE_ITEM_EXPANDING(self.tree, self.tree.GetId(), self.OnExpanding) from modules import Id wx.EVT_UPDATE_UI(self, Id.makeid(self, 'IDPM_DEL'), self.OnUpdateUI) #add init process self.callplugin('init', self) self.SetSizer(self.sizer) self.SetAutoLayout(True) self.popmenus = None
def __init__(self, parent): """Data Catalog Tree constructor.""" super(DataCatalogTree, self).__init__(parent) self._initVariablesCatalog() wx.EVT_TREE_BEGIN_DRAG(self, wx.ID_ANY, self.OnBeginDrag) wx.EVT_TREE_END_DRAG(self, wx.ID_ANY, self.OnEndDrag) wx.EVT_TREE_END_LABEL_EDIT(self, wx.ID_ANY, self.OnEditLabel) wx.EVT_TREE_BEGIN_LABEL_EDIT(self, wx.ID_ANY, self.OnStartEditLabel)
def __init__(self, parent, filename): # Use the WANTS_CHARS style so the panel doesn't eat the Return key. wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) wx.EVT_SIZE(self, self.OnSize) tID = wx.NewId() self.tree = MyTreeCtrl( self, tID, wx.DefaultPosition, wx.DefaultSize, wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS, #| wx.TR_MULTIPLE #| wx.TR_HIDE_ROOT ) isz = (16, 16) il = wx.ImageList(isz[0], isz[1]) # wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz) -> wx.ArtProvider.GetBitmap()/3 self.folderIdx = il.Add( wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) self.folderOpenIdx = il.Add( wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) self.fileIdx = il.Add( wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz)) #self.fileIdx = self.il.Add(images.getFile1Bitmap()) #self.smileidx = self.il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # NOTE: 1 tree items have to have a data object in order to be sorted. # 2 Since our compare just uses the labels we don't need real data, so we'll just # use None below for the item data. wx.EVT_TREE_ITEM_EXPANDED(self, tID, self.OnItemExpanded) wx.EVT_TREE_ITEM_COLLAPSED(self, tID, self.OnItemCollapsed) wx.EVT_TREE_SEL_CHANGED(self, tID, self.OnSelChanged) wx.EVT_TREE_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit) wx.EVT_TREE_END_LABEL_EDIT(self, tID, self.OnEndEdit) wx.EVT_TREE_ITEM_ACTIVATED(self, tID, self.OnActivate) wx.EVT_LEFT_DCLICK(self.tree, self.OnLeftDClick) wx.EVT_RIGHT_DOWN(self.tree, self.OnRightClick) wx.EVT_RIGHT_UP(self.tree, self.OnRightUp) #?? wx.EVT_COMMAND(self, 103,103, self.OnFileOpened) # Newer wxWidgets has no EVT_COMMAND # load default tree if filename != "": self.reload_tree(filename)
def __init__(self, parent, image_size=(16, 16), **traits): """ Creates a new tree viewer. 'parent' is the toolkit-specific control that is the tree's parent. 'image_size' is a tuple in the form (int width, int height) that specifies the size of the label images (if any) displayed in the tree. """ # Base class constructor. super(TreeViewer, self).__init__(**traits) # Create the toolkit-specific control. self.control = tree = wx.TreeCtrl(parent, -1, style=self._get_style()) # Get our actual Id. wxid = tree.GetId() # Wire up the wx tree events. wx.EVT_CHAR(tree, self._on_char) wx.EVT_LEFT_DOWN(tree, self._on_left_down) wx.EVT_RIGHT_DOWN(tree, self._on_right_down) wx.EVT_TREE_ITEM_ACTIVATED(tree, wxid, self._on_tree_item_activated) wx.EVT_TREE_ITEM_COLLAPSED(tree, wxid, self._on_tree_item_collapsed) wx.EVT_TREE_ITEM_COLLAPSING(tree, wxid, self._on_tree_item_collapsing) wx.EVT_TREE_ITEM_EXPANDED(tree, wxid, self._on_tree_item_expanded) wx.EVT_TREE_ITEM_EXPANDING(tree, wxid, self._on_tree_item_expanding) wx.EVT_TREE_BEGIN_LABEL_EDIT(tree, wxid, self._on_tree_begin_label_edit) wx.EVT_TREE_END_LABEL_EDIT(tree, wxid, self._on_tree_end_label_edit) wx.EVT_TREE_BEGIN_DRAG(tree, wxid, self._on_tree_begin_drag) wx.EVT_TREE_SEL_CHANGED(tree, wxid, self._on_tree_sel_changed) # The image list is a wxPython-ism that caches all images used in the # control. self._image_list = ImageList(image_size[0], image_size[1]) if self.show_images: tree.AssignImageList(self._image_list) # Mapping from element to wx tree item Ids. self._element_to_id_map = {} # Add the root item. if self.input is not None: self._add_element(None, self.input) return
def __init__(self, parent, mainframe, dirs=None): self.initmixin() wx.Panel.__init__(self, parent, -1) self.parent = parent self.mainframe = mainframe self.pref = mainframe.pref self.sizer = wx.BoxSizer(wx.VERTICAL) imagelist = mainframe.dirbrowser_imagelist self.dirbrowserimagelist = wx.ImageList(16, 16) self.close_image = self.add_image( common.getpngimage(imagelist['close'])) self.open_image = self.add_image(common.getpngimage(imagelist['open'])) self.item_image = self.add_image(common.getpngimage(imagelist['item'])) self.deal_file_images() style = wx.TR_EDIT_LABELS | wx.TR_SINGLE | wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS | wx.TR_TWIST_BUTTONS if wx.Platform == '__WXMSW__': style = style | wx.TR_ROW_LINES elif wx.Platform == '__WXGTK__': style = style | wx.TR_NO_LINES self.tree = wx.TreeCtrl(self, -1, style=style) self.tree.SetImageList(self.dirbrowserimagelist) self.sizer.Add(self.tree, 1, wx.EXPAND) self.root = self.tree.AddRoot('DirBrowser') #add drop target self.SetDropTarget(MyFileDropTarget(self)) # wx.EVT_TREE_SEL_CHANGED(self.tree, self.tree.GetId(), self.OnChanged) wx.EVT_TREE_BEGIN_LABEL_EDIT(self.tree, self.tree.GetId(), self.OnBeginChangeLabel) wx.EVT_TREE_END_LABEL_EDIT(self.tree, self.tree.GetId(), self.OnChangeLabel) wx.EVT_TREE_ITEM_ACTIVATED(self.tree, self.tree.GetId(), self.OnSelected) # wx.EVT_TREE_ITEM_RIGHT_CLICK(self.tree, self.tree.GetId(), self.OnRClick) wx.EVT_RIGHT_UP(self.tree, self.OnRClick) wx.EVT_RIGHT_DOWN(self.tree, self.OnRightDown) wx.EVT_TREE_DELETE_ITEM(self.tree, self.tree.GetId(), self.OnDeleteItem) wx.EVT_LEFT_DCLICK(self.tree, self.OnDoubleClick) wx.EVT_TREE_ITEM_EXPANDING(self.tree, self.tree.GetId(), self.OnExpanding) wx.EVT_KEY_DOWN(self.tree, self.OnKeyDown) wx.EVT_CHAR(self.tree, self.OnChar) self.SetSizer(self.sizer) self.SetAutoLayout(True) self.nodes = {} self.ID = 1 self.cache = None #@add_project self.callplugin_once('add_project', DirBrowser.project_names) pop_menus = copy.deepcopy(DirBrowser.popmenulist) self.popmenus = makemenu.makepopmenu(self, pop_menus) self.dirmenu_ids = [self.IDPM_ADD_DIRS] wx.EVT_UPDATE_UI(self, self.IDPM_CUT, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_COPY, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_PASTE, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_CLOSE, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_ADDFILE, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_ADDPATH, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_DELETE, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_REFRESH, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_RENAME, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_IGNORETHIS, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_IGNORETHISTYPE, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_OPENDEFAULT, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_SETPROJ, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_COMMANDLINE, self.OnUpdateUI) wx.EVT_UPDATE_UI(self, self.IDPM_PRINTDIR, self.OnUpdateUI) self.popmenus = None if dirs: for i in dirs: self.addpath(i, False) self.callplugin('init', self)
def __init__(self, parent, image_size=(16, 16), **traits): """ Creates a new tree. 'parent' is the toolkit-specific control that is the tree's parent. 'image_size' is a tuple in the form (int width, int height) that specifies the size of the images (if required) displayed in the tree. """ # Base class constructors. super(Tree, self).__init__(**traits) # Get our wx Id. wxid = wx.NewId() # Create the toolkit-specific control. self.control = tree = _Tree(self, parent, wxid, style=self._get_style()) # Wire up the wx tree events. wx.EVT_CHAR(tree, self._on_char) wx.EVT_LEFT_DOWN(tree, self._on_left_down) # fixme: This is not technically correct as context menus etc should # appear on a right up (or right click). Unfortunately, if we # change this to 'EVT_RIGHT_UP' wx does not fire the event unless the # right mouse button is double clicked 8^() Sad, but true! wx.EVT_RIGHT_DOWN(tree, self._on_right_down) # fixme: This is not technically correct as we would really like to use # 'EVT_TREE_ITEM_ACTIVATED'. Unfortunately, (in 2.6 at least), it # throws an exception when the 'Enter' key is pressed as the wx tree # item Id in the event seems to be invalid. It also seems to cause # any child frames that my be created in response to the event to # appear *behind* the parent window, which is, errrr, not great ;^) wx.EVT_LEFT_DCLICK(tree, self._on_tree_item_activated) #wx.EVT_TREE_ITEM_ACTIVATED(tree, wxid, self._on_tree_item_activated) wx.EVT_TREE_ITEM_COLLAPSING(tree, wxid, self._on_tree_item_collapsing) wx.EVT_TREE_ITEM_COLLAPSED(tree, wxid, self._on_tree_item_collapsed) wx.EVT_TREE_ITEM_EXPANDING(tree, wxid, self._on_tree_item_expanding) wx.EVT_TREE_ITEM_EXPANDED(tree, wxid, self._on_tree_item_expanded) wx.EVT_TREE_BEGIN_LABEL_EDIT(tree, wxid, self._on_tree_begin_label_edit) wx.EVT_TREE_END_LABEL_EDIT(tree, wxid, self._on_tree_end_label_edit) wx.EVT_TREE_BEGIN_DRAG(tree, wxid, self._on_tree_begin_drag) wx.EVT_TREE_SEL_CHANGED(tree, wxid, self._on_tree_sel_changed) wx.EVT_TREE_DELETE_ITEM(tree, wxid, self._on_tree_delete_item) # Enable the tree as a drag and drop target. self.control.SetDropTarget(PythonDropTarget(self)) # The image list is a wxPython-ism that caches all images used in the # control. self._image_list = ImageList(image_size[0], image_size[1]) if self.show_images: tree.AssignImageList(self._image_list) # Mapping from node to wx tree item Ids. self._node_to_id_map = {} # Add the root node. if self.root is not None: self._add_root_node(self.root) # Listen for changes to the model. self._add_model_listeners(self.model) return