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
class Ui_MainWindow(object): def setupUi(self, MainWindow): lbMinWidth = 65 # leMinWidth = 200 MainWindow.setObjectName("MainWindow") MainWindow.resize(400, 310) # self.centralwidget = QWidget(MainWindow) self.mainSplitter = QSplitter(Qt.Horizontal, MainWindow) self.mainSplitter.setObjectName("centralwidget") self.mainSplitter.setProperty("childrenCollapsible", False) MainWindow.setCentralWidget(self.mainSplitter) self.leftSplitter = QSplitter(Qt.Vertical, self.mainSplitter) self.leftSplitter.setProperty("childrenCollapsible", False) ##### login_gbox self.login_gbox = QGroupBox(self.leftSplitter) self.login_gbox.setFlat(True) self.login_gbox.setObjectName("login_gbox") login_gbox_layout = QVBoxLayout(self.login_gbox) login_gbox_csf_layout = QHBoxLayout() login_gbox_account_layout = QHBoxLayout() login_gbox_connect_layout = QHBoxLayout() login_gbox_layout.addLayout(login_gbox_csf_layout) login_gbox_layout.addLayout(login_gbox_account_layout) login_gbox_layout.addLayout(login_gbox_connect_layout) self.lb_client_secrets_file_path = QLabel(self.login_gbox) self.lb_client_secrets_file_path.setObjectName("lb_client_secrets_file_path") self.lb_client_secrets_file_path.setMinimumWidth(lbMinWidth) self.client_secrets_file_path_le = QLineEdit(self.login_gbox) self.client_secrets_file_path_le.setObjectName("client_secrets_file_path_le") self.client_secret_file_path_tBtn = QToolButton(self.login_gbox) self.client_secret_file_path_tBtn.setObjectName("client_secret_file_path_tBtn") login_gbox_csf_layout.addWidget(self.lb_client_secrets_file_path) login_gbox_csf_layout.addWidget(self.client_secrets_file_path_le) login_gbox_csf_layout.addWidget(self.client_secret_file_path_tBtn) self.lb_account = QLabel(self.login_gbox) self.lb_account.setMaximumWidth(lbMinWidth) self.lb_account.setObjectName("lb_account") self.remove_account_btn = QToolButton(self.login_gbox) self.remove_account_btn.setObjectName("remove_account_btn") self.remove_account_btn.setMinimumWidth(20) self.remove_account_btn.setEnabled(False) self.add_account_btn = QToolButton(self.login_gbox) self.add_account_btn.setObjectName("add_account_btn") self.add_account_btn.setMinimumWidth(20) self.accounts_cb = QComboBox(self.login_gbox) self.accounts_cb.setObjectName("accounts_cb") login_gbox_account_layout.addWidget(self.lb_account) login_gbox_account_layout.addWidget(self.remove_account_btn) login_gbox_account_layout.addWidget(self.add_account_btn) login_gbox_account_layout.addWidget(self.accounts_cb) self.lb_decryption_key = QLabel(self.login_gbox) self.lb_decryption_key.setObjectName("lb_decryption_key") self.lb_decryption_key.setMinimumWidth(lbMinWidth) self.lb_decryption_key.hide() self.decryption_key_le = QLineEdit(self.login_gbox) self.decryption_key_le.setEchoMode(QLineEdit.Password) self.decryption_key_le.setObjectName("decryption_key_le") self.decryption_key_le.hide() self.connect_btn = QPushButton(self.login_gbox) self.connect_btn.setEnabled(False) self.connect_btn.setObjectName("connect_btn") login_gbox_connect_layout.addWidget(self.lb_decryption_key) login_gbox_connect_layout.addWidget(self.decryption_key_le) login_gbox_connect_layout.addWidget(self.connect_btn) #### search_gbox self.search_gbox = QGroupBox(self.leftSplitter) self.search_gbox.setFlat(True) self.search_gbox.setObjectName("search_gbox") self.search_gbox.hide() search_gbox_layout = QVBoxLayout(self.search_gbox) search_gbox_mailbox_layout = QVBoxLayout() search_gbox_date_layout = QHBoxLayout() search_gbox_from_layout = QHBoxLayout() search_gbox_to_layout = QHBoxLayout() search_gbox_subject_layout = QHBoxLayout() search_gbox_threads_layout = QHBoxLayout() search_gbox_paramaters_layout = QHBoxLayout() search_gbox_layout.addLayout(search_gbox_mailbox_layout) search_gbox_layout.addLayout(search_gbox_date_layout) search_gbox_layout.addLayout(search_gbox_from_layout) search_gbox_layout.addLayout(search_gbox_to_layout) search_gbox_layout.addLayout(search_gbox_subject_layout) search_gbox_layout.addLayout(search_gbox_threads_layout) search_gbox_layout.addLayout(search_gbox_paramaters_layout) self.lb_select_mailbox = QLabel(self.search_gbox) self.lb_select_mailbox.setObjectName("lb_select_mailbox") self.mailboxes_lw = QListWidget(self.search_gbox) self.mailboxes_lw.setEditTriggers(QAbstractItemView.NoEditTriggers) self.mailboxes_lw.setSelectionMode(QAbstractItemView.ExtendedSelection) self.mailboxes_lw.setObjectName("mailboxes_lw") search_gbox_mailbox_layout.addWidget(self.lb_select_mailbox) search_gbox_mailbox_layout.addWidget(self.mailboxes_lw) self.after_date_cb = QCheckBox(self.search_gbox) self.after_date_cb.setObjectName("after_date_cb") self.after_date_cb.setMinimumWidth(lbMinWidth) self.after_date_cb.setMaximumWidth(lbMinWidth) self.after_date_edit = QDateEdit(self.search_gbox) self.after_date_edit.setCalendarPopup(True) self.after_date_edit.setObjectName("after_date_edit") self.after_date_edit.setDate(QDate.currentDate().addDays(-365)) self.after_date_edit.setMaximumDate(QDate.currentDate()) self.after_date_edit.setEnabled(False) self.before_date_cb = QCheckBox(self.search_gbox) self.before_date_cb.setObjectName("before_date_cb") self.before_date_cb.setMinimumWidth(70) self.before_date_cb.setMaximumWidth(70) self.before_date_edit = QDateEdit(self.search_gbox) self.before_date_edit.setCalendarPopup(True) self.before_date_edit.setObjectName("before_date_edit") self.before_date_edit.setDate(QDate.currentDate()) self.before_date_edit.setMaximumDate(QDate.currentDate()) self.before_date_edit.setEnabled(False) search_gbox_date_layout.addWidget(self.after_date_cb) search_gbox_date_layout.addWidget(self.after_date_edit) search_gbox_date_layout.addWidget(self.before_date_cb) search_gbox_date_layout.addWidget(self.before_date_edit) self.lb_from = QLabel(self.search_gbox) self.lb_from.setObjectName("lb_from") self.lb_from.setMinimumWidth(lbMinWidth) self.from_le = QLineEdit(self.search_gbox) self.from_le.setObjectName("from_le") search_gbox_from_layout.addWidget(self.lb_from) search_gbox_from_layout.addWidget(self.from_le) self.lb_to = QLabel(self.search_gbox) self.lb_to.setObjectName("lb_to") self.lb_to.setMinimumWidth(lbMinWidth) self.to_le = QLineEdit(self.search_gbox) self.to_le.setObjectName("to_le") search_gbox_to_layout.addWidget(self.lb_to) search_gbox_to_layout.addWidget(self.to_le) self.lb_subject = QLabel(self.search_gbox) self.lb_subject.setObjectName("lb_subject") self.lb_subject.setMinimumWidth(lbMinWidth) self.subject_le = QLineEdit(self.search_gbox) self.subject_le.setObjectName("subject_le") search_gbox_subject_layout.addWidget(self.lb_subject) search_gbox_subject_layout.addWidget(self.subject_le) self.lb_threads = QLabel(self.search_gbox) self.lb_threads.setObjectName("lb_threads") self.lb_threads.setMaximumWidth(lbMinWidth) self.thread_count_sb = QSpinBox(self.search_gbox) self.thread_count_sb.setMinimum(1) self.thread_count_sb.setMaximum(10) self.thread_count_sb.setObjectName("thread_count_sb") self.html_radio = QRadioButton(self.search_gbox) self.html_radio.setObjectName("html_radio") self.text_radio = QRadioButton(self.search_gbox) self.text_radio.setObjectName("text_radio") self.extactTypeButtonGroup = QButtonGroup(self) self.extactTypeButtonGroup.addButton(self.html_radio) self.extactTypeButtonGroup.addButton(self.text_radio) self.html_radio.setChecked(True) self.search_btn = QPushButton(self.search_gbox) self.search_btn.setObjectName("search_btn") search_gbox_threads_layout.addWidget(self.lb_threads) search_gbox_threads_layout.addWidget(self.thread_count_sb) search_gbox_threads_layout.addWidget(self.html_radio) search_gbox_threads_layout.addWidget(self.text_radio) search_gbox_threads_layout.addWidget(self.search_btn) self.parameters_cb = QCheckBox(self.search_gbox) self.parameters_cb.setText("") self.parameters_cb.setObjectName("parameters_cb") self.parameters_le = QLineEdit(self.search_gbox) self.parameters_le.setEnabled(False) self.parameters_le.setObjectName("parameters_le") search_gbox_paramaters_layout.addWidget(self.parameters_cb) search_gbox_paramaters_layout.addWidget(self.parameters_le) #### log_gbox self.log_gbox = QGroupBox(self.leftSplitter) self.log_gbox.setFlat(True) self.log_gbox.setObjectName("log_gbox") log_layout = QVBoxLayout(self.log_gbox) self.log_te = QTextEdit(self.log_gbox) self.log_te.setLineWrapMode(QTextEdit.NoWrap) self.log_te.setReadOnly(True) self.log_te.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse) self.log_te.setObjectName("log_te") self.disconnect_btn = QPushButton(self.log_gbox) self.disconnect_btn.setObjectName("disconnect_btn") self.disconnect_btn.hide() log_layout.addWidget(self.log_te) log_layout_btn = QHBoxLayout() log_layout.addLayout(log_layout_btn) log_layout_btn.addWidget(self.disconnect_btn) log_layout_btn.addStretch() #### links_gbox self.links_gbox = QGroupBox(self.mainSplitter) self.links_gbox.setFlat(True) self.links_gbox.setObjectName("links_gbox") self.links_gbox.hide() links_gbox_layout = QVBoxLayout(self.links_gbox) links_gbox_links_layout = QVBoxLayout() links_gbox_buttons_layout = QHBoxLayout() links_gbox_layout.addLayout(links_gbox_links_layout) links_gbox_layout.addLayout(links_gbox_buttons_layout) self.links_text_edit = QTextEdit(self.links_gbox) self.links_text_edit.setObjectName("links_text_edit") links_gbox_links_layout.addWidget(self.links_text_edit) self.export_txt_btn = QPushButton(self.links_gbox) self.export_txt_btn.setObjectName("export_txt_btn") self.export_txt_btn.setEnabled(False) self.export_html_btn = QPushButton(self.links_gbox) self.export_html_btn.setObjectName("export_html_btn") self.export_html_btn.setEnabled(False) links_gbox_buttons_layout.addWidget(self.export_txt_btn) links_gbox_buttons_layout.addWidget(self.export_html_btn) ### menubar self.menubar = QMenuBar(MainWindow) # self.menubar.setGeometry(QRect(0, 0, 860, 21)) self.menubar.setObjectName("menubar") self.menu_file = QMenu(self.menubar) self.menu_file.setObjectName("menu_file") self.menu_help = QMenu(self.menubar) self.menu_help.setObjectName("menu_help") MainWindow.setMenuBar(self.menubar) self.action_about = QAction(MainWindow) self.action_about.setObjectName("action_about") self.action_About_Qt = QAction(MainWindow) self.action_About_Qt.setObjectName("action_About_Qt") self.action_exit = QAction(MainWindow) self.action_exit.setObjectName("action_exit") self.actionSave = QAction(MainWindow) self.actionSave.setObjectName("actionSave") self.action_Gmail_Advanced_Search_Syntax = QAction(MainWindow) self.action_Gmail_Advanced_Search_Syntax.setObjectName("action_Gmail_Advanced_Search_Syntax") self.menu_file.addAction(self.action_exit) self.menu_help.addAction(self.action_Gmail_Advanced_Search_Syntax) self.menu_help.addSeparator() self.menu_help.addAction(self.action_about) self.menu_help.addAction(self.action_About_Qt) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_help.menuAction()) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.client_secrets_file_path_le, self.client_secret_file_path_tBtn) MainWindow.setTabOrder(self.client_secret_file_path_tBtn, self.remove_account_btn) MainWindow.setTabOrder(self.remove_account_btn, self.add_account_btn) MainWindow.setTabOrder(self.add_account_btn, self.accounts_cb) MainWindow.setTabOrder(self.decryption_key_le, self.connect_btn) MainWindow.setTabOrder(self.connect_btn, self.log_te) MainWindow.setTabOrder(self.log_te, self.mailboxes_lw) MainWindow.setTabOrder(self.mailboxes_lw, self.after_date_cb) MainWindow.setTabOrder(self.after_date_cb, self.after_date_edit) MainWindow.setTabOrder(self.after_date_edit, self.before_date_cb) MainWindow.setTabOrder(self.before_date_cb, self.before_date_edit) MainWindow.setTabOrder(self.before_date_edit, self.from_le) MainWindow.setTabOrder(self.from_le, self.to_le) MainWindow.setTabOrder(self.to_le, self.subject_le) MainWindow.setTabOrder(self.subject_le, self.thread_count_sb) MainWindow.setTabOrder(self.thread_count_sb, self.html_radio) MainWindow.setTabOrder(self.html_radio, self.text_radio) MainWindow.setTabOrder(self.text_radio, self.search_btn) MainWindow.setTabOrder(self.search_btn, self.parameters_cb) MainWindow.setTabOrder(self.parameters_cb, self.parameters_le) MainWindow.setTabOrder(self.parameters_le, self.disconnect_btn) MainWindow.setTabOrder(self.disconnect_btn, self.links_text_edit) MainWindow.setTabOrder(self.links_text_edit, self.export_txt_btn) MainWindow.setTabOrder(self.export_txt_btn, self.export_html_btn) MainWindow.setTabOrder(self.export_html_btn, self.mailboxes_lw) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Gmail URL Parser", None, QApplication.UnicodeUTF8)) self.login_gbox.setTitle(QApplication.translate("MainWindow", " Client secrets file path ", None, QApplication.UnicodeUTF8)) self.client_secrets_file_path_le.setPlaceholderText(QApplication.translate("MainWindow", "Please select your client secrets file", None, QApplication.UnicodeUTF8)) self.lb_client_secrets_file_path.setText(QApplication.translate("MainWindow", "Path", None, QApplication.UnicodeUTF8)) self.connect_btn.setText(QApplication.translate("MainWindow", "Connect", None, QApplication.UnicodeUTF8)) self.client_secret_file_path_tBtn.setText(QApplication.translate("MainWindow", "...", None, QApplication.UnicodeUTF8)) self.lb_account.setText(QApplication.translate("MainWindow", "Account", None, QApplication.UnicodeUTF8)) self.add_account_btn.setText(QApplication.translate("MainWindow", "+", None, QApplication.UnicodeUTF8)) self.remove_account_btn.setText(QApplication.translate("MainWindow", "-", None, QApplication.UnicodeUTF8)) self.decryption_key_le.setPlaceholderText(QApplication.translate("MainWindow", "Decryption key", None, QApplication.UnicodeUTF8)) self.lb_decryption_key.setText(QApplication.translate("MainWindow", "Key", None, QApplication.UnicodeUTF8)) self.log_gbox.setTitle(QApplication.translate("MainWindow", " Log ", None, QApplication.UnicodeUTF8)) self.search_gbox.setTitle(QApplication.translate("MainWindow", " Search Parameters ", None, QApplication.UnicodeUTF8)) self.lb_to.setText(QApplication.translate("MainWindow", "To", None, QApplication.UnicodeUTF8)) self.lb_from.setText(QApplication.translate("MainWindow", "From", None, QApplication.UnicodeUTF8)) self.lb_subject.setText(QApplication.translate("MainWindow", "Subject", None, QApplication.UnicodeUTF8)) self.search_btn.setText(QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.after_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "yyyy-MM-dd", None, QApplication.UnicodeUTF8)) self.before_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "yyyy-MM-dd", None, QApplication.UnicodeUTF8)) self.lb_select_mailbox.setToolTip(QApplication.translate("MainWindow", "<html><head/><body><p>Select multiple items to select labels</p></body></html>", None, QApplication.UnicodeUTF8)) self.lb_select_mailbox.setText(QApplication.translate("MainWindow", "Select Mailbox or Labels", None, QApplication.UnicodeUTF8)) self.after_date_cb.setText(QApplication.translate("MainWindow", "After", None, QApplication.UnicodeUTF8)) self.before_date_cb.setText(QApplication.translate("MainWindow", "Before", None, QApplication.UnicodeUTF8)) self.html_radio.setText(QApplication.translate("MainWindow", "html", None, QApplication.UnicodeUTF8)) self.text_radio.setText(QApplication.translate("MainWindow", "text", None, QApplication.UnicodeUTF8)) self.lb_threads.setText(QApplication.translate("MainWindow", "Threads", None, QApplication.UnicodeUTF8)) self.links_gbox.setTitle(QApplication.translate("MainWindow", " Links ", None, QApplication.UnicodeUTF8)) self.disconnect_btn.setText(QApplication.translate("MainWindow", "Disconnect", None, QApplication.UnicodeUTF8)) self.export_txt_btn.setText(QApplication.translate("MainWindow", "Export as txt", None, QApplication.UnicodeUTF8)) self.export_html_btn.setText(QApplication.translate("MainWindow", "Export as HTML", None, QApplication.UnicodeUTF8)) self.menu_file.setTitle(QApplication.translate("MainWindow", "File", None, QApplication.UnicodeUTF8)) self.menu_help.setTitle(QApplication.translate("MainWindow", "Help", None, QApplication.UnicodeUTF8)) self.action_about.setText(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8)) self.action_About_Qt.setText(QApplication.translate("MainWindow", "About Qt", None, QApplication.UnicodeUTF8)) self.action_exit.setText(QApplication.translate("MainWindow", "Exit", None, QApplication.UnicodeUTF8)) self.action_exit.setShortcut(QApplication.translate("MainWindow", "Ctrl+Q", None, QApplication.UnicodeUTF8)) self.actionSave.setText(QApplication.translate("MainWindow", "Save", None, QApplication.UnicodeUTF8)) self.action_Gmail_Advanced_Search_Syntax.setText(QApplication.translate("MainWindow", "Gmail Advanced Search Syntax", None, QApplication.UnicodeUTF8))
class WasteItems(): """Item waste management tab""" global logger def __init__(self): ### logger.info('Inside WasteItems') self.wastedetail_tab_1 = QWidget() self.wastedetail_tab_1.setObjectName("wastedetail_tab_1") self.verticalLayout_9 = QVBoxLayout(self.wastedetail_tab_1) self.verticalLayout_9.setObjectName("verticalLayout_9") self.verticalLayout_8 = QVBoxLayout() self.verticalLayout_8.setObjectName("verticalLayout_8") self.horizontalLayout_12 = QHBoxLayout() self.horizontalLayout_12.setObjectName("horizontalLayout_12") self.waste_fromdate_label = QLabel(self.wastedetail_tab_1) self.waste_fromdate_label.setObjectName('waste_fromdate_label') self.horizontalLayout_12.addWidget(self.waste_fromdate_label) self.waste_fromdate_dateedit = QDateEdit(self.wastedetail_tab_1) self.waste_fromdate_dateedit.setCalendarPopup(True) self.waste_fromdate_dateedit.setObjectName("waste_fromdate_dateedit") self.horizontalLayout_12.addWidget(self.waste_fromdate_dateedit) self.waste_todate_label = QLabel(self.wastedetail_tab_1) self.waste_todate_label.setObjectName('waste_todate_label') self.horizontalLayout_12.addWidget(self.waste_todate_label) self.waste_todate_dateedit = QDateEdit(self.wastedetail_tab_1) self.waste_todate_dateedit.setCalendarPopup(True) self.waste_todate_dateedit.setObjectName("waste_todate_dateedit") self.waste_todate_dateedit.setMaximumDate(QDate.currentDate()) self.horizontalLayout_12.addWidget(self.waste_todate_dateedit) spacerItem28 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_12.addItem(spacerItem28) self.waste_table_search_button = QPushButton(self.wastedetail_tab_1) self.waste_table_search_button.setObjectName( "waste_table_search_button") self.horizontalLayout_12.addWidget(self.waste_table_search_button) self.verticalLayout_8.addLayout(self.horizontalLayout_12) self.waste_table = QTableWidget(self.wastedetail_tab_1) self.waste_table.setObjectName("waste_table") self.waste_table.setColumnCount(6) self.waste_table.setRowCount(0) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(2, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(3, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(4, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(5, item) self.waste_table.horizontalHeader().setCascadingSectionResizes(False) self.waste_table.horizontalHeader().setStretchLastSection(True) self.waste_table.verticalHeader().setVisible(False) self.waste_table.verticalHeader().setCascadingSectionResizes(False) self.waste_table.setSortingEnabled(True) self.verticalLayout_8.addWidget(self.waste_table) self.verticalLayout_9.addLayout(self.verticalLayout_8) ##retranslate self.waste_fromdate_label.setText( QApplication.translate("MainWindow", "From Date", None, QApplication.UnicodeUTF8)) self.waste_fromdate_dateedit.setDisplayFormat( QApplication.translate("MainWindow", "dd/MM/yyyy", None, QApplication.UnicodeUTF8)) self.waste_todate_label.setText( QApplication.translate("MainWindow", "To Date", None, QApplication.UnicodeUTF8)) self.waste_todate_dateedit.setDisplayFormat( QApplication.translate("MainWindow", "dd/MM/yyyy", None, QApplication.UnicodeUTF8)) self.waste_table_search_button.setText( QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(0).setText( QApplication.translate("MainWindow", "Code", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(1).setText( QApplication.translate("MainWindow", "Item", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(2).setText( QApplication.translate("MainWindow", "Category", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(3).setText( QApplication.translate("MainWindow", "Units", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(4).setText( QApplication.translate("MainWindow", "Quantity", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(5).setText( QApplication.translate("MainWindow", "Reason", None, QApplication.UnicodeUTF8)) ###signals and slots && other stuffs # self.mainwindow = Ui_MainWindow # just for the ease of finding the attributes in pycharm self.item = WasteIngredients() self.waste_fromdate_dateedit.setDate(QDate.currentDate()) self.waste_todate_dateedit.setDate(QDate.currentDate()) self.waste_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.waste_table_search_button.clicked.connect(self.search_discard) self.wastedetail_tab_1.setFocusPolicy(Qt.StrongFocus) self.wastedetail_tab_1.focusInEvent = self.load_rows def load_rows(self, event=None): """calling add row to restructure the table every time container resizes""" self.add_row_to_table() def search_discard(self): """ searches the discard from_date and to_date :return:none """ f_date = self.waste_fromdate_dateedit.text() from_date = datetime.strptime(f_date, '%d/%m/%Y') t_date = self.waste_todate_dateedit.text() to_date = datetime.strptime(t_date, '%d/%m/%Y') to_date = to_date + timedelta(hours=23, minutes=59, seconds=59) dataobj = self.item.find_itemdiscard(from_date=from_date, to_date=to_date) self.add_row_to_table(*dataobj) def add_row_to_table(self, *args): """ complex stuff of auto complete to be added to each combo box :return: """ table = self.waste_table if args: table.clearContents() table.setRowCount(0) table.setRowCount(len(args)) for i, j in enumerate(args): code = QTableWidgetItem(j['code']) table.setItem(i, 0, code) item = QTableWidgetItem(j['item']) table.setItem(i, 1, item) category = QTableWidgetItem(j['category']) table.setItem(i, 2, category) unit = QTableWidgetItem(str(j['units'])) table.setItem(i, 3, unit) quantity = QTableWidgetItem(str(j['quantity'])) table.setItem(i, 4, quantity) reason = QTableWidgetItem(j['reason_for_discard']) table.setItem(i, 5, reason) 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)) table.horizontalHeader().setStretchLastSection(True)
class WasteDish(): """Dish waste management tab""" global logger def __init__(self): ### logger.info('Inside WasteDish') self.wastedetail_tab_1 = QWidget() self.wastedetail_tab_1.setObjectName("wastedetail_tab_1") self.verticalLayout_9 = QVBoxLayout(self.wastedetail_tab_1) self.verticalLayout_9.setObjectName("verticalLayout_9") self.verticalLayout_8 = QVBoxLayout() self.verticalLayout_8.setObjectName("verticalLayout_8") self.horizontalLayout_12 = QHBoxLayout() self.horizontalLayout_12.setObjectName("horizontalLayout_12") self.waste_fromdate_label = QLabel(self.wastedetail_tab_1) self.waste_fromdate_label.setObjectName('waste_fromdate_label') self.horizontalLayout_12.addWidget(self.waste_fromdate_label) self.waste_fromdate_dateedit = QDateEdit(self.wastedetail_tab_1) self.waste_fromdate_dateedit.setCalendarPopup(True) self.waste_fromdate_dateedit.setObjectName("waste_fromdate_dateedit") self.horizontalLayout_12.addWidget(self.waste_fromdate_dateedit) self.waste_todate_label = QLabel(self.wastedetail_tab_1) self.waste_todate_label.setObjectName('waste_todate_label') self.horizontalLayout_12.addWidget(self.waste_todate_label) self.waste_todate_dateedit = QDateEdit(self.wastedetail_tab_1) self.waste_todate_dateedit.setCalendarPopup(True) self.waste_todate_dateedit.setObjectName("waste_todate_dateedit") self.waste_todate_dateedit.setMaximumDate(QDate.currentDate()) self.horizontalLayout_12.addWidget(self.waste_todate_dateedit) spacerItem28 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_12.addItem(spacerItem28) self.waste_table_search_button = QPushButton(self.wastedetail_tab_1) self.waste_table_search_button.setObjectName( "waste_table_search_button") self.horizontalLayout_12.addWidget(self.waste_table_search_button) self.verticalLayout_8.addLayout(self.horizontalLayout_12) self.waste_table = QTableWidget(self.wastedetail_tab_1) self.waste_table.setObjectName("waste_table") self.waste_table.setColumnCount(5) self.waste_table.setRowCount(0) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(0, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(1, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(2, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(3, item) item = QTableWidgetItem() self.waste_table.setHorizontalHeaderItem(4, item) self.waste_table.horizontalHeader().setCascadingSectionResizes(False) self.waste_table.horizontalHeader().setStretchLastSection(True) self.waste_table.verticalHeader().setVisible(False) self.waste_table.verticalHeader().setCascadingSectionResizes(False) self.waste_table.setSortingEnabled(True) self.verticalLayout_8.addWidget(self.waste_table) self.horizontalLayout_13 = QHBoxLayout() self.horizontalLayout_13.setObjectName("horizontalLayout_13") self.waste_table_newrow_button = QPushButton(self.wastedetail_tab_1) self.waste_table_newrow_button.setObjectName( "waste_table_newrow_button") self.horizontalLayout_13.addWidget(self.waste_table_newrow_button) spacerItem29 = QSpacerItem(612, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) self.horizontalLayout_13.addItem(spacerItem29) self.waste_table_discard_button = QPushButton(self.wastedetail_tab_1) self.waste_table_discard_button.setObjectName( "waste_table_discard_button") self.horizontalLayout_13.addWidget(self.waste_table_discard_button) self.verticalLayout_8.addLayout(self.horizontalLayout_13) self.verticalLayout_9.addLayout(self.verticalLayout_8) ##retranslate self.waste_fromdate_label.setText( QApplication.translate("MainWindow", "From Date", None, QApplication.UnicodeUTF8)) self.waste_fromdate_dateedit.setDisplayFormat( QApplication.translate("MainWindow", "dd/MM/yyyy", None, QApplication.UnicodeUTF8)) self.waste_todate_label.setText( QApplication.translate("MainWindow", "To Date", None, QApplication.UnicodeUTF8)) self.waste_todate_dateedit.setDisplayFormat( QApplication.translate("MainWindow", "dd/MM/yyyy", None, QApplication.UnicodeUTF8)) self.waste_table_search_button.setText( QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(0).setText( QApplication.translate("MainWindow", "Code", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(1).setText( QApplication.translate("MainWindow", "Item", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(2).setText( QApplication.translate("MainWindow", "Category", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(3).setText( QApplication.translate("MainWindow", "Quantity", None, QApplication.UnicodeUTF8)) self.waste_table.horizontalHeaderItem(4).setText( QApplication.translate("MainWindow", "Reason", None, QApplication.UnicodeUTF8)) self.waste_table_newrow_button.setText( QApplication.translate("MainWindow", "New Row", None, QApplication.UnicodeUTF8)) self.waste_table_discard_button.setText( QApplication.translate("MainWindow", "Discard Item", None, QApplication.UnicodeUTF8)) self.wastedetail_tab_1.setTabOrder(self.waste_fromdate_dateedit, self.waste_todate_dateedit) self.wastedetail_tab_1.setTabOrder(self.waste_todate_dateedit, self.waste_table_search_button) ###signals and slots && other stuffs # self.mainwindow = Ui_MainWindow # just for the ease of finding the attributes in pycharm self.schedule = SchedulePurchase() self.suplier = BusinessParty(category='Supplier') self.add = AddStockInventory() self.item = WasteMenu() self.waste_fromdate_dateedit.setDate(QDate.currentDate()) self.waste_todate_dateedit.setDate(QDate.currentDate()) self.waste_table.setEditTriggers(QAbstractItemView.NoEditTriggers) self.waste_table_newrow_button.clicked.connect(self.add_new_blank_rows) self.waste_table_discard_button.clicked.connect(self.discard) self.waste_table_search_button.clicked.connect(self.search_discard) self.wastedetail_tab_1.setFocusPolicy(Qt.StrongFocus) self.wastedetail_tab_1.focusInEvent = self.load_rows def load_rows(self, event=None): pass def add_new_blank_rows(self): """ deletes the schedules in the database """ table = self.waste_table item = table.item(0, 0) if item: message = QMessageBox.critical(QMessageBox(), 'Warning!', 'This will remove all the entries', QMessageBox.Ok | QMessageBox.Cancel) if message == QMessageBox.Ok: table.setRowCount(0) table.clearContents() self.add_row_to_table('new') self.waste_table_discard_button.setVisible(True) elif not item: self.waste_table_discard_button.setVisible(True) self.add_row_to_table('new') def add_row_to_table(self, *args): """ complex stuff of auto complete to be added to each combo box :return: """ table = self.waste_table if args: if args[0] != 'new': table.clearContents() table.setRowCount(0) table.setRowCount(len(args)) for i, j in enumerate(args): code = QTableWidgetItem(j['code']) table.setItem(i, 0, code) item = QTableWidgetItem(j['item']) table.setItem(i, 1, item) category = QTableWidgetItem(j['category']) table.setItem(i, 2, category) quantity = QTableWidgetItem(str(j['quantity'])) table.setItem(i, 3, quantity) reason = QTableWidgetItem(j['reason_for_discard']) table.setItem(i, 4, reason) if args[0] == 'new': row = table.rowCount() + 1 table.setRowCount(row) codeline = QLineEdit() codeline.editingFinished.connect( lambda: self.get_details_of_code(row)) table.setCellWidget(row - 1, 0, codeline) itemcombo = QComboBox() self.fill_item_list(itemcombo) itemcombo.currentIndexChanged.connect( lambda: self.get_details_of_item(row)) table.setCellWidget(row - 1, 1, itemcombo) category = QTableWidgetItem() table.setItem(row - 1, 2, category) quantity = QLineEdit() table.setCellWidget(row - 1, 3, quantity) combo = QComboBox() combo.addItem("Cancelled") combo.addItem("Mishandling") combo.addItem("Excess") table.setCellWidget(row - 1, 4, combo) table.setColumnWidth(0, (table.width() / 5)) table.setColumnWidth(1, (table.width() / 5)) table.setColumnWidth(2, (table.width() / 5)) table.setColumnWidth(3, (table.width() / 5)) table.horizontalHeader().setStretchLastSection( True ) # important to resize last section else blank space after last column def fill_item_list(self, combo): """ fill the item combo box :param combo: the combobox object :return: none """ itemfield = combo itemfield.setStyleSheet("QAbstractItemView{" "background: #4B77BE;" "}") self.item.populate_item(itemfield) def get_details_of_code(self, rowcount): """ fills the item, category and units based on the code :param rowcount: the row count :return: none """ row = rowcount - 1 table = self.waste_table codeline = table.cellWidget(row, 0) data = self.item.get_details_of_code(codeline.text()) item = table.cellWidget(row, 1) index = item.findText(data['item']) item.setCurrentIndex(index) category = table.item(row, 2) category.setText(data['category']) def get_details_of_item(self, rowcount): """ fills the code, category and units based on the item :param rowcount: the row count :return: none """ row = rowcount - 1 table = self.waste_table itemcombo = table.cellWidget(row, 1) data = self.item.get_details_of_item(itemcombo.currentText()) code = table.cellWidget(row, 0) code.setText(data['code']) category = table.item(row, 2) category.setText(data['category']) def discard(self): """ saves the details in db before printing """ logger.info('WasteDish discard initiated') table = self.waste_table data = self.get_data() if data: for i in data: status = self.item.discard(i) if status: model_index = table.indexFromItem(i['model_item']) row = model_index.row() table.removeRow(row) else: msg = QMessageBox.critical(QMessageBox(), "Error!!", "The item cannot be discarded", QMessageBox.Ok) if msg == QMessageBox.Ok: return False def search_discard(self): """ searches the discard from_date and to_date :return:none """ table = self.waste_table item = table.cellWidget(0, 0) if item: msg = QMessageBox.critical(QMessageBox(), 'Warning!', 'This will delete all the rows added', QMessageBox.Ok | QMessageBox.Cancel) if msg == QMessageBox.Cancel: return False f_date = self.waste_fromdate_dateedit.text() from_date = datetime.strptime(f_date, '%d/%m/%Y') t_date = self.waste_todate_dateedit.text() to_date = datetime.strptime(t_date, '%d/%m/%Y') to_date = to_date + timedelta(hours=23, minutes=59, seconds=59) dataobj = self.item.find_itemdiscard(from_date=from_date, to_date=to_date) self.add_row_to_table(*dataobj) self.waste_table_discard_button.setVisible(False) def get_data(self): """ :return: fetches all the data for printing """ table = self.waste_table rows = table.rowCount() dataobj = [] for i in range(rows): dictionary = {} item = table.cellWidget(i, 0) if table.cellWidget( i, 0) is not None else table.item(i, 0) dictionary['code'] = item.text() if dictionary['code'] == '': break item = table.cellWidget(i, 1).currentText() if table.cellWidget( i, 1) is not None else table.item(i, 1).text() dictionary['item'] = item item = table.cellWidget(i, 2) if table.cellWidget( i, 2) is not None else table.item(i, 2) dictionary['category'] = item.text() item = table.cellWidget(i, 3) if table.cellWidget( i, 3) is not None else table.item(i, 3) dictionary['quantity'] = item.text() if dictionary['quantity'] == '': self.show_error('Quantity') return False item = table.cellWidget(i, 4).currentText() if table.cellWidget( i, 4) is not None else table.item(i, 4).text() dictionary['reason_for_discard'] = item dictionary['model_item'] = table.item(i, 2) dataobj.append(dictionary) return dataobj def show_error(self, text): """ :return: pops up an error """ QMessageBox.critical(QMessageBox(), "Fail!!", "Please Enter %s properly" % text, QMessageBox.Ok)
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(810, 492) lbMinWidth = 65 lbMinWidthLogin = 110 # leMinWidth = 200 # self.centralwidget = QWidget(MainWindow) self.mainSplitter = QSplitter(Qt.Horizontal, MainWindow) self.mainSplitter.setObjectName("centralwidget") self.mainSplitter.setProperty("childrenCollapsible", False) MainWindow.setCentralWidget(self.mainSplitter) self.leftSplitter = QSplitter(Qt.Vertical, self.mainSplitter) self.leftSplitter.setProperty("childrenCollapsible", False) # login_gbox self.login_gbox = QGroupBox(self.leftSplitter) self.login_gbox.setFlat(True) self.login_gbox.setObjectName("login_gbox") login_gbox_layout = QVBoxLayout(self.login_gbox) login_gbox_presets_layout = QHBoxLayout() login_gbox_server_layout = QHBoxLayout() login_gbox_ssl_layout = QHBoxLayout() login_gbox_address_layout = QHBoxLayout() login_gbox_pass_layout = QHBoxLayout() login_gbox_connect_layout = QHBoxLayout() login_gbox_layout.addLayout(login_gbox_presets_layout) login_gbox_layout.addLayout(login_gbox_server_layout) login_gbox_layout.addLayout(login_gbox_ssl_layout) login_gbox_layout.addLayout(login_gbox_address_layout) login_gbox_layout.addLayout(login_gbox_pass_layout) login_gbox_layout.addLayout(login_gbox_connect_layout) self.lb_presets = QLabel(self.login_gbox) self.lb_presets.setObjectName("lb_presets") self.lb_presets.setMinimumWidth(lbMinWidthLogin) self.lb_presets.setMaximumWidth(lbMinWidthLogin) self.presets_cbox = QComboBox(self.login_gbox) self.presets_cbox.setObjectName("presets_cbox") self.add_preset_btn = QPushButton(self.login_gbox) self.add_preset_btn.setObjectName("add_preset_btn") self.add_preset_btn.setMaximumWidth(30) self.remove_preset_btn = QPushButton(self.login_gbox) self.remove_preset_btn.setObjectName("remove_preset_btn") self.remove_preset_btn.setMaximumWidth(20) login_gbox_presets_layout.addWidget(self.lb_presets) login_gbox_presets_layout.addWidget(self.presets_cbox) login_gbox_presets_layout.addWidget(self.add_preset_btn) login_gbox_presets_layout.addWidget(self.remove_preset_btn) self.lb_imap_server = QLabel(self.login_gbox) self.lb_imap_server.setObjectName("lb_imap_server") self.lb_imap_server.setMinimumWidth(lbMinWidthLogin) self.imap_server_le = QLineEdit(self.login_gbox) self.imap_server_le.setObjectName("imap_server_le") login_gbox_server_layout.addWidget(self.lb_imap_server) login_gbox_server_layout.addWidget(self.imap_server_le) self.lb_ssl = QLabel(self.login_gbox) self.lb_ssl.setObjectName("lb_ssl") self.lb_ssl.setMinimumWidth(lbMinWidthLogin) self.lb_ssl.setMaximumWidth(lbMinWidthLogin) self.ssl_cb = QCheckBox(self.login_gbox) self.ssl_cb.setEnabled(False) self.ssl_cb.setCheckable(True) self.ssl_cb.setChecked(True) self.ssl_cb.setObjectName("ssl_cb") login_gbox_ssl_layout.addWidget(self.lb_ssl) login_gbox_ssl_layout.addWidget(self.ssl_cb) self.lb_adress = QLabel(self.login_gbox) self.lb_adress.setObjectName("lb_adress") self.lb_adress.setMinimumWidth(lbMinWidthLogin) self.adress_le = QLineEdit(self.login_gbox) self.adress_le.setInputMethodHints(Qt.ImhNone) self.adress_le.setObjectName("adress_le") login_gbox_address_layout.addWidget(self.lb_adress) login_gbox_address_layout.addWidget(self.adress_le) self.lb_pass = QLabel(self.login_gbox) self.lb_pass.setObjectName("lb_pass") self.lb_pass.setMinimumWidth(lbMinWidthLogin) self.pass_le = QLineEdit(self.login_gbox) self.pass_le.setText("") self.pass_le.setEchoMode(QLineEdit.Password) self.pass_le.setObjectName("pass_le") login_gbox_pass_layout.addWidget(self.lb_pass) login_gbox_pass_layout.addWidget(self.pass_le) self.connect_btn = QPushButton(self.login_gbox) self.connect_btn.setObjectName("connect_btn") login_gbox_connect_layout.addStretch() login_gbox_connect_layout.addWidget(self.connect_btn) # search_gbox self.search_gbox = QGroupBox(self.leftSplitter) self.search_gbox.hide() self.search_gbox.setObjectName("search_gbox") search_gbox_layout = QVBoxLayout(self.search_gbox) search_gbox_mailbox_layout = QVBoxLayout() search_gbox_date_layout = QHBoxLayout() search_gbox_from_layout = QHBoxLayout() search_gbox_to_layout = QHBoxLayout() search_gbox_subject_layout = QHBoxLayout() search_gbox_threads_layout = QHBoxLayout() search_gbox_paramaters_layout = QHBoxLayout() search_gbox_layout.addLayout(search_gbox_mailbox_layout) search_gbox_layout.addLayout(search_gbox_date_layout) search_gbox_layout.addLayout(search_gbox_from_layout) search_gbox_layout.addLayout(search_gbox_to_layout) search_gbox_layout.addLayout(search_gbox_subject_layout) search_gbox_layout.addLayout(search_gbox_threads_layout) search_gbox_layout.addLayout(search_gbox_paramaters_layout) self.lb_select_mailbox = QLabel(self.search_gbox) self.lb_select_mailbox.setObjectName("lb_select_mailbox") self.mailboxes_lw = QListWidget(self.search_gbox) self.mailboxes_lw.setEditTriggers(QAbstractItemView.NoEditTriggers) self.mailboxes_lw.setSelectionMode(QAbstractItemView.ExtendedSelection) self.mailboxes_lw.setObjectName("mailboxes_lw") search_gbox_mailbox_layout.addWidget(self.lb_select_mailbox) search_gbox_mailbox_layout.addWidget(self.mailboxes_lw) self.since_date_cb = QCheckBox(self.search_gbox) self.since_date_cb.setObjectName("since_date_cb") self.since_date_cb.setMinimumWidth(lbMinWidth) self.since_date_cb.setMaximumWidth(lbMinWidth) self.since_date_edit = QDateEdit(self.search_gbox) self.since_date_edit.setCalendarPopup(True) self.since_date_edit.setObjectName("since_date_edit") self.since_date_edit.setDate(QDate.currentDate().addDays(-365)) self.since_date_edit.setMaximumDate(QDate.currentDate()) self.since_date_edit.setEnabled(False) self.before_date_cb = QCheckBox(self.search_gbox) self.before_date_cb.setObjectName("before_date_cb") self.before_date_cb.setMinimumWidth(70) self.before_date_cb.setMaximumWidth(70) self.before_date_edit = QDateEdit(self.search_gbox) self.before_date_edit.setCalendarPopup(True) self.before_date_edit.setObjectName("before_date_edit") self.before_date_edit.setDate(QDate.currentDate()) self.before_date_edit.setMaximumDate(QDate.currentDate()) self.before_date_edit.setEnabled(False) search_gbox_date_layout.addWidget(self.since_date_cb) search_gbox_date_layout.addWidget(self.since_date_edit) search_gbox_date_layout.addWidget(self.before_date_cb) search_gbox_date_layout.addWidget(self.before_date_edit) self.lb_from = QLabel(self.search_gbox) self.lb_from.setObjectName("lb_from") self.lb_from.setMinimumWidth(lbMinWidth) self.from_le = QLineEdit(self.search_gbox) self.from_le.setObjectName("from_le") search_gbox_from_layout.addWidget(self.lb_from) search_gbox_from_layout.addWidget(self.from_le) self.lb_to = QLabel(self.search_gbox) self.lb_to.setObjectName("lb_to") self.lb_to.setMinimumWidth(lbMinWidth) self.to_le = QLineEdit(self.search_gbox) self.to_le.setObjectName("to_le") search_gbox_to_layout.addWidget(self.lb_to) search_gbox_to_layout.addWidget(self.to_le) self.lb_subject = QLabel(self.search_gbox) self.lb_subject.setObjectName("lb_subject") self.lb_subject.setMinimumWidth(lbMinWidth) self.subject_le = QLineEdit(self.search_gbox) self.subject_le.setObjectName("subject_le") search_gbox_subject_layout.addWidget(self.lb_subject) search_gbox_subject_layout.addWidget(self.subject_le) # self.lb_threads = QLabel(self.search_gbox) # self.lb_threads.setObjectName("lb_threads") # self.lb_threads.setMaximumWidth(lbMinWidth) # self.thread_count_sb = QSpinBox(self.search_gbox) # self.thread_count_sb.setMinimum(1) # self.thread_count_sb.setMaximum(10) # self.thread_count_sb.setObjectName("thread_count_sb") self.html_radio = QRadioButton(self.search_gbox) self.html_radio.setObjectName("html_radio") self.text_radio = QRadioButton(self.search_gbox) self.text_radio.setObjectName("text_radio") self.extactTypeButtonGroup = QButtonGroup(self) self.extactTypeButtonGroup.addButton(self.html_radio) self.extactTypeButtonGroup.addButton(self.text_radio) self.html_radio.setChecked(True) self.search_btn = QPushButton(self.search_gbox) self.search_btn.setObjectName("search_btn") # search_gbox_threads_layout.addWidget(self.lb_threads) # search_gbox_threads_layout.addWidget(self.thread_count_sb) search_gbox_threads_layout.addStretch() search_gbox_threads_layout.addWidget(self.html_radio) search_gbox_threads_layout.addWidget(self.text_radio) # search_gbox_threads_layout.addStretch() search_gbox_threads_layout.addWidget(self.search_btn) self.parameters_cb = QCheckBox(self.search_gbox) self.parameters_cb.setText("") self.parameters_cb.setObjectName("parameters_cb") self.parameters_le = QLineEdit(self.search_gbox) self.parameters_le.setEnabled(False) self.parameters_le.setObjectName("parameters_le") search_gbox_paramaters_layout.addWidget(self.parameters_cb) search_gbox_paramaters_layout.addWidget(self.parameters_le) # log_gbox self.log_gbox = QGroupBox(self.leftSplitter) self.log_gbox.setFlat(True) self.log_gbox.setObjectName("log_gbox") log_layout = QVBoxLayout(self.log_gbox) self.log_te = QTextEdit(self.log_gbox) self.log_te.setLineWrapMode(QTextEdit.NoWrap) self.log_te.setReadOnly(True) self.log_te.setTextInteractionFlags(Qt.TextSelectableByKeyboard | Qt.TextSelectableByMouse) self.log_te.setObjectName("log_te") self.disconnect_btn = QPushButton(self.log_gbox) self.disconnect_btn.setObjectName("disconnect_btn") self.disconnect_btn.hide() log_layout.addWidget(self.log_te) log_layout_btn = QHBoxLayout() log_layout.addLayout(log_layout_btn) log_layout_btn.addWidget(self.disconnect_btn) log_layout_btn.addStretch() # links_gbox self.links_gbox = QGroupBox(self.mainSplitter) self.links_gbox.setFlat(True) self.links_gbox.setObjectName("links_gbox") links_gbox_layout = QVBoxLayout(self.links_gbox) links_gbox_links_layout = QVBoxLayout() links_gbox_buttons_layout = QHBoxLayout() links_gbox_layout.addLayout(links_gbox_links_layout) links_gbox_layout.addLayout(links_gbox_buttons_layout) self.links_text_edit = QTextEdit(self.links_gbox) self.links_text_edit.setObjectName("links_text_edit") links_gbox_links_layout.addWidget(self.links_text_edit) self.export_txt_btn = QPushButton(self.links_gbox) self.export_txt_btn.setObjectName("export_txt_btn") self.export_txt_btn.setEnabled(False) self.export_html_btn = QPushButton(self.links_gbox) self.export_html_btn.setObjectName("export_html_btn") self.export_html_btn.setEnabled(False) links_gbox_buttons_layout.addWidget(self.export_txt_btn) links_gbox_buttons_layout.addWidget(self.export_html_btn) # menubar self.menubar = QMenuBar(MainWindow) self.menubar.setObjectName("menubar") self.menu_file = QMenu(self.menubar) self.menu_file.setObjectName("menu_file") self.menu_about = QMenu(self.menubar) self.menu_about.setObjectName("menu_about") MainWindow.setMenuBar(self.menubar) self.action_about = QAction(MainWindow) self.action_about.setObjectName("action_about") self.action_About_Qt = QAction(MainWindow) self.action_About_Qt.setObjectName("action_About_Qt") self.action_exit = QAction(MainWindow) self.action_exit.setObjectName("action_exit") self.actionSave = QAction(MainWindow) self.actionSave.setObjectName("actionSave") self.menu_file.addAction(self.action_exit) self.menu_about.addAction(self.action_about) self.menu_about.addAction(self.action_About_Qt) self.menubar.addAction(self.menu_file.menuAction()) self.menubar.addAction(self.menu_about.menuAction()) self.retranslateUi(MainWindow) QMetaObject.connectSlotsByName(MainWindow) MainWindow.setTabOrder(self.presets_cbox, self.imap_server_le) MainWindow.setTabOrder(self.imap_server_le, self.adress_le) MainWindow.setTabOrder(self.adress_le, self.pass_le) MainWindow.setTabOrder(self.pass_le, self.connect_btn) MainWindow.setTabOrder(self.connect_btn, self.log_te) MainWindow.setTabOrder(self.log_te, self.since_date_cb) MainWindow.setTabOrder(self.since_date_cb, self.since_date_edit) MainWindow.setTabOrder(self.since_date_edit, self.before_date_cb) MainWindow.setTabOrder(self.before_date_cb, self.before_date_edit) MainWindow.setTabOrder(self.before_date_edit, self.mailboxes_lw) MainWindow.setTabOrder(self.mailboxes_lw, self.from_le) MainWindow.setTabOrder(self.from_le, self.to_le) MainWindow.setTabOrder(self.to_le, self.subject_le) MainWindow.setTabOrder(self.subject_le, self.search_btn) MainWindow.setTabOrder(self.search_btn, self.links_text_edit) MainWindow.setTabOrder(self.links_text_edit, self.export_txt_btn) MainWindow.setTabOrder(self.export_txt_btn, self.export_html_btn) MainWindow.setTabOrder(self.export_html_btn, self.disconnect_btn) MainWindow.setTabOrder(self.disconnect_btn, self.add_preset_btn) MainWindow.setTabOrder(self.add_preset_btn, self.remove_preset_btn) MainWindow.setTabOrder(self.remove_preset_btn, self.ssl_cb) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(QApplication.translate("MainWindow", "Email Link Extractor", None, QApplication.UnicodeUTF8)) self.login_gbox.setTitle(QApplication.translate("MainWindow", " Login", None, QApplication.UnicodeUTF8)) self.lb_presets.setText(QApplication.translate("MainWindow", "Server Presets", None, QApplication.UnicodeUTF8)) self.add_preset_btn.setText(QApplication.translate("MainWindow", "+", None, QApplication.UnicodeUTF8)) self.remove_preset_btn.setText(QApplication.translate("MainWindow", "-", None, QApplication.UnicodeUTF8)) self.lb_imap_server.setText(QApplication.translate("MainWindow", "IMAP Server", None, QApplication.UnicodeUTF8)) self.lb_ssl.setText(QApplication.translate("MainWindow", "SSL", None, QApplication.UnicodeUTF8)) self.ssl_cb.setText(QApplication.translate("MainWindow", "Port : 993", None, QApplication.UnicodeUTF8)) self.lb_adress.setText(QApplication.translate("MainWindow", "Adress", None, QApplication.UnicodeUTF8)) self.lb_pass.setText(QApplication.translate("MainWindow", "Password", None, QApplication.UnicodeUTF8)) self.connect_btn.setText(QApplication.translate("MainWindow", "Connect", None, QApplication.UnicodeUTF8)) self.lb_select_mailbox.setText(QApplication.translate("MainWindow", "Select Mailbox", None, QApplication.UnicodeUTF8)) self.search_gbox.setTitle(QApplication.translate("MainWindow", " Search Parameters", None, QApplication.UnicodeUTF8)) self.since_date_cb.setText(QApplication.translate("MainWindow", "Since", None, QApplication.UnicodeUTF8)) self.since_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "dd-MMM-yyyy", None, QApplication.UnicodeUTF8)) self.before_date_cb.setText(QApplication.translate("MainWindow", "Before", None, QApplication.UnicodeUTF8)) self.before_date_edit.setDisplayFormat(QApplication.translate("MainWindow", "dd-MMM-yyyy", None, QApplication.UnicodeUTF8)) self.html_radio.setText(QApplication.translate("MainWindow", "html", None, QApplication.UnicodeUTF8)) self.text_radio.setText(QApplication.translate("MainWindow", "text", None, QApplication.UnicodeUTF8)) # self.lb_threads.setText(QApplication.translate("MainWindow", "Threads", None, QApplication.UnicodeUTF8)) self.lb_from.setText(QApplication.translate("MainWindow", "From", None, QApplication.UnicodeUTF8)) self.lb_to.setText(QApplication.translate("MainWindow", "To", None, QApplication.UnicodeUTF8)) self.lb_subject.setText(QApplication.translate("MainWindow", "Subject", None, QApplication.UnicodeUTF8)) self.search_btn.setText(QApplication.translate("MainWindow", "Search", None, QApplication.UnicodeUTF8)) self.links_gbox.setTitle(QApplication.translate("MainWindow", " Links", None, QApplication.UnicodeUTF8)) self.export_html_btn.setText(QApplication.translate("MainWindow", "Export as HTML", None, QApplication.UnicodeUTF8)) self.export_txt_btn.setText(QApplication.translate("MainWindow", "Export as txt", None, QApplication.UnicodeUTF8)) self.log_gbox.setTitle(QApplication.translate("MainWindow", " Log", None, QApplication.UnicodeUTF8)) self.disconnect_btn.setText(QApplication.translate("MainWindow", "Disconnect", None, QApplication.UnicodeUTF8)) self.menu_file.setTitle(QApplication.translate("MainWindow", "File", None, QApplication.UnicodeUTF8)) self.menu_about.setTitle(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8)) self.action_about.setText(QApplication.translate("MainWindow", "About", None, QApplication.UnicodeUTF8)) self.action_About_Qt.setText(QApplication.translate("MainWindow", "About Qt", None, QApplication.UnicodeUTF8)) self.action_exit.setText(QApplication.translate("MainWindow", "Exit", None, QApplication.UnicodeUTF8)) self.action_exit.setShortcut(QApplication.translate("MainWindow", "Ctrl+Q", None, QApplication.UnicodeUTF8)) self.actionSave.setText(QApplication.translate("MainWindow", "Save", None, QApplication.UnicodeUTF8))