Esempio n. 1
0
 def slotActionAdmin(self):
     logging.info("MainWindow->slotActionAdmin()")
     
     # create page if not already created
     if not self.pageadminindex:
         self.pageadmin = PageAdmin(self, self.databaseCon)
         self.pageadmin.userChanged.connect(self.slotUserChanged)
         self.pageadminindex = self.pages.addWidget(self.pageadmin)
     
     self.pageadmin.refresh()
     self.pages.setCurrentIndex(self.pageadminindex)
Esempio n. 2
0
    def __init__(self):
        """Initiate the main window"""
        logging.info("Tracks initiated...")
        QtGui.QMainWindow.__init__(self)

        # for bling on windows(tm)
        self.doWinComposite = False
        try:
            if os.name == "nt" and self.isWindowsCompositionEnabled():
                    self.setAttribute(QtCore.Qt.WA_NoSystemBackground, True)
                    from ctypes import windll, c_int, byref
                    windll.dwmapi.DwmExtendFrameIntoClientArea(c_int(self.winId()), byref(c_int(-1)))
                    self.doWinComposite = True
            QtCore.QDir.addSearchPath("image", sys.path[0] + "/")
        except:
            None
        
        # set the window icon
        self.setWindowIcon(QtGui.QIcon(sys.path[0] + "/icon.png"))
        
        # open the database file
        # Locate the database file, or create a new one
        knowFile = False
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        # The last file accessed is contained in the settings
        if self.settings.contains("database/lastfile"):
            filepath = str(self.settings.value("database/lastfile").toString())
            if os.path.exists(filepath):
                #self.database = DbAccess(filepath)
                self.databaseCon = sqlite3.connect(filepath)
                self.databaseCon.row_factory = sqlite3.Row
                knowFile = True
        # If we have no record of the last file accessed
        if not knowFile:
            existing = QtGui.QMessageBox.question(self, "tracks queue: No file found", "Do you have an existing tracks database file?\n\n" +
            "No: \tA dialog will ask where to save a new database.\n" +
            "Yes: \tA dialog will ask where to find the existing database.\n", QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)

            # User has an existing Database file
            if existing == QtGui.QMessageBox.Yes:
                dialog = QtGui.QFileDialog
                filename = dialog.getOpenFileName(self, "Open Database", QtCore.QDir.homePath(), "*.db")

                self.databaseCon = sqlite3.connect(str(filename))
                self.databaseCon.row_factory = sqlite3.Row
                self.settings.setValue("database/lastfile", QtCore.QVariant(filename))

            # User needs to create a  new Database file
            elif existing == QtGui.QMessageBox.No:
                dialog = QtGui.QFileDialog
                filename = dialog.getSaveFileName(self, "Save New Database", QtCore.QDir.homePath(), "*.db")
                templatePath = sys.path[0]
                templatePath = templatePath + "/template.db"

                # Copy the template database to the selected location
                import shutil
                shutil.copyfile(templatePath, filename)

                self.databaseCon = sqlite3.connect(str(filename))
                self.databaseCon.row_factory = sqlite3.Row
                self.settings.setValue("database/lastfile", QtCore.QVariant(filename))

        # Set up the user interface from Designer.
        self.setupUi(self)
        if self.doWinComposite:
            self.lefttoolbar.setStyleSheet("QToolBar { border: 0px }")
            self.righttoolbar.setStyleSheet("QToolBar { border: 0px }")
            self.setStyleSheet("QGroupBox { border: 0px }")
        
        # Restore window geometry
        if self.settings.contains("geometry"):
            self.restoreGeometry(self.settings.value("geometry").toByteArray())
        
        # The pages, not created now apart from home
        self.pagehomeindex = None
        self.pagestarredindex = None
        self.pageprojectsindex = None
        self.pageprojectviewindex = None
        self.pageticklerindex = None
        self.pagecalendarindex = None
        self.pagedoneindex = None
        self.pagecontextsindex = None
        self.pagecontextviewindex = None
        self.pageadminindex = None
        
        self.pagehome = PageHome(self,self.databaseCon)
        self.pagehome.gotoProject.connect(self.slotGotoProject)
        self.pagehome.gotoContext.connect(self.slotGotoContext)
        #self.pagehome.refresh()
        #self.pages.insertWidget(0,self.pagehome)
        self.pagehomeindex = self.pages.addWidget(self.pagehome)
        self.pages.setCurrentIndex(self.pagehomeindex)
        
        # Get the current user
        if self.settings.contains("database/user"):
            self.current_user_id = int(self.settings.value("database/user").toString())
            self.pagehome.refresh(self.current_user_id)
        else:
            self.current_user_id = False
