示例#1
0
    def __init__(self, parent=None):
        super(CreateTeam, self).__init__(parent)
        ModelCreateTeam.__init__(self)

        self.flow_create_team = TeamsFlow()

        QtCore.QObject.connect(self.submit_team,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.create_team)
        QtCore.QMetaObject.connectSlotsByName(self)

        # Tray icon application
        self.tray_icon = None
        self.tray_icon = TrayIcon(self)

        self.retranslateUi(self)
示例#2
0
    def __init__(self, parent=None):
        super(CreateTask, self).__init__(parent)
        ModelCreateTask.__init__(self)

        self.projects = list()
        self.flow_create_task = TasksFlow()

        self.project_assign()

        QtCore.QObject.connect(self.submit_task,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.create_task)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.retranslateUi(self)

        # Tray icon application
        self.tray_icon = None
        self.tray_icon = TrayIcon(self)
示例#3
0
class CreateProject(QtGui.QDialog, ModelCreatePoject):
    def __init__(self, parent=None):
        super(CreateProject, self).__init__(parent)
        ModelCreatePoject.__init__(self)

        self.flow_create_project = ProjectsFlow()

        QtCore.QObject.connect(self.submit_project,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.create_project)
        QtCore.QMetaObject.connectSlotsByName(self)

        # Tray icon application
        self.tray_icon = None
        self.tray_icon = TrayIcon(self)

        self.retranslateUi(self)

    def create_project(self):
        """
        Create project
        The default status of the project is active
        :return:
        """
        project = self.project_name.text()

        self.flow_create_project.add_project(
            str(project).encode('utf-8'), True)
        self.accept()

        # TODO : add to translation
        title = "Projects Flow"
        message = str(project) + " created."

        self.tray_icon.display_message(title, message)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Create Project", None))
        ModelCreatePoject.retranslateUi(self, Dialog)
示例#4
0
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)
        ModelWindow.__init__(self)

        # Tables properties
        self.last_work_days.setSelectionMode(
            QtGui.QAbstractItemView.SingleSelection)
        self.last_work_days.setSelectionBehavior(
            QtGui.QAbstractItemView.SelectRows)
        self.last_work_days.setColumnCount(8)
        self.last_work_days.verticalHeader().setVisible(False)
        self.last_work_days.setHorizontalHeaderItem(
            0, QtGui.QTableWidgetItem("Start"))
        self.last_work_days.setHorizontalHeaderItem(
            1, QtGui.QTableWidgetItem("Lunch"))
        self.last_work_days.setHorizontalHeaderItem(
            2, QtGui.QTableWidgetItem("After Lunch"))
        self.last_work_days.setHorizontalHeaderItem(
            3, QtGui.QTableWidgetItem("End"))
        self.last_work_days.setHorizontalHeaderItem(
            4, QtGui.QTableWidgetItem("Total"))
        self.last_work_days.setHorizontalHeaderItem(
            5, QtGui.QTableWidgetItem("Username"))
        self.last_work_days.setHorizontalHeaderItem(
            6, QtGui.QTableWidgetItem("Tasks"))
        self.last_work_days.setHorizontalHeaderItem(
            7, QtGui.QTableWidgetItem("ID"))

        self.last_work_days.hideColumn(7)

        self.ui_translate(self)

        # Instance Collection
        self.collection = Collection()

        self.stage = "morning"

        if not os.path.isfile("data.db"):
            self.file_exist = False

            # Display data on table.
            self.construct_data_grid()
        else:
            self.file_exist = True

        # TODO: Workaround to verify if sqlite file exist.
        try:
            self.update_table()
        except Exception:
            pass

        self._update_watch = UpdateWatch(self)
        self._update_watch.updated.connect(self.update_text)

        # Set signals slots
        QtCore.QObject.connect(self.start,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.buddy_action)
        QtCore.QObject.connect(self.export_xls,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.export)
        QtCore.QObject.connect(self.refress_work_days,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.update_table)
        QtCore.QObject.connect(self.tasks,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.tasks_main)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.start.clicked.connect(self._update_watch.start)

        # Main menu items
        self.actionExit.triggered.connect(self.close_application)
        self.actionAbout.triggered.connect(self.display_about)
        self.actionExport.triggered.connect(self.export)
        # View menu items
        self.actionCompact.triggered.connect(self.set_compact_view)
        self.actionFull.triggered.connect(self.set_full_view)
        # Project menu items
        self.actionCreate.triggered.connect(self.create_project)
        self.actionProjects.triggered.connect(self.window_projects)

        # Tasks menu items
        self.actionCreate_2.triggered.connect(self.create_task)
        self.actionTasks.triggered.connect(self.window_tasks)

        # Teams menu
        self.actionCreate_3.triggered.connect(self.create_teams)

        # BuddyTable.py main instance
        self.buddy_main = Work()

        # Write data to status bar, this is the database file and file size.
        self.statusbar.showMessage("Click on button Start Day")

        # Initialize the context menu for QWidget table.
        self.context_menu = None

        # Tray icon application
        self.tray_icon = None
        self.tray_icon = TrayIcon(self)
