示例#1
0
 def __init__(self, parent, databaseCon):
     logging.info("PageHome->__init__(self, parent, databaseCon)")
     QtGui.QWidget.__init__(self, parent)
     self.databaseCon = databaseCon
     #self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
     #latitudeLabel = QtGui.QLabel("Latitude:")
     #layout = QtGui.QGridLayout(self)
     #layout.addWidget(latitudeLabel, 0, 0)
     
     # The main page layout
     self.horizontalLayout = QtGui.QHBoxLayout(self)
     self.horizontalLayout.setSpacing(0)
     self.horizontalLayout.setMargin(0)
     
     # Scroll area for lists
     self.scrollArea = QtGui.QScrollArea()
     self.scrollArea.setWidgetResizable(True)
     
     # Layout for scroll area
     widget = QtGui.QWidget()
     self.scrollArea.setWidget(widget)
     self.verticalLayout = QtGui.QVBoxLayout(widget)
     
     self.horizontalLayout.addWidget(self.scrollArea)      
     
     # Add the action editor form 
     self.actionEditor = WidgetActionEditor(self.databaseCon)
     self.actionEditor.setVisible(False)
     self.horizontalLayout.addWidget(self.actionEditor)
     self.actionEditor.actionModified.connect(self.refresh)
     
     # Add a vertical spacer
     spacerItem = QtGui.QSpacerItem(
         1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
     self.verticalLayout.addItem(spacerItem)
     
     # Set of contexts to be displayed
     self.homeContexts = {}
     
     # add the list completed actions
     sqlCompleted = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                    projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                    todos.context_id = contexts.id AND todos.user_id=contexts.user_id) LEFT JOIN projects on \
                    todos.project_id = projects.id AND todos.user_id=projects.user_id where todos.state=\
                    'completed' AND todos.user_id=%s order by todos.completed_at DESC limit 7" % (2)
     completedList = WidgetActionList(self.databaseCon, "Recently Completed Actions", sqlCompleted,False)
     completedList.setDisplayProjectFirst(True)
     completedList.setDisplayCompletedAt(True)
     completedList.editAction.connect(self.actionEditor.setCurrentActionID)   
     completedList.actionModified.connect(self.refresh)
     completedList.gotoProject.connect(self.slotGotoProject)
     completedList.gotoContext.connect(self.slotGotoContext)
     self.homeContexts["completed"] = completedList
     self.verticalLayout.insertWidget(0, completedList)
     
     self.current_user_id = None
