def __init__(self, cfgKey=None, cfgSect=None): self.ConfigKey = cfgKey self.ConfigSection = cfgSect if not self.ConfigSection: self.ConfigSection = u'GENERAL' if self.ConfigKey == None: self.ConfigKey = self.GetName() # Add to recognized configuration keys SetDefaultConfigKey(self.ConfigKey, self.GetDefaultValue()) # Set state using config file if found state = ReadConfig(self.ConfigKey) ret_codes = ( ConfCode.FILE_NOT_FOUND, ConfCode.KEY_NOT_DEFINED, ConfCode.KEY_NO_EXIST, ) # FIXME: if state not in (ret_codes): self.SetValue(state) else: Logger.Debug(__name__, u'Key not found: {}'.format(self.ConfigKey)) # *** Event Handling *** # if isinstance(self, wx.CheckBox): self.Bind(wx.EVT_CHECKBOX, self.OnToggle)
def ChangeWorkingDirectory(target_dir): if DebugEnabled(): Logger.Debug(__name__, u'ChangeWorkingDirectory: {}'.format(target_dir), newline=True) print(u' Working dir before: {}'.format(os.getcwd())) success = False try: os.chdir(target_dir) config_dir = ReadConfig(u'workingdir') if config_dir != target_dir: WriteConfig(u'workingdir', target_dir) success = True except OSError: # Default to the user's home directory if os.path.isdir(PATH_home): os.chdir(PATH_home) if DebugEnabled(): print(u' Working dir after: {}\n'.format(os.getcwd())) return success
def OnQuit(self, event=None): if self.ProjectDirty: if not ConfirmationDialog( self, GT(u'Quit?'), text=GT( u'You will lose any unsaved information')).Confirmed(): return maximized = self.IsMaximized() # Get window attributes and save to config file # Save default window settings if maximized # FIXME: Better solution? if maximized: WriteConfig(u'size', GetDefaultConfigValue(u'size')) WriteConfig(u'position', GetDefaultConfigValue(u'position')) WriteConfig(u'center', GetDefaultConfigValue(u'center')) WriteConfig(u'maximize', True) else: WriteConfig(u'position', self.GetPositionTuple()) WriteConfig(u'size', self.GetSizeTuple()) WriteConfig(u'center', False) WriteConfig(u'maximize', False) config_wdir = ReadConfig(u'workingdir') current_wdir = os.getcwd() # Workaround for issues with some dialogs not writing to config if config_wdir != current_wdir: WriteConfig(u'workingdir', current_wdir) self.Destroy()
def createMenuBar(parent): testing = u'alpha' in GetTestList() or DebugEnabled() menubar = MenuBar(parent) menu_file = wx.Menu() menubar.Append(menu_file, GT(u'File'), menuid.FILE) # This menu is filled from wiz.wizard.Wizard.SetPages menubar.Append(wx.Menu(), GT(u'Page'), menuid.PAGE) # *** File Menu *** # mitems_file = [ ( menuid.NEW, GT(u'New project'), GT(u'Start a new project'), ), ( menuid.OPEN, GT(u'Open'), GT(u'Open a previously saved project'), ), ( menuid.SAVE, GT(u'Save'), GT(u'Save current project'), ), ( menuid.SAVEAS, GT(u'Save as'), GT(u'Save current project with a new filename'), ), None, ( menuid.QBUILD, GT(u'Quick Build'), GT(u'Build a package from an existing build tree'), ICON_CLOCK, ), None, ( menuid.EXIT, GT(u'Quit'), GT(u'Exit Debreate'), ), ] if testing: mitems_file.append((menuid.ALIEN, GT(u'Convert packages'), GT(u'Convert between package types'))) # Adding all menus to menu bar mitems = (mitems_file, ) for menu_list in mitems: for mitem in menu_list: if not mitem: menu_file.AppendSeparator() else: itm = wx.MenuItem(menu_file, mitem[0], mitem[1], mitem[2]) if len(mitem) > 3: itm.SetBitmap(mitem[3]) menu_file.AppendItem(itm) # ----- Options Menu parent.menu_opt = wx.Menu() # Show/Hide tooltips parent.opt_tooltips = wx.MenuItem(parent.menu_opt, menuid.TOOLTIPS, GT(u'Show tooltips'), GT(u'Show or hide tooltips'), kind=wx.ITEM_CHECK) # A bug with wx 2.8 does not allow tooltips to be toggled off if wx.MAJOR_VERSION > 2: parent.menu_opt.AppendItem(parent.opt_tooltips) if parent.menu_opt.FindItemById(menuid.TOOLTIPS): show_tooltips = ReadConfig(u'tooltips') if show_tooltips != ConfCode.KEY_NO_EXIST: parent.opt_tooltips.Check(show_tooltips) else: parent.opt_tooltips.Check(GetDefaultConfigValue(u'tooltips')) parent.OnToggleToolTips() # *** Option Menu: open logs directory *** # if GetExecutable(u'xdg-open'): mitm_logs_open = wx.MenuItem(parent.menu_opt, menuid.OPENLOGS, GT(u'Open logs directory')) parent.menu_opt.AppendItem(mitm_logs_open) wx.EVT_MENU(parent, menuid.OPENLOGS, parent.OnLogDirOpen) # *** OS distribution names cache *** # opt_distname_cache = wx.MenuItem( parent.menu_opt, menuid.DIST, GT(u'Update dist names cache'), GT(u'Creates/Updates list of distribution names for changelog page')) parent.menu_opt.AppendItem(opt_distname_cache) mitm_ccache = wx.MenuItem(parent.menu_opt, menuid.CCACHE, GT(u'Clear local cache')) parent.menu_opt.AppendItem(mitm_ccache) # ----- Help Menu menu_help = wx.Menu() # ----- Version update mitm_update = wx.MenuItem( menu_help, menuid.UPDATE, GT(u'Check for update'), GT(u'Check if a new version is available for download')) mitm_update.SetBitmap(ICON_LOGO) menu_help.AppendItem(mitm_update) menu_help.AppendSeparator() # Menu with links to the Debian Policy Manual webpages parent.menu_policy = wx.Menu() policy_links = ( ( refid.DPM, GT(u'Debian Policy Manual'), u'https://www.debian.org/doc/debian-policy', ), ( refid.DPMCtrl, GT(u'Control files'), u'https://www.debian.org/doc/debian-policy/ch-controlfields.html', ), ( refid.DPMLog, GT(u'Changelog'), u'https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog', ), ( refid.UPM, GT(u'Ubuntu Policy Manual'), u'http://people.canonical.com/~cjwatson/ubuntu-policy/policy.html/', ), ( refid.LINT_TAGS, GT(u'Lintian Tags Explanation'), u'https://lintian.debian.org/tags-all.html', ), ( refid.LINT_OVERRIDE, GT(u'Overriding Lintian Tags'), u'https://lintian.debian.org/manual/section-2.4.html', ), ( refid.LAUNCHERS, GT(u'Launchers / Desktop entries'), u'https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/', ), # Unofficial links None, ( refid.DEBSRC, GT(u'Building debs from Source'), u'http://www.quietearth.us/articles/2006/08/16/Building-deb-package-from-source', ), # This is here only temporarily for reference ( refid.MAN, GT(u'Writing manual pages'), u'https://liw.fi/manpages/', ), ) for LINK in policy_links: if not LINK: parent.menu_policy.AppendSeparator() elif len(LINK) > 2: link_id = LINK[0] label = LINK[1] url = LINK[2] if len(LINK) > 3: icon = LINK[3] else: icon = ICON_GLOBE mitm = wx.MenuItem(parent.menu_policy, link_id, label, url) mitm.SetBitmap(icon) parent.menu_policy.AppendItem(mitm) wx.EVT_MENU(parent, link_id, parent.OpenPolicyManual) mitm_manual = wx.MenuItem(menu_help, wx.ID_HELP, GT(u'Manual'), GT(u'Open a usage document')) mitm_about = wx.MenuItem(menu_help, wx.ID_ABOUT, GT(u'About'), GT(u'About Debreate')) menu_help.AppendMenu(-1, GT(u'Reference'), parent.menu_policy) menu_help.AppendSeparator() menu_help.AppendItem(mitm_manual) menu_help.AppendItem(mitm_about) if parent.menu_opt.GetMenuItemCount(): menubar.Append(parent.menu_opt, GT(u'Options'), menuid.OPTIONS) menubar.Append(menu_help, GT(u'Help'), menuid.HELP) # catching menu events wx.EVT_MENU(parent, menuid.CCACHE, parent.OnClearCache) return menubar
def __init__(self, pos, size): wx.Frame.__init__(self, None, wx.ID_ANY, default_title, pos, size) # Make sure that this frame is set as the top window if not wx.GetApp().GetTopWindow() == self: Logger.Debug(__name__, GT(u'Setting MainWindow instance as top window')) wx.GetApp().SetTopWindow(self) testing = u'alpha' in GetTestList() or DebugEnabled() if DebugEnabled(): self.SetTitle(u'{} ({})'.format(default_title, GT(u'debugging'))) self.SetMinSize(wx.Size(640, 400)) # ----- Set Titlebar Icon self.SetIcon(Icon(LOGO)) # *** Status Bar *** # StatusBar(self) # *** Menus *** # menubar = MenuBar(self) menu_file = wx.Menu() menubar.Append(menu_file, GT(u'File'), menuid.FILE) # This menu is filled from wiz.wizard.Wizard.SetPages menubar.Append(wx.Menu(), GT(u'Page'), menuid.PAGE) # *** File Menu *** # mitems_file = [ ( menuid.NEW, GT(u'New project'), GT(u'Start a new project'), ), ( menuid.OPEN, GT(u'Open'), GT(u'Open a previously saved project'), ), ( menuid.SAVE, GT(u'Save'), GT(u'Save current project'), ), ( menuid.SAVEAS, GT(u'Save as'), GT(u'Save current project with a new filename'), ), None, ( menuid.QBUILD, GT(u'Quick Build'), GT(u'Build a package from an existing build tree'), ICON_CLOCK, ), None, ( menuid.EXIT, GT(u'Quit'), GT(u'Exit Debreate'), ), ] if testing: mitems_file.append((menuid.ALIEN, GT(u'Convert packages'), GT(u'Convert between package types'))) # Adding all menus to menu bar mitems = (mitems_file, ) for menu_list in mitems: for mitem in menu_list: if not mitem: menu_file.AppendSeparator() else: itm = wx.MenuItem(menu_file, mitem[0], mitem[1], mitem[2]) if len(mitem) > 3: itm.SetBitmap(mitem[3]) menu_file.AppendItem(itm) # *** Action Menu *** # menu_action = wx.Menu() mitm_build = wx.MenuItem(menu_action, menuid.BUILD, GT(u'Build'), GT(u'Start building .deb package')) menu_action.AppendItem(mitm_build) # ----- Options Menu menu_opt = wx.Menu() # Show/Hide tooltips self.opt_tooltips = wx.MenuItem(menu_opt, menuid.TOOLTIPS, GT(u'Show tooltips'), GT(u'Show or hide tooltips'), kind=wx.ITEM_CHECK) # A bug with wx 2.8 does not allow tooltips to be toggled off if wx.MAJOR_VERSION > 2: menu_opt.AppendItem(self.opt_tooltips) if menu_opt.FindItemById(menuid.TOOLTIPS): show_tooltips = ReadConfig(u'tooltips') if show_tooltips != ConfCode.KEY_NO_EXIST: self.opt_tooltips.Check(show_tooltips) else: self.opt_tooltips.Check(GetDefaultConfigValue(u'tooltips')) self.OnToggleToolTips() # Project compression options self.menu_compress = wx.Menu() opt_z_none = wx.MenuItem( self.menu_compress, ident.ZIP_NONE, GT(u'Uncompressed'), GT(u'Use uncompressed tarball for project save format'), kind=wx.ITEM_RADIO) opt_z_gz = wx.MenuItem( self.menu_compress, ident.ZIP_GZ, GT(u'Gzip'), GT(u'Use compressed Gzip tarball for project save format'), kind=wx.ITEM_RADIO) opt_z_bz2 = wx.MenuItem( self.menu_compress, ident.ZIP_BZ2, GT(u'Bzip2'), GT(u'Use compressed Bzip2 tarball for project save format'), kind=wx.ITEM_RADIO) opt_z_zip = wx.MenuItem( self.menu_compress, ident.ZIP_ZIP, GT(u'Zip'), GT(u'Use compressed zip file for project save format'), kind=wx.ITEM_RADIO) opts_compress = [ opt_z_none, opt_z_gz, opt_z_bz2, opt_z_zip, ] if GetExecutable(u'tar') != None: opt_z_xz = wx.MenuItem( self.menu_compress, ident.ZIP_XZ, GT(u'XZ'), GT(u'Use compressed xz tarball for project save format'), kind=wx.ITEM_RADIO) opts_compress.insert(3, opt_z_xz) for OPT in opts_compress: self.menu_compress.AppendItem(OPT) wx.EVT_MENU(self.menu_compress, OPT.GetId(), self.OnSetCompression) # Default compression self.menu_compress.Check(ident.ZIP_BZ2, True) menu_opt.AppendSubMenu( self.menu_compress, GT(u'Project Compression'), GT(u'Set the compression type for project save output')) # *** Option Menu: open logs directory *** # if GetExecutable(u'xdg-open'): mitm_logs_open = wx.MenuItem(menu_opt, menuid.OPENLOGS, GT(u'Open logs directory')) menu_opt.AppendItem(mitm_logs_open) wx.EVT_MENU(menu_opt, menuid.OPENLOGS, self.OnLogDirOpen) # *** OS distribution names cache *** # opt_distname_cache = wx.MenuItem( menu_opt, menuid.DIST, GT(u'Update dist names cache'), GT(u'Creates/Updates list of distribution names for changelog page' )) menu_opt.AppendItem(opt_distname_cache) # ----- Help Menu menu_help = wx.Menu() # ----- Version update mitm_update = wx.MenuItem( menu_help, menuid.UPDATE, GT(u'Check for update'), GT(u'Check if a new version is available for download')) mitm_update.SetBitmap(ICON_LOGO) menu_help.AppendItem(mitm_update) menu_help.AppendSeparator() # Menu with links to the Debian Policy Manual webpages self.menu_policy = wx.Menu() policy_links = ( ( refid.DPM, GT(u'Debian Policy Manual'), u'https://www.debian.org/doc/debian-policy', ), ( refid.DPMCtrl, GT(u'Control files'), u'https://www.debian.org/doc/debian-policy/ch-controlfields.html', ), ( refid.DPMLog, GT(u'Changelog'), u'https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog', ), ( refid.UPM, GT(u'Ubuntu Policy Manual'), u'http://people.canonical.com/~cjwatson/ubuntu-policy/policy.html/', ), ( refid.LINT_TAGS, GT(u'Lintian Tags Explanation'), u'https://lintian.debian.org/tags-all.html', ), ( refid.LINT_OVERRIDE, GT(u'Overriding Lintian Tags'), u'https://lintian.debian.org/manual/section-2.4.html', ), ( refid.LAUNCHERS, GT(u'Launchers / Desktop entries'), u'https://www.freedesktop.org/wiki/Specifications/desktop-entry-spec/', ), # Unofficial links None, ( refid.DEBSRC, GT(u'Building debs from Source'), u'http://www.quietearth.us/articles/2006/08/16/Building-deb-package-from-source', ), # This is here only temporarily for reference ( refid.MAN, GT(u'Writing manual pages'), u'https://liw.fi/manpages/', ), ) for LINK in policy_links: if not LINK: self.menu_policy.AppendSeparator() elif len(LINK) > 2: link_id = LINK[0] label = LINK[1] url = LINK[2] if len(LINK) > 3: icon = LINK[3] else: icon = ICON_GLOBE mitm = wx.MenuItem(self.menu_policy, link_id, label, url) mitm.SetBitmap(icon) self.menu_policy.AppendItem(mitm) wx.EVT_MENU(self, link_id, self.OpenPolicyManual) mitm_help = wx.MenuItem(menu_help, wx.ID_HELP, GT(u'Help'), GT(u'Open a usage document')) mitm_about = wx.MenuItem(menu_help, wx.ID_ABOUT, GT(u'About'), GT(u'About Debreate')) menu_help.AppendMenu(-1, GT(u'Reference'), self.menu_policy) menu_help.AppendSeparator() menu_help.AppendItem(mitm_help) menu_help.AppendItem(mitm_about) menubar.Append(menu_action, GT(u'Action'), menuid.ACTION) if menu_opt.GetMenuItemCount(): menubar.Append(menu_opt, GT(u'Options'), menuid.OPTIONS) menubar.Append(menu_help, GT(u'Help'), menuid.HELP) self.Wizard = Wizard(self) # Menu for debugging & running tests if DebugEnabled(): self.menu_debug = wx.Menu() menubar.Append(self.menu_debug, GT(u'Debug'), menuid.DEBUG) self.menu_debug.AppendItem( wx.MenuItem(self.menu_debug, menuid.LOG, GT(u'Show log'), GT(u'Toggle debug log window'), kind=wx.ITEM_CHECK)) if u'log-window' in parsed_args_s: self.menu_debug.Check(menuid.LOG, True) self.log_window = None # Window colors self.menu_debug.AppendItem( wx.MenuItem(self.menu_debug, menuid.THEME, GT(u'Toggle window colors'))) wx.EVT_MENU(self, menuid.THEME, self.OnToggleTheme) # *** Current Project Status *** # self.LoadedProject = None self.ProjectDirty = False self.dirty_mark = u' *' menu_file.Enable(wx.ID_SAVE, self.ProjectDirty) # *** Event Handling *** # wx.EVT_MENU(self, menuid.NEW, self.OnProjectNew) wx.EVT_MENU(self, menuid.OPEN, self.OnProjectOpen) wx.EVT_MENU(self, menuid.SAVE, self.OnProjectSave) wx.EVT_MENU(self, menuid.SAVEAS, self.OnProjectSaveAs) wx.EVT_MENU(self, menuid.QBUILD, self.OnQuickBuild) wx.EVT_MENU(self, menuid.EXIT, self.OnQuit) wx.EVT_MENU(self, menuid.TOOLTIPS, self.OnToggleToolTips) wx.EVT_MENU(self, menuid.DIST, self.OnUpdateDistNamesCache) wx.EVT_MENU(self, menuid.UPDATE, self.OnCheckUpdate) wx.EVT_MENU(self, menuid.HELP, self.OnHelp) wx.EVT_MENU(self, menuid.ABOUT, self.OnAbout) self.Bind(EVT_CHANGE_PAGE, self.OnWizardBtnPage) # Custom close event shows a dialog box to confirm quit wx.EVT_CLOSE(self, self.OnQuit) # *** Layout *** # lyt_main = BoxSizer(wx.VERTICAL) lyt_main.Add(self.Wizard, 1, wx.EXPAND) self.SetAutoLayout(True) self.SetSizer(lyt_main) self.Layout()