示例#5
0
class Window(QtGui.QMainWindow, ModelWindow):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)
        ModelWindow.__init__(self)

        # Tables properties
        self.last_work_days.setSelectionMode(
            QtGui.QAbstractItemView.SingleSelection)
        self.last_work_days.setSelectionBehavior(
            QtGui.QAbstractItemView.SelectRows)
        self.last_work_days.setColumnCount(8)
        self.last_work_days.verticalHeader().setVisible(False)
        self.last_work_days.setHorizontalHeaderItem(
            0, QtGui.QTableWidgetItem("Start"))
        self.last_work_days.setHorizontalHeaderItem(
            1, QtGui.QTableWidgetItem("Lunch"))
        self.last_work_days.setHorizontalHeaderItem(
            2, QtGui.QTableWidgetItem("After Lunch"))
        self.last_work_days.setHorizontalHeaderItem(
            3, QtGui.QTableWidgetItem("End"))
        self.last_work_days.setHorizontalHeaderItem(
            4, QtGui.QTableWidgetItem("Total"))
        self.last_work_days.setHorizontalHeaderItem(
            5, QtGui.QTableWidgetItem("Username"))
        self.last_work_days.setHorizontalHeaderItem(
            6, QtGui.QTableWidgetItem("Tasks"))
        self.last_work_days.setHorizontalHeaderItem(
            7, QtGui.QTableWidgetItem("ID"))

        self.last_work_days.hideColumn(7)

        self.ui_translate(self)

        # Instance Collection
        self.collection = Collection()

        self.stage = "morning"

        if not os.path.isfile("data.db"):
            self.file_exist = False

            # Display data on table.
            self.construct_data_grid()
        else:
            self.file_exist = True

        # TODO: Workaround to verify if sqlite file exist.
        try:
            self.update_table()
        except Exception:
            pass

        self._update_watch = UpdateWatch(self)
        self._update_watch.updated.connect(self.update_text)

        # Set signals slots
        QtCore.QObject.connect(self.start,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.buddy_action)
        QtCore.QObject.connect(self.export_xls,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.export)
        QtCore.QObject.connect(self.refress_work_days,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.update_table)
        QtCore.QObject.connect(self.tasks,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.tasks_main)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.start.clicked.connect(self._update_watch.start)

        # Main menu items
        self.actionExit.triggered.connect(self.close_application)
        self.actionAbout.triggered.connect(self.display_about)
        self.actionExport.triggered.connect(self.export)
        # View menu items
        self.actionCompact.triggered.connect(self.set_compact_view)
        self.actionFull.triggered.connect(self.set_full_view)
        # Project menu items
        self.actionCreate.triggered.connect(self.create_project)
        self.actionProjects.triggered.connect(self.window_projects)

        # Tasks menu items
        self.actionCreate_2.triggered.connect(self.create_task)
        self.actionTasks.triggered.connect(self.window_tasks)

        # Teams menu
        self.actionCreate_3.triggered.connect(self.create_teams)

        # BuddyTable.py main instance
        self.buddy_main = Work()

        # Write data to status bar, this is the database file and file size.
        self.statusbar.showMessage("Click on button Start Day")

        # Initialize the context menu for QWidget table.
        self.context_menu = None

        # Tray icon application
        self.tray_icon = None
        self.tray_icon = TrayIcon(self)

    def ui_translate(self, main_window):
        ModelWindow.ui_translate(self, main_window)

    def show_message_show_hide_tray(self, title, message):
        """
        Show and hide and display message in the toast format
        :param title:
        :param message:
        :return:
        """
        self.tray_icon.display_message(title, message)

    def buddy_action(self):
        if self.buddy_main.state() == "Void":
            self.buddy_main.create_data()

            self.buddy_main.start()
            self._update_watch.update_watch_status(True)
            self.statusbar.showMessage("Currently on morning shift")
            self.show_message_show_hide_tray("Workbuddy - Status Update",
                                             "Currently on morning shift")

            self.start.setText("Launch")

        elif self.buddy_main.state() == "Started":

            self.buddy_main.launch()
            self._update_watch.pause_watch(False)
            self.statusbar.showMessage("Finally lunch time")
            self.show_message_show_hide_tray("Workbuddy - Status Update",
                                             "Finally lunch time")

            self.start.setText("Start After Launch")

        elif self.buddy_main.state() == "Launch":
            self.buddy_main.return_from_launch()
            self._update_watch.pause_watch(True)
            self.statusbar.showMessage("Currently on afternoon shift")
            self.show_message_show_hide_tray("Workbuddy - Status Update",
                                             "Currently on afternoon shift")

            self.start.setText("End Day")

        elif self.buddy_main.state() == "After_Launch":
            self.buddy_main.end_day()

            self.start.setText("Start Day")

            self._update_watch.terminate()

            self._update_watch.update_watch_status(False)
            self.label.setText(
                "<html><head/><body><p align=\"center\">HH:MM:SS</p></body></html>"
            )
            self.statusbar.showMessage("Click on button Start Day")
            self.show_message_show_hide_tray("Workbuddy - Status Update",
                                             "End day")

        else:
            raise ValueError("Invalid Option")

    def update_table(self):
        """
        Update work log table
        :return:
        """
        self.clear_table()

        # Instance Collection
        self.collection = Collection()

        # Display data on table.
        self.construct_data_grid()

    def clear_table(self):
        """
        Clear work log table
        :return:
        """
        self.last_work_days.clearContents()

    def update_text(self, text):
        self.label.setText(text)

    def construct_data_grid(self):
        # Get all data from table buddy and convert to python object list.
        all_data = self.collection.get_all_data()
        all_data = list(all_data)

        self.last_work_days.setRowCount(len(all_data))

        row_counter = 0
        for row in all_data:
            header = self.last_work_days.horizontalHeader()

            # Add ID to GUI table
            self.last_work_days.setItem(row_counter, 7,
                                        QtGui.QTableWidgetItem(str(row.Id)))
            header.setResizeMode(7, QtGui.QHeaderView.ResizeToContents)

            # Add username to GUI table
            self.last_work_days.setItem(row_counter, 5,
                                        QtGui.QTableWidgetItem(row.Username))
            header.setResizeMode(5, QtGui.QHeaderView.ResizeToContents)

            # Add Total, this value could be empty (None).
            if row.Total is not None:
                self.last_work_days.setItem(
                    row_counter, 4, QtGui.QTableWidgetItem(str(row.Total)))
            else:
                self.last_work_days.setItem(row_counter, 4,
                                            QtGui.QTableWidgetItem("EMPTY"))
            header.setResizeMode(4, QtGui.QHeaderView.ResizeToContents)

            # Add end work time in date format to GUI table.
            if row.EndWorkTime is not None:
                self.last_work_days.setItem(
                    row_counter, 3, QtGui.QTableWidgetItem(row.EndWorkTime))
            else:
                self.last_work_days.setItem(row_counter, 3,
                                            QtGui.QTableWidgetItem("EMPTY"))
            header.setResizeMode(3, QtGui.QHeaderView.ResizeToContents)

            # Add after lunch time in date format to GUI table.
            if row.StartAfterLunch is not None:
                self.last_work_days.setItem(
                    row_counter, 2,
                    QtGui.QTableWidgetItem(row.StartAfterLunch))
            else:
                self.last_work_days.setItem(row_counter, 2,
                                            QtGui.QTableWidgetItem("EMPTY"))
            header.setResizeMode(2, QtGui.QHeaderView.ResizeToContents)

            # Add lunch time in date format to GUI table.
            if row.LunchTime is not None:
                self.last_work_days.setItem(
                    row_counter, 1, QtGui.QTableWidgetItem(row.LunchTime))
            else:
                self.last_work_days.setItem(row_counter, 1,
                                            QtGui.QTableWidgetItem("EMPTY"))
            header.setResizeMode(1, QtGui.QHeaderView.ResizeToContents)

            # Add start work time in date format to GUI table.
            if row.StartWorkTime is not None:
                self.last_work_days.setItem(
                    row_counter, 0, QtGui.QTableWidgetItem(row.StartWorkTime))
            else:
                self.last_work_days.setItem(row_counter, 0,
                                            QtGui.QTableWidgetItem("EMPTY"))
            header.setResizeMode(0, QtGui.QHeaderView.ResizeToContents)

            row_counter += 1

    def contextMenuEvent(self, event):
        self.context_menu = QtGui.QMenu(self)
        action_rename = QtGui.QAction('SetDate', self)
        action_tasks = QtGui.QAction('AddTasks', self)
        action_rename.triggered.connect(self.define_date)
        self.context_menu.addAction(action_rename)
        self.context_menu.addAction(action_tasks)
        self.context_menu.popup(QtGui.QCursor.pos())

    def define_date(self):
        day_hours = list()
        for header in range(0, 4):
            day_hours.append(
                self.last_work_days.item(self.last_work_days.currentRow(),
                                         header).text())

        day_hours.append(
            self.last_work_days.item(self.last_work_days.currentRow(),
                                     7).text())

        edit = Edit(day_hours)
        edit.exec_()

    @staticmethod
    def display_about():
        about = About()
        about.exec_()

    @staticmethod
    def export():
        export = Export()
        export.export_csv()

    @staticmethod
    def tasks_main():
        tasks = Tasks()
        tasks.exec_()

    @staticmethod
    def close_application():
        # TODO: Implement a better way to close the application when changeEvent was triggered without event object
        warning = Warning(
            "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">"
            "Close WorkBuddy ?"
            "</span></p></body></html>")
        warning.exec_()

        if warning.event_action is True:
            sys.exit()

    def set_compact_view(self):
        self.last_work_days.hide()
        self.centralwidget.setMinimumSize(QtCore.QSize(600, 100))
        self.setMaximumSize(600, 143)
        self.resize(600, 143)

    def set_full_view(self):
        self.last_work_days.show()
        self.centralwidget.setMinimumSize(QtCore.QSize(944, 616))
        self.resize(944, 663)

    @staticmethod
    def create_project():
        create = CreateProject()
        create.exec_()

    @staticmethod
    def create_teams():
        create = CreateTeam()
        create.exec_()

    @staticmethod
    def window_projects():
        projects = Projects()
        projects.exec_()

    @staticmethod
    def window_tasks():
        tasks = Tasks()
        tasks.exec_()

    @staticmethod
    def create_task():
        create_task = CreateTask()
        create_task.exec_()

    def changeEvent(self, event):
        """
        This function get the minimize event.
        :param event:
        :return:
        """
        # Get the main window state event.
        if event.type() == QtCore.QEvent.WindowStateChange:
            if self.windowState() == QtCore.Qt.WindowMinimized:
                self.hide()

                self.tray_icon.show()
                self.tray_icon.showMessage(
                    "WorkBuddy is running in background!",
                    "Double click on Icon to activate the Window.")

    def closeEvent(self, event):
        warning = Warning(
            "<html><head/><body><p align=\"center\"><span style=\" font-weight:600;\">"
            "Close WorkBuddy ?"
            "</span></p></body></html>")
        warning.exec_()

        event.ignore()

        if warning.event_action is True:
            event.accept()
