def __init__(self, parent, id=-1, value="", pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, search_func=None, cancel_func=None): # wx.TE_PROCESS_ENTER is required for # EVT_TEXT_ENTER event to work. style |= wx.TE_PROCESS_ENTER wx.SearchCtrl.__init__(self, parent, id, value, pos, size, style) self.ShowCancelButton(True) self.SetCancelBitmap(fpwx.wxbmp("clear")) self.Bind(wx.EVT_TEXT_ENTER, self.OnTextEntered) self.Bind(wx.EVT_MENU_RANGE, self.OnMenuItem, id=1, id2=self.max_searches) self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.on_cancel) ## Callbacks self.do_search_func = search_func self.do_clear_func = cancel_func ## History self.searches = []
def __init__(self, parent, startdir): wx.GenericDirCtrl.__init__(self, parent, -1, dir=startdir, style=wx.DIRCTRL_DIR_ONLY) self.treectrl = self.GetTreeCtrl() self.SelectPath(startdir, True) # create the image list: isz = (16, 16) il = wx.ImageList(isz[0], isz[1]) # Add images to list. You need to keep this exact order for # this to work! # Dec 2017: Added item # 7, the little eye icon. bmplst = [ 'icon_closed_folder', 'icon_open_folder', 'icon_root', 'icon_drive', 'icon_cdrom', 'icon_ext_drive', 'icon_ext_drive', 'view16x16' ] [il.Add(fpwx.wxbmp(f)) for f in bmplst] # assign image list: self.il = il self.treectrl.SetImageList(il) # Set the initial icon sid = self.treectrl.GetSelection() self._set_icon(sid) # I can't get it to scroll to the selected dir ## Sept 2017 ## Trying to ensure the tree is scrolled to the start dir. No go so far. #s = self.tree.GetSelection() #print s #print dir(s) #import pdb; pdb.set_trace() #self.tree.EnsureVisible(s) #self.tree.ScrollTo(s) #self.treectrl.ScrollTo(sid), etc. self.treectrl.Bind(wx.EVT_TREE_SEL_CHANGED, self.__OnThing)
def __init__(self, parent, title): ## Draw the frame title = u"{} - {}".format(title, locale.getpreferredencoding()) wx.Frame.__init__(self, parent, -1, title, fpsys.config.pos, fpsys.config.size, name="fontypython") #print "Main frame:", self.GetSizeTuple()[0] ## Try to show an icon ## Oct 2017: Seems Unity (at least) doesn't even bother... try: i = wx.EmptyIcon() i.CopyFromBitmap(fpwx.wxbmp('fplogo')) self.SetIcon(i) except: pass ## STATUS BAR ## --------------------------------------- self.sb = StatusBar(self) self.SetStatusBar(self.sb) ## MENUS ## --------------------------------------- # tools selection help self.menuBar = wx.MenuBar() ## FILE MENU : Changed to "Tools" menu Sep 2009 menu1 = wx.Menu() menu1.Append(id_from_flag[flag_settings], _("&Settings\tCtrl+S"), _("Change settings")) ## Jan 18 2008 ## Nov 2017: retired: menu1.Append( 102, ## _("&Check fonts"), _("Find those fonts that crash Fonty.") ) self.id_purge = wx.NewId() menu1.Append( self.id_purge, _("&Purge Pog.See TogglePurgeMenuItem for actual string."), _("Remove all ghost fonts from the selected Pog.")) self.MENUPURGE = menu1 ## Nov 2017: Hush fonts menu1.Append( id_from_flag[flag_hush_fonts], _("&Hush fonts\tCtrl+H"), _("Silence all the noisy system fonts and focus only on those you want," )) menu1.AppendSeparator() self.id_exit = wx.NewId() self.exit = menu1.Append(self.id_exit, _("&Exit"), _("Close the app")) ## Tools self.menuBar.Append(menu1, _("&Tools")) ## SELECT MENU: June 2009 menu3 = wx.Menu() self.id_selall = wx.NewId() menu3.Append( self.id_selall, _("&Select ALL the source fonts"), _("Select ABSOLUTELY ALL the fonts in the chosen source.")) self.id_selnone = wx.NewId() menu3.Append(self.id_selnone, _("&Clear ENTIRE selection"), _("Clear the selection completely.")) self.menuBar.Append(menu3, _("&Selection")) self.MENUSELECTION = menu3 ## HELP MENU menu2 = wx.Menu() menu2.Append(id_from_flag[flag_help], _("H&elp\tF1")) menu2.Append(id_from_flag[flag_about], _("&About")) self.menuBar.Append(menu2, _("&Help")) self.SetMenuBar(self.menuBar) ## Setup the ESC key and the LEFT / RIGHT keys escape_key_id = wx.NewId() # Get a unique id for the ESC key accel = wx.AcceleratorTable([ (wx.ACCEL_NORMAL, wx.WXK_ESCAPE, escape_key_id), # use ESC id here (wx.ACCEL_CTRL, wx.WXK_RIGHT, wx.ID_FORWARD), (wx.ACCEL_CTRL, wx.WXK_LEFT, wx.ID_BACKWARD) ]) self.SetAcceleratorTable(accel) ## Do this generic bind for all MENU EVENTS now. ## Then specific ones afterwards; else this one supercedes them. ## This is for the menus that open DismissablePanels: ## Help, About, Settings self.Bind(wx.EVT_MENU, self.toggle_dismissable_panel) ## Bind the Left and Right key shortcuts. self.Bind(wx.EVT_MENU, self.OnAccelKey, id=wx.ID_FORWARD) self.Bind(wx.EVT_MENU, self.OnAccelKey, id=wx.ID_BACKWARD) ## The frame's close window button. self.Bind(wx.EVT_CLOSE, self.endApp) ## Bind events for the exit menu self.Bind(wx.EVT_MENU, self.endApp, self.exit) ## Bind the ESCAPE key self.Bind(wx.EVT_MENU, self.onHandleESC, id=escape_key_id) # And ESC id here! #NOV 2017: Retiring this menu #I think PILLOW is more stable and I don't want to support the #extra code for the gui of this. The command line already does #a good job (-c) and my crash dialogue tells the user what to do. ##self.Bind(wx.EVT_MENU, self.menuCheckFonts, id = 102 ) self.Bind(wx.EVT_MENU, self.menuPurgePog, id=self.id_purge) # June 2009 self.Bind(wx.EVT_MENU, self.menuSelectionALL, id=self.id_selall) self.Bind(wx.EVT_MENU, self.menuSelectionNONE, id=self.id_selnone) ## Catch buttons in various panels. The panels have not been ## declared yet. See below. ## NB: THESE BINDS HAPPEN SECOND, *AFTER* toggle_dismissable_panel ## has Skipped. ## The first Bind EVT_BUTTON is last in the code, see just below. ## 1. .toggle_dismissable_panel --> Does a Skip() to ## 2. Here: ## Catch the Apply button in the settings panel. self.Bind(wx.EVT_BUTTON, self.apply_settings, id=wx.ID_APPLY) ## Catch the Zip button in the choose_zipdir_panel self.Bind(wx.EVT_BUTTON, self.do_pog_zip, id=button_ids['id_do_the_actual_zip']) ## Catch the Huch button in hush_panel self.Bind(wx.EVT_BUTTON, self.do_hush_unhush, id=button_ids['id_hush_button']) ## Vague Bind. Not specific to id. ## HAPPENS FIRST even though it's last in the code. ## 1. The close (X) button of the DismissablePanels ## 2. The ZIP button (Skipped to here from TargetPogChooser) self.Bind(wx.EVT_BUTTON, self.toggle_dismissable_panel) ## THE MAIN GUI ## ------------------------------------------------------------------ MINSCREENWIDTH = 800 #old skool minw = 360 # pretty much the width of the left hand side. fvminw = MINSCREENWIDTH - minw # The width of the rhs. ms = wx.Size(minw, 1) ## PRIMARY GUI ## =========== ## No splitters at all. ## Box across: two ## Left box: Box vertical: two (source/target) ## Right box: Fontview ## :- kind of shape. self.panelFontSources = FontSourcesPanel(self) self.panelFontSources.SetMinSize(ms) self.panelTargetPogChooser = TargetPogChooser( self, button_ids['id_zip_pog_button']) self.panelTargetPogChooser.SetMinSize(ms) self.fontViewPanel = FontViewPanel(self) self.fontViewPanel.SetMinSize(wx.Size(fvminw, 1)) ## Oct/Nov 2017 ## Moved some dialogues into the app as panels: ## Help self.help_panel = HelpPanel(self) #self.help_panel.Hide() ## About self.about_panel = AboutPanel(self) #self.about_panel.Hide() ## I will use fontViewPanel as the standard to ## measure widths in these DismissablePanels wfunc = self.fontViewPanel.GetSize ## The Settings self.settings_panel = SettingsPanel(self, wfunc) #self.settings_panel.Hide() ## Zip Pog panel self.choose_zipdir_panel = ChooseZipDirPanel(self, wfunc) #self.choose_zipdir_panel.Hide() ## Hush panel self.hush_panel = HushPanel(self, wfunc) stsizer = wx.BoxSizer(wx.VERTICAL) stsizer.Add(self.panelFontSources, 1, wx.EXPAND | wx.ALL, border=5) stsizer.Add(self.panelTargetPogChooser, 1, wx.EXPAND | wx.ALL, border=5) lrsizer = wx.BoxSizer(wx.HORIZONTAL) lrsizer.Add(stsizer, 0, wx.EXPAND) lrsizer.Add(self.fontViewPanel, 1, wx.EXPAND | wx.ALL, border=5) lrsizer.Add(self.help_panel, 1, wx.EXPAND) lrsizer.Add(self.about_panel, 1, wx.EXPAND) lrsizer.Add(self.settings_panel, 1, wx.EXPAND) lrsizer.Add(self.choose_zipdir_panel, 1, wx.EXPAND) lrsizer.Add(self.hush_panel, 1, wx.EXPAND) self.SetSizer(lrsizer) ## A system to control the hide/show of these panels. self.panel_state = flag_normal self.panel_dict = { flag_normal: self.fontViewPanel, flag_help: self.help_panel, flag_about: self.about_panel, flag_settings: self.settings_panel, flag_choosedir: self.choose_zipdir_panel, flag_hush_fonts: self.hush_panel, } ## ## Very out of date. Left for future maybes. ## ##splitter window of 2 across ##left: a panel with sizer of two high of: source, then target guis ##right: fontview ##This one freezes the app when you resize to the right... :( ## Hard to reproduce. I used gdb and got it to crash, then ## did a 'bt' and saw some complaints about get text extents ## might be a bug in my font drawing code..? ## self.spw = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) ## This line seems less crashy, but not much less: ## self.spw = wx.SplitterWindow(self) #fvminw = MINSCREENWIDTH #self.spw = wx.SplitterWindow(self, style=wx.SP_LIVE_UPDATE) #self.spw.SetMinimumPaneSize(minw) #p1 = wx.Panel(self.spw) #self.panelFontSources = FontSourcesPanel(p1) #self.panelTargetPogChooser = TargetPogChooser(p1) #stsizer = wx.BoxSizer(wx.VERTICAL) #stsizer.Add( self.panelFontSources, 1, wx.EXPAND|wx.ALL,border = 5 ) #stsizer.Add( self.panelTargetPogChooser, 1, wx.EXPAND|wx.ALL,border = 5 ) #p1.SetSizer(stsizer) #self.fontViewPanel = FontViewPanel(self.spw) #self.fontViewPanel.SetMinSize(wx.Size(fvminw,1)) #self.spw.SplitVertically( p1, self.fontViewPanel)#, self.initpos) ## Thanks to the multiSplitterWindow code from the demo: #self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.onSplitterPosChanging) #self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.onSplitterPosChanged) ##Only used if whatgui != 1 #def onSplitterPosChanging(self,evt): # """ # A Splitter is moving - PRESENT TENSE. Let's do the least work poss. # """ # esp = evt.GetSashPosition() # print esp # if esp > 500: # evt.Veto() # return ##Only used if whatgui != 1 #def onSplitterPosChanged( self, evt ): # """ # A Splitter has been moved - PAST TENSE. # We only want to redraw the fonts when the splitter dragging is over. # """ # ps.pub( update_font_view ) # starts a HUGE chain of calls. ## Frame resizing sanity code self.resized = False self.Bind(wx.EVT_IDLE, self.onIdle) self.Bind(wx.EVT_SIZE, self.onFrameSize) ## GUI ENDS ## ============= self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) ## Now to subscribe to have my various def called from other places: ps.sub(show_error, self.ErrorBox) ps.sub(show_error_and_abort, self.ErrorAbort) ps.sub(show_message, self.MessageBox) ps.sub(print_to_status_bar, self.StatusbarPrint) ## Dec 2007 - Used on middle click in gui_Fitmap.py ps.sub(open_settings_panel, self.open_settings_panel) ps.sub(toggle_selection_menu_item, self.toggleSelectionMenuItem) ps.sub(toggle_purge_menu_item, self.TogglePurgeMenuItem) ps.sub(ensure_fontview_shown, self.ensure_fontview_shown) ## call the big one - the big chief, the big cheese: ## This eventually draws all the Fitmaps - giving the middle a width. ps.pub( update_font_view) #See gui_FontView.py under class FontViewPanel self.SetMinSize(wx.Size(MINSCREENWIDTH, 600)) #Old Skool: Assuming monitor size... # Don't do Fit. # It makes the FRAME size DOWN to the minimum children's size! ## self.Fit() self.Layout() ## This is to draw the correct icons depending on cli params. self.panelTargetPogChooser.pogTargetlist.toggle_list_icons_according_to_selection( False)
def __init__(self, parent): wx.Panel.__init__(self, parent, id=-1) self.firstrun = True self.pageindex = 1 # I start here self.total_number_of_pages = 0 self.filter = "" self.TICKMAP = None self._TICK = fpwx.wxbmp('tick') self._CROSS = fpwx.wxbmp('cross') #Sept 2009 ## Bitmaps to be used in the Fitmap drawing. ## Fetched from there as dict items. It got weird. self.SEGFAULT = fpwx.wxbmp('font_segfault') self.NO_DRAW = fpwx.wxbmp('font_cannot_draw') self.NOT_FOUND = fpwx.wxbmp('font_not_found') self.INFO_ITEM = fpwx.wxbmp('font_info_item') self.TICKSMALL = fpwx.wxbmp('ticksmall') self.BUTTON_CHARMAP = fpwx.wxbmp('button_charmap') self.BUTTON_CHARMAP_OVER = fpwx.wxbmp('button_charmap_over') ## -- ## Dicts for use in state ## self._setup_state_dicts() ## ## START GUI ## === #icon_open_folder = fpwx.wxbmp("icon_open_folder") #icon_pog = fpwx.wxbmp("pog16x16") #icon_pog_installed = fpwx.wxbmp("pog16x16.installed") ## Sizer: to hold all the others main_view_sizer = wx.BoxSizer(wx.VERTICAL) ## Sizer: Icon and Main Label icon_and_text_sizer = wx.BoxSizer(wx.HORIZONTAL) ## Sizer: Filter and Pager controls filter_and_pager_sizer = wx.BoxSizer(wx.HORIZONTAL) ## Icon view_icon = fpwx.icon(self, 'icon_viewing') # Main heading self.main_font_info_label = fpwx.h1(self, u"..", ellip=wx.ST_ELLIPSIZE_END, Layout_func=self.Layout) icon_and_text_sizer.Add(view_icon, 0, wx.EXPAND | wx.ALIGN_CENTER_HORIZONTAL | wx.RIGHT, border=4) icon_and_text_sizer.Add(self.main_font_info_label, 1, wx.EXPAND | wx.TOP | wx.ALIGN_CENTER_HORIZONTAL, border=6) ## The status label self.status_text = fpwx.label(self, u"Subinfo", ellip=wx.ST_ELLIPSIZE_END, Layout_func=self.Layout) ## Quick search Bold Italic Regular buttons ## It occurs to me that these are English words... ## Do fonts contain i18n on styles? ## See: https://fontforge.github.io/fontstyles.html idBold = wx.NewId() idItalic = wx.NewId() self.idRegular = wx.NewId() self.BIR = { idBold: { 'style': "bold", 'truth': False, 'instance': None }, idItalic: { 'style': "italic", 'truth': False, 'instance': None }, self.idRegular: { 'style': "regular", 'truth': False, 'instance': None } } toggle_sizer = wx.BoxSizer(wx.HORIZONTAL) for idy, dic in self.BIR.iteritems(): bBIR = wx.ToggleButton(self, idy, size=(32, -1), style=wx.NO_BORDER) #Remarked label to show icons instead, label=dic['label']) bBIR.Bind(wx.EVT_TOGGLEBUTTON, self.onBIR) bmp = fpwx.wxbmp('icon_{}'.format(dic['style'])) bBIR.SetBitmap(bmp) bBIR.SetToolTipString(_("Filter {} fonts").format(dic['style'])) self.BIR[idy]['instance'] = bBIR toggle_sizer.Add(bBIR, 1, wx.EXPAND) filter_and_pager_sizer.Add(toggle_sizer, 1, wx.EXPAND) # Search box - has two callbacks self.search_filter = SearchFilter( self, search_func=self.do_search, cancel_func=self.on_clear_button_click) self.last_filter_string = "" filter_and_pager_sizer.Add( self.search_filter, 5, wx.ALIGN_LEFT | wx.EXPAND \ | wx.RIGHT, border = 6) ## The pager pulldown pager_label = fpwx.label(self, _(u"Page:")) self.pager_combo = wx.ComboBox(self, -1, value="1", choices=["busy"], style=wx.CB_DROPDOWN | wx.TE_PROCESS_ENTER) self.pager_combo.Bind(wx.EVT_COMBOBOX, self.onPagechoiceClick) self.pager_combo.Bind(wx.EVT_TEXT_ENTER, self.onPagerChoiceTextEnter) filter_and_pager_sizer.Add(pager_label, 0, wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=6) filter_and_pager_sizer.Add(self.pager_combo, 1) #, wx.ALIGN_RIGHT ) ## The SCROLLED FONT VIEW panel: self.scrolledFontView = ScrolledFontView(self) ## Sizer: for buttons prev, main, next bottom_buttons_sizer = wx.BoxSizer(wx.HORIZONTAL) #July 2016 #========= # The stock icon on the button was not showing under gtk3. # This stock button has not been translated into Afrikaans yet. (Dec 2007) # I can't tell you how this fkuced me around! # July 2016 - remarked : self.next_button = wx.Button(self, wx.ID_FORWARD) # I have switched to a bitmapbutton. I hope this works... ### # For future: # example = wx.BitmapButton(self, -1, fpwx.wxbmp( "xxx" ), # style = wx.NO_BORDER) # Previous button #self.previous_button = wx.BitmapButton( self, wx.ID_BACKWARD, # wx.ArtProvider.GetBitmap( # wx.ART_GO_BACK, wx.ART_BUTTON, (32,32) )) self.previous_button = wx.BitmapButton(self, wx.ID_BACKWARD, fpwx.wxbmp('icon_prev_page')) # Main button self.button_main = wx.Button(self, label=" ") self.buttMainLastLabel = " " # Next button #self.next_button = wx.BitmapButton( self, wx.ID_FORWARD, # wx.ArtProvider.GetBitmap( # wx.ART_GO_FORWARD, wx.ART_BUTTON, (32,32) )) self.next_button = wx.BitmapButton(self, wx.ID_FORWARD, fpwx.wxbmp('icon_next_page')) self.previous_button.Enable(False) # Starts out disabled bottom_buttons_sizer.Add(self.previous_button, 0, wx.EXPAND | wx.RIGHT, border=8) bottom_buttons_sizer.Add(self.button_main, 1, wx.EXPAND | wx.RIGHT, border=8) bottom_buttons_sizer.Add(self.next_button, 0, wx.EXPAND) ## Start at the top: the icon and label main_view_sizer.Add(icon_and_text_sizer, 0, wx.EXPAND) ## Sub label main_view_sizer.Add(self.status_text, 0, wx.EXPAND | wx.TOP, border=4) ## Fill the Choice and Filter main_view_sizer.Add(filter_and_pager_sizer, 0, wx.EXPAND | wx.TOP, border=8) ## Fill the SIZER FOR THE SCROLLED FONT VIEW main_view_sizer.Add(self.scrolledFontView, 1, wx.EXPAND | wx.TOP, border=8) ## Fill the bottom buttons main_view_sizer.Add(bottom_buttons_sizer, 0, wx.EXPAND | wx.TOP, border=10) ## Do the voodoo thang self.SetSizer(main_view_sizer) ## This Fit is NB. It sets the width ## for all panels to come. ## Remove it and the various AutoWrapStaticText ## objects fail hard. self.Fit() ## Bind events self.previous_button.Bind(wx.EVT_BUTTON, self.navClick) self.next_button.Bind(wx.EVT_BUTTON, self.navClick) self.Bind(wx.EVT_BUTTON, self.onMainClick, self.button_main) #.GetId() ) ## Advertise some local functions: ps.sub(left_or_right_key_pressed, self.OnLeftOrRightKey) ##DND: class FontViewPanel ps.sub(toggle_main_button, self.ToggleMainButton) ##DND: Called in gui_Fitmap ps.sub(update_font_view, self.MainFontViewUpdate) ##DND: class FontViewPanel ps.sub(reset_to_page_one, self.ResetToPageOne) ##DND: class FontViewPanel
def __init__(self, parent, name="notebook_not_named"): wx.Notebook.__init__(self, parent, style=wx.NB_TOP, name = name) self.imlist = wx.ImageList(16, 16) pan1 = wx.Panel(self) ## THE DIR CONTROL self.dircontrol = DirControl(pan1) # Get a ref to the dircontrol. self.tree = self.dircontrol.GetTreeCtrl() ## Add them to a sizer box = wx.BoxSizer(wx.VERTICAL) box.Add( self.dircontrol,1, wx.EXPAND ) pan1.SetSizer(box) box.Layout() self.pogindexselected = 0 ## The SOURCE POG control pan2 = wx.Panel(self) page = 0 s = None if fpsys.state.viewpattern == "P": s = fpsys.state.viewobject.name if s == "EMPTY": s= None #Very first run, the view will be an EMPTY object. page = 1 self.ctrlPogSource = PogChooser(pan2, whoami="SOURCEPOG", select = s) ps.sub( source_pog_has_been_selected, self.OnViewPogClick) ##DND: class NoteBook ps.sub( select_no_view_pog, self.SelectNoView) ##DND: class NoteBook ps.sub( add_pog_item_to_source, self.AddItem ) #DND: class NoteBook ps.sub( remove_pog_item_from_source, self.RemoveItem ) #DND: class NoteBook ## Dud tree events, causing bad behaviour: ## EVT_LIST_ITEM_SELECTED ## EVT_LEFT_UP ## Bind to another event solve the problem of ## EVT_LEFT_UP firing when the little ## open-branch/tree arrow was pressed. ## 5.3.2009 Michael Hoeft ## Nov 2017: Also subscribe this for use in wxgui - since ## I moved the recurseFolders into there. ps.sub( fake_click_the_source_dir_control, self.__onDirCtrlClick ) self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.__onDirCtrlClick) ## Had a context menu, but not using it. #self.tree.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu) box2 = wx.BoxSizer(wx.HORIZONTAL) box2.Add(self.ctrlPogSource,1,wx.EXPAND) pan2.SetSizer(box2) box2.Layout() self.AddPage(pan1, _("Source Folders")) self.AddPage(pan2, _("Source Pogs")) # sadly, the artprovider icons suck, and I can't get access # to the "stock items" either. F**k it. source_folder_icon = self.imlist.Add( fpwx.wxbmp('icon_source_folder_16x16') ) source_pog_icon = self.imlist.Add( fpwx.wxbmp('icon_source_pog_16x16') ) self.AssignImageList(self.imlist) self.SetPageImage(0, source_folder_icon) self.SetPageImage(1, source_pog_icon) self.SetSelection(page) # Dec 2017: Remarked this Bind. See notes in old handler #self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, # self.onPageChanged) # Bind page changed event ## If the app is started with a Folder as the Source, then ## check if we must recurse. If so, fake a click to kick that off. ## Sept 2017 if fpsys.state.viewpattern == "F": self.__onDirCtrlClick() # Fake an event
def __init__(self, parent, whoami, select=None): """ select is None or a Pog that will be selected in the control. """ self.indexselected = -1 self.lastindexselected = -1 self.parent = parent self.whoami = whoami ## Use Class-level attributes to record the history of ## the instantiation of this class. These vars do not ## belong to the instances, but to this one class. ## We keep refs to the two parents of this class. ## __VIEW and __TARGET are useful when I want to ## refer to the *other* one from <whatever I am> if whoami == "SOURCEPOG": PogChooser.__VIEW = self style = wx.LC_LIST | wx.LC_SORT_ASCENDING | wx.LC_SINGLE_SEL else: PogChooser.__TARGET = self style = wx.LC_LIST | wx.LC_SORT_ASCENDING il = wx.ImageList(16, 16, True) il.Add(wxbmp('pog16x16')) il.Add(wxbmp('pog16x16.installed')) il.Add(wxbmp('pog16x16.target')) # Dec 2007: triangle target il.Add(wxbmp('view16x16')) # Dec 2017: little eye wx.ListCtrl.__init__(self, parent, -1, style=style | wx.SUNKEN_BORDER, name="pog_chooser") self.AssignImageList(il, wx.IMAGE_LIST_SMALL) self.fillPogList() ## Highlight the pog selected (the last one, or the ## cli chosen one) ## Done manually because things are still in an __init__ ## state. if select: i = self.FindItem(-1, select) self.indexselected = i # Set to help initial icon settings self.SetItemImage(i, self.icon_viewing) self.Select(i, True) #else: ## Nov 2017 ## == "FichteFoll" hit a bug here. ## When fp starts with zero pogs ... :O ... ## there's an index problem with self.Select ## Fix: Just exlude this else branch. self.ClearBackground() self.items = None self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onSelect) ## This one is a double click event ## self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.__onActivate) #self.SetCursor(wx.StockCursor(wx.CURSOR_HAND)) ## This subscribe line here will register TWICE ## with the global "ps" - since this PogChooser class ## is instanced twice (view and target). ## I.e. There will be two "self".ChangeIcon funcs ## fired on any one ps.pub(change_pog_icon) call. ps.sub(change_pog_icon, self.ChangeIcon) ##DND: class PogChooser
def __init__(self, parent, flag, someicon=None, somelabel="...", extra_padding=0, wfunc=None): id = id_from_flag[flag] self.id = id sz = (-1, -1) if wfunc: sz = wfunc() # seems work.. was:(wfunc()[0],-1) wx.Panel.__init__(self, parent, id, size=sz, style=wx.NO_FULL_REPAINT_ON_RESIZE) #self.SetMinSize(sz) # necc? Meh. Seems not.. self.parent = parent self.flag = flag ## Go fetch the .. whatever ## Seems I settled on returning a sizer from __post_init__ whatever = self.__post_init__() ## Pad the whole thing some whatever_sizer = wx.BoxSizer(wx.VERTICAL) whatever_sizer.Add(whatever, 1, wx.EXPAND | wx.ALL, border=8 + extra_padding) l = fpwx.h1(self, somelabel) x_button = wx.BitmapButton(self, -1, fpwx.wxbmp("icon_X"), style=wx.NO_BORDER) x_button.SetToolTipString(_("Dismiss. ESC key does the same.")) #x_button = wx.Button(self, -1, label="X", # style = wx.NO_BORDER | wx.BU_EXACTFIT) self.Bind(wx.EVT_BUTTON, self.__x_pressed, x_button) hbox = wx.BoxSizer(wx.HORIZONTAL) if someicon: hbox.Add(fpwx.icon(self, someicon), 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=12) else: hbox.Add((1, 1), 0, wx.EXPAND) # push the label down to better align with the X hbox.Add(l, 1, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.TOP, border=6) hbox.Add(x_button, 0, wx.ALIGN_RIGHT | wx.BOTTOM, border=4) hbox.Add((8, 8), 0) self.vbox = wx.BoxSizer(wx.VERTICAL) self.vbox.Add(hbox, 0, wx.EXPAND | wx.TOP, border=16) #Wanted more space above. self.vbox.Add(whatever_sizer, 1, wx.EXPAND) self.SetSizer(self.vbox) #self.Fit() self.Layout() self.SetFocus() self._firstshow = True self.Bind(wx.EVT_SHOW, self.__catch_show_or_hide)