def InitApp(self): self.SetAppName('StupidGit') wx.TheApp = self self.app_windows = [] if sys.platform == 'darwin': self.hiddenWindow = HiddenWindow() self.SetExitOnFrameDelete(False) wx.App_SetMacAboutMenuItemId(xrc.XRCID('aboutMenuItem')) wx.App_SetMacExitMenuItemId(xrc.XRCID('quitMenuItem'))
def _processNewItem(self, itm, daboItem): """After a menu item is created, perform any platform-specific handling.""" id_ = itm.GetId() if id_ == wx.ID_ABOUT: # Put the about menu in the App Menu on Mac wx.App_SetMacAboutMenuItemId(id_) cap = daboItem.Parent.Caption wx.App_SetMacHelpMenuTitleName(cap) # Process any 'special' menus try: special = daboItem._special except AttributeError: return if special == "pref": # Put the prefs item in the App Menu on Mac self.Parent._mac_pref_menu_item_id = id_ wx.App_SetMacPreferencesMenuItemId(id_)
def create_menubar(self): self._main_menu = wx.MenuBar() # Make a File menu exitId = wx.NewId() menu = wx.Menu() menu.Append(exitId, 'E&xit\tAlt-F4', 'Exits the program.') wx.EVT_MENU(self, exitId, self.on_file_exit) wx.App_SetMacExitMenuItemId(exitId) self._main_menu.Append(menu, '&File') # Make a Help menu helpId = wx.NewId() menu = wx.Menu() menu.Append( helpId, '&About %s' % __NAME__, 'Displays program information, version number, ' 'and copyright.') wx.App_SetMacAboutMenuItemId(helpId) wx.EVT_MENU(self, helpId, self.on_help_about) self._main_menu.Append(menu, '&Help') # Add this menu bar to self self.SetMenuBar(self._main_menu)
def __init__(self, parent, id, title, res): # Initialize logging logger = logging.getLogger('dicompyler') # Configure the exception hook to process threads as well self.InstallThreadExcepthook() # Remap the exception hook so that we can log and display exceptions def LogExcepthook(*exc_info): # Log the exception text = "".join(traceback.format_exception(*exc_info)) logger.error("Unhandled exception: %s", text) pub.sendMessage('logging.exception', text) sys.excepthook = LogExcepthook # Modify the logging system from pydicom to capture important messages pydicom_logger = logging.getLogger('pydicom') for l in pydicom_logger.handlers: pydicom_logger.removeHandler(l) # Add file logger logpath = os.path.join(guiutil.get_data_dir(), 'logs') if not os.path.exists(logpath): os.makedirs(logpath) self.fh = logging.handlers.RotatingFileHandler(os.path.join( logpath, 'dicompyler.log'), maxBytes=524288, backupCount=7) self.fh.setFormatter( logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s - %(message)s')) self.fh.setLevel(logging.WARNING) logger.addHandler(self.fh) pydicom_logger.addHandler(self.fh) # Add console logger if not frozen if not util.main_is_frozen(): self.ch = logging.StreamHandler() self.ch.setFormatter( logging.Formatter('%(levelname)s: %(message)s')) self.ch.setLevel(logging.WARNING) logger.addHandler(self.ch) pydicom_logger.addHandler(self.ch) # Otherwise if frozen, send stdout/stderror to /dev/null since # logging the messages seems to cause instability due to recursion else: devnull = open(os.devnull, 'w') sys.stdout = devnull sys.stderr = devnull # Set the window size if guiutil.IsMac(): size = (900, 700) else: size = (850, 625) wx.Frame.__init__(self, parent, id, title, pos=wx.DefaultPosition, size=size, style=wx.DEFAULT_FRAME_STYLE) # Set up the status bar self.sb = self.CreateStatusBar(3) # set up resource file and config file self.res = res # Set window icon if not guiutil.IsMac(): self.SetIcon(guiutil.get_icon()) # Load the main panel for the program self.panelGeneral = self.res.LoadPanel(self, 'panelGeneral') # Initialize the General panel controls self.notebook = XRCCTRL(self, 'notebook') self.notebookTools = XRCCTRL(self, 'notebookTools') self.lblPlanName = XRCCTRL(self, 'lblPlanName') self.lblRxDose = XRCCTRL(self, 'lblRxDose') self.lblPatientName = XRCCTRL(self, 'lblPatientName') self.lblPatientID = XRCCTRL(self, 'lblPatientID') self.lblPatientGender = XRCCTRL(self, 'lblPatientGender') self.lblPatientDOB = XRCCTRL(self, 'lblPatientDOB') self.choiceStructure = XRCCTRL(self, 'choiceStructure') self.lblStructureVolume = XRCCTRL(self, 'lblStructureVolume') self.lblStructureMinDose = XRCCTRL(self, 'lblStructureMinDose') self.lblStructureMaxDose = XRCCTRL(self, 'lblStructureMaxDose') self.lblStructureMeanDose = XRCCTRL(self, 'lblStructureMeanDose') self.cclbStructures = guiutil.ColorCheckListBox( self.notebookTools, 'structure') self.cclbIsodoses = guiutil.ColorCheckListBox(self.notebookTools, 'isodose') # Modify the control and font size on Mac controls = [self.notebookTools, self.choiceStructure] if guiutil.IsMac(): font = wx.SystemSettings.GetFont(wx.SYS_DEFAULT_GUI_FONT) font.SetPointSize(10) for control in controls: control.SetWindowVariant(wx.WINDOW_VARIANT_SMALL) control.SetFont(font) # Setup the layout for the frame mainGrid = wx.BoxSizer(wx.VERTICAL) hGrid = wx.BoxSizer(wx.HORIZONTAL) if guiutil.IsMac(): hGrid.Add(self.panelGeneral, 1, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTRE, border=4) else: hGrid.Add(self.panelGeneral, 1, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTRE) mainGrid.Add(hGrid, 1, flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTRE) # Load the menu for the frame menuMain = self.res.LoadMenuBar('menuMain') # If we are running on Mac OS X, alter the menu location if guiutil.IsMac(): wx.App_SetMacAboutMenuItemId(XRCID('menuAbout')) wx.App_SetMacPreferencesMenuItemId(XRCID('menuPreferences')) wx.App_SetMacExitMenuItemId(XRCID('menuExit')) # Set the menu as the default menu for this frame self.SetMenuBar(menuMain) # Setup Tools menu self.menuShowLogs = menuMain.FindItemById( XRCID('menuShowLogs')).GetMenu() self.menuPlugins = menuMain.FindItemById( XRCID('menuPluginManager')).GetMenu() # Setup Import menu self.menuImport = menuMain.FindItemById( XRCID('menuImportPlaceholder')).GetMenu() self.menuImport.Delete( menuMain.FindItemById(XRCID('menuImportPlaceholder')).GetId()) self.menuImportItem = menuMain.FindItemById(XRCID('menuImport')) self.menuImportItem.Enable(False) # Setup Export menu self.menuExport = menuMain.FindItemById( XRCID('menuExportPlaceholder')).GetMenu() self.menuExport.Delete( menuMain.FindItemById(XRCID('menuExportPlaceholder')).GetId()) self.menuExportItem = menuMain.FindItemById(XRCID('menuExport')) self.menuExportItem.Enable(False) # Bind menu events to the proper methods wx.EVT_MENU(self, XRCID('menuOpen'), self.OnOpenPatient) wx.EVT_MENU(self, XRCID('menuExit'), self.OnClose) wx.EVT_MENU(self, XRCID('menuPreferences'), self.OnPreferences) wx.EVT_MENU(self, XRCID('menuShowLogs'), self.OnShowLogs) wx.EVT_MENU(self, XRCID('menuPluginManager'), self.OnPluginManager) wx.EVT_MENU(self, XRCID('menuAbout'), self.OnAbout) wx.EVT_MENU(self, XRCID('menuHomepage'), self.OnHomepage) wx.EVT_MENU(self, XRCID('menuLicense'), self.OnLicense) # Load the toolbar for the frame toolbarMain = self.res.LoadToolBar(self, 'toolbarMain') self.SetToolBar(toolbarMain) self.toolbar = self.GetToolBar() # Setup main toolbar controls folderbmp = wx.Bitmap(util.GetResourcePath('folder_user.png')) self.maintools = [{ 'label': "Open Patient", 'bmp': folderbmp, 'shortHelp': "Open Patient...", 'eventhandler': self.OnOpenPatient }] for m, tool in enumerate(self.maintools): self.toolbar.AddLabelTool(m + 1, tool['label'], tool['bmp'], shortHelp=tool['shortHelp']) self.Bind(wx.EVT_TOOL, tool['eventhandler'], id=m + 1) self.toolbar.Realize() # Bind interface events to the proper methods wx.EVT_CHOICE(self, XRCID('choiceStructure'), self.OnStructureSelect) self.Bind(wx.EVT_ACTIVATE, self.OnActivate) self.Bind(wx.EVT_CLOSE, self.OnClose) self.notebook.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.OnPageChanged) # Events to work around a focus bug in Windows self.notebook.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) self.notebook.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) self.notebookTools.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown) self.notebookTools.Bind(wx.EVT_MOUSEWHEEL, self.OnMouseWheel) self.SetSizer(mainGrid) self.Layout() #Set the Minumum size self.SetMinSize(size) self.Centre(wx.BOTH) # Initialize the welcome notebook tab panelWelcome = self.res.LoadPanel(self.notebook, 'panelWelcome') self.notebook.AddPage(panelWelcome, 'Welcome') # Set the version on the welcome notebook tab XRCCTRL(self, 'lblVersion').SetLabel('Version ' + __version__) # Initialize the tools notebook self.notebookTools.AddPage(self.cclbStructures, 'Structures') self.notebookTools.AddPage(self.cclbIsodoses, 'Isodoses') # Create the data folder datapath = guiutil.get_data_dir() if not os.path.exists(datapath): os.mkdir(datapath) # Initialize the preferences if guiutil.IsMac(): self.prefmgr = preferences.PreferencesManager(parent=None, appname='dicompyler') else: self.prefmgr = preferences.PreferencesManager(parent=None, appname='dicompyler', name='Options') sp = wx.StandardPaths.Get() self.generalpreftemplate = [{ 'DICOM Import Settings': [{ 'name': 'Import Location', 'type': 'choice', 'values': ['Remember Last Used', 'Always Use Default'], 'default': 'Remember Last Used', 'callback': 'general.dicom.import_location_setting' }, { 'name': 'Default Location', 'type': 'directory', 'default': unicode(sp.GetDocumentsDir()), 'callback': 'general.dicom.import_location' }] }, { 'Plugin Settings': [{ 'name': 'User Plugins Location', 'type': 'directory', 'default': unicode(os.path.join(datapath, 'plugins')), 'callback': 'general.plugins.user_plugins_location', 'restart': True }] }, { 'Calculation Settings': [{ 'name': 'DVH Calculation', 'type': 'choice', 'values': ['Use RT Dose DVH if Present', 'Always Recalculate DVH'], 'default': 'Use RT Dose DVH if Present', 'callback': 'general.calculation.dvh_recalc' }] }, { 'Advanced Settings': [{ 'name': 'Enable Detailed Logging', 'type': 'checkbox', 'default': False, 'callback': 'general.advanced.detailed_logging' }] }] self.preftemplate = [{'General': self.generalpreftemplate}] pub.sendMessage('preferences.updated.template', self.preftemplate) # Initialize variables self.ptdata = {} # Set up pubsub pub.subscribe(self.OnLoadPatientData, 'patient.updated.raw_data') pub.subscribe(self.OnStructureCheck, 'colorcheckbox.checked.structure') pub.subscribe(self.OnStructureUncheck, 'colorcheckbox.unchecked.structure') pub.subscribe(self.OnIsodoseCheck, 'colorcheckbox.checked.isodose') pub.subscribe(self.OnIsodoseUncheck, 'colorcheckbox.unchecked.isodose') pub.subscribe(self.OnUpdatePlugins, 'general.plugins.user_plugins_location') pub.subscribe(self.OnUpdatePreferences, 'general') pub.subscribe(self.OnUpdateStatusBar, 'main.update_statusbar') pub.subscribe(self.OnOpenPatient, 'dicomgui.show') # Send a message to the logging system to turn on/off detailed logging pub.sendMessage('preferences.requested.value', 'general.advanced.detailed_logging') # Create the default user plugin path self.userpluginpath = os.path.join(datapath, 'plugins') if not os.path.exists(self.userpluginpath): os.mkdir(self.userpluginpath) # Load and initialize plugins self.plugins = [] self.pluginsDisabled = [] pub.sendMessage('preferences.requested.value', 'general.plugins.user_plugins_location') pub.sendMessage('preferences.requested.value', 'general.calculation.dvh_recalc') pub.sendMessage('preferences.requested.value', 'general.plugins.disabled_list') pub.sendMessage('preferences.requested.values', 'general.window')
def __init__(self, parent=None): style = wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.RESIZE_BORDER if misc.check_wx_version(2, 5): style |= wx.CLOSE_BOX wx.Frame.__init__(self, parent, -1, "wxGlade v%s" % common.version, style=style) self.CreateStatusBar(1) if parent is None: parent = self common.palette = self # to provide a reference accessible # by the various widget classes icon = wx.EmptyIcon() bmp = wx.Bitmap(os.path.join(common.wxglade_path, "icons/icon.xpm"), wx.BITMAP_TYPE_XPM) icon.CopyFromBitmap(bmp) self.SetIcon(icon) self.SetBackgroundColour( wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) menu_bar = wx.MenuBar() file_menu = wx.Menu(style=wx.MENU_TEAROFF) view_menu = wx.Menu(style=wx.MENU_TEAROFF) help_menu = wx.Menu(style=wx.MENU_TEAROFF) wx.ToolTip_SetDelay(1000) # load the available code generators common.load_code_writers() # load the available widgets and sizers core_btns, custom_btns = common.load_widgets() sizer_btns = common.load_sizers() append_item = misc.append_item self.TREE_ID = TREE_ID = wx.NewId() append_item(view_menu, TREE_ID, _("Show &Tree\tF2")) self.PROPS_ID = PROPS_ID = wx.NewId() self.RAISE_ID = RAISE_ID = wx.NewId() append_item(view_menu, PROPS_ID, _("Show &Properties\tF3")) append_item(view_menu, RAISE_ID, _("&Raise All\tF4")) NEW_ID = wx.NewId() append_item(file_menu, NEW_ID, _("&New\tCtrl+N"), wx.ART_NEW) NEW_FROM_TEMPLATE_ID = wx.NewId() append_item(file_menu, NEW_FROM_TEMPLATE_ID, _("New from &Template...\tShift+Ctrl+N")) OPEN_ID = wx.NewId() append_item(file_menu, OPEN_ID, _("&Open...\tCtrl+O"), wx.ART_FILE_OPEN) SAVE_ID = wx.NewId() append_item(file_menu, SAVE_ID, _("&Save\tCtrl+S"), wx.ART_FILE_SAVE) SAVE_AS_ID = wx.NewId() append_item(file_menu, SAVE_AS_ID, _("Save As...\tShift+Ctrl+S"), wx.ART_FILE_SAVE_AS) SAVE_TEMPLATE_ID = wx.NewId() append_item(file_menu, SAVE_TEMPLATE_ID, _("Save As Template...")) file_menu.AppendSeparator() RELOAD_ID = wx.ID_REFRESH #wx.NewId() append_item(file_menu, RELOAD_ID, _("&Refresh\tf5")) #, wx.ART_REDO) GENERATE_CODE_ID = wx.NewId() append_item(file_menu, GENERATE_CODE_ID, _("&Generate Code\tCtrl+G"), wx.ART_EXECUTABLE_FILE) file_menu.AppendSeparator() IMPORT_ID = wx.NewId() append_item(file_menu, IMPORT_ID, _("&Import from XRC...\tCtrl+I")) EXIT_ID = wx.NewId() file_menu.AppendSeparator() append_item(file_menu, EXIT_ID, _('E&xit\tCtrl+Q'), wx.ART_QUIT) PREFS_ID = wx.ID_PREFERENCES #NewId() view_menu.AppendSeparator() MANAGE_TEMPLATES_ID = wx.NewId() append_item(view_menu, MANAGE_TEMPLATES_ID, _('Templates Manager...')) view_menu.AppendSeparator() append_item(view_menu, PREFS_ID, _('Preferences...')) #wx.ART_HELP_SETTINGS) menu_bar.Append(file_menu, _("&File")) menu_bar.Append(view_menu, _("&View")) TUT_ID = wx.NewId() append_item(help_menu, TUT_ID, _('Contents\tF1'), wx.ART_HELP) ABOUT_ID = wx.ID_ABOUT #wx.NewId() append_item(help_menu, ABOUT_ID, _('About...')) #, wx.ART_QUESTION) menu_bar.Append(help_menu, _('&Help')) parent.SetMenuBar(menu_bar) # Mac tweaks... if wx.Platform == "__WXMAC__": wx.App_SetMacAboutMenuItemId(ABOUT_ID) wx.App_SetMacPreferencesMenuItemId(PREFS_ID) wx.App_SetMacExitMenuItemId(EXIT_ID) wx.App_SetMacHelpMenuTitleName(_('&Help')) # file history support if misc.check_wx_version(2, 3, 3): self.file_history = wx.FileHistory( config.preferences.number_history) self.file_history.UseMenu(file_menu) files = config.load_history() files.reverse() for path in files: self.file_history.AddFileToHistory(path.strip()) def open_from_history(event): if not self.ask_save(): return infile = self.file_history.GetHistoryFile(event.GetId() - wx.ID_FILE1) # ALB 2004-10-15 try to restore possible autosave content... if common.check_autosaved(infile) and \ wx.MessageBox(_("There seems to be auto saved data for " "this file: do you want to restore it?"), _("Auto save detected"), style=wx.ICON_QUESTION|wx.YES_NO) == wx.YES: common.restore_from_autosaved(infile) else: common.remove_autosaved(infile) self._open_app(infile) wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, open_from_history) wx.EVT_MENU(self, TREE_ID, self.show_tree) wx.EVT_MENU(self, PROPS_ID, self.show_props_window) wx.EVT_MENU(self, RAISE_ID, self.raise_all) wx.EVT_MENU(self, NEW_ID, self.new_app) wx.EVT_MENU(self, NEW_FROM_TEMPLATE_ID, self.new_app_from_template) wx.EVT_MENU(self, OPEN_ID, self.open_app) wx.EVT_MENU(self, SAVE_ID, self.save_app) wx.EVT_MENU(self, SAVE_AS_ID, self.save_app_as) wx.EVT_MENU(self, SAVE_TEMPLATE_ID, self.save_app_as_template) def generate_code(event): common.app_tree.app.generate_code() wx.EVT_MENU(self, GENERATE_CODE_ID, generate_code) wx.EVT_MENU(self, EXIT_ID, lambda e: self.Close()) wx.EVT_MENU(self, TUT_ID, self.show_tutorial) wx.EVT_MENU(self, ABOUT_ID, self.show_about_box) wx.EVT_MENU(self, PREFS_ID, self.edit_preferences) wx.EVT_MENU(self, MANAGE_TEMPLATES_ID, self.manage_templates) wx.EVT_MENU(self, IMPORT_ID, self.import_xrc) wx.EVT_MENU(self, RELOAD_ID, self.reload_app) PREVIEW_ID = wx.NewId() def preview(event): if common.app_tree.cur_widget is not None: p = misc.get_toplevel_widget(common.app_tree.cur_widget) if p is not None: p.preview(None) wx.EVT_MENU(self, PREVIEW_ID, preview) self.accel_table = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('N'), NEW_ID), (wx.ACCEL_CTRL, ord('O'), OPEN_ID), (wx.ACCEL_CTRL, ord('S'), SAVE_ID), (wx.ACCEL_CTRL | wx.ACCEL_SHIFT, ord('S'), SAVE_AS_ID), (wx.ACCEL_CTRL, ord('G'), GENERATE_CODE_ID), (wx.ACCEL_CTRL, ord('I'), IMPORT_ID), (0, wx.WXK_F1, TUT_ID), (wx.ACCEL_CTRL, ord('Q'), EXIT_ID), (0, wx.WXK_F5, RELOAD_ID), (0, wx.WXK_F2, TREE_ID), (0, wx.WXK_F3, PROPS_ID), (0, wx.WXK_F4, RAISE_ID), (wx.ACCEL_CTRL, ord('P'), PREVIEW_ID), ]) # Tutorial window ## self.tut_frame = None # layout # if there are custom components, add the toggle box... if custom_btns: main_sizer = wx.BoxSizer(wx.VERTICAL) show_core_custom = ToggleButtonBox( self, -1, [_("Core components"), _("Custom components")], 0) if misc.check_wx_version(2, 5): core_sizer = wx.FlexGridSizer( 0, config.preferences.buttons_per_row) custom_sizer = wx.FlexGridSizer( 0, config.preferences.buttons_per_row) else: core_sizer = wx.GridSizer(0, config.preferences.buttons_per_row) custom_sizer = wx.GridSizer(0, config.preferences.buttons_per_row) self.SetAutoLayout(True) # core components for b in core_btns: core_sizer.Add(b) for sb in sizer_btns: core_sizer.Add(sb) # custom components for b in custom_btns: custom_sizer.Add(b) if misc.check_wx_version(2, 5): custom_sizer.Show(b, False) custom_sizer.Layout() main_sizer.Add(show_core_custom, 0, wx.EXPAND) main_sizer.Add(core_sizer, 0, wx.EXPAND) main_sizer.Add(custom_sizer, 0, wx.EXPAND) self.SetSizer(main_sizer) if not misc.check_wx_version(2, 5): main_sizer.Show(custom_sizer, False) #main_sizer.Show(1, False) main_sizer.Fit(self) # events to display core/custom components if misc.check_wx_version(2, 5): def on_show_core_custom(event): show_core = True show_custom = False if event.GetValue() == 1: show_core = False show_custom = True for b in custom_btns: custom_sizer.Show(b, show_custom) for b in core_btns: core_sizer.Show(b, show_core) for b in sizer_btns: core_sizer.Show(b, show_core) core_sizer.Layout() custom_sizer.Layout() main_sizer.Layout() else: def on_show_core_custom(event): to_show = core_sizer to_hide = custom_sizer if event.GetValue() == 1: to_show, to_hide = to_hide, to_show main_sizer.Show(to_show, True) main_sizer.Show(to_hide, False) main_sizer.Layout() EVT_TOGGLE_BOX(self, show_core_custom.GetId(), on_show_core_custom) # ... otherwise (the common case), just add the palette of core buttons else: sizer = wx.GridSizer(0, config.preferences.buttons_per_row) self.SetAutoLayout(True) # core components for b in core_btns: sizer.Add(b) for sb in sizer_btns: sizer.Add(sb) self.SetSizer(sizer) sizer.Fit(self) # Properties window frame_style = wx.DEFAULT_FRAME_STYLE frame_tool_win = config.preferences.frame_tool_win if frame_tool_win: frame_style |= wx.FRAME_NO_TASKBAR | wx.FRAME_FLOAT_ON_PARENT frame_style &= ~wx.MINIMIZE_BOX if wx.Platform != '__WXGTK__': frame_style |= wx.FRAME_TOOL_WINDOW self.frame2 = wx.Frame(self, -1, _('Properties - <app>'), style=frame_style) self.frame2.SetBackgroundColour( wx.SystemSettings_GetColour(wx.SYS_COLOUR_BTNFACE)) self.frame2.SetIcon(icon) sizer_tmp = wx.BoxSizer(wx.VERTICAL) property_panel = wxGladePropertyPanel(self.frame2, -1) #---- 2003-06-22 Fix for what seems to be a GTK2 bug (notebooks) misc.hidden_property_panel = wx.Panel(self.frame2, -1) sz = wx.BoxSizer(wx.VERTICAL) sz.Add(property_panel, 1, wx.EXPAND) sz.Add(misc.hidden_property_panel, 1, wx.EXPAND) self.frame2.SetSizer(sz) sz.Show(misc.hidden_property_panel, False) self.property_frame = self.frame2 #-------------------------------------------------------- property_panel.SetAutoLayout(True) self.hidden_frame = wx.Frame(self, -1, "") self.hidden_frame.Hide() sizer_tmp.Add(property_panel, 1, wx.EXPAND) self.frame2.SetAutoLayout(True) self.frame2.SetSizer(sizer_tmp) sizer_tmp = wx.BoxSizer(wx.VERTICAL) def hide_frame2(event): #menu_bar.Check(PROPS_ID, False) self.frame2.Hide() wx.EVT_CLOSE(self.frame2, hide_frame2) wx.EVT_CLOSE(self, self.cleanup) common.property_panel = property_panel # Tree of widgets self.tree_frame = wx.Frame(self, -1, _('wxGlade: Tree'), style=frame_style) self.tree_frame.SetIcon(icon) import application app = application.Application(common.property_panel) common.app_tree = WidgetTree(self.tree_frame, app) self.tree_frame.SetSize((300, 300)) app.notebook.Show() sizer_tmp.Add(app.notebook, 1, wx.EXPAND) property_panel.SetSizer(sizer_tmp) sizer_tmp.Fit(property_panel) def on_tree_frame_close(event): #menu_bar.Check(TREE_ID, False) self.tree_frame.Hide() wx.EVT_CLOSE(self.tree_frame, on_tree_frame_close) # check to see if there are some remembered values prefs = config.preferences if prefs.remember_geometry: #print 'initializing geometry' try: x, y, w, h = prefs.get_geometry('main') misc.set_geometry(self, (x, y)) except Exception, e: pass misc.set_geometry(self.frame2, prefs.get_geometry('properties')) misc.set_geometry(self.tree_frame, prefs.get_geometry('tree'))
def setupMenus(self): frame = self.GetParent() if Utils.iAmOnMac(): wx.App_SetMacExitMenuItemId(self.ID_EXIT) wx.App_SetMacPreferencesMenuItemId(self.ID_PREFS) wx.App_SetMacAboutMenuItemId(self.ID_ABOUT) #menus self.filemenu = wx.Menu() self.filemenu.Append(self.ID_NEW, '&' + ('New Script') + '\tCtrl+N', _("Make new script")) self.filemenu.Append(self.ID_OPEN, '&' + _('Open Module...') + '\tCtrl+O', _("Open a File")) self.filemenu.AppendSeparator() self.filemenu.Append(self.ID_SAVE, '&' + _('Save') + '\tCtrl+S', _("Save File")) self.filemenu.Append(self.ID_SAVEAS, '&' + _('Save As...') + '\tShift+Ctrl+S', _("Save File under a new name")) if not Utils.iAmOnMac(): self.filemenu.Append(self.ID_EXIT,_('E&xit') + '\tAlt-X', _("Quit NeverScript")) self.filemenu.Enable(self.ID_SAVE,False) self.filemenu.Enable(self.ID_SAVEAS,False) self.editmenu = wx.Menu() self.setupEditMenu() helpmenu = wx.Menu() helpmenu.Append(self.ID_ABOUT, '&' + _('About...'), _("About NeverScript")) helpmenu.Append(self.ID_HELP,'&'+ _('NeverScript Help'), _("NeverScript Help")) menuBar = wx.MenuBar() menuBar.Append(self.filemenu,"&" + _("File")) menuBar.Append(self.editmenu, "&" + _("Edit")) menuBar.Append(helpmenu, "&" + _("Help")) frame.SetMenuBar(menuBar) # wx.EVT_MENU(frame,self.ID_NEW,self.OnNew) # wx.EVT_MENU(frame,self.ID_OPEN,self.openFile) # wx.EVT_MENU(frame,self.ID_SAVE,self.saveFile) # wx.EVT_MENU(frame,self.ID_SAVEAS,self.saveFileAs) # wx.EVT_MENU(frame,self.ID_ABOUT,self.about) # wx.EVT_MENU(frame,self.ID_EXIT,self.exit) # wx.EVT_MENU(frame,self.ID_HELP,self.help) # wx.EVT_MENU(frame,self.ID_PREFS,self.OnPreferences) frame.Bind(wx.EVT_MENU,self.OnNew,id=self.ID_NEW) frame.Bind(wx.EVT_MENU,self.openFile,id=self.ID_OPEN) frame.Bind(wx.EVT_MENU,self.saveFile,id=self.ID_SAVE) frame.Bind(wx.EVT_MENU,self.saveFileAs,id=self.ID_SAVEAS) frame.Bind(wx.EVT_MENU,self.about,id=self.ID_ABOUT) frame.Bind(wx.EVT_MENU,self.exit,id=self.ID_EXIT) frame.Bind(wx.EVT_MENU,self.help,id=self.ID_HELP) frame.Bind(wx.EVT_MENU,self.OnPreferences,id=self.ID_PREFS) self.filemenu.Enable(self.ID_SAVEAS,False) self.editmenu.Enable(self.ID_COPY,False) self.editmenu.Enable(self.ID_DEL,False) self.editmenu.Enable(self.ID_PASTE,False) self.editmenu.Enable(self.ID_CUT,False) self.filemenu.Enable(self.ID_NEW,False) self.filemenu.Enable(self.ID_SAVE,False) if self.standalone: self.editmenu.Enable(self.ID_PREFS,True)
def __init__(self, img_viewer, path, **kwds): wx.Frame.__init__(self, None, -1, "") self.window_1 = wx.SplitterWindow(self, -1, style=0) self.window_1_pane_1 = wx.Panel(self.window_1, -1, style=0) self.window_2 = wx.SplitterWindow(self.window_1_pane_1, -1, style=0) self.window_2_pane_1 = wx.Panel(self.window_2, -1, style=0) if wx.Platform == '__WXGTK__': nbstyle = wx.NB_BOTTOM else: nbstyle = 0 self.preview_notebook = wx.Notebook(self.window_2, -1, style=nbstyle) #self.preview_panel = preview.PreviewPanel(self.window_2, -1) self.preview_panel = preview.PreviewPanel(self.preview_notebook, -1) self.exif_info = exif_info.ExifInfo(self.preview_notebook) self.preview_notebook.AddPage(self.preview_panel, _("Preview")) self.preview_notebook.AddPage(self.exif_info, _("Exif data")) self.window_1_pane_2 = wx.Panel(self.window_1, -1, style=0) self.statusbar = self.CreateStatusBar(4) self.notebook = wx.Notebook(self.window_2_pane_1, -1) self.dir_ctrl = dirctrl.DirCtrl(self.notebook, -1, style=wx.SUNKEN_BORDER | wx.DIRCTRL_DIR_ONLY) self.bookmarks = bmarks.BookMarksCtrl(self.notebook) self.albums = albums.AlbumsCtrl(self.notebook) self.viewer = img_viewer self.viewer.cornice_browser = self self.options = kwds self.picture_list = picture_list.PictureList(self.window_1_pane_2, -1, self.options, self) self.albums.picture_list = self.picture_list # Menu Bar res = wx.xrc.XmlResource.Get() res.Load('resources.xrc') self.SetMenuBar(res.LoadMenuBar('menubar')) self.bind_menubar_events() if wx.Platform == '__WXMAC__': wx.App_SetMacAboutMenuItemId(wx.xrc.XRCID('about')) wx.App_SetMacPreferencesMenuItemId(wx.xrc.XRCID('preferences')) wx.App_SetMacExitMenuItemId(wx.xrc.XRCID('exit')) wx.App_SetMacHelpMenuTitleName('Help') # Tool Bar ## res.Load('toolbars.xrc') common.load_from_theme('toolbars.xrc') self.SetToolBar(res.LoadToolBar(self, 'browser_toolbar')) index = common.config.getint('cornice', 'default_view') if index == 0: self.GetToolBar().ToggleTool(wx.xrc.XRCID('report_view'), True) self.GetMenuBar().Check(wx.xrc.XRCID('report_view'), True) else: self.GetToolBar().ToggleTool(wx.xrc.XRCID('thumbs_view'), True) self.GetMenuBar().Check(wx.xrc.XRCID('thumbs_view'), True) self.__do_layout() self.__set_properties() if common.config.getboolean('cornice', 'show_hidden'): self.GetMenuBar().Check(wx.xrc.XRCID('show_hidden'), True) self.dir_ctrl.ShowHidden(True) self.dir_ctrl.SetPath(path) #--- hack to fix bug of dir_ctrl --- tree = self.dir_ctrl.GetTreeCtrl() tree.EnsureVisible(tree.GetSelection()) #----------------------------------- if common.config.getint('cornice', 'default_view') == 1: # do this later, otherwise if started in thumbs view, the layout # is messed up... wx.CallAfter(self.picture_list.set_path, path) else: self.picture_list.set_path(path) # dir selection... and thumbs/report view TIMER_ID = wx.NewId() self.which_case = 0 # 0 = dir_selection, 1 = details, 2 = thumbnails self.set_path_timer = wx.Timer(self, TIMER_ID) ###wx.EVT_TIMER(self, TIMER_ID, self.on_timer) wx.EvtHandler.Bind(self, wx.EVT_TIMER, self.on_timer, id=TIMER_ID) ###wx.EVT_TREE_SEL_CHANGED(self.dir_ctrl, -1, #self.dir_ctrl.GetTreeCtrl().GetId(), ### self.on_tree_sel_changed) wx.EvtHandler.Bind(self.dir_ctrl, wx.EVT_TREE_SEL_CHANGED, self.on_tree_sel_changed, id=-1) ###wx.EVT_IDLE(self, self.on_idle) wx.EvtHandler.Bind(self, wx.EVT_IDLE, self.on_idle) ###picture_list.EVT_PL_CHANGE_PATH(self.picture_list, -1, ###self.on_pl_change_path) wx.EvtHandler.Bind(self.picture_list, picture_list.EVT_PL_CHANGE_PATH, self.on_pl_change_path, id=-1) ID_FOCUS_PATH = wx.NewId() self.SetAcceleratorTable(wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('l'), ID_FOCUS_PATH) ])) # focus the dircompleter... #wx.EVT_MENU(self, ID_FOCUS_PATH, self.picture_list.focus_path) wx.EvtHandler.Bind(self, wx.EVT_MENU, self.picture_list.focus_path, id=ID_FOCUS_PATH) self.show_exif(False)
def create_menu(self, parent): menu_bar = wx.MenuBar() compat.wx_ToolTip_SetDelay(1000) compat.wx_ToolTip_SetAutoPop(30000) append_menu_item = misc.append_menu_item # File menu file_menu = wx.Menu(style=wx.MENU_TEAROFF) NEW = append_menu_item(file_menu, -1, _("&New\tCtrl+N"), wx.ART_NEW) misc.bind_menu_item(self, NEW, self.new_app) item = append_menu_item(file_menu, -1, _("New from &Template...\tShift+Ctrl+N")) misc.bind_menu_item(self, item, self.new_app_from_template) OPEN = append_menu_item(file_menu, -1, _("&Open...\tCtrl+O"), wx.ART_FILE_OPEN) misc.bind_menu_item(self, OPEN, self.open_app) SAVE = append_menu_item(file_menu, -1, _("&Save\tCtrl+S"), wx.ART_FILE_SAVE) misc.bind_menu_item(self, SAVE, self.save_app) SAVE_AS = append_menu_item(file_menu, -1, _("Save As..."), wx.ART_FILE_SAVE_AS) misc.bind_menu_item(self, SAVE_AS, self.save_app_as) item = append_menu_item(file_menu, -1, _("Save As Template...")) misc.bind_menu_item(self, item, self.save_app_as_template) file_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- item = append_menu_item(file_menu, wx.ID_REFRESH, _("&Refresh Preview\tF5")) misc.bind_menu_item(self, item, self.preview) GENERATE_CODE = append_menu_item(file_menu, -1, _("&Generate Code\tCtrl+G"), wx.ART_EXECUTABLE_FILE) misc.bind_menu_item(self, GENERATE_CODE, lambda: common.app_tree.app.generate_code()) file_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- item = append_menu_item(file_menu, -1, _("&Import from XRC...")) misc.bind_menu_item(self, item, self.import_xrc) file_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- EXIT = append_menu_item(file_menu, -1, _('E&xit\tCtrl+Q'), wx.ART_QUIT) misc.bind_menu_item(self, EXIT, self.Close) menu_bar.Append(file_menu, _("&File")) # View menu view_menu = wx.Menu(style=wx.MENU_TEAROFF) TREE = append_menu_item(view_menu, -1, _("Show &Tree\tF2")) misc.bind_menu_item(self, TREE, self.show_tree) PROPS = append_menu_item(view_menu, -1, _("Show &Properties\tF3")) misc.bind_menu_item(self, PROPS, self.show_props_window) RAISE = append_menu_item(view_menu, -1, _("&Raise All\tF4")) misc.bind_menu_item(self, RAISE, self.raise_all) DESIGN = append_menu_item(view_menu, -1, _("Show &Design\tF6")) misc.bind_menu_item(self, DESIGN, self.show_design_window) view_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- item = append_menu_item(view_menu, -1, _('Template Manager...')) misc.bind_menu_item(self, item, self.manage_templates) view_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- item = append_menu_item(view_menu, wx.ID_PREFERENCES, _('Preferences...')) misc.bind_menu_item(self, item, self.edit_preferences) menu_bar.Append(view_menu, _("&View")) # Help menu help_menu = wx.Menu(style=wx.MENU_TEAROFF) MANUAL = append_menu_item(help_menu, -1, _('Manual\tF1'), wx.ART_HELP) misc.bind_menu_item(self, MANUAL, self.show_manual) #item = append_menu_item(help_menu, -1, _('Tutorial')) #misc.bind_menu_item(self, item, self.show_tutorial) help_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- i = append_menu_item(help_menu, -1, _('Mailing list')) misc.bind_menu_item(self, i, self.show_mailing_list) i = append_menu_item(help_menu, -1, _('Bug tracker')) misc.bind_menu_item(self, i, self.show_bug_tracker) i = append_menu_item(help_menu, -1, _('Releases')) misc.bind_menu_item(self, i, self.show_releases) help_menu.AppendSeparator( ) # ---------------------------------------------------------------------------------- item = append_menu_item(help_menu, wx.ID_ABOUT, _('About')) misc.bind_menu_item(self, item, self.show_about_box) menu_bar.Append(help_menu, _('&Help')) parent.SetMenuBar(menu_bar) # Mac tweaks... if wx.Platform == "__WXMAC__": if compat.IS_PHOENIX: wx.PyApp.SetMacAboutMenuItemId(wx.ID_ABOUT) wx.PyApp.SetMacPreferencesMenuItemId(wx.ID_PREFERENCES) wx.PyApp.SetMacExitMenuItemId(wx.ID_EXIT) wx.PyApp.SetMacHelpMenuTitleName(_('&Help')) else: wx.App_SetMacAboutMenuItemId(wx.ID_ABOUT) wx.App_SetMacPreferencesMenuItemId(wx.ID_PREFERENCES) wx.App_SetMacExitMenuItemId(wx.ID_EXIT) wx.App_SetMacHelpMenuTitleName(_('&Help')) # file history support self.file_history = wx.FileHistory(config.preferences.number_history) self.file_history.UseMenu(file_menu) files = common.load_file_history() files.reverse() for path in files: self.file_history.AddFileToHistory(path.strip()) self.Bind(wx.EVT_MENU_RANGE, self.open_from_history, id=wx.ID_FILE1, id2=wx.ID_FILE9)
def create_menu(self, parent): menu_bar = wx.MenuBar() file_menu = wx.Menu(style=wx.MENU_TEAROFF) view_menu = wx.Menu(style=wx.MENU_TEAROFF) help_menu = wx.Menu(style=wx.MENU_TEAROFF) compat.wx_ToolTip_SetDelay(1000) compat.wx_ToolTip_SetAutoPop(30000) append_menu_item = misc.append_menu_item self.TREE_ID = TREE_ID = wx.NewId() append_menu_item(view_menu, TREE_ID, _("Show &Tree\tF2")) self.PROPS_ID = PROPS_ID = wx.NewId() self.RAISE_ID = RAISE_ID = wx.NewId() append_menu_item(view_menu, PROPS_ID, _("Show &Properties\tF3")) append_menu_item(view_menu, RAISE_ID, _("&Raise All\tF4")) NEW_ID = wx.NewId() append_menu_item(file_menu, NEW_ID, _("&New\tCtrl+N"), wx.ART_NEW) NEW_FROM_TEMPLATE_ID = wx.NewId() append_menu_item(file_menu, NEW_FROM_TEMPLATE_ID, _("New from &Template...\tShift+Ctrl+N")) OPEN_ID = wx.NewId() append_menu_item(file_menu, OPEN_ID, _("&Open...\tCtrl+O"), wx.ART_FILE_OPEN) SAVE_ID = wx.NewId() append_menu_item(file_menu, SAVE_ID, _("&Save\tCtrl+S"), wx.ART_FILE_SAVE) SAVE_AS_ID = wx.NewId() append_menu_item(file_menu, SAVE_AS_ID, _("Save As...\tShift+Ctrl+S"), wx.ART_FILE_SAVE_AS) SAVE_TEMPLATE_ID = wx.NewId() append_menu_item(file_menu, SAVE_TEMPLATE_ID, _("Save As Template...")) file_menu.AppendSeparator() append_menu_item(file_menu, wx.ID_REFRESH, _("&Refresh Preview\tF5")) GENERATE_CODE_ID = wx.NewId() append_menu_item(file_menu, GENERATE_CODE_ID, _("&Generate Code\tCtrl+G"), wx.ART_EXECUTABLE_FILE) file_menu.AppendSeparator() IMPORT_ID = wx.NewId() append_menu_item(file_menu, IMPORT_ID, _("&Import from XRC...")) EXIT_ID = wx.NewId() file_menu.AppendSeparator() append_menu_item(file_menu, EXIT_ID, _('E&xit\tCtrl+Q'), wx.ART_QUIT) PREFS_ID = wx.ID_PREFERENCES view_menu.AppendSeparator() MANAGE_TEMPLATES_ID = wx.NewId() append_menu_item(view_menu, MANAGE_TEMPLATES_ID, _('Template Manager...')) view_menu.AppendSeparator() append_menu_item(view_menu, PREFS_ID, _('Preferences...')) menu_bar.Append(file_menu, _("&File")) menu_bar.Append(view_menu, _("&View")) MANUAL_ID = wx.NewId() append_menu_item(help_menu, MANUAL_ID, _('Manual\tF1'), wx.ART_HELP) TUTORIAL_ID = wx.NewId() append_menu_item(help_menu, TUTORIAL_ID, _('Tutorial')) help_menu.AppendSeparator() ABOUT_ID = wx.ID_ABOUT append_menu_item(help_menu, ABOUT_ID, _('About')) menu_bar.Append(help_menu, _('&Help')) parent.SetMenuBar(menu_bar) # Mac tweaks... if wx.Platform == "__WXMAC__": wx.App_SetMacAboutMenuItemId(ABOUT_ID) wx.App_SetMacPreferencesMenuItemId(PREFS_ID) wx.App_SetMacExitMenuItemId(EXIT_ID) wx.App_SetMacHelpMenuTitleName(_('&Help')) # file history support self.file_history = wx.FileHistory(config.preferences.number_history) self.file_history.UseMenu(file_menu) files = common.load_history() files.reverse() for path in files: self.file_history.AddFileToHistory(path.strip()) wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, self.open_from_history) wx.EVT_MENU(self, TREE_ID, self.show_tree) wx.EVT_MENU(self, PROPS_ID, self.show_props_window) wx.EVT_MENU(self, RAISE_ID, self.raise_all) wx.EVT_MENU(self, NEW_ID, self.new_app) wx.EVT_MENU(self, NEW_FROM_TEMPLATE_ID, self.new_app_from_template) wx.EVT_MENU(self, OPEN_ID, self.open_app) wx.EVT_MENU(self, SAVE_ID, self.save_app) wx.EVT_MENU(self, SAVE_AS_ID, self.save_app_as) wx.EVT_MENU(self, SAVE_TEMPLATE_ID, self.save_app_as_template) def generate_code(event): common.app_tree.app.generate_code() wx.EVT_MENU(self, GENERATE_CODE_ID, generate_code) wx.EVT_MENU(self, EXIT_ID, lambda e: self.Close()) wx.EVT_MENU(self, MANUAL_ID, self.show_manual) wx.EVT_MENU(self, TUTORIAL_ID, self.show_tutorial) wx.EVT_MENU(self, ABOUT_ID, self.show_about_box) wx.EVT_MENU(self, PREFS_ID, self.edit_preferences) wx.EVT_MENU(self, MANAGE_TEMPLATES_ID, self.manage_templates) wx.EVT_MENU(self, IMPORT_ID, self.import_xrc) wx.EVT_MENU(self, wx.ID_REFRESH, self.preview) # self.reload_app) PREVIEW_ID = wx.NewId() wx.EVT_MENU(self, PREVIEW_ID, self.preview) self.accel_table = wx.AcceleratorTable([ (wx.ACCEL_CTRL, ord('N'), NEW_ID), (wx.ACCEL_CTRL, ord('O'), OPEN_ID), (wx.ACCEL_CTRL, ord('S'), SAVE_ID), (wx.ACCEL_CTRL | wx.ACCEL_SHIFT, ord('S'), SAVE_AS_ID), (wx.ACCEL_CTRL, ord('G'), GENERATE_CODE_ID), #(wx.ACCEL_CTRL, ord('I'), IMPORT_ID), (0, wx.WXK_F1, MANUAL_ID), (wx.ACCEL_CTRL, ord('Q'), EXIT_ID), (0, wx.WXK_F5, wx.ID_REFRESH), (0, wx.WXK_F2, TREE_ID), (0, wx.WXK_F3, PROPS_ID), (0, wx.WXK_F4, RAISE_ID), (wx.ACCEL_CTRL, ord('P'), PREVIEW_ID), ])
def updateMenus(self): """Create the main frame menus based on menuItems array.""" global menuItems self.menuCommandMap = {} # Array of menus. Number to wxMenu. self.menus = {} # Three levels of priority. for level in range(len(menuItems)): if len(menuItems[level]) == 0: # No menu for this. self.menus[level] = None continue self.menus[level] = wx.Menu() self.menuBar.Append(self.menus[level], language.translate("menu-" + str(level))) # Sort the items based on groups, and append separators where necessary. menuItems[level].sort(lambda x, y: cmp(x[3], y[3])) separated = [] previousItem = None for item in menuItems[level]: if previousItem and previousItem[3] != item[3]: separated.append(('-', '', False, item[3])) separated.append(item) previousItem = item # Create the menu items. for itemId, itemCommand, itemSeparate, itemGroup in separated: if itemId == '-': # This is just a separator. self.menus[level].AppendSeparator() continue if itemSeparate and self.menus[level].GetMenuItemCount() > 0: self.menus[level].AppendSeparator() menuItemId = 'menu-' + itemId accel = '' if language.isDefined(menuItemId + '-accel'): accel = "\t" + language.translate(menuItemId + '-accel') # Generate a new ID for the item. wxId = wx.NewId() self.menuCommandMap[wxId] = itemCommand self.menus[level].Append( wxId, uniConv(language.translate(menuItemId) + accel)) wx.EVT_MENU(self, wxId, self.onPopupCommand) if host.isMac(): # Special menu items on Mac. if itemId == 'about': wx.App_SetMacAboutMenuItemId(wxId) if itemId == 'quit': wx.App_SetMacExitMenuItemId(wxId) if itemId == 'show-snowberry-settings': wx.App_SetMacPreferencesMenuItemId(wxId) if host.isMac(): # Special Help menu on Mac. wx.App_SetMacHelpMenuTitleName( language.translate('menu-' + str(MENU_HELP))) self.SetMenuBar(self.menuBar)