示例#6
0
class CreateTask(QtGui.QDialog, ModelCreateTask):
    def __init__(self, parent=None):
        super(CreateTask, self).__init__(parent)
        ModelCreateTask.__init__(self)

        self.projects = list()
        self.flow_create_task = TasksFlow()

        self.project_assign()

        QtCore.QObject.connect(self.submit_task,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               self.create_task)
        QtCore.QMetaObject.connectSlotsByName(self)

        self.retranslateUi(self)

        # Tray icon application
        self.tray_icon = None
        self.tray_icon = TrayIcon(self)

    def project_assign(self):
        """
        Defining the project assigned
        :return:
        """
        projects = self.flow_create_task.get_projects()

        for project in projects:
            project_map = dict()
            project_map.update({"Project": project.Project, "Id": project.Id})
            self.projects.append(project_map)

            self.associated_project.addItem(project.Project)

    def create_task(self):
        """
        Create project
        The default status of the project is active
        :return:
        """
        task = self.task_name.text()

        selected_project_id = None

        for project in self.projects:
            if self.associated_project.currentText() == project.get("Project"):
                selected_project_id = project.get("Id")

        description = self.task_description.toPlainText()

        self.flow_create_task.add_task(str(task), 1, selected_project_id,
                                       description)
        self.accept()

        # TODO : add to translation
        title = "Tasks Flow"
        message = task + " created."

        self.tray_icon.display_message(title, message)

    def retranslateUi(self, Dialog):
        Dialog.setWindowTitle(_translate("Dialog", "Create Task", None))
        ModelCreateTask.retranslateUi(self, Dialog)