def __init__(self, mainwindow, parent, id, style): wx.TreeCtrl.__init__(self, parent, id, style=style) self.parent=parent self.mainwindow=mainwindow wx.EVT_TREE_ITEM_EXPANDED(self, id, self.OnItemExpanded) wx.EVT_TREE_SEL_CHANGED(self,id, self.OnItemSelected) self.dirmenu=wx.Menu() self.dirmenu.Append(guihelper.ID_FV_NEWSUBDIR, "Make subdirectory ...") self.dirmenu.Append(guihelper.ID_FV_NEWFILE, "New File ...") self.dirmenu.AppendSeparator() self.dirmenu.Append(guihelper.ID_FV_BACKUP, "Backup directory ...") self.dirmenu.Append(guihelper.ID_FV_BACKUP_TREE, "Backup entire tree ...") self.dirmenu.Append(guihelper.ID_FV_RESTORE, "Restore ...") self.dirmenu.AppendSeparator() self.dirmenu.Append(guihelper.ID_FV_REFRESH, "Refresh") self.dirmenu.AppendSeparator() self.dirmenu.Append(guihelper.ID_FV_DELETE, "Delete") self.dirmenu.AppendSeparator() self.dirmenu.Append(guihelper.ID_FV_TOTAL_REFRESH, "Refresh Filesystem") self.dirmenu.Append(guihelper.ID_FV_OFFLINEPHONE, "Offline Phone") self.dirmenu.Append(guihelper.ID_FV_REBOOTPHONE, "Reboot Phone") self.dirmenu.Append(guihelper.ID_FV_MODEMMODE, "Go to modem mode") # generic menu self.genericmenu=wx.Menu() self.genericmenu.Append(guihelper.ID_FV_TOTAL_REFRESH, "Refresh Filesystem") self.genericmenu.Append(guihelper.ID_FV_OFFLINEPHONE, "Offline Phone") self.genericmenu.Append(guihelper.ID_FV_REBOOTPHONE, "Reboot Phone") self.genericmenu.Append(guihelper.ID_FV_MODEMMODE, "Go to modem mode") wx.EVT_MENU(self.genericmenu, guihelper.ID_FV_TOTAL_REFRESH, self.OnRefresh) wx.EVT_MENU(self.genericmenu, guihelper.ID_FV_OFFLINEPHONE, parent.OnPhoneOffline) wx.EVT_MENU(self.genericmenu, guihelper.ID_FV_REBOOTPHONE, parent.OnPhoneReboot) wx.EVT_MENU(self.genericmenu, guihelper.ID_FV_MODEMMODE, parent.OnModemMode) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_NEWSUBDIR, self.OnNewSubdir) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_NEWFILE, self.OnNewFile) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_DELETE, self.OnDirDelete) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_BACKUP, self.OnBackupDirectory) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_BACKUP_TREE, self.OnBackupTree) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_RESTORE, self.OnRestore) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_REFRESH, self.OnDirRefresh) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_TOTAL_REFRESH, self.OnRefresh) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_OFFLINEPHONE, parent.OnPhoneOffline) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_REBOOTPHONE, parent.OnPhoneReboot) wx.EVT_MENU(self.dirmenu, guihelper.ID_FV_MODEMMODE, parent.OnModemMode) wx.EVT_RIGHT_DOWN(self, self.OnRightDown) wx.EVT_RIGHT_UP(self, self.OnRightUp) self.image_list=wx.ImageList(16, 16) self.img_dir=self.image_list.Add(wx.ArtProvider_GetBitmap(guihelper.ART_FOLDER, wx.ART_OTHER, (16, 16))) self.img_dir_open=self.image_list.Add(wx.ArtProvider_GetBitmap(guihelper.ART_FOLDER_OPEN, wx.ART_OTHER, (16, 16))) self.SetImageList(self.image_list) self.add_files=[] self.add_target="" self.droptarget=fileview.MyFileDropTarget(self, True, True) self.SetDropTarget(self.droptarget) self.ResetView()
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, 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