コード例 #1
0
    def __OnShowDatabaseWizard(self, event): 
        """ User wants to switch DB's or upgrade, or create a DB, or create a demo db.
            This can also be auto invoked by the application to let the user select a DB """

        dlg = WelcomeDlg.WelcomeDlg(self)            
        dlg.Centre()
        dlg.ShowModal()
        dlg.Destroy()

        if not db.engine.Get().IsOpened():    
            self.Close()
            return

        viewmgr.signalDbChange()
コード例 #2
0
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        # create menu
        self.__menuBar = wx.MenuBar()
        self.SetMenuBar(self.__menuBar)

        # file menu	
        mnu = wx.Menu()        
        self.__menuShowDatabaseWizard = wx.MenuItem(mnu, wx.NewId(), "&Show Database Wizard ...", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuShowDatabaseWizard)
        self.__menuOptions = wx.MenuItem(mnu, wx.NewId(), "&Preferences ...", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuOptions)
        mnu.AppendSeparator()
        self.__menuExit = wx.MenuItem(mnu, wx.NewId(), "E&xit", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuExit)
        self.__menuBar.Append(mnu, "&File")

        # songs menu
        mnu = wx.Menu()
        self.__menuAddNewSong = wx.MenuItem(mnu, wx.NewId(), "&Add New ...\tCtrl+N", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuAddNewSong)
        self.__menuEditSong = wx.MenuItem(mnu, wx.NewId(), "&Edit ...\tCtrl+E", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuEditSong)
        self.__menuDeleteSong = wx.MenuItem(mnu, wx.NewId(), "&Delete\tCtrl+D", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuDeleteSong)
        
        # status submenu
        self.__menu_status_lookup = {}
        items = [ ("&In progress", songs.SS_STARTED), 
                  ("&Not Practicing", songs.SS_POSTPONED),
                  ("&Completed!", songs.SS_COMPLETED) ]
        
        smnu = wx.Menu()
        for i in items:
            mi = wx.MenuItem(smnu, wx.NewId(), i[0], "", wx.ITEM_NORMAL)
            smnu.AppendItem(mi)
            self.__menu_status_lookup[mi.GetId()] = i[1]
            self.Bind(wx.EVT_MENU, self.__OnChangeStatus, mi)        
        
        mnu.AppendSubMenu(smnu, "Set &Status To")
        self.__menuSongStatus = smnu

        self.__menuEditReset = wx.MenuItem(mnu, wx.NewId(), "Reset &History", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuEditReset)    

        mnu.AppendSeparator()
        self.__menuEditCategories = wx.MenuItem(mnu, wx.NewId(), "Edit &Categories ...\tCtrl+Shift+C", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuEditCategories)
        self.__menuBar.Append(mnu, "&Song")
        
        # window layout menu
        mnu = wx.Menu()
        self.__menuRestoreLayout = wx.MenuItem(mnu, wx.NewId(), "&Restore Default Layout", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuRestoreLayout)
        mnu.AppendSeparator()
        self.__menuToggleEditView = wx.MenuItem(mnu, wx.NewId(), "Show &Editors", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuToggleEditView)
        self.__menuToggleSongSelect = wx.MenuItem(mnu, wx.NewId(), "Show &Song Selector", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuToggleSongSelect)
        self.__menuToggelSongFilter = wx.MenuItem(mnu, wx.NewId(), "Show Song &Filter", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuToggelSongFilter)
        mnu.AppendSeparator()
        self.__menuBrowserMode = wx.MenuItem(mnu, wx.NewId(), "&Browser Mode", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuBrowserMode)
        self.__menuEditorMode = wx.MenuItem(mnu, wx.NewId(), "Editor &Mode", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuEditorMode)
        self.__menuBar.Append(mnu, "&Windows")

        # attachments menu
        mnu = wx.Menu()
        self.__menuCreateAttachDir = wx.MenuItem(mnu, wx.NewId(), "&Create Folder ...", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuCreateAttachDir)
        mnu.AppendSeparator()
        self.__menuAddAttachments = wx.MenuItem(mnu, wx.NewId(), "&Add ...", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuAddAttachments)
        self.__menuEditAttachments = wx.MenuItem(mnu, wx.NewId(), "&Edit ...", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuEditAttachments)
        self.__menuRefreshAttachments = wx.MenuItem(mnu, wx.NewId(), "&Refresh", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuRefreshAttachments)
        self.__menuBar.Append(mnu, "&Attachments")
        
        # help menu
        mnu = wx.Menu()
        self.__menuHelpVisitSite = wx.MenuItem(mnu, wx.NewId(), "&Visit Site .. ", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuHelpVisitSite)
        mnu.AppendSeparator()
        self.__menuHelpAbout = wx.MenuItem(mnu, wx.NewId(), "&About ...", "", wx.ITEM_NORMAL)
        mnu.AppendItem(self.__menuHelpAbout)
        self.__menuBar.Append(mnu, "&Help")
        
        # set all properties
        self.SetTitle("Guitar Portfolio")
        self.Layout()

        self.Bind(wx.EVT_MENU, self.__OnShowDatabaseWizard, self.__menuShowDatabaseWizard)
        self.Bind(wx.EVT_MENU, self.__OnShowOptions, self.__menuOptions)
        self.Bind(wx.EVT_MENU, self.OnExit, self.__menuExit)
        self.Bind(wx.EVT_MENU, self.__OnAddNewSong, self.__menuAddNewSong)
        self.Bind(wx.EVT_MENU, self.__OnEditNewSong, self.__menuEditSong)
        self.Bind(wx.EVT_MENU, self.__OnDeleteSong, self.__menuDeleteSong)
        self.Bind(wx.EVT_MENU, self.__OnEditCategories, self.__menuEditCategories)
        self.Bind(wx.EVT_MENU, self.__OnRestoreLayout, self.__menuRestoreLayout)
        self.Bind(wx.EVT_MENU, self.__OnToggleEditWindow, self.__menuToggleEditView)
        self.Bind(wx.EVT_MENU, self.__OnToggleSongSelector, self.__menuToggleSongSelect)
        self.Bind(wx.EVT_MENU, self.__OnToggleFilterWindow, self.__menuToggelSongFilter)
        self.Bind(wx.EVT_MENU, self.__OnBrowserMode, self.__menuBrowserMode)
        self.Bind(wx.EVT_MENU, self.__OnEditorMode, self.__menuEditorMode)
        self.Bind(wx.EVT_MENU, self.__OnVisitSite, self.__menuHelpVisitSite)
        self.Bind(wx.EVT_MENU, self.__OnAbout, self.__menuHelpAbout)
        self.Bind(wx.EVT_MENU, self.__OnCreateAttachmentsDir, self.__menuCreateAttachDir)
        self.Bind(wx.EVT_MENU, self.__OnAddAttachments, self.__menuAddAttachments)
        self.Bind(wx.EVT_MENU, self.__OnEditAttachments, self.__menuEditAttachments)
        self.Bind(wx.EVT_MENU, self.__OnRefreshAttachments, self.__menuRefreshAttachments)

        self.SetIcon(wx.IconFromBitmap(icon_main_window.getBitmap()))
        self.Bind(wx.EVT_CLOSE, self.__OnClose)

        # tell AUI to manage this frame        
        self.__aui = wx.aui.AuiManager()
        self.__aui.SetManagedWindow(self)

        # construct the left panels
        self.__aui.AddPane(SongsPanel.SongsPanel(parent = self), wx.aui.AuiPaneInfo().
                           Name("songspanel").Caption("Songs").MinSize(wx.Size(280,100)).
                           BestSize(wx.Size(280, 200)).Left().MaximizeButton(True))

        self.__aui.AddPane(SongFilterPanel.SongFilterPanel(self), wx.aui.AuiPaneInfo().Name("filterpanel").Caption("Filter").
                           MinSize(wx.Size(250,100)).BestSize(wx.Size(250, 100)).Left().MaximizeButton(True))

        # construct the bottom panel
        self.__songEditNotebook = EditorNotebook.EditorNotebook(self)
        self.__aui.AddPane(self.__songEditNotebook, wx.aui.AuiPaneInfo().
                          Name("editpanel").Caption("Edit").MinSize(wx.Size(200,205)).
                          Bottom().MaximizeButton(True))

        # construct the middle part
        self.__aui.AddPane(CurrInfoNotebook.CurrInfoNotebook(self), wx.aui.AuiPaneInfo().
                           Name("currsong").Caption("Information").
                           CenterPane().CloseButton(False).MaximizeButton(True))

        self.__aui.Update()

        self._filter = viewmgr.Get()

        # hook up event handlers
        Publisher().subscribe(self.__SignalOnQueryAddSong, viewmgr.SIGNAL_ADD_SONG)
        Publisher().subscribe(self.__SignalOnSongSelected, viewmgr.SIGNAL_SONG_SELECTED)
        Publisher().subscribe(self.__SignalOnQueryEditSong, viewmgr.SIGNAL_EDIT_SONG)
        Publisher().subscribe(self.__SignalOnQueryDeleteSong, viewmgr.SIGNAL_DELETE_SONG)
        Publisher().subscribe(self.__SignalOnSongUpdated, viewmgr.SIGNAL_SONG_UPDATED)
        Publisher().subscribe(self.__SignalOnQueryEditAttachments, viewmgr.SIGNAL_EDIT_LINKS)
        Publisher().subscribe(self.__SignalOnOpenEditInformation, viewmgr.SIGNAL_SHOW_EDIT_INFO)
        Publisher().subscribe(self.__SignalOnOpenEditLyrics, viewmgr.SIGNAL_SHOW_EDIT_LYRICS)
        Publisher().subscribe(self.__SignalOnOpenEditProgres, viewmgr.SIGNAL_SHOW_EDIT_PROGR)
        Publisher().subscribe(self.__SignalOnCreateLinksDir, viewmgr.SIGNAL_LINKS_DIR_CREATED)
        
        # dependent on the layout settings, we restore the old perspective, or save the default
        cfg = appcfg.Get()
        pers = cfg.Read(appcfg.CFG_LAYOUT_DEFAULT, '')
        if not pers:
            # save default for restoring
            pers = self.__aui.SavePerspective()
            cfg.Write(appcfg.CFG_LAYOUT_DEFAULT, pers)
        else:
            # load last one
            pers = cfg.Read(appcfg.CFG_LAYOUT_LAST, '')
            if pers:
                self.__aui.LoadPerspective(pers)                

        # retrieve height / width of main window
        width = cfg.ReadInt(appcfg.CFG_LAYOUT_LAST_W, 800)
        height = cfg.ReadInt(appcfg.CFG_LAYOUT_LAST_H, 800)

        self.SetSize((width, height)) 
        self.Center()

        # open database (or not) when unsuccesful an event is posted to
        # show the wizard on the next OnIdle event
        self.__dbValid = False
        dbpath = appcfg.Get().Read(appcfg.CFG_DBPATH, '')
        if dbpath:
            status = db.engine.Get().Open(dbpath)
            self.__dbValid = (status == db.engine.DB_OPEN_OK)
        if not self.__dbValid:
            evt = wx.CommandEvent(wx.wxEVT_COMMAND_MENU_SELECTED, self.__menuShowDatabaseWizard.GetId())
            self.AddPendingEvent(evt)
        else:
            viewmgr.signalDbChange()
            
        # at the end, make sure we are in the correct edit state
        # TODO: Shouldn't we use OnUpdateUI event instead?
        self.__SyncMenuItems()