def initUI(self):
     self.dateEdit = QDateEdit()
     layout = QGridLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     layout.addWidget(self.dateEdit, 0, 0)
     layout.addItem(QSpacerItem(20, 20, QSizePolicy.Minimum, QSizePolicy.Expanding))
     self.setLayout(layout)
Esempio n. 2
0
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(598, 450)
        self.icon = QIcon(":/icons/uglytheme/48x48/polibeepsync.png")
        Form.setWindowIcon(self.icon)
        Form.setLocale(QLocale(QLocale.English, QLocale.UnitedStates))
        self.verticalLayout = QVBoxLayout(Form)
        self.verticalLayout.setObjectName("verticalLayout")

        self.tabWidget = QTabWidget(Form)
        self.tabWidget.setObjectName("tabWidget")

        # Tab General Settings
        self.tab = QWidget()
        self.tab.setObjectName("tab")
        self.horizontalLayout = QHBoxLayout(self.tab)
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName("verticalLayout_2")
        self.gridLayout = QGridLayout()
        self.gridLayout.setObjectName("gridLayout")
        self.label_2 = QLabel(self.tab)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 3, 0, 1, 1)
        self.label = QLabel(self.tab)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 1, 0, 1, 1)
        self.password = QLineEdit(self.tab)
        self.password.setMaximumSize(QSize(139, 16777215))
        self.password.setEchoMode(QLineEdit.Password)
        self.password.setObjectName("password")
        self.gridLayout.addWidget(self.password, 3, 1, 1, 1)
        self.userCode = QLineEdit(self.tab)
        self.userCode.setMaximumSize(QSize(139, 16777215))
        self.userCode.setText("")
        self.userCode.setObjectName("userCode")
        self.gridLayout.addWidget(self.userCode, 1, 1, 1, 1)
        spacerItem = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                 QSizePolicy.Minimum)
        self.gridLayout.addItem(spacerItem, 1, 2, 1, 1)
        self.verticalLayout_2.addLayout(self.gridLayout)
        self.trylogin = QPushButton(self.tab)
        self.trylogin.setMaximumSize(QSize(154, 16777215))
        self.trylogin.setObjectName("trylogin")
        self.verticalLayout_2.addWidget(self.trylogin)
        self.login_attempt = QLabel(self.tab)
        self.login_attempt.setText("Logging in, please wait.")
        self.login_attempt.setStyleSheet("color: rgba(0, 0, 0, 0);")
        self.login_attempt.setObjectName("login_attempt")
        self.verticalLayout_2.addWidget(self.login_attempt)
        spacerItem1 = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                  QSizePolicy.Expanding)
        self.verticalLayout_2.addItem(spacerItem1)
        self.horizontalLayout_3 = QHBoxLayout()
        self.horizontalLayout_3.setObjectName("horizontalLayout_3")
        self.label_4 = QLabel(self.tab)
        self.label_4.setObjectName("label_4")
        self.horizontalLayout_3.addWidget(self.label_4)
        self.rootfolder = QLineEdit(self.tab)
        self.rootfolder.setMinimumSize(QSize(335, 0))
        self.rootfolder.setMaximumSize(QSize(335, 16777215))
        self.rootfolder.setInputMask("")
        self.rootfolder.setReadOnly(True)
        self.rootfolder.setObjectName("rootfolder")
        self.horizontalLayout_3.addWidget(self.rootfolder)
        self.changeRootFolder = QPushButton(self.tab)
        self.changeRootFolder.setObjectName("changeRootFolder")
        self.horizontalLayout_3.addWidget(self.changeRootFolder)
        spacerItem2 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                  QSizePolicy.Minimum)
        self.horizontalLayout_3.addItem(spacerItem2)
        self.verticalLayout_2.addLayout(self.horizontalLayout_3)
        self.horizontalLayout_5 = QHBoxLayout()
        self.horizontalLayout_5.setObjectName("horizontalLayout_5")
        self.label_5 = QLabel(self.tab)
        self.label_5.setObjectName("label_5")
        self.horizontalLayout_5.addWidget(self.label_5)
        self.timerMinutes = QSpinBox(self.tab)
        self.timerMinutes.setObjectName("timerMinutes")
        self.horizontalLayout_5.addWidget(self.timerMinutes)
        self.label_6 = QLabel(self.tab)
        self.label_6.setObjectName("label_6")
        self.horizontalLayout_5.addWidget(self.label_6)
        self.syncNow = QPushButton(self.tab)
        self.syncNow.setObjectName("syncNow")
        self.horizontalLayout_5.addWidget(self.syncNow)
        spacerItem3 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                  QSizePolicy.Minimum)
        self.horizontalLayout_5.addItem(spacerItem3)
        self.verticalLayout_2.addLayout(self.horizontalLayout_5)
        self.addSyncNewCourses = QCheckBox(self.tab)
        self.addSyncNewCourses.setObjectName("addSyncNewCourses")
        self.verticalLayout_2.addWidget(self.addSyncNewCourses)
        self.horizontalLayout.addLayout(self.verticalLayout_2)
        self.tabWidget.addTab(self.tab, "")

        # Tab Courses
        self.tab_2 = QWidget()
        self.tab_2.setObjectName("tab_2")
        self.horizontalLayout_2 = QHBoxLayout(self.tab_2)
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName("verticalLayout_3")
        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.refreshCourses = QPushButton(self.tab_2)
        self.refreshCourses.setObjectName("refreshCourses")
        self.horizontalLayout_6.addWidget(self.refreshCourses)
        spacerItem4 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                  QSizePolicy.Minimum)
        self.horizontalLayout_6.addItem(spacerItem4)
        self.verticalLayout_3.addLayout(self.horizontalLayout_6)
        self.coursesView = CoursesListView(self.tab_2)
        self.coursesView.setObjectName("coursesView")
        self.verticalLayout_3.addWidget(self.coursesView)
        self.horizontalLayout_2.addLayout(self.verticalLayout_3)
        self.tabWidget.addTab(self.tab_2, "")

        # Tab Status
        self.tab_3 = QWidget()
        self.tab_3.setObjectName("tab_3")
        self.horizontalLayout_7 = QHBoxLayout(self.tab_3)
        self.horizontalLayout_7.setObjectName("horizontalLayout_7")
        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName("verticalLayout_4")
        self.horizontalLayout_8 = QHBoxLayout()
        self.horizontalLayout_8.setObjectName("horizontalLayout_8")
        self.about = QPushButton(self.tab_3)
        self.about.setObjectName("about")
        self.horizontalLayout_8.addWidget(self.about)
        spacerItem5 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                  QSizePolicy.Minimum)
        self.horizontalLayout_8.addItem(spacerItem5)
        self.verticalLayout_4.addLayout(self.horizontalLayout_8)
        self.status = QTextEdit(self.tab_3)
        self.status.setTextInteractionFlags(Qt.TextSelectableByKeyboard
                                            | Qt.TextSelectableByMouse)
        self.status.setObjectName("status")
        self.verticalLayout_4.addWidget(self.status)
        self.horizontalLayout_7.addLayout(self.verticalLayout_4)
        self.tabWidget.addTab(self.tab_3, "")

        self.tab_4 = QWidget()
        self.tab_4.setObjectName("tab_4")
        self.verticalLayout.addWidget(self.tabWidget)

        self.okButton = QDialogButtonBox(Form)
        self.okButton.setStandardButtons(QDialogButtonBox.Ok)
        self.okButton.setObjectName("okButton")
        self.okButton.clicked.connect(self.hide)
        self.verticalLayout.addWidget(self.okButton)

        self.statusLabel = QLabel(Form)
        self.statusLabel.setObjectName("statusLabel")
        self.verticalLayout.addWidget(self.statusLabel)

        self.retranslateUi(Form)
        self.tabWidget.setCurrentIndex(0)
        QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        Form.setWindowTitle("poliBeePsync")
        if pysideVersion == '1.2.2':
            self.label_2.setText(
                QApplication.translate("Form", "Password", None,
                                       QApplication.UnicodeUTF8))
            self.label.setText(
                QApplication.translate("Form", "User code", None,
                                       QApplication.UnicodeUTF8))
            self.trylogin.setText(
                QApplication.translate("Form", "Try login credentials", None,
                                       QApplication.UnicodeUTF8))
            self.login_attempt.setText(
                QApplication.translate("Form", "Login successful", None,
                                       QApplication.UnicodeUTF8))
            self.label_4.setText(
                QApplication.translate("Form", "Root folder", None,
                                       QApplication.UnicodeUTF8))
            self.changeRootFolder.setText(
                QApplication.translate("Form", "Change", None,
                                       QApplication.UnicodeUTF8))
            self.label_5.setText(
                QApplication.translate("Form", "Sync every", None,
                                       QApplication.UnicodeUTF8))
            self.label_6.setText(
                QApplication.translate("Form", "minutes", None,
                                       QApplication.UnicodeUTF8))
            self.syncNow.setText(
                QApplication.translate("Form", "Sync now", None,
                                       QApplication.UnicodeUTF8))
            self.addSyncNewCourses.setText(
                QApplication.translate(
                    "Form", "Automatically add and sync new available courses",
                    None, QApplication.UnicodeUTF8))
            self.tabWidget.setTabText(
                self.tabWidget.indexOf(self.tab),
                QApplication.translate("Form", "General settings", None,
                                       QApplication.UnicodeUTF8))
            self.refreshCourses.setText(
                QApplication.translate("Form", "Refresh list", None,
                                       QApplication.UnicodeUTF8))
            self.tabWidget.setTabText(
                self.tabWidget.indexOf(self.tab_2),
                QApplication.translate("Form", "Courses", None,
                                       QApplication.UnicodeUTF8))
            self.about.setText(
                QApplication.translate("Form", "About", None,
                                       QApplication.UnicodeUTF8))
            self.tabWidget.setTabText(
                self.tabWidget.indexOf(self.tab_3),
                QApplication.translate("Form", "Status", None,
                                       QApplication.UnicodeUTF8))
        else:
            self.label_2.setText(
                QApplication.translate("Form", "Password", None))
            self.label.setText(
                QApplication.translate("Form", "User code", None))
            self.trylogin.setText(
                QApplication.translate("Form", "Try login credentials", None))
            self.login_attempt.setText(
                QApplication.translate("Form", "Login successful", None))
            self.label_4.setText(
                QApplication.translate("Form", "Root folder", None))
            self.changeRootFolder.setText(
                QApplication.translate("Form", "Change", None))
            self.label_5.setText(
                QApplication.translate("Form", "Sync every", None))
            self.label_6.setText(
                QApplication.translate("Form", "minutes", None))
            self.syncNow.setText(
                QApplication.translate("Form", "Sync now", None))
            self.addSyncNewCourses.setText(
                QApplication.translate(
                    "Form", "Automatically add and sync new available courses",
                    None))
            self.tabWidget.setTabText(
                self.tabWidget.indexOf(self.tab),
                QApplication.translate("Form", "General settings", None))
            self.refreshCourses.setText(
                QApplication.translate("Form", "Refresh list", None))
            self.tabWidget.setTabText(
                self.tabWidget.indexOf(self.tab_2),
                QApplication.translate("Form", "Courses", None))
            self.about.setText(QApplication.translate("Form", "About", None))
            self.tabWidget.setTabText(
                self.tabWidget.indexOf(self.tab_3),
                QApplication.translate("Form", "Status", None))
