def __init__(self, parent, log): wx.ListCtrl.__init__(self, parent, -1, style=wx.LC_REPORT | wx.LC_VIRTUAL | wx.LC_HRULES | wx.LC_VRULES) self.log = log self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.InsertColumn(0, "First") self.InsertColumn(1, "Second") self.InsertColumn(2, "Third") self.SetColumnWidth(0, 175) self.SetColumnWidth(1, 175) self.SetColumnWidth(2, 175) self.SetItemCount(1000000) self.attr1 = wx.ListItemAttr() self.attr1.SetBackgroundColour("yellow") self.attr2 = wx.ListItemAttr() self.attr2.SetBackgroundColour("light blue") self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
def __init__(self, parent, log): wx.ListCtrl.__init__( self, parent, -1, style=wx.LC_REPORT|wx.LC_VIRTUAL|wx.LC_HRULES|wx.LC_VRULES ) self.log = log self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.InsertColumn(0, "First") self.InsertColumn(1, "Second") self.InsertColumn(2, "Third") self.SetColumnWidth(0, 175) self.SetColumnWidth(1, 175) self.SetColumnWidth(2, 175) self.SetItemCount(1000000) self.attr1 = wx.ListItemAttr() self.attr1.SetBackgroundColour("yellow") self.attr2 = wx.ListItemAttr() self.attr2.SetBackgroundColour("light blue") self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected)
def __init__(self, parent, id, log): wx.Notebook.__init__( self, parent, id, size=(21, 21), style=wx.BK_DEFAULT #wx.BK_TOP #wx.BK_BOTTOM #wx.BK_LEFT #wx.BK_RIGHT # | wx.NB_MULTILINE ) self.log = log win = self.makeColorPanel(wx.BLUE) self.AddPage(win, "Blue") st = wx.StaticText( win.win, -1, "You can put nearly any type of window here,\n" "and if the platform supports it then the\n" "tabs can be on any side of the notebook.", (10, 10)) st.SetForegroundColour(wx.WHITE) st.SetBackgroundColour(wx.BLUE) # Show how to put an image on one of the notebook tabs, # first make the image list: il = wx.ImageList(16, 16) idx1 = il.Add(images.getSmilesBitmap()) self.AssignImageList(il) # now put an image on the first tab we just created: self.SetPageImage(0, idx1) win = self.makeColorPanel(wx.RED) self.AddPage(win, "Red") win = ScrolledWindow.MyCanvas(self) self.AddPage(win, 'ScrolledWindow') win = self.makeColorPanel(wx.GREEN) self.AddPage(win, "Green") win = GridSimple.SimpleGrid(self, log) self.AddPage(win, "Grid") win = ListCtrl.TestListCtrlPanel(self, log) self.AddPage(win, 'List') win = self.makeColorPanel(wx.CYAN) self.AddPage(win, "Cyan") win = self.makeColorPanel(wx.NamedColour('Midnight Blue')) self.AddPage(win, "Midnight Blue") win = self.makeColorPanel(wx.NamedColour('Indian Red')) self.AddPage(win, "Indian Red") self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
def __init__(self, parent, id, log): wx.Notebook.__init__(self, parent, id, size=(21,21), style= wx.BK_DEFAULT #wx.BK_TOP #wx.BK_BOTTOM #wx.BK_LEFT #wx.BK_RIGHT # | wx.NB_MULTILINE ) self.log = log win = self.makeColorPanel(wx.BLUE) self.AddPage(win, "Blue") st = wx.StaticText(win.win, -1, "You can put nearly any type of window here,\n" "and if the platform supports it then the\n" "tabs can be on any side of the notebook.", (10, 10)) st.SetForegroundColour(wx.WHITE) st.SetBackgroundColour(wx.BLUE) # Show how to put an image on one of the notebook tabs, # first make the image list: il = wx.ImageList(16, 16) idx1 = il.Add(images.getSmilesBitmap()) self.AssignImageList(il) # now put an image on the first tab we just created: self.SetPageImage(0, idx1) win = self.makeColorPanel(wx.RED) self.AddPage(win, "Red") win = ScrolledWindow.MyCanvas(self) self.AddPage(win, 'ScrolledWindow') win = self.makeColorPanel(wx.GREEN) self.AddPage(win, "Green") win = GridSimple.SimpleGrid(self, log) self.AddPage(win, "Grid") win = ListCtrl.TestListCtrlPanel(self, log) self.AddPage(win, 'List') win = self.makeColorPanel(wx.CYAN) self.AddPage(win, "Cyan") win = self.makeColorPanel(wx.NamedColour('Midnight Blue')) self.AddPage(win, "Midnight Blue") win = self.makeColorPanel(wx.NamedColour('Indian Red')) self.AddPage(win, "Indian Red") self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGING, self.OnPageChanging)
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.log = log tID = wx.NewId() self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) self.list = TestListCtrl( self, tID, style=wx.LC_REPORT #| wx.BORDER_SUNKEN | wx.BORDER_NONE | wx.LC_EDIT_LABELS | wx.LC_SORT_ASCENDING #| wx.LC_NO_HEADER #| wx.LC_VRULES #| wx.LC_HRULES #| wx.LC_SINGLE_SEL ) self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.PopulateList() # Now that the list exists we can init the other base class, # see wx/lib/mixins/listctrl.py self.itemDataMap = musicdata listmix.ColumnSorterMixin.__init__(self, 3) #self.SortListItems(0, True) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.list) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.list) self.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnItemDelete, self.list) self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list) self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.OnColRightClick, self.list) self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.OnColBeginDrag, self.list) self.Bind(wx.EVT_LIST_COL_DRAGGING, self.OnColDragging, self.list) self.Bind(wx.EVT_LIST_COL_END_DRAG, self.OnColEndDrag, self.list) self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.list) self.list.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) self.list.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) # for wxMSW self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) # for wxGTK self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
def __init__(self, parent, app): wxPanel.__init__(self, parent, -1, style=wxWANTS_CHARS) # wxTAB_TRAVERSAL) tID = wxNewId() self.il = wxImageList(16, 16) self.app = app self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) self.list = TransferListCtrl( self, tID, style=wxLC_REPORT | wxLC_EDIT_LABELS # | wxSUNKEN_BORDER # | wxLC_VRULES | wxLC_HRULES | wxLC_HRULES, size=(100, 100), pos=(50, 50), ) self.list.SetImageList(self.il, wxIMAGE_LIST_SMALL) self.itemDataMap = {} self.SetupList() # TODO: Column sorting is disabled now because nick2index loses # its associations and starts writing to the wrong column. # wxColumnSorterMixin.__init__(self, 3) # XXX: These are left over from wxListCtrl demo. # TODO: Do something useful with them EVT_SIZE(self, self.OnSize) EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected) EVT_LIST_ITEM_DESELECTED(self, tID, self.OnItemDeselected) EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated) EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete) EVT_LIST_COL_CLICK(self, tID, self.OnColClick) EVT_LIST_COL_RIGHT_CLICK(self, tID, self.OnColRightClick) EVT_LIST_COL_BEGIN_DRAG(self, tID, self.OnColBeginDrag) EVT_LIST_COL_DRAGGING(self, tID, self.OnColDragging) EVT_LIST_COL_END_DRAG(self, tID, self.OnColEndDrag) # Begin and end rename EVT_LIST_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit) EVT_LIST_END_LABEL_EDIT(self, tID, self.OnEndEdit) EVT_LEFT_DCLICK(self.list, self.OnDoubleClick) EVT_RIGHT_DOWN(self.list, self.OnRightDown) # for wxMSW EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick) # for wxGTK EVT_RIGHT_UP(self.list, self.OnRightClick)
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.log = log tID = wx.NewId() self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) self.list = TestListCtrl(self, tID, style=wx.LC_REPORT #| wx.BORDER_SUNKEN | wx.BORDER_NONE | wx.LC_EDIT_LABELS | wx.LC_SORT_ASCENDING #| wx.LC_NO_HEADER #| wx.LC_VRULES #| wx.LC_HRULES #| wx.LC_SINGLE_SEL ) self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.PopulateList() # Now that the list exists we can init the other base class, # see wx/lib/mixins/listctrl.py self.itemDataMap = musicdata listmix.ColumnSorterMixin.__init__(self, 3) #self.SortListItems(0, True) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.list) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.list) self.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnItemDelete, self.list) self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list) self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.OnColRightClick, self.list) self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.OnColBeginDrag, self.list) self.Bind(wx.EVT_LIST_COL_DRAGGING, self.OnColDragging, self.list) self.Bind(wx.EVT_LIST_COL_END_DRAG, self.OnColEndDrag, self.list) self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.list) self.list.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) self.list.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) # for wxMSW self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) # for wxGTK self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
def OnContextMenu(self, event): self.log.WriteText("OnContextMenu\n") # only do this part the first time so the events are only bound once # # Yet another anternate way to do IDs. Some prefer them up top to # avoid clutter, some prefer them close to the object of interest # for clarity. if not hasattr(self, "popupID1"): self.popupID1 = wx.NewId() self.popupID2 = wx.NewId() self.popupID3 = wx.NewId() self.popupID4 = wx.NewId() self.popupID5 = wx.NewId() self.popupID6 = wx.NewId() self.popupID7 = wx.NewId() self.popupID8 = wx.NewId() self.popupID9 = wx.NewId() self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1) self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2) self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4) self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5) self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6) self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7) self.Bind(wx.EVT_MENU, self.OnPopupEight, id=self.popupID8) self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9) # make a menu menu = wx.Menu() # Show how to put an icon in the menu item = wx.MenuItem(menu, self.popupID1,"One") bmp = images.getSmilesBitmap() item.SetBitmap(bmp) menu.AppendItem(item) # add some other items menu.Append(self.popupID2, "Two") menu.Append(self.popupID3, "Three") menu.Append(self.popupID4, "Four") menu.Append(self.popupID5, "Five") menu.Append(self.popupID6, "Six") # make a submenu sm = wx.Menu() sm.Append(self.popupID8, "sub item 1") sm.Append(self.popupID9, "sub item 1") menu.AppendMenu(self.popupID7, "Test Submenu", sm) # Popup the menu. If an item is selected then its handler # will be called before PopupMenu returns. self.PopupMenu(menu) menu.Destroy()
def OnRightClick(self, event): self.log.WriteText("OnRightClick\n") # only do this part the first time so the events are only bound once # # Yet another anternate way to do IDs. Some prefer them up top to # avoid clutter, some prefer them close to the object of interest # for clarity. if not hasattr(self, "popupID1"): self.popupID1 = wx.NewId() self.popupID2 = wx.NewId() self.popupID3 = wx.NewId() self.popupID4 = wx.NewId() self.popupID5 = wx.NewId() self.popupID6 = wx.NewId() self.popupID7 = wx.NewId() self.popupID8 = wx.NewId() self.popupID9 = wx.NewId() self.Bind(wx.EVT_MENU, self.OnPopupOne, id=self.popupID1) self.Bind(wx.EVT_MENU, self.OnPopupTwo, id=self.popupID2) self.Bind(wx.EVT_MENU, self.OnPopupThree, id=self.popupID3) self.Bind(wx.EVT_MENU, self.OnPopupFour, id=self.popupID4) self.Bind(wx.EVT_MENU, self.OnPopupFive, id=self.popupID5) self.Bind(wx.EVT_MENU, self.OnPopupSix, id=self.popupID6) self.Bind(wx.EVT_MENU, self.OnPopupSeven, id=self.popupID7) self.Bind(wx.EVT_MENU, self.OnPopupEight, id=self.popupID8) self.Bind(wx.EVT_MENU, self.OnPopupNine, id=self.popupID9) # make a menu menu = wx.Menu() # Show how to put an icon in the menu item = wx.MenuItem(menu, self.popupID1, "One") bmp = images.getSmilesBitmap() item.SetBitmap(bmp) menu.AppendItem(item) # add some other items menu.Append(self.popupID2, "Two") menu.Append(self.popupID3, "Three") menu.Append(self.popupID4, "Four") menu.Append(self.popupID5, "Five") menu.Append(self.popupID6, "Six") # make a submenu sm = wx.Menu() sm.Append(self.popupID8, "sub item 1") sm.Append(self.popupID9, "sub item 1") menu.AppendMenu(self.popupID7, "Test Submenu", sm) # Popup the menu. If an item is selected then its handler # will be called before PopupMenu returns. self.PopupMenu(menu, event.GetPosition()) menu.Destroy()
def __init__(self, parent): wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) tID = wx.NewId() self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) self.file1Idx = self.il.Add(images.getFile1Bitmap()) self.list = MyListCtrl( self, tID, style=wx.LC_REPORT | wx.SUNKEN_BORDER | wx.LC_EDIT_LABELS #| wx.LC_NO_HEADER #| wx.LC_VRULES | wx.LC_HRULES ) self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.PopulateList() # Now that the list exists we can init the other base class, # see wxPython/lib/mixins/listctrl.py ColumnSorterMixin.__init__(self, 3) #self.SortListItems(0, True) EVT_SIZE(self, self.OnSize) EVT_LIST_ITEM_SELECTED(self, tID, self.OnItemSelected) EVT_LIST_ITEM_DESELECTED(self, tID, self.OnItemDeselected) EVT_LIST_ITEM_ACTIVATED(self, tID, self.OnItemActivated) EVT_LIST_DELETE_ITEM(self, tID, self.OnItemDelete) EVT_LIST_COL_CLICK(self, tID, self.OnColClick) EVT_LIST_COL_RIGHT_CLICK(self, tID, self.OnColRightClick) EVT_LIST_COL_BEGIN_DRAG(self, tID, self.OnColBeginDrag) EVT_LIST_COL_DRAGGING(self, tID, self.OnColDragging) EVT_LIST_COL_END_DRAG(self, tID, self.OnColEndDrag) EVT_LIST_BEGIN_LABEL_EDIT(self, tID, self.OnBeginEdit) EVT_LEFT_DCLICK(self.list, self.OnDoubleClick) EVT_RIGHT_DOWN(self.list, self.OnRightDown) # for wxMSW EVT_COMMAND_RIGHT_CLICK(self.list, tID, self.OnRightClick) # for wxGTK EVT_RIGHT_UP(self.list, self.OnRightClick)
def __init__(self, obj, parent): wx.Panel.__init__(self, parent) self.dirPath = "" # Buttons - Choose, Add, Create Folders, Remove (or with the delete key) wx.Button(self, 1, 'Choose Project Folder', (10, 5)) wx.Button(self, 2, 'Add', (10, 435)) wx.Button(self, 3, 'Remove', (88,435)) wx.Button(self, 4, 'Make Defaults', (170,435)) wx.Button(self, 5, 'Create Folders', (295, 435)) self.tree = wx.TreeCtrl(self, -1, (10,30), wx.Size(400,400), style=wx.SIMPLE_BORDER|wx.TR_HAS_BUTTONS) isz = (16,16) il = wx.ImageList(isz[0], isz[1]) self.fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) self.fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) self.fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) self.smileidx = il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # Get XML file # Call fillmeup tmpPath = os.path.split((os.path.abspath(wsm.__file__))) wsm.userpaths = tmpPath[0] + '/user_paths.xml' self.xml = ET.parse(wsm.userpaths) # Consider trying '//user_paths.xml' root = self.fillmeup() # expand root self.tree.Expand(root) # Bindings self.Bind(wx.EVT_BUTTON, self.OnChoose, id=1) self.Bind(wx.EVT_BUTTON, self.OnAdd, id=2) self.Bind(wx.EVT_BUTTON, self.OnRemove, id=3) self.Bind(wx.EVT_BUTTON, self.userDefaults, id=4) self.Bind(wx.EVT_BUTTON, self.OnCreate, id=5) self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.tree) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndEdit, self.tree) self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) self.tree.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def __init__(self, parent, ID, pos=wxDefaultPosition, size=wxDefaultSize, style=wxLC_REPORT|wxLC_VIRTUAL|wxSUNKEN_BORDER):#|wxLC_VRULES|wxLC_HRULES): wxListCtrl.__init__(self, parent, ID, pos, size, style) wxListCtrlAutoWidthMixin.__init__(self) self.columntitles = [("title", "Title"), ("publicname", "Public Name"), ("TVsourceurl", "URL"), ("TVlastnewitem", "Last new Item"), ("TVitemsfetched", "Items Fetched"), ("TVlastfetched", "Last Request")] self.columntokey = [] pos = 0 for key, title in self.columntitles: self.InsertColumn(pos, title) pos += 1 self.columntokey.append(key) #self.SetColumnWidth(0, 175) #self.SetColumnWidth(1, 175) #self.SetColumnWidth(2, 175) self.itemlist = ListCtrlItemList() self.SetItemCount(len(self.itemlist)) self.il = wxImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) numColumns = self.GetColumnCount() self._colSortFlag = [0] * numColumns self._col = -1 # WDR: handler declarations for ServiceList EVT_LIST_ITEM_ACTIVATED(self, self.GetId(), self.OnItemactivated) EVT_LIST_ITEM_SELECTED(self, self.GetId(), self.OnItemselected) EVT_LIST_DELETE_ALL_ITEMS(self, self.GetId(), self.OnDeleteallitems) EVT_LIST_DELETE_ITEM(self, self.GetId(), self.OnDeleteitem) EVT_LIST_END_LABEL_EDIT(self, self.GetId(), self.OnLabeledit) EVT_LIST_ITEM_RIGHT_CLICK(self, self.GetId(), self.OnItemrightclick) EVT_LIST_INSERT_ITEM(self, self.GetId(), self.OnInsertitem) EVT_LIST_ITEM_DESELECTED(self, self.GetId(), self.OnItemdeselected) EVT_LIST_COL_CLICK(self, self.GetId(), self.OnColClick)
def __init__(self, parent=None, id=-1, title='Player management', pos=wx.DefaultPosition, size=wx.DefaultSize): wx.Frame.__init__(self, parent, id, title, pos, size) wx.InitAllImageHandlers() self.icon = images.getMondrianIcon() self.SetIcon(self.icon) # Load XRC resource if not USE_RESOURCE: self.res = wxPython.xrc.wxXmlResource('playerdb.xrc') panel = self.res.LoadPanel(self, 'playerdb_panel') menubar = self.res.LoadMenuBar('playerdb_menu') else: resource.InitXmlResource() panel = wxPython.xrc.wxXmlResource_Get().LoadPanel( self, 'playerdb_panel') menubar = wxPython.xrc.wxXmlResource_Get().LoadMenuBar( 'playerdb_menu') # Layout self.SetMenuBar(menubar) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(panel, 1, wx.EXPAND) self.SetSizer(sizer) sizer.SetSizeHints(self) # Init lists self.friends_list = wxPython.xrc.XRCCTRL(self, 'friends_list', wx.ListBox) self.bozo_list = wxPython.xrc.XRCCTRL(self, 'bozo_list', wx.ListBox) self.all_list = wxPython.xrc.XRCCTRL(self, 'all_list', wx.ListCtrl) img_list = wx.ImageList(16, 16) img_list.Add(images.getSmilesBitmap()) img_list.Add(images.getBozoBitmap()) self.all_list.AssignImageList(img_list, wx.IMAGE_LIST_SMALL) self.flag_filter = 0 self.init_lists() # Event table wx.EVT_BUTTON(self, wxPython.xrc.XRCID('add_friend'), self.OnAddFriend) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('remove_friend'), self.OnRemoveFriend) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('add_bozo'), self.OnAddBozo) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('remove_bozo'), self.OnRemoveBozo) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('all_add'), self.OnAddToAll) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('all_remove'), self.OnRemoveFromAll) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('all_edit'), self.OnAllEdit) wx.EVT_BUTTON(self, wx.ID_EXIT, self.OnClose) wx.EVT_MENU(self, wx.ID_EXIT, self.OnClose) wx.EVT_CLOSE(self, self.OnClose) wx.EVT_BUTTON(self, wxPython.xrc.XRCID('reload'), self.OnReload) wx.EVT_MENU(self, wxPython.xrc.XRCID('reload'), self.OnReload) wx.EVT_MENU(self, wxPython.xrc.XRCID('cleanup'), self.OnCleanupDB) wx.EVT_MENU(self, wxPython.xrc.XRCID('edit_flags'), self.OnEditFlags) wx.EVT_MENU(self, wxPython.xrc.XRCID('scan_games'), self.OnScanDir) wx.EVT_MENU(self, wxPython.xrc.XRCID('list_games'), self.OnListGames) wx.EVT_MENU(self, wxPython.xrc.XRCID('cleanup_games'), self.OnCleanupGames) wx.EVT_MENU(self, wxPython.xrc.XRCID('show_graph_of'), self.OnShowGraphOf) wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout) wx.EVT_LISTBOX_DCLICK(self, wxPython.xrc.XRCID('friends_list'), self.OnFriendsDblClick) wx.EVT_LISTBOX_DCLICK(self, wxPython.xrc.XRCID('bozo_list'), self.OnBozosDblClick) wx.EVT_LIST_ITEM_ACTIVATED(self, wxPython.xrc.XRCID('all_list'), self.OnAllDblClick) wx.EVT_LIST_ITEM_SELECTED(self, wxPython.xrc.XRCID('all_list'), self.OnAllItemSelected) wx.EVT_LIST_ITEM_RIGHT_CLICK(self, wxPython.xrc.XRCID('all_list'), self.OnAllItemRightClick) wx.EVT_CHOICE(self, wxPython.xrc.XRCID('filter_flag'), self.OnFilterFlag) # Init and load custom flag categories for i in range(0, NUMBER_CUSTOM_FLAGS): self.flag_categories.append((0, '')) self.load_edit_flags(load_config()) self.filter_choice = wxPython.xrc.XRCCTRL(self, 'filter_flag', wx.Choice) self.init_filter_choice()
def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, -1) self.Bind(wx.EVT_SIZE, self.OnSize) self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE #wx.TR_TWIST_BUTTONS #| wx.TR_ROW_LINES #| wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT # By default the style will be adjusted on # Mac to use twisty buttons and no lines. If # you would rather control this yourself then # add this style. #| wx.TR_DONT_ADJUST_MAC ) isz = (16,16) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) smileidx = il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # create some columns self.tree.AddColumn("Main column") self.tree.AddColumn("Column 1") self.tree.AddColumn("Column 2") self.tree.SetMainColumn(0) # the one with the tree in it... self.tree.SetColumnWidth(0, 175) self.root = self.tree.AddRoot("The Root Item") self.tree.SetItemText(self.root, "col 1 root", 1) self.tree.SetItemText(self.root, "col 2 root", 2) self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded) for x in range(15): txt = "Item %d" % x child = self.tree.AppendItem(self.root, txt) self.tree.SetItemText(child, txt + "(c1)", 1) self.tree.SetItemText(child, txt + "(c2)", 2) self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded) for y in range(5): txt = "item %d-%s" % (x, chr(ord("a")+y)) last = self.tree.AppendItem(child, txt) self.tree.SetItemText(last, txt + "(c1)", 1) self.tree.SetItemText(last, txt + "(c2)", 2) self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded) for z in range(5): txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z) item = self.tree.AppendItem(last, txt) self.tree.SetItemText(item, txt + "(c1)", 1) self.tree.SetItemText(item, txt + "(c2)", 2) self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected) self.tree.Expand(self.root) self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def __init__(self, parent, id, log): wx.Frame.__init__(self, parent, id, 'Playing with menus', size=(400, 200)) self.log = log self.CenterOnScreen() self.CreateStatusBar() self.SetStatusText("This is the statusbar") tc = wx.TextCtrl(self, -1, """ A bunch of bogus menus have been created for this frame. You can play around with them to see how they behave and then check the source for this sample to see how to implement them. """, style=wx.TE_READONLY | wx.TE_MULTILINE) # Prepare the menu bar menuBar = wx.MenuBar() # 1st menu from left menu1 = wx.Menu() menu1.Append(101, "&Mercury", "This the text in the Statusbar") menu1.Append(102, "&Venus", "") menu1.Append(103, "&Earth", "You may select Earth too") menu1.AppendSeparator() menu1.Append(104, "&Close", "Close this frame") # Add menu to the menu bar menuBar.Append(menu1, "&Planets") # 2nd menu from left menu2 = wx.Menu() menu2.Append(201, "Hydrogen") menu2.Append(202, "Helium") # a submenu in the 2nd menu submenu = wx.Menu() submenu.Append(2031, "Lanthanium") submenu.Append(2032, "Cerium") submenu.Append(2033, "Praseodymium") menu2.AppendMenu(203, "Lanthanides", submenu) # Append 2nd menu menuBar.Append(menu2, "&Elements") menu3 = wx.Menu() # Radio items menu3.Append(301, "IDLE", "a Python shell using tcl/tk as GUI", wx.ITEM_RADIO) menu3.Append(302, "PyCrust", "a Python shell using wxPython as GUI", wx.ITEM_RADIO) menu3.Append(303, "psi", "a simple Python shell using wxPython as GUI", wx.ITEM_RADIO) menu3.AppendSeparator() menu3.Append(304, "project1", "", wx.ITEM_NORMAL) menu3.Append(305, "project2", "", wx.ITEM_NORMAL) menuBar.Append(menu3, "&Shells") menu4 = wx.Menu() # Check menu items menu4.Append(401, "letters", "abcde...", wx.ITEM_CHECK) menu4.Append(402, "digits", "123...", wx.ITEM_CHECK) menu4.Append(403, "letters and digits", "abcd... + 123...", wx.ITEM_CHECK) menuBar.Append(menu4, "Chec&k") menu5 = wx.Menu() # Show how to put an icon in the menu item = wx.MenuItem(menu5, 500, "&Smile!\tCtrl+S", "This one has an icon") item.SetBitmap(images.getSmilesBitmap()) menu5.AppendItem(item) # Shortcuts menu5.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!") menu5.AppendSeparator() menu5.Append(502, "Hello\tShift+H") menu5.AppendSeparator() menu5.Append(503, "remove the submenu") menu6 = wx.Menu() menu6.Append(601, "Submenu Item") menu5.AppendMenu(504, "submenu", menu6) menu5.Append(505, "remove this menu") menu5.Append(506, "this is updated") menu5.Append(507, "insert after this...") menu5.Append(508, "...and before this") menuBar.Append(menu5, "&Fun") self.SetMenuBar(menuBar) # Menu events self.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.OnMenuHighlight) self.Bind(wx.EVT_MENU, self.Menu101, id=101) self.Bind(wx.EVT_MENU, self.Menu102, id=102) self.Bind(wx.EVT_MENU, self.Menu103, id=103) self.Bind(wx.EVT_MENU, self.CloseWindow, id=104) self.Bind(wx.EVT_MENU, self.Menu201, id=201) self.Bind(wx.EVT_MENU, self.Menu202, id=202) self.Bind(wx.EVT_MENU, self.Menu2031, id=2031) self.Bind(wx.EVT_MENU, self.Menu2032, id=2032) self.Bind(wx.EVT_MENU, self.Menu2033, id=2033) self.Bind(wx.EVT_MENU, self.Menu301To303, id=301) self.Bind(wx.EVT_MENU, self.Menu301To303, id=302) self.Bind(wx.EVT_MENU, self.Menu301To303, id=303) self.Bind(wx.EVT_MENU, self.Menu304, id=304) self.Bind(wx.EVT_MENU, self.Menu305, id=305) # Range of menu items self.Bind(wx.EVT_MENU_RANGE, self.Menu401To403, id=401, id2=403) self.Bind(wx.EVT_MENU, self.Menu500, id=500) self.Bind(wx.EVT_MENU, self.Menu501, id=501) self.Bind(wx.EVT_MENU, self.Menu502, id=502) self.Bind(wx.EVT_MENU, self.TestRemove, id=503) self.Bind(wx.EVT_MENU, self.TestRemove2, id=505) self.Bind(wx.EVT_MENU, self.TestInsert, id=507) self.Bind(wx.EVT_MENU, self.TestInsert, id=508) wx.GetApp().Bind(wx.EVT_UPDATE_UI, self.TestUpdateUI, id=506)
def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style) self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) self.SetLexer(stc.STC_LEX_PYTHON) self.SetKeyWords(0, " ".join(keyword.kwlist)) self.SetProperty("fold", "1") self.SetProperty("tab.timmy.whinge.level", "1") self.SetMargins(0,0) self.SetViewWhiteSpace(False) #self.SetBufferedDraw(False) #self.SetViewEOL(True) #self.SetEOLMode(stc.STC_EOL_CRLF) #self.SetUseAntiAliasing(True) self.SetEdgeMode(stc.STC_EDGE_BACKGROUND) self.SetEdgeColumn(78) # Setup a margin to hold fold markers #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER? self.SetMarginType(2, stc.STC_MARGIN_SYMBOL) self.SetMarginMask(2, stc.STC_MASK_FOLDERS) self.SetMarginSensitive(2, True) self.SetMarginWidth(2, 12) if self.fold_symbols == 0: # Arrow pointing right for contracted folders, arrow pointing down for expanded self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black"); elif self.fold_symbols == 1: # Plus for contracted folders, minus for expanded self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black"); elif self.fold_symbols == 2: # Like a flattened tree control using circular headers and curved joins self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040"); self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040"); self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040"); self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040"); self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040"); elif self.fold_symbols == 3: # Like a flattened tree control using square headers self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080") self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI) self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed) # Make some styles, The lexer defines what each style is used for, we # just have to define what each style looks like. This set is adapted from # Scintilla sample property files. # Global default styles for all languages self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) self.StyleClearAll() # Reset all to be like the default # Global default styles for all languages self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces) self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces) self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold") self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold") # Python styles # Default self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces) # Comments self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces) # Number self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces) # String self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) # Single quoted string self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) # Keyword self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces) # Triple quotes self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces) # Triple double quotes self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces) # Class name definition self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces) # Function or method name definition self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces) # Operators self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces) # Identifiers self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces) # Comment-blocks self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces) # End of line where string is not closed self.StyleSetSpec(stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces) self.SetCaretForeground("BLUE") # register some images for use in the AutoComplete box. self.RegisterImage(1, images.getSmilesBitmap()) self.RegisterImage(2, images.getFile1Bitmap()) self.RegisterImage(3, images.getCopy2Bitmap())
def __init__(self, parent, log): wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.log = log tID = wx.NewId() sizer = wx.BoxSizer(wx.VERTICAL) if wx.Platform == "__WXMAC__" and \ hasattr(wx.GetApp().GetTopWindow(), "LoadDemo"): self.useNative = wx.CheckBox(self, -1, "Use native listctrl") self.useNative.SetValue( not wx.SystemOptions.GetOptionInt("mac.listctrl.always_use_generic") ) self.Bind(wx.EVT_CHECKBOX, self.OnUseNative, self.useNative) sizer.Add(self.useNative, 0, wx.ALL | wx.ALIGN_RIGHT, 4) self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) self.list = TestListCtrl(self, tID, style=wx.LC_REPORT #| wx.BORDER_SUNKEN | wx.BORDER_NONE | wx.LC_EDIT_LABELS | wx.LC_SORT_ASCENDING #| wx.LC_NO_HEADER #| wx.LC_VRULES #| wx.LC_HRULES #| wx.LC_SINGLE_SEL ) self.list.SetImageList(self.il, wx.IMAGE_LIST_SMALL) sizer.Add(self.list, 1, wx.EXPAND) self.PopulateList() # Now that the list exists we can init the other base class, # see wx/lib/mixins/listctrl.py self.itemDataMap = musicdata listmix.ColumnSorterMixin.__init__(self, 3) #self.SortListItems(0, True) self.SetSizer(sizer) self.SetAutoLayout(True) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.list) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.list) self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.list) self.Bind(wx.EVT_LIST_DELETE_ITEM, self.OnItemDelete, self.list) self.Bind(wx.EVT_LIST_COL_CLICK, self.OnColClick, self.list) self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.OnColRightClick, self.list) self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.OnColBeginDrag, self.list) self.Bind(wx.EVT_LIST_COL_DRAGGING, self.OnColDragging, self.list) self.Bind(wx.EVT_LIST_COL_END_DRAG, self.OnColEndDrag, self.list) self.Bind(wx.EVT_LIST_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.list) self.list.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) self.list.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) # for wxMSW self.list.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick) # for wxGTK self.list.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
def __init__(self, parent, id, log): wx.Frame.__init__(self, parent, id, 'Playing with menus', size=(400, 200)) self.log = log self.CenterOnScreen() self.CreateStatusBar() self.SetStatusText("This is the statusbar") tc = wx.TextCtrl(self, -1, """ A bunch of bogus menus have been created for this frame. You can play around with them to see how they behave and then check the source for this sample to see how to implement them. """, style=wx.TE_READONLY|wx.TE_MULTILINE) # Prepare the menu bar menuBar = wx.MenuBar() # 1st menu from left menu1 = wx.Menu() menu1.Append(101, "&Mercury", "This the text in the Statusbar") menu1.Append(102, "&Venus", "") menu1.Append(103, "&Earth", "You may select Earth too") menu1.AppendSeparator() menu1.Append(104, "&Close", "Close this frame") # Add menu to the menu bar menuBar.Append(menu1, "&Planets") # 2nd menu from left menu2 = wx.Menu() menu2.Append(201, "Hydrogen") menu2.Append(202, "Helium") # a submenu in the 2nd menu submenu = wx.Menu() submenu.Append(2031,"Lanthanium") submenu.Append(2032,"Cerium") submenu.Append(2033,"Praseodymium") menu2.AppendMenu(203, "Lanthanides", submenu) # Append 2nd menu menuBar.Append(menu2, "&Elements") menu3 = wx.Menu() # Radio items menu3.Append(301, "IDLE", "a Python shell using tcl/tk as GUI", wx.ITEM_RADIO) menu3.Append(302, "PyCrust", "a Python shell using wxPython as GUI", wx.ITEM_RADIO) menu3.Append(303, "psi", "a simple Python shell using wxPython as GUI", wx.ITEM_RADIO) menu3.AppendSeparator() menu3.Append(304, "project1", "", wx.ITEM_NORMAL) menu3.Append(305, "project2", "", wx.ITEM_NORMAL) menuBar.Append(menu3, "&Shells") menu4 = wx.Menu() # Check menu items menu4.Append(401, "letters", "abcde...", wx.ITEM_CHECK) menu4.Append(402, "digits", "123...", wx.ITEM_CHECK) menu4.Append(403, "letters and digits", "abcd... + 123...", wx.ITEM_CHECK) menuBar.Append(menu4, "Chec&k") menu5 = wx.Menu() # Show how to put an icon in the menu item = wx.MenuItem(menu5, 500, "&Smile!\tCtrl+S", "This one has an icon") item.SetBitmap(images.getSmilesBitmap()) menu5.AppendItem(item) # Shortcuts menu5.Append(501, "Interesting thing\tCtrl+A", "Note the shortcut!") menu5.AppendSeparator() menu5.Append(502, "Hello\tShift+H") menu5.AppendSeparator() menu5.Append(503, "remove the submenu") menu6 = wx.Menu() menu6.Append(601, "Submenu Item") menu5.AppendMenu(504, "submenu", menu6) menu5.Append(505, "remove this menu") menu5.Append(506, "this is updated") menu5.Append(507, "insert after this...") menu5.Append(508, "...and before this") menuBar.Append(menu5, "&Fun") self.SetMenuBar(menuBar) # Menu events self.Bind(wx.EVT_MENU_HIGHLIGHT_ALL, self.OnMenuHighlight) self.Bind(wx.EVT_MENU, self.Menu101, id=101) self.Bind(wx.EVT_MENU, self.Menu102, id=102) self.Bind(wx.EVT_MENU, self.Menu103, id=103) self.Bind(wx.EVT_MENU, self.CloseWindow, id=104) self.Bind(wx.EVT_MENU, self.Menu201, id=201) self.Bind(wx.EVT_MENU, self.Menu202, id=202) self.Bind(wx.EVT_MENU, self.Menu2031, id=2031) self.Bind(wx.EVT_MENU, self.Menu2032, id=2032) self.Bind(wx.EVT_MENU, self.Menu2033, id=2033) self.Bind(wx.EVT_MENU, self.Menu301To303, id=301) self.Bind(wx.EVT_MENU, self.Menu301To303, id=302) self.Bind(wx.EVT_MENU, self.Menu301To303, id=303) self.Bind(wx.EVT_MENU, self.Menu304, id=304) self.Bind(wx.EVT_MENU, self.Menu305, id=305) # Range of menu items self.Bind(wx.EVT_MENU_RANGE, self.Menu401To403, id=401, id2=403) self.Bind(wx.EVT_MENU, self.Menu500, id=500) self.Bind(wx.EVT_MENU, self.Menu501, id=501) self.Bind(wx.EVT_MENU, self.Menu502, id=502) self.Bind(wx.EVT_MENU, self.TestRemove, id=503) self.Bind(wx.EVT_MENU, self.TestRemove2, id=505) self.Bind(wx.EVT_MENU, self.TestInsert, id=507) self.Bind(wx.EVT_MENU, self.TestInsert, id=508) wx.GetApp().Bind(wx.EVT_UPDATE_UI, self.TestUpdateUI, id=506)
def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, -1) self.Bind(wx.EVT_SIZE, self.OnSize) self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE #wx.TR_TWIST_BUTTONS #| wx.TR_ROW_LINES #| wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT # By default the style will be adjusted on # Mac to use twisty buttons and no lines. If # you would rather control this yourself then # add this style. #| wx.TR_DONT_ADJUST_MAC ) isz = (16,16) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz)) smileidx = il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # create some columns self.tree.AddColumn("Main column") self.tree.AddColumn("Column 1") self.tree.AddColumn("Column 2") self.tree.SetMainColumn(0) # the one with the tree in it... self.tree.SetColumnWidth(0, 175) self.root = self.tree.AddRoot("The Root Item") self.tree.SetItemText(self.root, "col 1 root", 1) self.tree.SetItemText(self.root, "col 2 root", 2) self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded) for x in range(15): txt = "Item %d" % x child = self.tree.AppendItem(self.root, txt) self.tree.SetItemText(child, txt + "(c1)", 1) self.tree.SetItemText(child, txt + "(c2)", 2) self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded) for y in range(5): txt = "item %d-%s" % (x, chr(ord("a")+y)) last = self.tree.AppendItem(child, txt) self.tree.SetItemText(last, txt + "(c1)", 1) self.tree.SetItemText(last, txt + "(c2)", 2) self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded) for z in range(5): txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z) item = self.tree.AppendItem(last, txt) self.tree.SetItemText(item, txt + "(c1)", 1) self.tree.SetItemText(item, txt + "(c2)", 2) self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected) self.tree.Expand(self.root) self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def __init__(self, parent, id, title): # the setting need to keep self.dirname = "" self.flnm = "" self.tracerinfo = "/geos/u23/enkf_std/diaginfo.dat" self.diaginfo = "/geos/u23/enkf_std/tracerinfo.dat" self.bpdata_list = None self.ifig = 0 try: deffile = open(default_setting_file, 'r') lines = deffile.readlines() deffile.close() for line in lines: if 'DIR:' in line: terms = line.split() self.dirname = terms[1].strip() elif 'FLNM' in line: terms = line.split() self.flnm = terms[1].strip() elif ('TRACERINFO:' in line): terms = line.split() self.tracerinfo = terms[1].strip() elif ('DIAGINFO:' in line): terms = line.split() self.diaginfo = terms[1].strip() except IOError: self.dirname = "/geos/u23/enkf_std/enkf_output/" self.flnm = "restart.EN0001-EN0024.20030101" self.fullname = self.dirname + self.flnm self.tracerinfo = "/geos/u23/enkf_std/enkf_output/diaginfo.EN0001-EN0024.dat" self.diaginfo = "/geos/u23/enkf_std/enkf_output/tracerinfo.EN0001-EN0024.dat" if (self.dirname in self.flnm): self.fullname = self.flnm else: self.fullname = self.dirname + '/' + self.flnm wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(880, 800)) # self.control=wx.TextCtrl(self, 1, style=wx.TE_MULTILINE) self.CreateStatusBar() filemenu = wx.Menu() filemenu.Append(ID_LOAD, "&Load", "Load BPCH2 FILE") filemenu.Append(ID_SAVE_SETTING, "&Save Setting", "Save Current Settings") filemenu.AppendSeparator() filemenu.Append(ID_EXIT, "E&xit", "Terminate the program") setmenu = wx.Menu() setmenu.Append(ID_SET, "Ch&oose Info", "Set Tracer & Diag Info files") helpmenu = wx.Menu() helpmenu.Append(ID_ABOUT, "&About", "About wx BPCH dump") menuBar = wx.MenuBar() menuBar.Append(filemenu, "&File") menuBar.Append(setmenu, "&Configure") menuBar.Append(helpmenu, "&Help") wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) wx.EVT_MENU(self, ID_EXIT, self.OnExit) wx.EVT_MENU(self, ID_LOAD, self.OnLoad) wx.EVT_MENU(self, ID_SAVE_SETTING, self.OnSaveSetting) wx.EVT_MENU(self, ID_SET, self.OnSet) self.SetMenuBar(menuBar) # set up the list box self.il = wx.ImageList(16, 16) self.idx1 = self.il.Add(images.getSmilesBitmap()) self.sm_up = self.il.Add(images.getSmallUpArrowBitmap()) self.sm_dn = self.il.Add(images.getSmallDnArrowBitmap()) bmp_browse = wx.Bitmap('/geos/u23/enkf_std/minus4.ico') panel_w = wx.Panel(self, -1) vbox = wx.BoxSizer(wx.VERTICAL) panel_file = wx.Panel(panel_w, -1) hbox1 = wx.BoxSizer(wx.HORIZONTAL) label_file = wx.StaticText(panel_file, -1, 'File Name:') hbox1.Add(label_file, 0, wx.ALL | wx.ALIGN_RIGHT, 10) self.text_file = wx.TextCtrl(panel_file, -1, size=(-1, 30)) self.text_file.SetValue(self.fullname) hbox1.Add( self.text_file, 1, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_CENTRE_HORIZONTAL | wx.EXPAND, 10) self.browsebtn = wx.BitmapButton(panel_file, ID_BROWSE, bmp_browse, size=(30, 30)) self.Bind(wx.EVT_BUTTON, self.OnClick_Browse, self.browsebtn) hbox1.Add(self.browsebtn, 0, wx.RIGHT | wx.TOP | wx.BOTTOM | wx.ALIGN_RIGHT, 10) self.loadbtn = wx.Button(panel_file, ID_LOAD, "Load", size=(60, 30)) hbox1.Add(self.loadbtn, 0, wx.ALL, 10) self.Bind(wx.EVT_BUTTON, self.OnLoad, self.loadbtn) panel_file.SetSizer(hbox1) vbox.Add(panel_file, 0, wx.ALL | wx.EXPAND, 1) panel_list = wx.Panel(panel_w, -1) self.infolist = wx.ListCtrl(panel_list, -1, style=wx.LC_REPORT) self.currentItem = -1 self.infolist.SetImageList(self.il, wx.IMAGE_LIST_SMALL) self.infolist.InsertColumn(0, 'No') self.infolist.InsertColumn(1, 'Category') self.infolist.InsertColumn(2, 'Name') self.infolist.InsertColumn(3, 'Unit') self.infolist.InsertColumn(4, 'TAU0') self.infolist.InsertColumn(5, 'TAU1') self.infolist.InsertColumn(6, 'NX') self.infolist.InsertColumn(7, 'NY') self.infolist.InsertColumn(8, 'NZ') self.infolist.InsertColumn(9, 'Max') self.infolist.InsertColumn(10, 'Min') self.infolist.SetColumnWidth(0, 80) self.infolist.SetColumnWidth(1, 80) self.infolist.SetColumnWidth(2, 80) self.infolist.SetColumnWidth(3, 80) self.infolist.SetColumnWidth(4, 100) self.infolist.SetColumnWidth(5, 100) self.infolist.SetColumnWidth(6, 40) self.infolist.SetColumnWidth(7, 40) self.infolist.SetColumnWidth(8, 40) self.infolist.SetColumnWidth(9, 120) self.infolist.SetColumnWidth(10, 120) self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemSelected, self.infolist) self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self.OnItemDeselected, self.infolist) # self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnItemActivated, self.infolist) self.infolist.Bind(wx.EVT_LEFT_DCLICK, self.OnDoubleClick) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.infolist, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 1) sizer.Add((-1, 5)) panel_list.SetSizer(sizer) vbox.Add(panel_list, 1, wx.ALL | wx.EXPAND | wx.ALIGN_CENTER_VERTICAL, 5) panel_vals = wx.Panel(panel_w, -1) hbox = wx.BoxSizer(wx.HORIZONTAL) label_x = wx.StaticText(panel_vals, -1, 'IX:', size=(30, 30)) hbox.Add(label_x, 0, wx.ALL | wx.ALIGN_RIGHT, 10) self.text_x = wx.TextCtrl(panel_vals, -1, style=wx.TE_PROCESS_ENTER, size=(-1, 30)) hbox.Add(self.text_x, 1, wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND, 10) self.text_x.SetValue('0') self.text_x.Enable(False) self.text_x.Bind(wx.EVT_TEXT_ENTER, self.EvtTextEnter_x) self.text_x.Bind(wx.EVT_KILL_FOCUS, self.EvtTextKillFocus_x) label_y = wx.StaticText(panel_vals, -1, 'IY:', size=(30, 30)) hbox.Add(label_y, 0, wx.ALL | wx.ALIGN_RIGHT, 10) self.text_y = wx.TextCtrl(panel_vals, -1, style=wx.TE_PROCESS_ENTER, size=(-1, 30)) hbox.Add(self.text_y, 1, wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND, 10) self.text_y.SetValue('0') self.text_y.Enable(False) self.Bind(wx.EVT_TEXT_ENTER, self.EvtTextEnter_y, self.text_y) self.text_y.Bind(wx.EVT_KILL_FOCUS, self.EvtTextKillFocus_y) label_z = wx.StaticText(panel_vals, -1, 'IZ:', size=(30, 30)) hbox.Add(label_z, 0, wx.ALL | wx.ALIGN_RIGHT, 10) self.text_z = wx.TextCtrl(panel_vals, -1, style=wx.TE_PROCESS_ENTER, size=(-1, 30)) hbox.Add(self.text_z, 1, wx.ALL | wx.ALIGN_RIGHT | wx.EXPAND, 10) self.text_z.SetValue('0') self.text_z.Enable(False) self.Bind(wx.EVT_TEXT_ENTER, self.EvtTextEnter_z, self.text_z) self.text_z.Bind(wx.EVT_KILL_FOCUS, self.EvtTextKillFocus_z) label_v = wx.StaticText(panel_vals, -1, 'VAL:', size=(60, 30)) hbox.Add(label_v, 0, wx.ALL | wx.ALIGN_LEFT, 10) self.text_v = wx.TextCtrl(panel_vals, -1, size=(-1, 30)) hbox.Add(self.text_v, 1, wx.ALL | wx.ALIGN_LEFT | wx.EXPAND, 10) self.text_v.Enable(False) self.ix, self.iy, self.iz = 0, 0, 0 panel_vals.SetSizer(hbox) # panel python # vbox.Add(panel_vals, 0, wx.ALL | wx.EXPAND, 1) self.err_on = False self.panel_cmd = wx.Panel(panel_w, -1) # locals={'cur_l':cur_l, 'test_d':test_d} # self.myshell=pysh.shell.Shell(self.panel_cmd, -1,locals=locals, size=(850, 300)) # help(self.myshell) self.myshell = pysh.shell.Shell(self.panel_cmd, -1, size=(850, 300)) # vbox.Add(self.panel_cmd, 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTRE_HORIZONTAL, 10) # vbox.Add(self.panel_cmd, 1, wx.ALL|wx.EXPAND|wx.ALIGN_CENTRE_HORIZONTAL, 10) vbox.Add(self.panel_cmd, 0, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_LEFT, 10) vbox.Add((-1, 5)) panel_w.SetSizer(vbox) # panel list self.Centre() self.Show(True)
def __init__(self, parent, log): # Use the WANTS_CHARS style so the panel doesn't eat the Return key. wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.Bind(wx.EVT_SIZE, self.OnSize) self.log = log 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 , self.log) isz = (16,16) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_REPORT_VIEW, wx.ART_OTHER, isz)) smileidx = il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # NOTE: For some reason tree items have to have a data object in # order to be sorted. Since our compare just uses the labels # we don't need any real data, so we'll just use None below for # the item data. self.root = self.tree.AddRoot("The Root Item") self.tree.SetPyData(self.root, None) self.tree.SetItemImage(self.root, fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, fldropenidx, wx.TreeItemIcon_Expanded) for x in range(15): child = self.tree.AppendItem(self.root, "Item %d" % x) self.tree.SetPyData(child, None) self.tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded) for y in range(5): last = self.tree.AppendItem(child, "item %d-%s" % (x, chr(ord("a")+y))) self.tree.SetPyData(last, None) self.tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded) for z in range(5): item = self.tree.AppendItem(last, "item %d-%s-%d" % (x, chr(ord("a")+y), z)) self.tree.SetPyData(item, None) self.tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(item, smileidx, wx.TreeItemIcon_Selected) self.tree.Expand(self.root) self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree) self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.tree) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndEdit, self.tree) self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate, self.tree) self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightClick) self.tree.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def __init__(self, parent, log): self.log = log wx.Panel.__init__(self, parent, -1) self.Bind(wx.EVT_SIZE, self.OnSize) self.tree = gizmos.TreeListCtrl(self, -1, style = wx.TR_DEFAULT_STYLE #| wx.TR_HAS_BUTTONS #| wx.TR_TWIST_BUTTONS #| wx.TR_ROW_LINES #| wx.TR_COLUMN_LINES #| wx.TR_NO_LINES | wx.TR_FULL_ROW_HIGHLIGHT ) isz = (16,16) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add(wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) smileidx = il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # create some columns self.tree.AddColumn("Main column") self.tree.AddColumn("Column 1") self.tree.AddColumn("Column 2") self.tree.SetMainColumn(0) # the one with the tree in it... self.tree.SetColumnWidth(0, 175) self.root = self.tree.AddRoot("The Root Item") self.tree.SetItemText(self.root, "col 1 root", 1) self.tree.SetItemText(self.root, "col 2 root", 2) self.tree.SetItemImage(self.root, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, fldropenidx, which = wx.TreeItemIcon_Expanded) for x in range(15): txt = "Item %d" % x child = self.tree.AppendItem(self.root, txt) self.tree.SetItemText(child, txt + "(c1)", 1) self.tree.SetItemText(child, txt + "(c2)", 2) self.tree.SetItemImage(child, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(child, fldropenidx, which = wx.TreeItemIcon_Expanded) for y in range(5): txt = "item %d-%s" % (x, chr(ord("a")+y)) last = self.tree.AppendItem(child, txt) self.tree.SetItemText(last, txt + "(c1)", 1) self.tree.SetItemText(last, txt + "(c2)", 2) self.tree.SetItemImage(last, fldridx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(last, fldropenidx, which = wx.TreeItemIcon_Expanded) for z in range(5): txt = "item %d-%s-%d" % (x, chr(ord("a")+y), z) item = self.tree.AppendItem(last, txt) self.tree.SetItemText(item, txt + "(c1)", 1) self.tree.SetItemText(item, txt + "(c2)", 2) self.tree.SetItemImage(item, fileidx, which = wx.TreeItemIcon_Normal) self.tree.SetItemImage(item, smileidx, which = wx.TreeItemIcon_Selected) self.tree.Expand(self.root) self.tree.GetMainWindow().Bind(wx.EVT_RIGHT_UP, self.OnRightUp) self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate)
def __init__(self, parent, log): # Use the WANTS_CHARS style so the panel doesn't eat the Return key. wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS) self.Bind(wx.EVT_SIZE, self.OnSize) self.log = log 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 , self.log) isz = (16, 16) il = wx.ImageList(isz[0], isz[1]) fldridx = il.Add( wx.ArtProvider_GetBitmap(wx.ART_FOLDER, wx.ART_OTHER, isz)) fldropenidx = il.Add( wx.ArtProvider_GetBitmap(wx.ART_FILE_OPEN, wx.ART_OTHER, isz)) fileidx = il.Add( wx.ArtProvider_GetBitmap(wx.ART_NORMAL_FILE, wx.ART_OTHER, isz)) smileidx = il.Add(images.getSmilesBitmap()) self.tree.SetImageList(il) self.il = il # NOTE: For some reason tree items have to have a data object in # order to be sorted. Since our compare just uses the labels # we don't need any real data, so we'll just use None below for # the item data. self.root = self.tree.AddRoot("The Root Item") self.tree.SetPyData(self.root, None) self.tree.SetItemImage(self.root, fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(self.root, fldropenidx, wx.TreeItemIcon_Expanded) for x in range(15): child = self.tree.AppendItem(self.root, "Item %d" % x) self.tree.SetPyData(child, None) self.tree.SetItemImage(child, fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(child, fldropenidx, wx.TreeItemIcon_Expanded) for y in range(5): last = self.tree.AppendItem( child, "item %d-%s" % (x, chr(ord("a") + y))) self.tree.SetPyData(last, None) self.tree.SetItemImage(last, fldridx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(last, fldropenidx, wx.TreeItemIcon_Expanded) for z in range(5): item = self.tree.AppendItem( last, "item %d-%s-%d" % (x, chr(ord("a") + y), z)) self.tree.SetPyData(item, None) self.tree.SetItemImage(item, fileidx, wx.TreeItemIcon_Normal) self.tree.SetItemImage(item, smileidx, wx.TreeItemIcon_Selected) self.tree.Expand(self.root) self.Bind(wx.EVT_TREE_ITEM_EXPANDED, self.OnItemExpanded, self.tree) self.Bind(wx.EVT_TREE_ITEM_COLLAPSED, self.OnItemCollapsed, self.tree) self.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, self.tree) self.Bind(wx.EVT_TREE_BEGIN_LABEL_EDIT, self.OnBeginEdit, self.tree) self.Bind(wx.EVT_TREE_END_LABEL_EDIT, self.OnEndEdit, self.tree) self.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnActivate, self.tree) self.tree.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick) self.tree.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown) self.tree.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
def __init__(self, parent, ID, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0): stc.StyledTextCtrl.__init__(self, parent, ID, pos, size, style) self.CmdKeyAssign(ord('B'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMIN) self.CmdKeyAssign(ord('N'), stc.STC_SCMOD_CTRL, stc.STC_CMD_ZOOMOUT) self.SetLexer(stc.STC_LEX_PYTHON) self.SetKeyWords(0, " ".join(keyword.kwlist)) self.SetProperty("fold", "1") self.SetProperty("tab.timmy.whinge.level", "1") self.SetMargins(0, 0) self.SetViewWhiteSpace(False) #self.SetBufferedDraw(False) #self.SetViewEOL(True) #self.SetEOLMode(stc.STC_EOL_CRLF) #self.SetUseAntiAliasing(True) self.SetEdgeMode(stc.STC_EDGE_BACKGROUND) self.SetEdgeColumn(78) # Setup a margin to hold fold markers #self.SetFoldFlags(16) ### WHAT IS THIS VALUE? WHAT ARE THE OTHER FLAGS? DOES IT MATTER? self.SetMarginType(2, stc.STC_MARGIN_SYMBOL) self.SetMarginMask(2, stc.STC_MASK_FOLDERS) self.SetMarginSensitive(2, True) self.SetMarginWidth(2, 12) if self.fold_symbols == 0: # Arrow pointing right for contracted folders, arrow pointing down for expanded self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_ARROWDOWN, "black", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_ARROW, "black", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "black", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "black", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black") elif self.fold_symbols == 1: # Plus for contracted folders, minus for expanded self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_MINUS, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_PLUS, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_EMPTY, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_EMPTY, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_EMPTY, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_EMPTY, "white", "black") self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_EMPTY, "white", "black") elif self.fold_symbols == 2: # Like a flattened tree control using circular headers and curved joins self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_CIRCLEMINUS, "white", "#404040") self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_CIRCLEPLUS, "white", "#404040") self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#404040") self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNERCURVE, "white", "#404040") self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_CIRCLEPLUSCONNECTED, "white", "#404040") self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_CIRCLEMINUSCONNECTED, "white", "#404040") self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNERCURVE, "white", "#404040") elif self.fold_symbols == 3: # Like a flattened tree control using square headers self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPEN, stc.STC_MARK_BOXMINUS, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDER, stc.STC_MARK_BOXPLUS, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDERSUB, stc.STC_MARK_VLINE, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDERTAIL, stc.STC_MARK_LCORNER, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDEREND, stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDEROPENMID, stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080") self.MarkerDefine(stc.STC_MARKNUM_FOLDERMIDTAIL, stc.STC_MARK_TCORNER, "white", "#808080") self.Bind(stc.EVT_STC_UPDATEUI, self.OnUpdateUI) self.Bind(stc.EVT_STC_MARGINCLICK, self.OnMarginClick) self.Bind(wx.EVT_KEY_DOWN, self.OnKeyPressed) # Make some styles, The lexer defines what each style is used for, we # just have to define what each style looks like. This set is adapted from # Scintilla sample property files. # Global default styles for all languages self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) self.StyleClearAll() # Reset all to be like the default # Global default styles for all languages self.StyleSetSpec(stc.STC_STYLE_DEFAULT, "face:%(helv)s,size:%(size)d" % faces) self.StyleSetSpec(stc.STC_STYLE_LINENUMBER, "back:#C0C0C0,face:%(helv)s,size:%(size2)d" % faces) self.StyleSetSpec(stc.STC_STYLE_CONTROLCHAR, "face:%(other)s" % faces) self.StyleSetSpec(stc.STC_STYLE_BRACELIGHT, "fore:#FFFFFF,back:#0000FF,bold") self.StyleSetSpec(stc.STC_STYLE_BRACEBAD, "fore:#000000,back:#FF0000,bold") # Python styles # Default self.StyleSetSpec(stc.STC_P_DEFAULT, "fore:#000000,face:%(helv)s,size:%(size)d" % faces) # Comments self.StyleSetSpec(stc.STC_P_COMMENTLINE, "fore:#007F00,face:%(other)s,size:%(size)d" % faces) # Number self.StyleSetSpec(stc.STC_P_NUMBER, "fore:#007F7F,size:%(size)d" % faces) # String self.StyleSetSpec(stc.STC_P_STRING, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) # Single quoted string self.StyleSetSpec(stc.STC_P_CHARACTER, "fore:#7F007F,face:%(helv)s,size:%(size)d" % faces) # Keyword self.StyleSetSpec(stc.STC_P_WORD, "fore:#00007F,bold,size:%(size)d" % faces) # Triple quotes self.StyleSetSpec(stc.STC_P_TRIPLE, "fore:#7F0000,size:%(size)d" % faces) # Triple double quotes self.StyleSetSpec(stc.STC_P_TRIPLEDOUBLE, "fore:#7F0000,size:%(size)d" % faces) # Class name definition self.StyleSetSpec(stc.STC_P_CLASSNAME, "fore:#0000FF,bold,underline,size:%(size)d" % faces) # Function or method name definition self.StyleSetSpec(stc.STC_P_DEFNAME, "fore:#007F7F,bold,size:%(size)d" % faces) # Operators self.StyleSetSpec(stc.STC_P_OPERATOR, "bold,size:%(size)d" % faces) # Identifiers self.StyleSetSpec(stc.STC_P_IDENTIFIER, "fore:#000000,face:%(helv)s,size:%(size)d" % faces) # Comment-blocks self.StyleSetSpec(stc.STC_P_COMMENTBLOCK, "fore:#7F7F7F,size:%(size)d" % faces) # End of line where string is not closed self.StyleSetSpec( stc.STC_P_STRINGEOL, "fore:#000000,face:%(mono)s,back:#E0C0E0,eol,size:%(size)d" % faces) self.SetCaretForeground("BLUE") # register some images for use in the AutoComplete box. self.RegisterImage(1, images.getSmilesBitmap()) self.RegisterImage(2, wx.ArtProvider.GetBitmap(wx.ART_NEW, size=(16, 16))) self.RegisterImage( 3, wx.ArtProvider.GetBitmap(wx.ART_COPY, size=(16, 16)))