#            self.pageadmin.refresh()
#            self.pages.setCurrentIndex(9)
            self.pageadmin = PageAdmin(self, self.databaseCon)
            self.pageadmin.userChanged.connect(self.slotUserChanged)
            self.pageadmin.refresh()
            self.pageadminindex = self.pages.addWidget(self.pageadmin)
            self.pages.setCurrentIndex(self.pageadminindex)
        
        # Action Icons
        self.actionHome.setIcon(QtGui.QIcon(sys.path[0] + "/icons/home.png"))
        self.actionStarred.setIcon(QtGui.QIcon(sys.path[0] + "/icons/important.png"))
        self.actionProjects.setIcon(QtGui.QIcon(sys.path[0] + "/icons/projects.png"))
        self.actionTickler.setIcon(QtGui.QIcon(sys.path[0] + "/icons/tickler.png"))
        self.actionAdmin.setIcon(QtGui.QIcon(sys.path[0] + "/icons/admin.png"))
        self.actionAdd.setIcon(QtGui.QIcon(sys.path[0] + "/icons/add-new.png"))
        
        # Create Other actions
        # Repeating
        self.actionRepeating = QtGui.QAction(self)
        self.actionRepeating.setText(QtGui.QApplication.translate("MainWindow", "Repeating Actions", None, QtGui.QApplication.UnicodeUTF8))
        self.actionRepeating.setObjectName(_fromUtf8("actionRepeating"))
        self.actionRepeating.setEnabled(False)
        # Statistics
        self.actionStatistics = QtGui.QAction(self)
        self.actionStatistics.setText(QtGui.QApplication.translate("MainWindow", "Statistics", None, QtGui.QApplication.UnicodeUTF8))
        self.actionStatistics.setObjectName(_fromUtf8("actionStatistics"))
        self.actionStatistics.setEnabled(False)

        
        # Add the "View" toolbar menu
        self.viewMenu = QtGui.QMenu(self)
        self.viewMenu.addAction(self.actionCalendar)
        self.viewMenu.addAction(self.actionDone)
        self.viewMenu.addAction(self.actionStatistics)
        self.viewToolButton = QtGui.QToolButton(self)
        self.viewToolButton.setText("View")
        self.viewToolButton.setMenu(self.viewMenu)
        self.viewToolButton.setPopupMode(QtGui.QToolButton.InstantPopup)
        self.righttoolbar.addWidget(self.viewToolButton)
        
        # Add the "Organise" toolbar menu
        self.organiseMenu = QtGui.QMenu(self)
        self.organiseMenu.addAction(self.actionContexts)
        self.organiseMenu.addAction(self.actionRepeating)
        self.organiseToolButton = QtGui.QToolButton(self)
        self.organiseToolButton.setText("Organise")
        self.organiseToolButton.setMenu(self.organiseMenu)
        self.organiseToolButton.setPopupMode(QtGui.QToolButton.InstantPopup)
        self.righttoolbar.addWidget(self.organiseToolButton)      
        
        # Connect actions
        self.actionHome.triggered.connect(self.slotActionHome)
        self.actionStarred.triggered.connect(self.slotActionStarred)
        self.actionProjects.triggered.connect(self.slotActionProjects)
        self.actionTickler.triggered.connect(self.slotActionTickler)
        self.actionCalendar.triggered.connect(self.slotActionCalendar)
        self.actionContexts.triggered.connect(self.slotActionContexts)
        self.actionDone.triggered.connect(self.slotActionDone)
        self.actionAdmin.triggered.connect(self.slotActionAdmin)
        self.actionAdd.triggered.connect(self.slotActionAdd)
        
        
        
        # Set up keyboard shortcuts
        QtGui.QShortcut(QtGui.QKeySequence("pgUp"),self,self.shortcutPageUp)
        QtGui.QShortcut(QtGui.QKeySequence("pgDown"),self,self.shortcutPageDown)
        QtGui.QShortcut(QtGui.QKeySequence("ctrl+pgDown"),self,self.shortcutCtrlPageDown)
        QtGui.QShortcut(QtGui.QKeySequence("ctrl+pgUp"),self,self.shortcutCtrlPageUp)