我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用wx.ImageList()。
def LoadIconList(self): isz = (16, 16) self.tree_fs.icon_list = wx.ImageList(*isz) folder = wx.Icon( 'icons/ic_folder_black_18dp.png', wx.BITMAP_TYPE_PNG, isz[0], isz[1], ) folder_open = wx.Icon( 'icons/ic_folder_open_black_18dp.png', wx.BITMAP_TYPE_PNG, isz[0], isz[1], ) self.tree_fs.icon_fldridx = self.tree_fs.icon_list.AddIcon(folder) self.tree_fs.icon_fldropenidx = self.tree_fs.icon_list.AddIcon(folder_open) self.tree_fs.icon_fileidx = self.tree_fs.icon_list.AddIcon(wx.ArtProvider.GetIcon(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) self.tree_fs.SetImageList(self.tree_fs.icon_list)
def __init__(self, nsHost, nsPort, bcAddr): """ :Parameters: - `nsHost`: the name server host to connect to. This is the name of the host or the ip. - `nsPort`: the name server port. By default the Pyro name server port is 9090 - `bcAddr`: override for the broadcast address. """ wx.Frame.__init__(self, None, -1, 'Pyro Name Server') self.nsHost = nsHost self.nsPort = nsPort self.bcAddr = bcAddr self.NS = None self._build() imageList = wx.ImageList(16,16) self.__idGroup = imageList.Add(wx.BitmapFromXPMData(GROUP_XPM)) self.__idItem = imageList.Add(wx.BitmapFromXPMData(ITEM_XPM)) self.__idGroupOpen = imageList.Add(wx.BitmapFromXPMData(GROUP_OPEN_XPM)) self.treeCtrlItems.SetImageList(imageList) self.__imageList = imageList self._bindEvents() # binding stdout to my own txtCtrl Log. sys.stdout = self.txtCtrlLog self._log("Pyro version: "+Pyro.constants.VERSION) self.nsc_findNS() if self.NS: self.update() #-- public methods --#
def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "CustomTreeCtrl Demo") # Create a CustomTreeCtrl instance custom_tree = CT.CustomTreeCtrl(self, agwStyle=wx.TR_DEFAULT_STYLE) # Add a root node to it root = custom_tree.AddRoot("The Root Item") # Create an image list to add icons next to an item il = wx.ImageList(16, 16) fldridx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, (16, 16))) fldropenidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, (16, 16))) fileidx = il.Add(wx.ArtProvider.GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, (16, 16))) custom_tree.SetImageList(il) custom_tree.SetItemImage(root, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(root, fldropenidx, wx.TreeItemIcon_Expanded) list = [ 'http://app.finance.china.com.cn/forex', 'http://app.finance.china.com.cn/report/list.php', 'http://app.finance.china.com.cn/stock/bill'] for x in list: child = custom_tree.AppendItem(root, "Item %s" % x) custom_tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded) for y in list: last = custom_tree.AppendItem(child, "item-%s-%s" % (x,y)) custom_tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal) custom_tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded) for z in list: item = custom_tree.AppendItem(last, "item %s-%s-%s" % (x,y,z)) custom_tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal) custom_tree.Expand(root) # our normal wxApp-derived class, as usual
def __init__(self, parent, window): self.ParentWindow = window self._init_ctrls(parent) # Define Tree item icon list self.TreeImageList = wx.ImageList(16, 16) self.TreeImageDict = {} # Icons for other items for imgname, itemtype in [ # editables ("PROJECT", ITEM_PROJECT), ("TRANSITION", ITEM_TRANSITION), ("ACTION", ITEM_ACTION), ("CONFIGURATION", ITEM_CONFIGURATION), ("RESOURCE", ITEM_RESOURCE), ("DATATYPE", ITEM_DATATYPE), ("ACTION", "action_block"), ("IL", "IL"), ("ST", "ST")]: self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(imgname)) for itemtype in ["function", "functionBlock", "program", "comment", "block", "io_variable", "connector", "contact", "coil", "step", "transition", "jump", "var_local", "var_input", "var_inout", "var_output"]: self.TreeImageDict[itemtype] = self.TreeImageList.Add(GetBitmap(itemtype.upper())) # Assign icon list to TreeCtrl self.SearchResultsTree.SetImageList(self.TreeImageList) self.ResetSearchResults()
def __init__(self, controller_uid): UIViewBase.__init__(self, controller_uid) UIM = UIManager() controller = UIM.get(self._controller_uid) parent_controller_uid = UIM._getparentuid(self._controller_uid) parent_controller = UIM.get(parent_controller_uid) wx.TreeCtrl.__init__(self, parent_controller.view, -1, wx.Point(0, 0), wx.Size(200, 250), wx.TR_DEFAULT_STYLE | wx.NO_BORDER) self._rootid = self.AddRoot(wx.EmptyString) self._set_project_name() self.SetItemData(self._rootid, (controller._PSEUDOROOTUID, None)) self.Bind(wx.EVT_TREE_ITEM_RIGHT_CLICK, self.on_rightclick) ''' imglist = wx.ImageList(16, 16, True, 2) imglist.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, wx.Size(16,16))) tree.AssignImageList(imglist) items.append(tree.AppendItem(root, "Item 1", 0)) ''' parent_controller.view._mgr.AddPane(self, wx.aui.AuiPaneInfo().Name("tree"). Caption("Object Manager").Left().Layer(1).Position(1). PinButton(True).MinimizeButton(True). CloseButton(False).MaximizeButton(True) ) parent_controller.view._mgr.Update() self.Bind(wx.EVT_TREE_BEGIN_DRAG, self._on_begin_drag)
def __init__(self, parent, folder, filter=None, editable=True): wx.Panel.__init__(self, parent, style=wx.TAB_TRAVERSAL) main_sizer = wx.BoxSizer(wx.VERTICAL) self.Tree = wx.TreeCtrl(self, style=(wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.SUNKEN_BORDER | wx.TR_HIDE_ROOT | wx.TR_LINES_AT_ROOT | wx.TR_EDIT_LABELS)) if wx.Platform == '__WXMSW__': self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnTreeItemExpanded, self.Tree) self.Tree.Bind(wx.EVT_LEFT_DOWN, self.OnTreeLeftDown) else: self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnTreeItemExpanded, self.Tree) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnTreeItemCollapsed, self.Tree) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnTreeBeginLabelEdit, self.Tree) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnTreeEndLabelEdit, self.Tree) main_sizer.AddWindow(self.Tree, 1, flag=wx.GROW) if filter is not None: self.Filter = wx.ComboBox(self, style=wx.CB_READONLY) self.Bind(wx.EVT_COMBOBOX, self.OnFilterChanged, self.Filter) main_sizer.AddWindow(self.Filter, flag=wx.GROW) else: self.Filter = None self.SetSizer(main_sizer) self.Folder = folder self.Editable = editable self.TreeImageList = wx.ImageList(16, 16) self.TreeImageDict = {} for item_type, bitmap in [(DRIVE, "tree_drive"), (FOLDER, "tree_folder"), (FILE, "tree_file")]: self.TreeImageDict[item_type] = self.TreeImageList.Add(GetBitmap(bitmap)) self.Tree.SetImageList(self.TreeImageList) self.Filters = {} if self.Filter is not None: filter_parts = filter.split("|") for idx in xrange(0, len(filter_parts), 2): if filter_parts[idx + 1] == "*.*": self.Filters[filter_parts[idx]] = "" else: self.Filters[filter_parts[idx]] = filter_parts[idx + 1].replace("*", "") self.Filter.Append(filter_parts[idx]) if idx == 0: self.Filter.SetStringSelection(filter_parts[idx]) self.CurrentFilter = self.Filters[self.Filter.GetStringSelection()] else: self.CurrentFilter = ""
def create_layout(self): self.main_grid = wx.BoxSizer(wx.HORIZONTAL) style = wx.TR_DEFAULT_STYLE | wx.TR_HIDE_ROOT | wx.TR_TWIST_BUTTONS | wx.TR_NO_LINES # style = wx.TR_HAS_BUTTONS | wx.TR_SINGLE | wx.TR_HIDE_ROOT image_list = wx.ImageList(16, 16) tree_ctrl_id = id_renew('settings.tree', update=True) tree_ctrl = wx.TreeCtrl(self, id=tree_ctrl_id, style=style) root_key = MODULE_KEY.join(['settings', 'tree', 'root']) root_node = tree_ctrl.AddRoot(translate_key(root_key)) for cat_name, category in self.categories.iteritems(): item_key = MODULE_KEY.join(['settings', cat_name]) item_data = wx.TreeItemData() item_data.SetData(item_key) item_node = tree_ctrl.AppendItem(root_node, translate_key(item_key), data=item_data) for module_name, module_settings in category.iteritems(): if not module_name == cat_name: if module_settings.get('gui', {}).get('icon'): icon = wx.Bitmap(module_settings['gui']['icon']) self.tree_ctrl_image_dict[module_name] = image_list.GetImageCount() image_list.Add(icon) else: self.tree_ctrl_image_dict[module_name] = -1 f_item_key = MODULE_KEY.join([item_key, module_name]) f_item_data = wx.TreeItemData() f_item_data.SetData(f_item_key) tree_ctrl.AppendItem(item_node, translate_key(module_name), image=self.tree_ctrl_image_dict[module_name], data=f_item_data) if self.show_icons: tree_ctrl.AssignImageList(image_list) tree_ctrl.ExpandAll() self.tree_ctrl = tree_ctrl self.Bind(wx.EVT_TREE_SEL_CHANGED, self.on_tree_ctrl_changed, id=tree_ctrl_id) self.main_grid.Add(tree_ctrl, 7, wx.EXPAND | wx.ALL, 7) content_page_id = id_renew(MODULE_KEY.join(['settings', 'content'])) self.content_page = wx.Panel(self, id=content_page_id) self.main_grid.Add(self.content_page, 15, wx.EXPAND) self.main_grid.Layout() self.SetSizer(self.main_grid) tree_ctrl.SelectItem(tree_ctrl.GetFirstChild(root_node)[0])