示例#2
0
 def __init__(self, parent, databaseCon):
     logging.info("PageStarred->__init__(self, parent, databaseCon)")
     QtGui.QWidget.__init__(self, parent)
     self.databaseCon = databaseCon
     self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
     #latitudeLabel = QtGui.QLabel("Latitude:")
     #layout = QtGui.QGridLayout(self)
     #layout.addWidget(latitudeLabel, 0, 0)
     
     # The main page layout
     self.horizontalLayout = QtGui.QHBoxLayout(self)
     self.horizontalLayout.setSpacing(0)
     self.horizontalLayout.setMargin(0)
     
     # Scroll area for lists
     self.scrollArea = QtGui.QScrollArea()
     self.scrollArea.setWidgetResizable(True)
     
     # Layout for scroll area
     widget = QtGui.QWidget()
     self.scrollArea.setWidget(widget)
     self.verticalLayout = QtGui.QVBoxLayout(widget)
     
     self.horizontalLayout.addWidget(self.scrollArea)      
     
     # Add the action editor form 
     self.actionEditor = WidgetActionEditor(self.databaseCon)
     self.actionEditor.setVisible(False)        
     self.horizontalLayout.addWidget(self.actionEditor)
     self.actionEditor.actionModified.connect(self.refresh)
     
     # Add a vertical spacer
     spacerItem = QtGui.QSpacerItem(
         1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
     self.verticalLayout.addItem(spacerItem)
     
     # Set of contexts to be displayed
     self.homeContexts = {}
     
     self.current_user_id =None
示例#3
0
    def __init__(self, parent, databaseCon):
        logging.info("PageCalendar->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        #latitudeLabel = QtGui.QLabel("Latitude:")
        #layout = QtGui.QGridLayout(self)
        #layout.addWidget(latitudeLabel, 0, 0)
        
        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        
        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        
        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)
        
        self.horizontalLayout.addWidget(self.scrollArea)      
        
        # Add the action editor form 
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)        
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)
        
        # Add the lists
        # Actions overdue
        self.overDueList = WidgetActionList(
            self.databaseCon, "Overdue", None, True)
        self.verticalLayout.addWidget(self.overDueList)
        self.overDueList.setDisplayShowFrom(True)
        self.overDueList.setDisplayProjectFirst(True)
        self.overDueList.setDisplayContextFirst(True)
        self.overDueList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.overDueList.actionModified.connect(self.refresh)
        self.overDueList.gotoProject.connect(self.slotGotoProject)
        self.overDueList.gotoContext.connect(self.slotGotoContext)

        # Actions due today
        self.dueTodayList = WidgetActionList(
            self.databaseCon, "Due today", None, True)
        self.verticalLayout.addWidget(self.dueTodayList)
        self.dueTodayList.setDisplayShowFrom(True)
        self.dueTodayList.setDisplayProjectFirst(True)
        self.dueTodayList.setDisplayContextFirst(True)
        self.dueTodayList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueTodayList.actionModified.connect(self.refresh)
        self.dueTodayList.gotoProject.connect(self.slotGotoProject)
        self.dueTodayList.gotoContext.connect(self.slotGotoContext)

        # Actions due this week (ending Sunday)
        self.dueWeekList = WidgetActionList(
            self.databaseCon, "Due this week", None, True)
        self.verticalLayout.addWidget(self.dueWeekList)
        self.dueWeekList.setDisplayShowFrom(True)
        self.dueWeekList.setDisplayProjectFirst(True)
        self.dueWeekList.setDisplayContextFirst(True)
        self.dueWeekList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueWeekList.actionModified.connect(self.refresh)
        self.dueWeekList.gotoProject.connect(self.slotGotoProject)
        self.dueWeekList.gotoContext.connect(self.slotGotoContext)

        # Actions due next week
        self.dueNextWeekList = WidgetActionList(
            self.databaseCon, "Due next week", None, True)
        self.verticalLayout.addWidget(self.dueNextWeekList)
        self.dueNextWeekList.setDisplayShowFrom(True)
        self.dueNextWeekList.setDisplayProjectFirst(True)
        self.dueNextWeekList.setDisplayContextFirst(True)
        self.dueNextWeekList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueNextWeekList.actionModified.connect(self.refresh)
        self.dueNextWeekList.gotoProject.connect(self.slotGotoProject)
        self.dueNextWeekList.gotoContext.connect(self.slotGotoContext)

        # All other future due actions
        self.dueFarList = WidgetActionList(
            self.databaseCon, "Due in the future", None, False)
        self.verticalLayout.addWidget(self.dueFarList)
        self.dueFarList.setDisplayShowFrom(True)
        self.dueFarList.setDisplayProjectFirst(True)
        self.dueFarList.setDisplayContextFirst(True)
        self.dueFarList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueFarList.actionModified.connect(self.refresh)
        self.dueFarList.gotoProject.connect(self.slotGotoProject)
        self.dueFarList.gotoContext.connect(self.slotGotoContext)
        
     
        
        
        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(
            1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        
        self.current_user_id = None
示例#4
0
class PageCalendar(QtGui.QWidget):
    # Signals
    gotoProject = QtCore.pyqtSignal(int)
    gotoContext = QtCore.pyqtSignal(int)
    
    def __init__(self, parent, databaseCon):
        logging.info("PageCalendar->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        #latitudeLabel = QtGui.QLabel("Latitude:")
        #layout = QtGui.QGridLayout(self)
        #layout.addWidget(latitudeLabel, 0, 0)
        
        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        
        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        
        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)
        
        self.horizontalLayout.addWidget(self.scrollArea)      
        
        # Add the action editor form 
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)        
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)
        
        # Add the lists
        # Actions overdue
        self.overDueList = WidgetActionList(
            self.databaseCon, "Overdue", None, True)
        self.verticalLayout.addWidget(self.overDueList)
        self.overDueList.setDisplayShowFrom(True)
        self.overDueList.setDisplayProjectFirst(True)
        self.overDueList.setDisplayContextFirst(True)
        self.overDueList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.overDueList.actionModified.connect(self.refresh)
        self.overDueList.gotoProject.connect(self.slotGotoProject)
        self.overDueList.gotoContext.connect(self.slotGotoContext)

        # Actions due today
        self.dueTodayList = WidgetActionList(
            self.databaseCon, "Due today", None, True)
        self.verticalLayout.addWidget(self.dueTodayList)
        self.dueTodayList.setDisplayShowFrom(True)
        self.dueTodayList.setDisplayProjectFirst(True)
        self.dueTodayList.setDisplayContextFirst(True)
        self.dueTodayList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueTodayList.actionModified.connect(self.refresh)
        self.dueTodayList.gotoProject.connect(self.slotGotoProject)
        self.dueTodayList.gotoContext.connect(self.slotGotoContext)

        # Actions due this week (ending Sunday)
        self.dueWeekList = WidgetActionList(
            self.databaseCon, "Due this week", None, True)
        self.verticalLayout.addWidget(self.dueWeekList)
        self.dueWeekList.setDisplayShowFrom(True)
        self.dueWeekList.setDisplayProjectFirst(True)
        self.dueWeekList.setDisplayContextFirst(True)
        self.dueWeekList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueWeekList.actionModified.connect(self.refresh)
        self.dueWeekList.gotoProject.connect(self.slotGotoProject)
        self.dueWeekList.gotoContext.connect(self.slotGotoContext)

        # Actions due next week
        self.dueNextWeekList = WidgetActionList(
            self.databaseCon, "Due next week", None, True)
        self.verticalLayout.addWidget(self.dueNextWeekList)
        self.dueNextWeekList.setDisplayShowFrom(True)
        self.dueNextWeekList.setDisplayProjectFirst(True)
        self.dueNextWeekList.setDisplayContextFirst(True)
        self.dueNextWeekList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueNextWeekList.actionModified.connect(self.refresh)
        self.dueNextWeekList.gotoProject.connect(self.slotGotoProject)
        self.dueNextWeekList.gotoContext.connect(self.slotGotoContext)

        # All other future due actions
        self.dueFarList = WidgetActionList(
            self.databaseCon, "Due in the future", None, False)
        self.verticalLayout.addWidget(self.dueFarList)
        self.dueFarList.setDisplayShowFrom(True)
        self.dueFarList.setDisplayProjectFirst(True)
        self.dueFarList.setDisplayContextFirst(True)
        self.dueFarList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.dueFarList.actionModified.connect(self.refresh)
        self.dueFarList.gotoProject.connect(self.slotGotoProject)
        self.dueFarList.gotoContext.connect(self.slotGotoContext)
        
     
        
        
        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(
            1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        
        self.current_user_id = None
        
    def refresh(self, userId=None):
        logging.info("PageCalendar->refresh()")
        if userId:
            self.current_user_id = userId
        
        # refresh those overdue
        sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND todos.due < DATE('now') AND todos.user_id=%s order by todos.due, projects.name" % (self.current_user_id)
        self.overDueList.setDBQuery(sql)

        # refresh those due today
        sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND todos.due = DATE('now') AND todos.user_id=%s order by todos.due, projects.name" % (self.current_user_id)
        self.dueTodayList.setDBQuery(sql)

        # refresh those due this week (less than or equal Sunday)
        sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND todos.due > DATE('now') AND todos.due <= DATE('now','weekday 0') AND todos.user_id=%s order by todos.due, projects.name" % (self.current_user_id)
        self.dueWeekList.setDBQuery(sql)

        # refresh those due next week
        sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND todos.due > DATE('now','weekday 0') AND todos.due <= DATE('now','weekday 0', '+7 days') AND todos.user_id=%s order by todos.due, projects.name" % (self.current_user_id)
        self.dueNextWeekList.setDBQuery(sql)

        # all other future due tasks
        sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND todos.due > DATE('now','weekday 0', '+7 days') AND todos.user_id=%s order by todos.due, projects.name" % (self.current_user_id)
        self.dueFarList.setDBQuery(sql)


        self.actionEditor.setCurrentUser(self.current_user_id)
    
        
    def setFormVisible(self, visible):
        logging.info("PageCalendar->setFormVisible(self, visible)")
        self.actionEditor.setVisible(visible)
        self.actionEditor.setFocus()
        
    def slotGotoProject(self, id):
        logging.info("PageCalendar->slotGotoProject(self, id)")
        self.emit(QtCore.SIGNAL("gotoProject(int)"), id)
        
    def slotGotoContext(self, id):
        logging.info("PageCalendar->slotGotoContext(self, id)")
        self.emit(QtCore.SIGNAL("gotoContext(int)"), id)
    
    def moveExclusiveExpandUp(self):
        logging.info("tracks->moveExclusiveExpandUp")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos < focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        for pos in posKeys:
            if focuspos and pos<focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
        
    def moveExclusiveExpandDown(self):
        logging.info("PageCalendar->moveExclusiveExpandDown(self)")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos > focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        
        for pos in posKeys:
            if focuspos and pos>focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
    
    def moveFocusUp(self):
        # moves the keyboard focus up to the next expanded list
        logging.info("PageCalendar->moveFocusUp")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        # set keyboard focus on the next highest list that is expanded
        for pos in posKeys:
            if pos<keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to highest list and expand
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
            
    def moveFocusDown(self):
        # moves the keyboard focus down to the next expanded list
        logging.info("PageCalendar->moveFocusDown")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        # set keyboard focus on the next lowest list that is expanded
        for pos in posKeys:
            if keyfocuspos and pos>keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to lowest list
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
示例#5
0
 def __init__(self, parent, databaseCon):
     logging.info("PageDone->__init__(self, parent, databaseCon)")
     QtGui.QWidget.__init__(self, parent)
     self.databaseCon = databaseCon
     self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
     #latitudeLabel = QtGui.QLabel("Latitude:")
     #layout = QtGui.QGridLayout(self)
     #layout.addWidget(latitudeLabel, 0, 0)
     
     # The main page layout
     self.horizontalLayout = QtGui.QHBoxLayout(self)
     self.horizontalLayout.setSpacing(0)
     self.horizontalLayout.setMargin(0)
     
     # Scroll area for lists
     self.scrollArea = QtGui.QScrollArea()
     self.scrollArea.setWidgetResizable(True)
     
     # Layout for scroll area
     widget = QtGui.QWidget()
     self.scrollArea.setWidget(widget)
     self.verticalLayout = QtGui.QVBoxLayout(widget)
     
     self.horizontalLayout.addWidget(self.scrollArea)      
     
     # Add the action editor form 
     self.actionEditor = WidgetActionEditor(self.databaseCon)
     self.actionEditor.setVisible(False)        
     self.horizontalLayout.addWidget(self.actionEditor)
     self.actionEditor.actionModified.connect(self.refresh)
     
     # Add the lists
     # This fortnight
     self.doneFortnightActionList = WidgetActionList(self.databaseCon, "Last Fortnight", None, True)
     self.doneFortnightActionList.setDisplayCompletedAt(True)
     self.doneFortnightActionList.setDisplayProjectFirst(True)
     #self.doneFortnightActionList.setShowEdit(False)
     self.doneFortnightActionList.editAction.connect(self.actionEditor.setCurrentActionID)
     self.doneFortnightActionList.setShowDelete(False)
     self.doneFortnightActionList.gotoProject.connect(self.slotGotoProject)
     self.doneFortnightActionList.gotoContext.connect(self.slotGotoContext)
     self.verticalLayout.addWidget(self.doneFortnightActionList)
     
     # Previous fortnight
     self.doneNextFortnightActionList = WidgetActionList(self.databaseCon, "Previous Fortnight", None, False)
     self.doneNextFortnightActionList.setDisplayCompletedAt(True)
     self.doneNextFortnightActionList.setDisplayProjectFirst(True)
     #self.doneNextFortnightActionList.setShowEdit(False)
     self.doneNextFortnightActionList.editAction.connect(self.actionEditor.setCurrentActionID)
     self.doneNextFortnightActionList.setShowDelete(False)
     self.doneNextFortnightActionList.gotoProject.connect(self.slotGotoProject)
     self.doneNextFortnightActionList.gotoContext.connect(self.slotGotoContext)
     self.verticalLayout.addWidget(self.doneNextFortnightActionList)
     
     # Older
     self.doneOlderActionList = WidgetActionList(self.databaseCon, "Older", None, False)
     self.doneOlderActionList.setDisplayCompletedAt(True)
     self.doneOlderActionList.setDisplayProjectFirst(True)
     #self.doneOlderActionList.setShowEdit(False)
     self.doneOlderActionList.editAction.connect(self.actionEditor.setCurrentActionID)
     self.doneOlderActionList.setShowDelete(False)
     self.doneOlderActionList.gotoProject.connect(self.slotGotoProject)
     self.doneOlderActionList.gotoContext.connect(self.slotGotoContext)
     self.doneOlderActionList.setHasDoubleExpander(True, 20)
     self.verticalLayout.addWidget(self.doneOlderActionList)
     
  
     
     
     # Add a vertical spacer
     spacerItem = QtGui.QSpacerItem(
         1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
     self.verticalLayout.addItem(spacerItem)
     
     self.current_user_id = None
示例#6
0
class PageStarred(QtGui.QWidget):
    # Signals
    gotoProject = QtCore.pyqtSignal(int)
    gotoContext = QtCore.pyqtSignal(int)
    
    def __init__(self, parent, databaseCon):
        logging.info("PageStarred->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        #latitudeLabel = QtGui.QLabel("Latitude:")
        #layout = QtGui.QGridLayout(self)
        #layout.addWidget(latitudeLabel, 0, 0)
        
        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        
        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        
        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)
        
        self.horizontalLayout.addWidget(self.scrollArea)      
        
        # Add the action editor form 
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)        
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)
        
        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(
            1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        
        # Set of contexts to be displayed
        self.homeContexts = {}
        
        self.current_user_id =None
        
    def refresh(self, userId=None):
        logging.info("PageStarred->refresh()")
        if userId:
            self.current_user_id = userId
        
        
        starredContextQuery = "select todos.context_id,contexts.name from todos, tags, taggings, contexts where todos.context_id=contexts.id AND todos.id=taggings.taggable_id and tags.id = taggings.tag_id and tags.name='starred' AND todos.state='active' AND todos.user_id=? group by todos.context_id order by contexts.name DESC"

        fetchedContexts = {}
        for row in self.databaseCon.execute(starredContextQuery, (self.current_user_id,)):
            fetchedContexts[row[0]] = row[1] 
            #print len(fetchedContexts)
            if self.homeContexts.has_key(row[0]):
                None
            else:
                sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                  todos.context_id = contexts.id AND todos.user_id=contexts.user_id) LEFT JOIN projects on \
                  todos.project_id = projects.id AND todos.user_id=projects.user_id, tags, taggings where  \
                  contexts.id=%s AND todos.id=taggings.taggable_id AND tags.id = taggings.tag_id AND tags.name='starred' AND todos.state='active' AND \
                  todos.id not in (select successor_id from dependencies where predecessor_id in (select id from todos where state='active')) and \
                  todos.state='active' and projects.state = 'active' and (todos.show_from<=DATE('now', 'localtime') or todos.show_from IS null)  \
                  AND todos.user_id=%s ORDER BY CASE WHEN todos.due IS null THEN 1 ELSE 0 END, todos.due, projects.name, todos.description" % (row[0], self.current_user_id)
                tracksAList = WidgetActionList(self.databaseCon,"@" + row[1], sql, True)
                tracksAList.setDisplayProjectFirst(True)
                tracksAList.editAction.connect(self.actionEditor.setCurrentActionID)    
                tracksAList.actionModified.connect(self.refresh)
                tracksAList.gotoProject.connect(self.slotGotoProject)
                tracksAList.gotoContext.connect(self.slotGotoContext)
                self.homeContexts[row[0]]=tracksAList
                self.verticalLayout.insertWidget(len(fetchedContexts)-1,tracksAList)
                
        # remove any contexts that may have been removed / hidden, refresh the others
        for key in self.homeContexts.keys():
            if key not in fetchedContexts.keys() and key != "completed":
                self.homeContexts[key].hide()
                self.verticalLayout.removeWidget(self.homeContexts[key])   
                del self.homeContexts[key] 
            else:
                self.homeContexts[key].refresh()
        
        self.actionEditor.setCurrentUser(self.current_user_id)
        
    def setFormVisible(self, visible):
        logging.info("PageStarred->setFormVisible(self, visible)")
        self.actionEditor.setVisible(visible)
        self.actionEditor.setFocus()
        
    def slotGotoProject(self, id):
        logging.info("PageStarred->slotGotoProject(self, id)")
        self.emit(QtCore.SIGNAL("gotoProject(int)"), id)
        
    def slotGotoContext(self, id):
        logging.info("PageStarred->slotGotoContext(self, id)")
        self.emit(QtCore.SIGNAL("gotoContext(int)"), id)
    
    def moveExclusiveExpandUp(self):
        logging.info("tracks->moveExclusiveExpandUp")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos < focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        for pos in posKeys:
            if focuspos and pos<focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
        
    def moveExclusiveExpandDown(self):
        logging.info("PageStarred->moveExclusiveExpandDown(self)")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos > focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        
        for pos in posKeys:
            if focuspos and pos>focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
    
    def moveFocusUp(self):
        # moves the keyboard focus up to the next expanded list
        logging.info("PageStarred->moveFocusUp")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        # set keyboard focus on the next highest list that is expanded
        for pos in posKeys:
            if pos<keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to highest list and expand
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
            
    def moveFocusDown(self):
        # moves the keyboard focus down to the next expanded list
        logging.info("PageStarred->moveFocusDown")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        # set keyboard focus on the next lowest list that is expanded
        for pos in posKeys:
            if keyfocuspos and pos>keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to lowest list
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
示例#7
0
    def __init__(self, parent, databaseCon):
        logging.info("PageTickler->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        # latitudeLabel = QtGui.QLabel("Latitude:")
        # layout = QtGui.QGridLayout(self)
        # layout.addWidget(latitudeLabel, 0, 0)

        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)

        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)

        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)

        self.horizontalLayout.addWidget(self.scrollArea)

        # Add the action editor form
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)

        # Add the lists
        # Actions started today
        self.startingToday = WidgetActionList(self.databaseCon, "Starting today", None, True)
        self.verticalLayout.addWidget(self.startingToday)
        self.startingToday.setDisplayShowFrom(True)
        self.startingToday.setDisplayProjectFirst(True)
        self.startingToday.setDisplayContextFirst(True)
        self.startingToday.editAction.connect(self.actionEditor.setCurrentActionID)
        self.startingToday.actionModified.connect(self.refresh)
        # self.startingToday.gotoProject.connect(self.gotoProject)
        # self.startingToday.gotoContext.connect(self.gotoContext)

        # Actions starting this week
        self.startingThisWeek = WidgetActionList(self.databaseCon, "Starting this week", None, True)
        self.verticalLayout.addWidget(self.startingThisWeek)
        self.startingThisWeek.setDisplayShowFrom(True)
        self.startingThisWeek.setDisplayProjectFirst(True)
        self.startingThisWeek.setDisplayContextFirst(True)
        self.startingThisWeek.editAction.connect(self.actionEditor.setCurrentActionID)
        self.startingThisWeek.actionModified.connect(self.refresh)
        # self.startingThisWeek.gotoProject.connect(self.gotoProject)
        # self.startingThisWeek.gotoContext.connect(self.gotoContext)

        # Actions starting next week
        self.startingNextWeek = WidgetActionList(self.databaseCon, "Starting next week", None, True)
        self.verticalLayout.addWidget(self.startingNextWeek)
        self.startingNextWeek.setDisplayShowFrom(True)
        self.startingNextWeek.setDisplayProjectFirst(True)
        self.startingNextWeek.setDisplayContextFirst(True)
        self.startingNextWeek.editAction.connect(self.actionEditor.setCurrentActionID)
        self.startingNextWeek.actionModified.connect(self.refresh)
        # self.startingNextWeek.gotoProject.connect(self.gotoProject)
        # self.startingNextWeek.gotoContext.connect(self.gotoContext)

        # All other actions starting in the future
        self.startingFuture = WidgetActionList(self.databaseCon, "Starting further in the future", None, False)
        self.verticalLayout.addWidget(self.startingFuture)
        self.startingFuture.setDisplayShowFrom(True)
        self.startingFuture.setDisplayProjectFirst(True)
        self.startingFuture.setDisplayContextFirst(True)
        self.startingFuture.editAction.connect(self.actionEditor.setCurrentActionID)
        self.startingFuture.actionModified.connect(self.refresh)
        # self.startingFuture.gotoProject.connect(self.gotoProject)
        # self.startingFuture.gotoContext.connect(self.gotoContext)

        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)

        self.current_user_id = None
    def __init__(self, parent, databaseCon):
        logging.info("PageContextView->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        #latitudeLabel = QtGui.QLabel("Latitude:")
        #layout = QtGui.QGridLayout(self)
        #layout.addWidget(latitudeLabel, 0, 0)
        
        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        
        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        
        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)
        
        self.horizontalLayout.addWidget(self.scrollArea)      
        
        # Add the action editor form 
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)
        
        # Context title
        self.contextTitle = QtGui.QLabel("blank title")
        font = QtGui.QFont()
        font.setPointSize(14)
        self.contextTitle.setFont(font)
        self.verticalLayout.addWidget(self.contextTitle)
        
        # The lists
        
        # Active actions
        sqlActive = None
        self.activeList = WidgetActionList(
            self.databaseCon,"Active Actions",sqlActive,True)
        self.verticalLayout.addWidget( self.activeList)
        self.activeList.setDisplayProjectFirst(True)
        self.activeList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.activeList.actionModified.connect(self.refresh)
        self.activeList.gotoProject.connect(self.gotoProject)
        #self.refreshables[self.projectstabid].append( self.activeList)

        # Deferred actions
        sqlDeferred = None
        self.deferredList = WidgetActionList(
            self.databaseCon, "Deferred/Pending Actions", sqlDeferred, False)
        self.deferredList.setDisplayShowFrom(True)
        self.deferredList.setDisplayProjectFirst(True)
        self.verticalLayout.addWidget(self.deferredList)
        self.deferredList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.deferredList.actionModified.connect(self.refresh)
        self.deferredList.gotoProject.connect(self.gotoProject)
        #self.refreshables[self.projectstabid].append(self.projectview_tracksDList)
        
        # Complete actions
        sqlCompleted = None
        self.completedList = WidgetActionList(
            self.databaseCon, "Completed Actions", sqlCompleted, False)
        self.completedList.setDisplayCompletedAt(True)
        self.completedList.setDisplayProjectFirst(True)
        self.completedList.setHasDoubleExpander(True, 10)
        self.verticalLayout.addWidget(self.completedList)
        self.completedList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.completedList.actionModified.connect(self.refresh)
        self.completedList.gotoProject.connect(self.gotoProject)
        #self.refreshables[self.projectstabid].append(self.projectview_tracksCList)

        
        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(
            1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        
        self.current_user_id = None
class PageContextView(QtGui.QWidget):
    # Signals
    gotoProject = QtCore.pyqtSignal(int)
    
    def __init__(self, parent, databaseCon):
        logging.info("PageContextView->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        #latitudeLabel = QtGui.QLabel("Latitude:")
        #layout = QtGui.QGridLayout(self)
        #layout.addWidget(latitudeLabel, 0, 0)
        
        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        
        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        
        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)
        
        self.horizontalLayout.addWidget(self.scrollArea)      
        
        # Add the action editor form 
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)
        
        # Context title
        self.contextTitle = QtGui.QLabel("blank title")
        font = QtGui.QFont()
        font.setPointSize(14)
        self.contextTitle.setFont(font)
        self.verticalLayout.addWidget(self.contextTitle)
        
        # The lists
        
        # Active actions
        sqlActive = None
        self.activeList = WidgetActionList(
            self.databaseCon,"Active Actions",sqlActive,True)
        self.verticalLayout.addWidget( self.activeList)
        self.activeList.setDisplayProjectFirst(True)
        self.activeList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.activeList.actionModified.connect(self.refresh)
        self.activeList.gotoProject.connect(self.gotoProject)
        #self.refreshables[self.projectstabid].append( self.activeList)

        # Deferred actions
        sqlDeferred = None
        self.deferredList = WidgetActionList(
            self.databaseCon, "Deferred/Pending Actions", sqlDeferred, False)
        self.deferredList.setDisplayShowFrom(True)
        self.deferredList.setDisplayProjectFirst(True)
        self.verticalLayout.addWidget(self.deferredList)
        self.deferredList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.deferredList.actionModified.connect(self.refresh)
        self.deferredList.gotoProject.connect(self.gotoProject)
        #self.refreshables[self.projectstabid].append(self.projectview_tracksDList)
        
        # Complete actions
        sqlCompleted = None
        self.completedList = WidgetActionList(
            self.databaseCon, "Completed Actions", sqlCompleted, False)
        self.completedList.setDisplayCompletedAt(True)
        self.completedList.setDisplayProjectFirst(True)
        self.completedList.setHasDoubleExpander(True, 10)
        self.verticalLayout.addWidget(self.completedList)
        self.completedList.editAction.connect(self.actionEditor.setCurrentActionID)
        self.completedList.actionModified.connect(self.refresh)
        self.completedList.gotoProject.connect(self.gotoProject)
        #self.refreshables[self.projectstabid].append(self.projectview_tracksCList)

        
        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(
            1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        
        self.current_user_id = None
        
    def refresh(self, user_id=None):
        logging.info("PageContextView->refresh()")
        if user_id:
            self.current_user_id = user_id
            
        self.activeList.refresh()
        self.deferredList.refresh()
        self.completedList.refresh()

        self.actionEditor.setCurrentUser(self.current_user_id)
    
    def setContext(self, id, user_id=None):
        """Changes the project page from a list of all projects to a detailed page of one specific project"""
        logging.info("PageContextView->setProject(" + str(id) + ")")
        if user_id:
            self.current_user_id = user_id

        #self.tabWidget.setCurrentIndex(self.projectstabid)
        #self.stackedWidget_2.setCurrentIndex(1)

        titleDescQuery = "SELECT contexts.name FROM contexts WHERE contexts.id = " + str(id)
        for row in self.databaseCon.execute(titleDescQuery):
            self.contextTitle.setText(str(row[0]))
            #self.projectview_actionEditor.setDefaultProject(row[0])
            self.actionEditor.setDefaultContext(str(row[0]))
            #self.projectview_actionEditor.setDefaultTags(row[3])
        self.actionEditor.cancelButtonClicked()


        self.activeList.setDBQuery("SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND todos.id not in (select successor_id from dependencies where predecessor_id in (select id from todos where state='active')) AND\
                       (show_from IS NULL OR show_from <= DATETIME('now')) AND todos.context_id= " + str(id) + " order by CASE WHEN todos.due IS null THEN 1 ELSE 0 END, todos.due, projects.name, todos.description")

        
        self.deferredList.setDBQuery("SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'active' AND (show_from > DATETIME('now') OR todos.id in (select successor_id from dependencies where predecessor_id in (select id from todos where state='active'))) \
                       AND todos.context_id= " + str(id) + " order by todos.show_from")

        self.completedList.setDBQuery("SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id) LEFT JOIN projects on \
                       todos.project_id = projects.id where todos.state=\
                       'completed' AND todos.context_id= " + str(id) + " order by todos.completed_at DESC")

        self.actionEditor.setCurrentUser(self.current_user_id)
        self.actionEditor.refresh()
        
    def setFormVisible(self, visible):
        logging.info("PageContextView->setFormVisible(self, visible)")
        self.actionEditor.setVisible(visible)
        self.actionEditor.setFocus()
        
    def slotGotoProject(self, id):
        logging.info("PageContextView->slotGotoProject(self, id)")
        self.emit(QtCore.SIGNAL("gotoProject(int)"), id)
    
    def moveExclusiveExpandUp(self):
        logging.info("tracks->moveExclusiveExpandUp")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos < focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        for pos in posKeys:
            if focuspos and pos<focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
        
    def moveExclusiveExpandDown(self):
        logging.info("PageContextView->moveExclusiveExpandDown(self)")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos > focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        
        for pos in posKeys:
            if focuspos and pos>focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
    
    def moveFocusUp(self):
        # moves the keyboard focus up to the next expanded list
        logging.info("PageContextView->moveFocusUp")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        # set keyboard focus on the next highest list that is expanded
        for pos in posKeys:
            if pos<keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to highest list and expand
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
            
    def moveFocusDown(self):
        # moves the keyboard focus down to the next expanded list
        logging.info("PageContextView->moveFocusDown")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        # set keyboard focus on the next lowest list that is expanded
        for pos in posKeys:
            if keyfocuspos and pos>keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to lowest list
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
示例#10
0
class PageHome(QtGui.QWidget):
    # Signals
    gotoProject = QtCore.pyqtSignal(int)
    gotoContext = QtCore.pyqtSignal(int)
    
    def __init__(self, parent, databaseCon):
        logging.info("PageHome->__init__(self, parent, databaseCon)")
        QtGui.QWidget.__init__(self, parent)
        self.databaseCon = databaseCon
        #self.settings = QtCore.QSettings("tracks-queue", "tracks-queue")
        #latitudeLabel = QtGui.QLabel("Latitude:")
        #layout = QtGui.QGridLayout(self)
        #layout.addWidget(latitudeLabel, 0, 0)
        
        # The main page layout
        self.horizontalLayout = QtGui.QHBoxLayout(self)
        self.horizontalLayout.setSpacing(0)
        self.horizontalLayout.setMargin(0)
        
        # Scroll area for lists
        self.scrollArea = QtGui.QScrollArea()
        self.scrollArea.setWidgetResizable(True)
        
        # Layout for scroll area
        widget = QtGui.QWidget()
        self.scrollArea.setWidget(widget)
        self.verticalLayout = QtGui.QVBoxLayout(widget)
        
        self.horizontalLayout.addWidget(self.scrollArea)      
        
        # Add the action editor form 
        self.actionEditor = WidgetActionEditor(self.databaseCon)
        self.actionEditor.setVisible(False)
        self.horizontalLayout.addWidget(self.actionEditor)
        self.actionEditor.actionModified.connect(self.refresh)
        
        # Add a vertical spacer
        spacerItem = QtGui.QSpacerItem(
            1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
        self.verticalLayout.addItem(spacerItem)
        
        # Set of contexts to be displayed
        self.homeContexts = {}
        
        # add the list completed actions
        sqlCompleted = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id AND todos.user_id=contexts.user_id) LEFT JOIN projects on \
                       todos.project_id = projects.id AND todos.user_id=projects.user_id where todos.state=\
                       'completed' AND todos.user_id=%s order by todos.completed_at DESC limit 7" % (2)
        completedList = WidgetActionList(self.databaseCon, "Recently Completed Actions", sqlCompleted,False)
        completedList.setDisplayProjectFirst(True)
        completedList.setDisplayCompletedAt(True)
        completedList.editAction.connect(self.actionEditor.setCurrentActionID)   
        completedList.actionModified.connect(self.refresh)
        completedList.gotoProject.connect(self.slotGotoProject)
        completedList.gotoContext.connect(self.slotGotoContext)
        self.homeContexts["completed"] = completedList
        self.verticalLayout.insertWidget(0, completedList)
        
        self.current_user_id = None
    
       
    def refresh(self, userId=None):
        logging.info("PageHome->refresh()")
        
        if userId:
            self.current_user_id = userId
        
        # which focus mode are we in, individually controlled, or single focus
        singlefocus = False
        #if self.settings.contains("homepage/singlefocus"):
        #    singlefocus = int(self.settings.value("homepage/singlefocus").toString())    
        # focus signal mapper
        self.focusListMapper = QtCore.QSignalMapper(self)
        self.focusListMapper.mapped[str].connect(self.slotFocusList)
        
        # If there are new contexts that we don't already have, add them
        activeContextQuery = "SELECT DISTINCT contexts.id, contexts.name FROM (todos LEFT JOIN contexts ON \
                  todos.context_id = contexts.id AND todos.user_id=contexts.user_id) LEFT JOIN projects on\
                  todos.project_id = projects.id AND todos.user_id=projects.user_id where\
                  todos.state='active' and \
                  projects.state = 'active' and \
                  contexts.hide='f' and \
                  (todos.show_from<=DATE('now', 'localtime') or todos.show_from IS null) and\
                  todos.id not in (select successor_id from dependencies where predecessor_id in (select id from todos where state='active'))\
                  AND todos.user_id = %s \
                  ORDER BY contexts.name" % (self.current_user_id)
        fetchedContexts = {}
        for row in self.databaseCon.execute(activeContextQuery):
            fetchedContexts[row[0]] = row[1] 
            #print len(fetchedContexts)
            if self.homeContexts.has_key(row[0]):
                None
            else:
                sql = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                  projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                  todos.context_id = contexts.id AND todos.user_id=contexts.user_id) LEFT JOIN projects on \
                  todos.project_id = projects.id AND todos.user_id=projects.user_id where contexts.id='%s' and \
                  todos.id not in (select successor_id from dependencies where predecessor_id in (select id from todos where state='active')) and\
                  todos.state='active' and projects.state = 'active' and (todos.show_from<=DATE('now', 'localtime') or todos.show_from IS null) \
                  AND todos.user_id=%s ORDER BY CASE WHEN todos.due IS null THEN 1 ELSE 0 END, todos.due, projects.name, todos.description" % (row[0], self.current_user_id)
                tracksAList = WidgetActionList(self.databaseCon,"@" + row[1], sql, True)
                tracksAList.setDisplayProjectFirst(True)
                tracksAList.editAction.connect(self.actionEditor.setCurrentActionID)    
                tracksAList.actionModified.connect(self.refresh)
                tracksAList.gotoProject.connect(self.slotGotoProject)
                tracksAList.gotoContext.connect(self.slotGotoContext)
                self.homeContexts[row[0]]=tracksAList
                self.verticalLayout.insertWidget(len(fetchedContexts)-1,tracksAList)
                
                # focus mapping
                tracksAList.setFocusMode(singlefocus)
                self.focusListMapper.setMapping(tracksAList, str(row[0]))
                tracksAList.getFocus.connect(self.focusListMapper.map)
                
        # focus mapping of completed list
        self.homeContexts["completed"].setFocusMode(singlefocus)
        self.focusListMapper.setMapping(self.homeContexts["completed"], str("completed"))
        self.homeContexts["completed"].getFocus.connect(self.focusListMapper.map)
                
        completed = self.homeContexts["completed"]
        sqlCompleted = "SELECT todos.id, todos.description, todos.state, contexts.id, contexts.name, \
                       projects.id, projects.name FROM (todos LEFT JOIN contexts ON \
                       todos.context_id = contexts.id AND todos.user_id=contexts.user_id) LEFT JOIN projects on \
                       todos.project_id = projects.id AND todos.user_id=projects.user_id where todos.state=\
                       'completed' AND todos.user_id=%s order by todos.completed_at DESC limit 7" % (self.current_user_id)
        completed.setDBQuery(sqlCompleted)
                
        # remove any contexts that may have been removed / hidden, refresh the others
        for key in self.homeContexts.keys():
            if key not in fetchedContexts.keys() and key != "completed":
                self.homeContexts[key].hide()
                self.verticalLayout.removeWidget(self.homeContexts[key])   
                del self.homeContexts[key] 
            else:
                self.homeContexts[key].refresh()
        
        self.actionEditor.setCurrentUser(self.current_user_id)
        
    def setFormVisible(self, visible):
        logging.info("PageHome->setFormVisible(self, visible)")
        self.actionEditor.setVisible(visible)
        self.actionEditor.setFocus()
        
    def slotGotoProject(self, id):
        logging.info("PageHome->slotGotoProject(self, id)")
        self.emit(QtCore.SIGNAL("gotoProject(int)"), id)
        
    def slotGotoContext(self, id):
        logging.info("PageHome->slotGotoContext(self, id)")
        self.emit(QtCore.SIGNAL("gotoContext(int)"), id)
        
    def slotFocusList(self, focuskey):
        logging.info("PageHome->slotFocusList(self, id)")
        
        # Prevent flickering as things change
        self.setUpdatesEnabled(False)
        
        # shrink all lists but the expanded list
        for key in self.homeContexts.keys():
            if str(key) != focuskey:
                self.homeContexts[key].setExpanded(False)
                
        # this is done after to prevent flicker
        for key in self.homeContexts.keys():
            if str(key) == focuskey:
                self.homeContexts[key].setExpanded(True)
                
        # Re-enable screen updates
        self.setUpdatesEnabled(True)
    
    def moveExclusiveExpandUp(self):
        logging.info("tracks->moveExclusiveExpandUp")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos < focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        for pos in posKeys:
            if focuspos and pos<focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
        
    def moveExclusiveExpandDown(self):
        logging.info("PageHome->moveExclusiveExpandDown(self)")

        # shrink all lists but the expanded list
        focuspos = None
        posList = {}
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isExpanded():
                if (not focuspos) or (pos > focuspos):
                    focuspos = pos
            self.homeContexts[key].setExpanded(False)
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        
        for pos in posKeys:
            if focuspos and pos>focuspos:
                self.homeContexts[posList[pos]].setExpanded(True)
                done = True
                break
        if done == False:
            self.homeContexts[posList[posKeys[len(posKeys)-1]]].setExpanded(True)
    
    def moveFocusUp(self):
        # moves the keyboard focus up to the next expanded list
        logging.info("PageHome->moveFocusUp")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort(reverse=True)
        done = False
        # set keyboard focus on the next highest list that is expanded
        for pos in posKeys:
            if pos<keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to highest list and expand
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()
            
    def moveFocusDown(self):
        # moves the keyboard focus down to the next expanded list
        logging.info("PageHome->moveFocusDown")
        keyfocuspos = None
        posList = {}
        # find the list with keyboard focus if there is one
        for key in self.homeContexts.keys():
            pos = self.homeContexts[key].pos().y()
            posList[pos] = key
            if self.homeContexts[key].isAncestorOf(QtGui.QApplication.focusWidget()):
                    keyfocuspos = pos  
        # sort the lists by position
        posKeys = posList.keys()
        posKeys.sort()
        done = False
        # set keyboard focus on the next lowest list that is expanded
        for pos in posKeys:
            if keyfocuspos and pos>keyfocuspos:
                if self.homeContexts[posList[pos]].isExpanded():
                    self.homeContexts[posList[pos]].listWidget.setFocus()
                else:
                    self.homeContexts[posList[pos]].toggleListButton.setFocus()
                done = True
                break
        # If none were expanded set to lowest list
        if done == False:
            if self.homeContexts[posList[posKeys[0]]].isExpanded():
                self.homeContexts[posList[posKeys[0]]].listWidget.setFocus()#setExpanded(True)
            else:
                self.homeContexts[posList[posKeys[0]]].toggleListButton.setFocus()