Esempio n. 3
0
class NotificationTab():
    """ui class for new notification tab"""
    global logger

    def __init__(self):
        #####
        logger.info('Inside PurchaseSchedule')
        self.notificationTab_tab_4 = QWidget()
        self.notificationTab_tab_4.setObjectName("notificationTab_tab_4")
        self.gridLayout_19 = QGridLayout(self.notificationTab_tab_4)
        self.gridLayout_19.setObjectName("gridLayout_19")
        ##
        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.title_label = QLabel(self.notificationTab_tab_4)
        self.title_label.setObjectName("title_label")
        self.horizontalLayout.addWidget(self.title_label)
        self.gridLayout_19.addLayout(self.horizontalLayout, 0, 0, 1, 1)
        ##
        self.horizontalLayout_6 = QHBoxLayout()
        self.horizontalLayout_6.setObjectName("horizontalLayout_6")
        self.id_label = QLabel(self.notificationTab_tab_4)
        self.id_label.setObjectName("id_label")
        self.horizontalLayout_6.addWidget(self.id_label)
        self.id_line = QLineEdit(self.notificationTab_tab_4)
        self.id_line.setObjectName("id_line")
        self.horizontalLayout_6.addWidget(self.id_line)
        self.notification_schedule_fromdate_label = QLabel(
            self.notificationTab_tab_4)
        self.notification_schedule_fromdate_label.setObjectName(
            "notification_schedule_fromdate_label")
        self.horizontalLayout_6.addWidget(
            self.notification_schedule_fromdate_label)
        self.notification_schedule_fromdate_dateedit = QDateEdit(
            self.notificationTab_tab_4)
        self.notification_schedule_fromdate_dateedit.setMaximumDate(
            QDate.currentDate())
        self.notification_schedule_fromdate_dateedit.setDate(
            QDate.currentDate())
        self.notification_schedule_fromdate_dateedit.setCalendarPopup(True)
        self.notification_schedule_fromdate_dateedit.setObjectName(
            "notification_schedule_fromdate_dateedit")
        self.horizontalLayout_6.addWidget(
            self.notification_schedule_fromdate_dateedit)
        self.notification_schedule_todate_label = QLabel(
            self.notificationTab_tab_4)
        self.notification_schedule_todate_label.setObjectName(
            "notification_schedule_todate_label")
        self.horizontalLayout_6.addWidget(
            self.notification_schedule_todate_label)
        self.notification_schedule_todate_dateedit = QDateEdit(
            self.notificationTab_tab_4)
        self.notification_schedule_todate_dateedit.setMaximumDate(
            QDate.currentDate())
        self.notification_schedule_todate_dateedit.setDate(QDate.currentDate())
        self.notification_schedule_todate_dateedit.setCalendarPopup(True)
        self.notification_schedule_todate_dateedit.setObjectName(
            "notification_schedule_todate_dateedit")
        self.horizontalLayout_6.addWidget(
            self.notification_schedule_todate_dateedit)
        self.type_label = QLabel(self.notificationTab_tab_4)
        self.type_label.setObjectName("type_label")
        self.horizontalLayout_6.addWidget(self.type_label)
        self.notification_states = QComboBox(self.notificationTab_tab_4)
        self.notification_states.setObjectName("notification_states")
        self.horizontalLayout_6.addWidget(self.notification_states)
        self.batch_label = QLabel(self.notificationTab_tab_4)
        self.batch_label.setObjectName("batch_label")
        self.horizontalLayout_6.addWidget(self.batch_label)
        self.notification_results = QComboBox(self.notificationTab_tab_4)
        self.notification_results.setObjectName("notification_results")
        self.horizontalLayout_6.addWidget(self.notification_results)
        self.gridLayout_19.addLayout(self.horizontalLayout_6, 1, 0, 1, 1)
        self.gridLayout_8 = QGridLayout()
        self.gridLayout_8.setObjectName("gridLayout_8")
        self.notification_schedule_table = QTableWidget(
            self.notificationTab_tab_4)
        self.notification_schedule_table.setObjectName(
            "notification_schedule_table")
        self.notification_schedule_table.setColumnCount(5)
        self.notification_schedule_table.setRowCount(0)
        self.notification_schedule_table.setWordWrap(True)
        item = QTableWidgetItem()
        self.notification_schedule_table.setHorizontalHeaderItem(0, item)
        item = QTableWidgetItem()
        self.notification_schedule_table.setHorizontalHeaderItem(1, item)
        item = QTableWidgetItem()
        self.notification_schedule_table.setHorizontalHeaderItem(2, item)
        item = QTableWidgetItem()
        self.notification_schedule_table.setHorizontalHeaderItem(3, item)
        item = QTableWidgetItem()
        self.notification_schedule_table.setHorizontalHeaderItem(4, item)
        self.notification_schedule_table.horizontalHeader(
        ).setCascadingSectionResizes(True)
        self.notification_schedule_table.horizontalHeader(
        ).setStretchLastSection(True)
        self.notification_schedule_table.verticalHeader().setVisible(False)
        self.notification_schedule_table.verticalHeader(
        ).setCascadingSectionResizes(True)
        self.notification_schedule_table.verticalHeader(
        ).setStretchLastSection(False)
        self.gridLayout_8.addWidget(self.notification_schedule_table, 0, 0, 1,
                                    5)
        self.notification_search_button = QPushButton(
            self.notificationTab_tab_4)
        self.notification_search_button.setObjectName(
            "notification_search_button")
        self.gridLayout_8.addWidget(self.notification_search_button, 1, 0, 1,
                                    1)
        spacerItem10 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                   QSizePolicy.Minimum)
        self.gridLayout_8.addItem(spacerItem10, 1, 2, 1, 1)
        self.notification_reset_button = QPushButton(
            self.notificationTab_tab_4)
        self.notification_reset_button.setObjectName(
            "notification_reset_button")
        self.gridLayout_8.addWidget(self.notification_reset_button, 1, 3, 1, 1)
        self.notification_load_more_button = QPushButton(
            self.notificationTab_tab_4)
        self.notification_load_more_button.setObjectName(
            "notification_load_more_button")
        self.gridLayout_8.addWidget(self.notification_load_more_button, 1, 4,
                                    1, 1)
        self.gridLayout_19.addLayout(self.gridLayout_8, 2, 0, 1, 1)
        ###retranslate
        self.title_label.setText(
            QApplication.translate(
                "MainWindow", "<html><head/><body><p align=\"center\">"
                "<span style=\" font-weight:600;font-size:20px\">"
                "<u>All Notifications</u></span></p></body></html>", None,
                QApplication.UnicodeUTF8))
        self.id_label.setText(
            QApplication.translate("MainWindow", "Message Id", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_fromdate_label.setText(
            QApplication.translate("MainWindow", "From Date", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_fromdate_dateedit.setDisplayFormat(
            QApplication.translate("MainWindow", "dd/MM/yyyy", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_todate_label.setText(
            QApplication.translate("MainWindow", "To Date", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_todate_dateedit.setDisplayFormat(
            QApplication.translate("MainWindow", "dd/MM/yyyy", None,
                                   QApplication.UnicodeUTF8))
        self.type_label.setText(
            QApplication.translate("MainWindow", "Type", None,
                                   QApplication.UnicodeUTF8))
        self.batch_label.setText(
            QApplication.translate("MainWindow", "Number of Notifications",
                                   None, QApplication.UnicodeUTF8))
        self.notification_schedule_table.horizontalHeaderItem(0).setText(
            QApplication.translate("MainWindow", "Message Id", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_table.horizontalHeaderItem(1).setText(
            QApplication.translate("MainWindow", "Date", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_table.horizontalHeaderItem(2).setText(
            QApplication.translate("MainWindow", "From", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_table.horizontalHeaderItem(3).setText(
            QApplication.translate("MainWindow", "Message", None,
                                   QApplication.UnicodeUTF8))
        self.notification_schedule_table.horizontalHeaderItem(4).setText(
            QApplication.translate("MainWindow", "State", None,
                                   QApplication.UnicodeUTF8))
        self.notification_search_button.setText(
            QApplication.translate("MainWindow", "Search", None,
                                   QApplication.UnicodeUTF8))
        self.notification_reset_button.setText(
            QApplication.translate("MainWindow", "Reset All", None,
                                   QApplication.UnicodeUTF8))
        self.notification_load_more_button.setText(
            QApplication.translate("MainWindow", "Load More", None,
                                   QApplication.UnicodeUTF8))
        ##signals and slotts && other stuffs
        self.scheduletable_count = 0
        self.addtable_count = 0
        # self.mainwindow = Ui_MainWindow  # just for the ease of finding the attributes in pycharm
        self.notification_schedule_table.setEditTriggers(
            QAbstractItemView.NoEditTriggers)
        self.batch_number = None
        self.notification_results.addItems([str(i) for i in range(1, 50, 5)])
        self.notification_states.addItems(['All', 'New', 'To Do', 'Done'])
        self.message = Messaging()
        self.notification_load_more_button.clicked.connect(self.load_more)
        self.notification_search_button.clicked.connect(self.search_messages)
        self.notification_reset_button.clicked.connect(self.reset_all)
        self.notificationTab_tab_4.setFocusPolicy(Qt.StrongFocus)
        self.notificationTab_tab_4.focusInEvent = self.load_rows
        # self.assign_shortcuts()

        # def assign_shortcuts(self):
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_search']),
        # self.notificationTab_tab_4, self.search_messages)
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_additem']),
        # self.notificationTab_tab_4, self.add_new_blank_rows)
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_print']),
        # self.notificationTab_tab_4, self.commit_and_print)
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_today']),
        # self.notificationTab_tab_4, lambda: self.load_messages('today'))
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_tommorow']),
        # self.notificationTab_tab_4, lambda: self.load_messages('tomorrow'))
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_thismonth']),
        # self.notificationTab_tab_4, lambda: self.load_messages('month'))
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_thisweek']),
        # self.notificationTab_tab_4, lambda: self.load_messages('week'))
        # QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_inventorynotification_clear']),
        # self.notificationTab_tab_4, self.clear_table)

    def add_messages(self, *args):
        """
        Populates the Schedules when we load the tab
        """
        table = self.notification_schedule_table
        if args:
            if args[0] != 'new':
                table.clearContents()
                table.setRowCount(0)
                table.setRowCount(len(args))
                for i, j in enumerate(args):
                    item = QTableWidgetItem(j['msg_id'])
                    table.setItem(i, 0, item)
                    item = QTableWidgetItem(j['date'])
                    table.setItem(i, 1, item)
                    item = QTableWidgetItem(
                        'Name:{}\nDesignation:{}\nAddress:{}'.format(
                            j['name'], j['designation'], j['address']))
                    table.setItem(i, 2, item)
                    item = QTableWidgetItem(
                        'Message Type:{}\nMessage:{}'.format(
                            j['msg_type'].title(), j['msg_body']))
                    table.setItem(i, 3, item)
                    states = QComboBox()
                    self.populate_states(states, j['msg_state'].title())
                    states.currentIndexChanged.connect(
                        lambda index, row=i: self.changed_state(row, index))
                    table.setCellWidget(i, 4, states)
            elif args[0] == 'new':
                initial = table.rowCount()
                row = table.rowCount() + len(args[1])
                table.setRowCount(row)
                forward_range = range(initial, row)
                for i, j in zip(forward_range, args[1]):
                    item = QTableWidgetItem(j['msg_id'])
                    table.setItem(i, 0, item)
                    item = QTableWidgetItem(j['date'])
                    table.setItem(i, 1, item)
                    item = QTableWidgetItem(
                        'Name:{}\nDesignation:{}\nAddress:{}'.format(
                            j['name'], j['designation'], j['address']))
                    table.setItem(i, 2, item)
                    item = QTableWidgetItem(
                        'Message Type:{}\nMessage:{}'.format(
                            j['msg_type'].title(), j['msg_body']))
                    table.setItem(i, 3, item)
                    states = QComboBox()
                    self.populate_states(states, j['msg_state'].title())
                    states.currentIndexChanged.connect(
                        lambda index, row=i: self.changed_state(row, index))
                    table.setCellWidget(i, 4, states)
        table.setColumnWidth(0, (table.width() * 0.5) / 5)
        table.setColumnWidth(1, (table.width() * 0.5) / 5)
        table.setColumnWidth(2, table.width() / 5)
        table.setColumnWidth(3, (table.width() * 2) / 5)
        self.notification_schedule_table.resizeRowsToContents()

    def populate_states(self, combo, state):
        """
        fills the supplier list for each item line
        :param combo: the combo box of suppliers
        :return:none
        """
        combo.setStyleSheet("QAbstractItemView{" "background: #4B77BE;" "}")
        combo.addItems(['New', 'To Do', 'Done'])
        index = combo.findText(state)
        combo.setCurrentIndex(index)

    def changed_state(self, row, index):
        """
        fill the item combo box
        :param combo: the combobox object
        :return: none
        """
        table = self.notification_schedule_table
        data = {}
        data['message_id'] = table.item(row, 0).text()
        data['msg_state'] = table.cellWidget(row, 4).currentText()
        msg = QMessageBox.information(
            QMessageBox(), 'Alert!!',
            'Do you want to change the status of the Message??',
            QMessageBox.Yes | QMessageBox.No)
        if msg == QMessageBox.Yes:
            report = self.message.update_message(data)
            if report:
                _ = QMessageBox.information(QMessageBox(), 'Success!!',
                                            'The Message was updated',
                                            QMessageBox.Yes | QMessageBox.No)
            else:
                _ = QMessageBox.critical(QMessageBox(), 'Error!!',
                                         'The Message was not updated',
                                         QMessageBox.Yes | QMessageBox.No)

    def search_messages(self):
        """
        Searches for messages when search button is pressed
        """
        logger.info('Notifications searching messages initiated')
        from_date = self.notification_schedule_fromdate_dateedit.text()
        to_date = self.notification_schedule_todate_dateedit.text()
        limit = self.notification_results.currentText()
        msg_id = self.id_line.text()
        msg_state = self.notification_states.currentText()
        dataobj = self.message.load_message(limit=limit,
                                            from_date=from_date,
                                            to_date=to_date,
                                            msg_id=msg_id,
                                            msg_state=msg_state)
        if dataobj:
            self.add_messages(*dataobj)
        else:
            self.notification_schedule_table.clearContents()
            self.notification_schedule_table.setRowCount(0)

    def load_more(self):
        """
        Searches for messages when search button is pressed
        """
        logger.info('Notifications searching messages initiated')
        from_date = self.notification_schedule_fromdate_dateedit.text()
        to_date = self.notification_schedule_todate_dateedit.text()
        limit = self.notification_results.currentText()
        msg_id = self.id_line.text()
        msg_state = self.notification_states.currentText()
        offset = self.notification_schedule_table.rowCount()
        dataobj = self.message.load_message(limit=limit,
                                            from_date=from_date,
                                            to_date=to_date,
                                            msg_id=msg_id,
                                            msg_state=msg_state,
                                            offset=offset)
        if dataobj:
            self.add_messages('new', dataobj)
        else:
            self.notification_schedule_table.clearContents()
            self.notification_schedule_table.setRowCount(0)

    def load_single_message(self, msg_id):  # api
        """method to load a single message"""
        self.reset_all()
        dataobj = self.message.load_message(msg_id=msg_id)
        if dataobj:
            self.add_messages('new', dataobj)
            self.id_line.setText(str(msg_id))
        else:
            self.notification_schedule_table.clearContents()
            self.notification_schedule_table.setRowCount(0)

    def load_rows(self, event):
        """
        :return:loads the rows
        """
        self.add_messages()

    def reset_all(self):
        """
        :return: resets the the data in the search text
        """
        try:
            self.id_line.clear()
            self.notification_schedule_table.clearContents()
            self.notification_schedule_table.setRowCount(0)
        except Exception as _:
            if settings.level == 10:
                logger.exception('raised exception')
            return False
Esempio n. 4
0
class MenuWeekday():
    """Tab to manage menu entry for each day"""
    global logger

    def __init__(self, day):
        ####
        logger.info('Inside MenuWeekday')
        self.menudetail_tab_1 = QWidget()
        self.menudetail_tab_1.setObjectName("menudetail_tab_1")
        self.gridLayout_20 = QGridLayout(self.menudetail_tab_1)
        self.gridLayout_20.setObjectName("gridLayout_20")
        self.menu_table = QTableWidget(self.menudetail_tab_1)
        self.menu_table.setSortingEnabled(True)
        self.menu_table.setObjectName("menu_table")
        self.menu_table.setColumnCount(6)
        self.menu_table.setRowCount(0)
        item = QTableWidgetItem()
        self.menu_table.setHorizontalHeaderItem(0, item)
        item = QTableWidgetItem()
        self.menu_table.setHorizontalHeaderItem(1, item)
        item = QTableWidgetItem()
        self.menu_table.setHorizontalHeaderItem(2, item)
        item = QTableWidgetItem()
        self.menu_table.setHorizontalHeaderItem(3, item)
        item = QTableWidgetItem()
        self.menu_table.setHorizontalHeaderItem(4, item)
        item = QTableWidgetItem()
        self.menu_table.setHorizontalHeaderItem(5, item)
        self.menu_table.horizontalHeader().setCascadingSectionResizes(False)
        self.menu_table.horizontalHeader().setStretchLastSection(True)
        self.menu_table.verticalHeader().setVisible(True)
        self.menu_table.verticalHeader().setCascadingSectionResizes(True)
        self.gridLayout_20.addWidget(self.menu_table, 0, 0, 1, 3)
        spacerItem22 = QSpacerItem(612, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        self.gridLayout_20.addItem(spacerItem22, 1, 0, 1, 1)
        self.menu_table_refresh_button = QPushButton(self.menudetail_tab_1)
        self.menu_table_refresh_button.setObjectName("menu_table_refresh_button")
        self.gridLayout_20.addWidget(self.menu_table_refresh_button, 1, 1, 1, 1)
        self.menu_table_add_button = QPushButton(self.menudetail_tab_1)
        self.menu_table_add_button.setObjectName("menu_table_add_button")
        self.gridLayout_20.addWidget(self.menu_table_add_button, 1, 2, 1, 1)
        ####retranslate
        self.menu_table.horizontalHeaderItem(0).setText(
            QApplication.translate("MainWindow", "Code", None, QApplication.UnicodeUTF8))
        self.menu_table.horizontalHeaderItem(1).setText(
            QApplication.translate("MainWindow", "Item", None, QApplication.UnicodeUTF8))
        self.menu_table.horizontalHeaderItem(2).setText(
            QApplication.translate("MainWindow", "Category", None, QApplication.UnicodeUTF8))
        self.menu_table.horizontalHeaderItem(3).setText(
            QApplication.translate("MainWindow", "Rate", None, QApplication.UnicodeUTF8))
        self.menu_table.horizontalHeaderItem(4).setText(
            QApplication.translate("MainWindow", "Per Day", None, QApplication.UnicodeUTF8))
        self.menu_table.horizontalHeaderItem(5).setText(
            QApplication.translate("MainWindow", "Available", None, QApplication.UnicodeUTF8))
        self.menu_table_refresh_button.setText(
            QApplication.translate("MainWindow", "Refresh", None, QApplication.UnicodeUTF8))
        self.menu_table_add_button.setText(
            QApplication.translate("MainWindow", "Add Dish", None, QApplication.UnicodeUTF8))
        ###signals and slots && other stuffs
        # self.mainwindow = Ui_MainWindow  # just for the ease of finding the attributes in pycharm
        self.day = day
        self.menu_table_add_button.clicked.connect(self.add_menu)
        self.menu_table.itemDoubleClicked.connect(self.popup_edit)
        self.menu_table_refresh_button.clicked.connect(self.update_menu)
        self.menu_table.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.menu_table.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.menu_table.setShowGrid(False)
        self.menu_table.setAlternatingRowColors(True)
        self.update_menu()
        self.popup = object
        self.menudetail_tab_1.setFocusPolicy(Qt.StrongFocus)
        self.menudetail_tab_1.focusInEvent = self.load_rows
        self.assign_shortcuts()

    def assign_shortcuts(self):
        """assign shortcuts"""
        QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_menumgtmonsun_view']),
                  self.menudetail_tab_1, self.row_selected)
        QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_menumgtmonsun_refresh']),
                  self.menudetail_tab_1, self.update_menu)
        QShortcut(QKeySequence(settings.custom_shortcut['key_tabcon_menumgtmonsun_add']),
                  self.menudetail_tab_1, self.add_menu)

    def row_selected(self):
        """selets a row entry"""
        rows = sorted(set(index.row() for index in
                          self.menu_table.selectedIndexes()))
        if rows:
            code = self.menu_table.item(rows[0], 0).text()
            name = self.menu_table.item(rows[0], 1).text()
            quantity = self.menu_table.item(rows[0], 4).text()
            self.add_menu(code, name, quantity)

    def add_menu(self, *args):
        """
        :return: Pops up a new dialogue to add the menus
        """
        if not args:
            self.popup = AddMenuFromList(parent=self, day=self.day)
            self.popup.exec_()
        else:
            self.popup = MenuQuantityEditPopup(parent=self, day=self.day, code=args[0], name=args[1], quantity=args[2])
            self.popup.exec_()

    def update_menu(self):
        """
        :return:Populates the menu table
        """
        menu = WeeklyMenu(day=self.day)
        menulist = menu.load_dish_per_Day()
        if not menulist == []:
            self.add_row(*menulist)
        else:
            self.menu_table.clearContents()
            self.menu_table.setRowCount(0)

    def popup_edit(self, item):
        """
        Pops up the menu to be edited
        :param item: item clicked
        :return:none
        """
        model_index = self.menu_table.indexFromItem(item)
        row = model_index.row()
        code = self.menu_table.item(row, 0).text()
        name = self.menu_table.item(row, 1).text()
        quantity = self.menu_table.item(row, 4).text()
        self.add_menu(code, name, quantity)

    def add_row(self, *args):
        """creates a new row entry"""
        table = self.menu_table
        if args:
            table.setRowCount(len(args))
            for i, j in enumerate(args):
                item = QTableWidgetItem(j['item_no'])
                table.setItem(i, 0, item)
                item = QTableWidgetItem(j['item'])
                table.setItem(i, 1, item)
                item = QTableWidgetItem(j['category'])
                table.setItem(i, 2, item)
                item = QTableWidgetItem(j['rate'])
                table.setItem(i, 3, item)
                item = QTableWidgetItem(j['per_day'])
                table.setItem(i, 4, item)
                item = QTableWidgetItem(j['available'])
                table.setItem(i, 5, item)
        table.setColumnWidth(0, table.width() / 6)
        table.setColumnWidth(1, table.width() / 6)
        table.setColumnWidth(2, table.width() / 6)
        table.setColumnWidth(3, table.width() / 6)
        table.setColumnWidth(4, table.width() / 6)

    def load_rows(self, event):
        """
        :return:checks and adds new rows
        """
        self.add_row()