def createBottomRightGroupBox(self): self.bottomRightGroupBox = QGroupBox("Group 3") self.bottomRightGroupBox.setCheckable(True) self.bottomRightGroupBox.setChecked(True) lineEdit = QLineEdit('s3cRe7') lineEdit.setEchoMode(QLineEdit.Password) spinBox = QSpinBox(self.bottomRightGroupBox) spinBox.setValue(50) dateTimeEdit = QDateTimeEdit(self.bottomRightGroupBox) dateTimeEdit.setDateTime(QDateTime.currentDateTime()) slider = QSlider(Qt.Horizontal, self.bottomRightGroupBox) slider.setValue(40) scrollBar = QScrollBar(Qt.Horizontal, self.bottomRightGroupBox) scrollBar.setValue(60) dial = QDial(self.bottomRightGroupBox) dial.setValue(30) dial.setNotchesVisible(True) layout = QGridLayout() layout.addWidget(lineEdit, 0, 0, 1, 2) layout.addWidget(spinBox, 1, 0, 1, 2) layout.addWidget(dateTimeEdit, 2, 0, 1, 2) layout.addWidget(slider, 3, 0) layout.addWidget(scrollBar, 4, 0) layout.addWidget(dial, 3, 1, 2, 1) layout.setRowStretch(5, 1) self.bottomRightGroupBox.setLayout(layout)
def addIssue(self): date = self.dateEntry.text() priority = self.priorityEntry.currentText() observer = self.observerEntry.currentText() revisionTeam = self.revisionTeamEntry.currentText() inspectionName = self.inspectionNameEntry.currentText() observationTheme = self.observationThemeEntry.currentText() facility = self.facilityEntry.currentText() facilitySupervisor = self.facilitySupervisorEntry.currentText() specificLocation = self.specificLocationEntry.toPlainText() inspectedDept = self.inspectedDepartmentEntry.currentText() inspectedContr = self.inspectedContractorEntry.currentText() inspectedSubcontr = self.inspectedSubcontractorEntry.currentText() deadline = self.deadlineEntry.text() if date and priority and observer and revisionTeam and inspectionName and observationTheme and facility\ and facilitySupervisor and specificLocation and inspectedDept and inspectedContr \ and inspectedSubcontr and deadline != "": try: query = "INSERT INTO issues (issue_date, issue_priority, issue_observer, issue_team," \ "issue_inspection, issue_theme, issue_facility, issue_fac_supervisor," \ "issue_spec_loc, issue_insp_dept, issue_insp_contr, issue_insp_subcontr, issue_deadline, created_on) " \ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" # The purpose of this block is to make created_on timestamp the same format as other dates currentTime = QDateTimeEdit() currentTime.setDateTime(QDateTime.currentDateTime()) now = currentTime.text() db.cur.execute( query, (date, priority, observer, revisionTeam, inspectionName, observationTheme, facility, facilitySupervisor, specificLocation, inspectedDept, inspectedContr, inspectedSubcontr, deadline, now)) db.conn.commit() QMessageBox.information(self, "Info", "Issue has been added") self.Parent.displayIssues() self.close() except: QMessageBox.information(self, "Info", "Issue has not been added") else: QMessageBox.information(self, "Info", "Fields cannot be empty")
class AddIssue(QWidget): def __init__(self, parent): QWidget.__init__(self) self.setWindowTitle("Add issue") self.setWindowIcon(QIcon("assets/icons/icon.ico")) self.setGeometry(450, 150, 750, 950) # self.setFixedSize(self.size()) self.Parent = parent self.UI() self.show() def UI(self): self.widgets() self.layouts() def widgets(self): self.scroll = QScrollArea() self.scroll.setWidgetResizable(True) # Top layout widgets self.addIssueImg = QLabel() self.img = QPixmap('assets/icons/create-issue.png') self.addIssueImg.setPixmap(self.img) self.addIssueImg.setAlignment(Qt.AlignCenter) self.titleText = QLabel("Add issue") self.titleText.setAlignment(Qt.AlignCenter) # Middle layout widgets self.issueInfoTitleText = QLabel("Issue info") self.issueInfoTitleText.setAlignment(Qt.AlignCenter) self.dateEntry = QDateTimeEdit() self.dateEntry.setDateTime(QDateTime.currentDateTime()) self.priorityEntry = QComboBox() self.priorityEntry.setEditable(True) self.observerEntry = QComboBox() self.observerEntry.setEditable(True) self.revisionTeamEntry = QComboBox() self.revisionTeamEntry.setEditable(True) self.inspectionNameEntry = QComboBox() self.inspectionNameEntry.setEditable(True) self.observationThemeEntry = QComboBox() self.observationThemeEntry.setEditable(True) self.facilityEntry = QComboBox() self.facilityEntry.setEditable(True) self.facilitySupervisorEntry = QComboBox() self.facilitySupervisorEntry.setEditable(True) self.specificLocationEntry = QTextEdit() self.inspectedDepartmentEntry = QComboBox() self.inspectedDepartmentEntry.setEditable(True) self.inspectedContractorEntry = QComboBox() self.inspectedContractorEntry.setEditable(True) self.inspectedSubcontractorEntry = QComboBox() self.inspectedSubcontractorEntry.setEditable(True) self.deadlineEntry = QDateTimeEdit() self.deadlineEntry.setDateTime(QDateTime.currentDateTime()) # Bottom layout widgets self.attachFilesBtn = QPushButton("Attach files") self.addActionBtn = QPushButton("Add action") self.rootCauseEntry = QComboBox() self.rootCauseEntry.setEditable(True) self.rootCauseDetailsEntry = QTextEdit() self.rootCauseActionPartyEntry = QComboBox() self.rootCauseActionPartyEntry.setEditable(True) self.addRootCauseBtn = QPushButton("Add root cause") self.submitObservationBtn = QPushButton("Add issue") self.submitObservationBtn.clicked.connect(self.addIssue) def layouts(self): self.mainLayout = QVBoxLayout() self.topLayout = QHBoxLayout() self.bottomLayout = QFormLayout() # Put elements into frames for visual distinction self.topFrame = QFrame() self.bottomFrame = QFrame() # Add widgets to top layout self.topLayout.addWidget(self.addIssueImg) self.topLayout.addWidget(self.titleText) self.topFrame.setLayout(self.topLayout) # Add widgets to middle layout self.bottomLayout.addRow(self.issueInfoTitleText) self.bottomLayout.addRow(QLabel("Inspection Date: "), self.dateEntry) self.bottomLayout.addRow(QLabel("Priority: "), self.priorityEntry) self.bottomLayout.addRow(QLabel("Observer: "), self.observerEntry) self.bottomLayout.addRow(QLabel("Revision Team: "), self.revisionTeamEntry) self.bottomLayout.addRow(QLabel("Inspection Name: "), self.inspectionNameEntry) self.bottomLayout.addRow(QLabel("HSE Theme: "), self.observationThemeEntry) self.bottomLayout.addRow(QLabel("Facility: "), self.facilityEntry) self.bottomLayout.addRow(QLabel("Facility supervisor: "), self.facilitySupervisorEntry) self.bottomLayout.addRow(QLabel("Specific location: "), self.specificLocationEntry) self.bottomLayout.addRow(QLabel("Inspected department: "), self.inspectedDepartmentEntry) self.bottomLayout.addRow(QLabel("Inspected contractor: "), self.inspectedContractorEntry) self.bottomLayout.addRow(QLabel("Inspected subcontractor: "), self.inspectedSubcontractorEntry) self.bottomLayout.addRow(QLabel("Deadline: "), self.deadlineEntry) self.bottomLayout.addRow(QLabel(""), self.attachFilesBtn) self.bottomLayout.addRow(QLabel(""), self.addActionBtn) self.bottomLayout.addRow(QLabel(""), self.addRootCauseBtn) self.bottomLayout.addRow(QLabel(""), self.submitObservationBtn) self.bottomFrame.setLayout(self.bottomLayout) # Make bottom frame scollable self.scroll.setWidget(self.bottomFrame) # Add frames to main layout self.mainLayout.addWidget(self.topFrame) self.mainLayout.addWidget(self.scroll) self.setLayout(self.mainLayout) def addIssue(self): date = self.dateEntry.text() priority = self.priorityEntry.currentText() observer = self.observerEntry.currentText() revisionTeam = self.revisionTeamEntry.currentText() inspectionName = self.inspectionNameEntry.currentText() observationTheme = self.observationThemeEntry.currentText() facility = self.facilityEntry.currentText() facilitySupervisor = self.facilitySupervisorEntry.currentText() specificLocation = self.specificLocationEntry.toPlainText() inspectedDept = self.inspectedDepartmentEntry.currentText() inspectedContr = self.inspectedContractorEntry.currentText() inspectedSubcontr = self.inspectedSubcontractorEntry.currentText() deadline = self.deadlineEntry.text() if date and priority and observer and revisionTeam and inspectionName and observationTheme and facility\ and facilitySupervisor and specificLocation and inspectedDept and inspectedContr \ and inspectedSubcontr and deadline != "": try: query = "INSERT INTO issues (issue_date, issue_priority, issue_observer, issue_team," \ "issue_inspection, issue_theme, issue_facility, issue_fac_supervisor," \ "issue_spec_loc, issue_insp_dept, issue_insp_contr, issue_insp_subcontr, issue_deadline, created_on) " \ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" # The purpose of this block is to make created_on timestamp the same format as other dates currentTime = QDateTimeEdit() currentTime.setDateTime(QDateTime.currentDateTime()) now = currentTime.text() db.cur.execute( query, (date, priority, observer, revisionTeam, inspectionName, observationTheme, facility, facilitySupervisor, specificLocation, inspectedDept, inspectedContr, inspectedSubcontr, deadline, now)) db.conn.commit() QMessageBox.information(self, "Info", "Issue has been added") self.Parent.displayIssues() self.close() except: QMessageBox.information(self, "Info", "Issue has not been added") else: QMessageBox.information(self, "Info", "Fields cannot be empty")
class EventPropertiesDialog(QDialog): def __init__(self): super().__init__(GlobalAccess().get_main_window()) def exec_(self): self.init_ui() return super().exec_() def init_ui(self): self.setFixedWidth(500) self.setWindowTitle(_('Event properties')) self.setWindowIcon(QIcon(config.ICON)) self.setSizeGripEnabled(False) self.setModal(True) self.layout = QFormLayout(self) self.label_main_title = QLabel(_('Main title')) self.item_main_title = QLineEdit() self.layout.addRow(self.label_main_title, self.item_main_title) self.label_sub_title = QLabel(_('Sub title')) self.item_sub_title = QTextEdit() self.item_sub_title.setMaximumHeight(100) self.layout.addRow(self.label_sub_title, self.item_sub_title) self.label_start_date = QLabel(_('Start date')) self.item_start_date = QDateTimeEdit() self.item_start_date.setDisplayFormat('yyyy.MM.dd HH:mm:ss') self.layout.addRow(self.label_start_date, self.item_start_date) self.label_end_date = QLabel(_('End date')) # self.item_end_date = QCalendarWidget() self.item_end_date = QDateTimeEdit() self.item_end_date.setDisplayFormat('yyyy.MM.dd HH:mm:ss') self.layout.addRow(self.label_end_date, self.item_end_date) self.label_location = QLabel(_('Location')) self.item_location = QLineEdit() self.layout.addRow(self.label_location, self.item_location) self.label_type = QLabel(_('Event type')) self.item_type = AdvComboBox() self.item_type.addItems(RaceType.get_titles()) self.layout.addRow(self.label_type, self.item_type) self.label_relay_legs = QLabel(_('Relay legs')) self.item_relay_legs = QSpinBox() self.item_relay_legs.setMinimum(1) self.item_relay_legs.setMaximum(20) self.item_relay_legs.setValue(3) self.layout.addRow(self.label_relay_legs, self.item_relay_legs) self.item_type.currentTextChanged.connect(self.change_type) self.label_refery = QLabel(_('Chief referee')) self.item_refery = QLineEdit() self.layout.addRow(self.label_refery, self.item_refery) self.label_secretary = QLabel(_('Secretary')) self.item_secretary = QLineEdit() self.layout.addRow(self.label_secretary, self.item_secretary) self.label_url = QLabel(_('URL')) self.item_url = QLineEdit() self.layout.addRow(self.label_url, self.item_url) def cancel_changes(): self.close() def apply_changes(): try: self.apply_changes_impl() except Exception as e: logging.error(str(e)) self.close() button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.button_ok = button_box.button(QDialogButtonBox.Ok) self.button_ok.setText(_('OK')) self.button_ok.clicked.connect(apply_changes) self.button_cancel = button_box.button(QDialogButtonBox.Cancel) self.button_cancel.setText(_('Cancel')) self.button_cancel.clicked.connect(cancel_changes) self.layout.addRow(button_box) self.set_values_from_model() self.show() def change_type(self): flag = self.item_type.currentText() == RaceType.RELAY.get_title() self.label_relay_legs.setVisible(flag) self.item_relay_legs.setVisible(flag) def set_values_from_model(self): obj = race() self.item_main_title.setText(str(obj.data.title)) self.item_sub_title.setText(str(obj.data.description)) self.item_location.setText(str(obj.data.location)) self.item_url.setText(str(obj.data.url)) self.item_refery.setText(str(obj.data.chief_referee)) self.item_secretary.setText(str(obj.data.secretary)) self.item_start_date.setDateTime(obj.data.get_start_datetime()) self.item_end_date.setDateTime(obj.data.get_end_datetime()) self.item_type.setCurrentText(obj.data.race_type.get_title()) self.item_relay_legs.setValue(obj.data.relay_leg_count) self.change_type() def apply_changes_impl(self): obj = race() start_date = self.item_start_date.dateTime().toPython() end_date = self.item_end_date.dateTime().toPython() obj.data.title = self.item_main_title.text() obj.data.description = self.item_sub_title.toPlainText() obj.data.description = obj.data.description.replace('\n', '<br>\n') obj.data.location = self.item_location.text() obj.data.url = self.item_url.text() obj.data.chief_referee = self.item_refery.text() obj.data.secretary = self.item_secretary.text() obj.data.start_datetime = start_date obj.data.end_datetime = end_date t = RaceType.get_by_name(self.item_type.currentText()) if t is not None: obj.data.race_type = t obj.data.relay_leg_count = self.item_relay_legs.value() obj.set_setting('system_zero_time', (start_date.hour, start_date.minute, 0)) ResultCalculation(race()).process_results() GlobalAccess().get_main_window().set_title()
class TransferWidget(AbstractOperationDetails): def __init__(self, parent=None): AbstractOperationDetails.__init__(self, parent) self.name = "Transfer" self.from_date_label = QLabel(self) self.from_account_label = QLabel(self) self.from_amount_label = QLabel(self) self.to_date_label = QLabel(self) self.to_account_label = QLabel(self) self.to_amount_label = QLabel(self) self.fee_account_label = QLabel(self) self.fee_amount_label = QLabel(self) self.comment_label = QLabel(self) self.arrow_account = QLabel(self) self.copy_date_btn = QPushButton(self) self.copy_amount_btn = QPushButton(self) self.main_label.setText(g_tr("TransferWidget", "Transfer")) self.from_date_label.setText(g_tr("TransferWidget", "Date/Time")) self.from_account_label.setText(g_tr("TransferWidget", "From")) self.from_amount_label.setText(g_tr("TransferWidget", "Amount")) self.to_date_label.setText(g_tr("TransferWidget", "Date/Time")) self.to_account_label.setText(g_tr("TransferWidget", "To")) self.to_amount_label.setText(g_tr("TransferWidget", "Amount")) self.fee_account_label.setText(g_tr("TransferWidget", "Fee from")) self.fee_amount_label.setText(g_tr("TransferWidget", "Fee amount")) self.comment_label.setText(g_tr("TransferWidget", "Note")) self.arrow_account.setText(" ➜ ") self.copy_date_btn.setText("➜") self.copy_date_btn.setFixedWidth( self.copy_date_btn.fontMetrics().width("XXXX")) self.copy_amount_btn.setText("➜") self.copy_amount_btn.setFixedWidth( self.copy_amount_btn.fontMetrics().width("XXXX")) self.withdrawal_timestamp = QDateTimeEdit(self) self.withdrawal_timestamp.setCalendarPopup(True) self.withdrawal_timestamp.setTimeSpec(Qt.UTC) self.withdrawal_timestamp.setFixedWidth( self.withdrawal_timestamp.fontMetrics().width( "00/00/0000 00:00:00") * 1.25) self.withdrawal_timestamp.setDisplayFormat("dd/MM/yyyy hh:mm:ss") self.deposit_timestamp = QDateTimeEdit(self) self.deposit_timestamp.setCalendarPopup(True) self.deposit_timestamp.setTimeSpec(Qt.UTC) self.deposit_timestamp.setFixedWidth( self.deposit_timestamp.fontMetrics().width("00/00/0000 00:00:00") * 1.25) self.deposit_timestamp.setDisplayFormat("dd/MM/yyyy hh:mm:ss") self.from_account_widget = AccountSelector(self) self.to_account_widget = AccountSelector(self) self.fee_account_widget = AccountSelector(self) self.withdrawal = AmountEdit(self) self.withdrawal.setAlignment(Qt.AlignRight) self.deposit = AmountEdit(self) self.deposit.setAlignment(Qt.AlignRight) self.fee = AmountEdit(self) self.fee.setAlignment(Qt.AlignRight) self.comment = QLineEdit(self) self.layout.addWidget(self.from_date_label, 1, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.from_account_label, 2, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.from_amount_label, 3, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.comment_label, 5, 0, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.withdrawal_timestamp, 1, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.from_account_widget, 2, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.withdrawal, 3, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.comment, 5, 1, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.copy_date_btn, 1, 2, 1, 1) self.layout.addWidget(self.arrow_account, 2, 2, 1, 1, Qt.AlignCenter) self.layout.addWidget(self.copy_amount_btn, 3, 2, 1, 1) self.layout.addWidget(self.to_date_label, 1, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.to_account_label, 2, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.to_amount_label, 3, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee_account_label, 4, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee_amount_label, 5, 3, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.deposit_timestamp, 1, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.to_account_widget, 2, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.deposit, 3, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee_account_widget, 4, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.fee, 5, 4, 1, 1, Qt.AlignLeft) self.layout.addWidget(self.commit_button, 0, 6, 1, 1) self.layout.addWidget(self.revert_button, 0, 7, 1, 1) self.layout.addItem(self.verticalSpacer, 6, 0, 1, 1) self.layout.addItem(self.horizontalSpacer, 1, 5, 1, 1) self.copy_date_btn.clicked.connect(self.onCopyDate) self.copy_amount_btn.clicked.connect(self.onCopyAmount) super()._init_db("transfers") self.mapper.setItemDelegate(TransferWidgetDelegate(self.mapper)) self.from_account_widget.changed.connect(self.mapper.submit) self.to_account_widget.changed.connect(self.mapper.submit) self.fee_account_widget.changed.connect(self.mapper.submit) self.mapper.addMapping(self.withdrawal_timestamp, self.model.fieldIndex("withdrawal_timestamp")) self.mapper.addMapping(self.from_account_widget, self.model.fieldIndex("withdrawal_account")) self.mapper.addMapping(self.withdrawal, self.model.fieldIndex("withdrawal")) self.mapper.addMapping(self.deposit_timestamp, self.model.fieldIndex("deposit_timestamp")) self.mapper.addMapping(self.to_account_widget, self.model.fieldIndex("deposit_account")) self.mapper.addMapping(self.deposit, self.model.fieldIndex("deposit")) self.mapper.addMapping(self.fee_account_widget, self.model.fieldIndex("fee_account")) self.mapper.addMapping(self.fee, self.model.fieldIndex("fee")) self.mapper.addMapping(self.comment, self.model.fieldIndex("note")) self.model.select() @Slot() def saveChanges(self): record = self.model.record(0) note = record.value(self.model.fieldIndex("note")) if not note: # If we don't have note - set it to NULL value # TODO - is it really needed? self.model.setData( self.model.index(0, self.model.fieldIndex("note")), None) # Set related fields NULL if we don't have fee. This is required for correct transfer processing fee_amount = record.value(self.model.fieldIndex("fee")) if not fee_amount: fee_amount = 0 if abs(float(fee_amount)) < Setup.CALC_TOLERANCE: self.model.setData( self.model.index(0, self.model.fieldIndex("fee_account")), None) self.model.setData( self.model.index(0, self.model.fieldIndex("fee")), None) super().saveChanges() def prepareNew(self, account_id): new_record = self.model.record() new_record.setNull("id") new_record.setValue( "withdrawal_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) new_record.setValue("withdrawal_account", account_id) new_record.setValue("withdrawal", 0) new_record.setValue( "deposit_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) new_record.setValue("deposit_account", 0) new_record.setValue("deposit", 0) new_record.setValue("fee_account", 0) new_record.setValue("fee", 0) new_record.setValue("asset", None) new_record.setValue("note", None) return new_record def copyToNew(self, row): new_record = self.model.record(row) new_record.setNull("id") new_record.setValue( "withdrawal_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) new_record.setValue( "deposit_timestamp", int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp())) return new_record @Slot() def onCopyDate(self): self.deposit_timestamp.setDateTime( self.withdrawal_timestamp.dateTime()) @Slot() def onCopyAmount(self): self.deposit.setText(self.withdrawal.text())
class DisplayIssue(QWidget): def __init__(self, parent): QWidget.__init__(self) self.setWindowTitle("View issue") self.setWindowIcon(QIcon("assets/icons/logo-dark.png")) self.setGeometry(450, 150, 750, 950) self.Parent = parent self.setStyleSheet(styles.mainStyle()) self.UI() self.show() def UI(self): self.issueDetails() self.widgets() self.layouts() def issueDetails(self): row = self.Parent.issuesTable.currentRow() issueId = self.Parent.issuesTable.item(row, 2).text() # Strip the ISS# from the id issueId = issueId.lstrip("ISS#") query = "SELECT * FROM issues WHERE issue_id=?" cur = db.cur issue = cur.execute(query, (issueId, )).fetchone() self.id = issue[0] self.date = issue[1] self.priority = issue[2] self.observer = issue[3] self.revTeam = issue[4] self.inspectorName = issue[5] self.theme = issue[6] self.facility = issue[7] self.facilitySupervisor = issue[8] self.specLocation = issue[9] self.inspectedDept = issue[10] self.inspectedContr = issue[11] self.inspectedSubcontr = issue[12] self.deadline = issue[13] self.status = issue[14] def widgets(self): self.dropdownData = IssuesDropdownData() # Top layout widgets self.issueImg = QLabel() self.img = QPixmap('assets/icons/logo-dark.png') self.issueImg.setPixmap(self.img) self.issueImg.setAlignment(Qt.AlignCenter) self.titleText = QLabel("Display issue") self.titleText.setAlignment(Qt.AlignCenter) # Bottom layout widgets self.idEntry = QLabel(str(self.id)) self.dateEntry = QDateTimeEdit(calendarPopup=True) self.dateEntry.setDateTime( QDateTime.fromString(self.date, "yyyy-MM-dd h:mm AP")) self.priorityEntry = QComboBox() self.priorityEntry.addItems(self.dropdownData.priorityItems()) self.priorityEntry.setCurrentText(self.priority) self.observerEntry = QComboBox() self.observerEntry.addItems(self.dropdownData.observerItems()) self.observerEntry.setCurrentText(self.observer) self.revTeamEntry = QComboBox() self.revTeamEntry.addItems(self.dropdownData.revTeamItems()) self.revTeamEntry.setCurrentText(self.revTeam) self.inspectionNameEntry = QComboBox() self.inspectionNameEntry.addItems(self.dropdownData.inspNameItems()) self.inspectionNameEntry.setCurrentText(self.inspectorName) self.themeEntry = QComboBox() self.themeEntry.addItems(self.dropdownData.hseThemeItems()) self.themeEntry.setCurrentText(self.theme) self.facilityEntry = QComboBox() self.facilityEntry.addItems(self.dropdownData.facilityItems()) self.facilityEntry.setCurrentText(self.facility) self.facilitySupervisorEntry = QComboBox() self.facilitySupervisorEntry.addItems( self.dropdownData.facSupervisorItems()) self.facilitySupervisorEntry.setCurrentText(self.facilitySupervisor) self.specLocationEntry = QTextEdit() self.specLocationEntry.setText(self.specLocation) self.inspectedDeptEntry = QComboBox() self.inspectedDeptEntry.addItems(self.dropdownData.inspDeptItems()) self.inspectedDeptEntry.setCurrentText(self.inspectedDept) self.inspectedContrEntry = QComboBox() self.inspectedContrEntry.addItems(self.dropdownData.inspContrItems()) self.inspectedContrEntry.setCurrentText(self.inspectedContr) self.inspectedSubcontrEntry = QComboBox() self.inspectedSubcontrEntry.addItems( self.dropdownData.inspSubcontrItems()) self.inspectedSubcontrEntry.setCurrentText(self.inspectedSubcontr) self.statusEntry = QComboBox() self.statusEntry.addItems(self.dropdownData.statusItems()) self.statusEntry.setCurrentText(self.status) self.deadlineEntry = QDateTimeEdit(calendarPopup=True) self.deadlineEntry.setDateTime( QDateTime.fromString(self.deadline, "yyyy-MM-dd h:mm AP")) self.updateBtn = QPushButton("Update") self.updateBtn.clicked.connect(self.updateIssue) self.deleteBtn = QPushButton("Delete") self.deleteBtn.clicked.connect(self.Parent.funcDeleteIssue) self.cancelBtn = QPushButton("Cancel") self.cancelBtn.clicked.connect(self.closeWindow) def layouts(self): self.mainLayout = QVBoxLayout() self.topLayout = QVBoxLayout() self.bottomLayout = QFormLayout() self.bottomBtnLayout = QHBoxLayout() self.topFrame = QFrame() self.bottomFrame = QFrame() # Add widgets self.topLayout.addWidget(self.titleText) self.topLayout.addWidget(self.issueImg) self.topFrame.setLayout(self.topLayout) self.bottomLayout.addRow("ID: ", self.idEntry) self.bottomLayout.addRow("Date: ", self.dateEntry) self.bottomLayout.addRow("Priority: ", self.priorityEntry) self.bottomLayout.addRow("Observer: ", self.observerEntry) self.bottomLayout.addRow("Revision Team: ", self.revTeamEntry) self.bottomLayout.addRow("Inspector name: ", self.inspectionNameEntry) self.bottomLayout.addRow("HSE theme: ", self.themeEntry) self.bottomLayout.addRow("Facility: ", self.facilityEntry) self.bottomLayout.addRow("Facility supervisor: ", self.facilitySupervisorEntry) self.bottomLayout.addRow("Specific location: ", self.specLocationEntry) self.bottomLayout.addRow("Inspected department: ", self.inspectedDeptEntry) self.bottomLayout.addRow("Inspected contractor: ", self.inspectedContrEntry) self.bottomLayout.addRow("Inspected subcontractor: ", self.inspectedSubcontrEntry) self.bottomLayout.addRow("Deadline: ", self.deadlineEntry) self.bottomLayout.addRow("Status: ", self.statusEntry) self.bottomBtnLayout.addWidget(self.cancelBtn) self.bottomBtnLayout.addItem( QSpacerItem(60, 40, QSizePolicy.Minimum, QSizePolicy.Expanding)) self.bottomBtnLayout.addWidget(self.deleteBtn) self.bottomBtnLayout.addWidget(self.updateBtn) self.bottomLayout.addRow(self.bottomBtnLayout) self.bottomFrame.setLayout(self.bottomLayout) self.mainLayout.addWidget(self.topFrame) self.mainLayout.addWidget(self.bottomFrame) self.setLayout(self.mainLayout) @Slot() def closeWindow(self): self.close() @Slot() def updateIssue(self): row = self.Parent.issuesTable.currentRow() issueId = self.Parent.issuesTable.item(row, 2).text() issueId = issueId.lstrip("ISS#") date = self.dateEntry.text() priority = self.priorityEntry.currentText() observer = self.observerEntry.currentText() revTeam = self.revTeamEntry.currentText() inspectionName = self.inspectionNameEntry.currentText() theme = self.themeEntry.currentText() facility = self.facilityEntry.currentText() facilitySupervisor = self.facilitySupervisorEntry.currentText() specLocation = self.specLocationEntry.toPlainText() inspDept = self.inspectedDeptEntry.currentText() inspContr = self.inspectedContrEntry.currentText() inspSubcontr = self.inspectedSubcontrEntry.currentText() status = self.statusEntry.currentText() print(status) deadline = self.deadlineEntry.text() if (date and priority and observer and revTeam and inspectionName and theme and facility and facilitySupervisor and specLocation and inspDept and deadline != ""): try: query = "UPDATE issues SET " \ "issue_date=?, " \ "issue_priority=?, " \ "issue_observer=?, " \ "issue_team=?," \ "issue_inspection=?, " \ "issue_theme=?, " \ "issue_facility=?, " \ "issue_fac_supervisor=?," \ "issue_spec_loc=?, " \ "issue_insp_dept=?, " \ "issue_insp_contr=?, " \ "issue_insp_subcontr=?," \ "issue_deadline=?, " \ "status=? " \ "WHERE issue_id=? " db.cur.execute( query, (date, priority, observer, revTeam, inspectionName, theme, facility, facilitySupervisor, specLocation, inspDept, inspContr, inspSubcontr, deadline, status, issueId)) db.conn.commit() QMessageBox.information(self, "Info", "Issue info updated") except: QMessageBox.information(self, "Info", "No changes made") else: QMessageBox.information(self, "Info", "Fields cannot be empty") self.Parent.funcDisplayIssues() self.close()
class AddIssue(QWidget): def __init__(self, parent): QWidget.__init__(self) self.setWindowTitle("Add issue") self.setWindowIcon(QIcon("assets/icons/icon.ico")) self.setGeometry(450, 150, 750, 950) # self.setFixedSize(self.size()) self.Parent = parent self.filePathName = "" self.UI() self.show() def UI(self): self.widgets() self.layouts() def widgets(self): self.scroll = QScrollArea() self.scroll.setWidgetResizable(True) self.dropdownData = IssuesDropdownData() # Top layout widgets self.addIssueImg = QLabel() self.img = QPixmap('assets/icons/create-issue.png') self.addIssueImg.setPixmap(self.img) self.addIssueImg.setAlignment(Qt.AlignCenter) self.titleText = QLabel("ADD ISSUE") self.titleText.setObjectName("add_issue_title_txt") self.titleText.setAlignment(Qt.AlignCenter) # Middle layout widgets self.dateEntry = QDateTimeEdit(calendarPopup=True) self.dateEntry.setDateTime(QDateTime.currentDateTime()) self.priorityEntry = QComboBox() self.priorityEntry.addItems(self.dropdownData.priorityItems()) self.observerEntry = QComboBox() self.observerEntry.addItems(self.dropdownData.observerItems()) self.revisionTeamEntry = QComboBox() self.revisionTeamEntry.addItems(self.dropdownData.revTeamItems()) self.inspectionNameEntry = QComboBox() self.inspectionNameEntry.addItems(self.dropdownData.inspNameItems()) self.observationThemeEntry = QComboBox() self.observationThemeEntry.addItems(self.dropdownData.hseThemeItems()) self.facilityEntry = QComboBox() self.facilityEntry.addItems(self.dropdownData.facilityItems()) self.facilitySupervisorEntry = QComboBox() self.facilitySupervisorEntry.addItems( self.dropdownData.facSupervisorItems()) self.specificLocationEntry = QTextEdit() self.inspectedDepartmentEntry = QComboBox() self.inspectedDepartmentEntry.addItems( self.dropdownData.inspDeptItems()) self.inspectedContractorEntry = QComboBox() self.inspectedContractorEntry.addItems( self.dropdownData.inspContrItems()) self.inspectedSubcontractorEntry = QComboBox() self.inspectedSubcontractorEntry.addItems( self.dropdownData.inspSubcontrItems()) self.deadlineEntry = QDateTimeEdit(calendarPopup=True) self.deadlineEntry.setDateTime(QDateTime.currentDateTime().addDays(14)) # Bottom layout widgets self.attachFilesBtn = QPushButton("Attach files") self.attachFilesBtn.clicked.connect(self.funcAttachFiles) self.addActionBtn = QPushButton("Add action") self.rootCauseEntry = QComboBox() self.rootCauseEntry.setEditable(True) self.rootCauseDetailsEntry = QTextEdit() self.rootCauseActionPartyEntry = QComboBox() self.rootCauseActionPartyEntry.setEditable(True) self.addRootCauseBtn = QPushButton("Add root cause") self.submitObservationBtn = QPushButton("Add issue") self.submitObservationBtn.clicked.connect(self.addIssue) self.cancelBtn = QPushButton("Cancel") self.cancelBtn.clicked.connect(self.closeWindow) def layouts(self): self.mainLayout = QVBoxLayout() self.topLayout = QHBoxLayout() self.bottomLayout = QFormLayout() self.bottomLayout.setVerticalSpacing(20) self.bottomBtnLayout = QHBoxLayout() # Put elements into frames for visual distinction self.topFrame = QFrame() self.bottomFrame = QFrame() # Add widgets to top layout # self.topLayout.addWidget(self.addIssueImg) self.topLayout.addWidget(self.titleText) self.topFrame.setLayout(self.topLayout) # Add widgets to middle layout # self.bottomLayout.addRow(self.issueInfoTitleText) self.bottomLayout.addRow(QLabel("Inspection Date: "), self.dateEntry) self.bottomLayout.addRow(QLabel("Priority: "), self.priorityEntry) self.bottomLayout.addRow(QLabel("Observer: "), self.observerEntry) self.bottomLayout.addRow(QLabel("Revision Team: "), self.revisionTeamEntry) self.bottomLayout.addRow(QLabel("Inspection Name: "), self.inspectionNameEntry) self.bottomLayout.addRow(QLabel("HSE Theme: "), self.observationThemeEntry) self.bottomLayout.addRow(QLabel("Facility: "), self.facilityEntry) self.bottomLayout.addRow(QLabel("Facility supervisor: "), self.facilitySupervisorEntry) self.bottomLayout.addRow(QLabel("Specific location: "), self.specificLocationEntry) self.bottomLayout.addRow(QLabel("Inspected department: "), self.inspectedDepartmentEntry) self.bottomLayout.addRow(QLabel("Inspected contractor: "), self.inspectedContractorEntry) self.bottomLayout.addRow(QLabel("Inspected subcontractor: "), self.inspectedSubcontractorEntry) self.bottomLayout.addRow(QLabel("Deadline: "), self.deadlineEntry) self.bottomLayout.addRow(QLabel(""), self.attachFilesBtn) # self.bottomLayout.addRow(QLabel(""), self.addActionBtn) # self.bottomLayout.addRow(QLabel(""), self.addRootCauseBtn) # self.bottomLayout.addRow(QLabel(""), self.submitObservationBtn) self.bottomBtnLayout.addWidget(self.cancelBtn) self.bottomBtnLayout.addItem( QSpacerItem(200, 5, QSizePolicy.Minimum, QSizePolicy.Expanding)) self.bottomBtnLayout.addWidget(self.submitObservationBtn) self.bottomBtnLayout.setAlignment(Qt.AlignBottom) self.bottomLayout.addRow(self.bottomBtnLayout) self.bottomFrame.setLayout(self.bottomLayout) # Make bottom frame scollable self.scroll.setWidget(self.bottomFrame) # Add frames to main layout self.mainLayout.addWidget(self.topFrame) self.mainLayout.addWidget(self.scroll) self.setLayout(self.mainLayout) @Slot() def closeWindow(self): self.close() @Slot() def addIssue(self): date = self.dateEntry.text() priority = self.priorityEntry.currentText() observer = self.observerEntry.currentText() revisionTeam = self.revisionTeamEntry.currentText() inspectionName = self.inspectionNameEntry.currentText() observationTheme = self.observationThemeEntry.currentText() facility = self.facilityEntry.currentText() facilitySupervisor = self.facilitySupervisorEntry.currentText() specificLocation = self.specificLocationEntry.toPlainText() inspectedDept = self.inspectedDepartmentEntry.currentText() inspectedContr = self.inspectedContractorEntry.currentText() inspectedSubcontr = self.inspectedSubcontractorEntry.currentText() deadline = self.deadlineEntry.text() # If user selected a file to attach, rename the file and copy it to media folder if self.filePathName != "": self.newFilePath = ShCopy2(self.filePathName, self.attachedFilePath) im = Image.open(self.filePathName) im_resized = self.crop_max_square(im).resize((800, 800), Image.LANCZOS) im_resized.save(self.attachedResizedFilePath) else: self.attachedFilePath = "" self.attachedResizedFilePath = "" if date and priority and observer and revisionTeam and inspectionName and observationTheme and facility \ and facilitySupervisor and specificLocation and inspectedDept and inspectedContr \ and inspectedSubcontr and deadline != "": try: query = "INSERT INTO issues (issue_date, issue_priority, issue_observer, issue_team," \ "issue_inspection, issue_theme, issue_facility, issue_fac_supervisor," \ "issue_spec_loc, issue_insp_dept, issue_insp_contr, issue_insp_subcontr, issue_deadline, " \ "created_on, photo_original_path, photo_resized_path) " \ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" # The purpose of this block is to make created_on timestamp the same format as other dates currentTime = QDateTimeEdit() currentTime.setDateTime(QDateTime.currentDateTime()) now = currentTime.text() db.cur.execute( query, (date, priority, observer, revisionTeam, inspectionName, observationTheme, facility, facilitySupervisor, specificLocation, inspectedDept, inspectedContr, inspectedSubcontr, deadline, now, self.attachedFilePath, self.attachedResizedFilePath)) db.conn.commit() QMessageBox.information(self, "Info", "Issue has been added") self.Parent.funcDisplayIssues() self.close() except: QMessageBox.information(self, "Info", "Issue has not been added") else: QMessageBox.information(self, "Info", "Fields cannot be empty") # Need to figure out how attach files to items in db @Slot() def funcAttachFiles(self): self.filePathName = QFileDialog.getOpenFileName( self, "Attach file...", "/", "Image files (*.jpg *.jpeg *.png)")[0] if osPath.isfile(self.filePathName): fileName, fileExt = osPath.splitext(self.filePathName) if fileExt == '.jpg' or fileExt == '.jpeg' or fileExt == '.png': date = datetime.now() randomSuffix = "".join( random.choice(string.ascii_lowercase) for i in range(15)) self.attachedFilePath = osPath.join( "assets", "media", "issues-media", "photos", ("{:%d%b%Y_%Hh%Mm}".format(date) + randomSuffix + fileExt)) self.attachedResizedFilePath = osPath.join( "assets", "media", "issues-media", "photos_resized", ("{:%d%b%Y_%Hh%Mm}".format(date) + randomSuffix + "_resized" + fileExt)) QMessageBox.information(self, "Info", "File attached successfully") else: QMessageBox.information(self, "Info", "Wrong file type!") else: QMessageBox.information(self, "Info", "No file selected") # Image processing functions @Slot() def crop_center(self, pil_img, crop_width, crop_height): img_width, img_height = pil_img.size fill_color = 'rgba(255, 255, 255, 1)' if pil_img.mode in ('RGBA', 'LA'): background = Image.new(pil_img.mode[:-1], pil_img.size, fill_color) background.paste(pil_img, pil_img.split()[-1]) image = background return pil_img.crop( ((img_width - crop_width) // 2, (img_height - crop_height) // 2, (img_width + crop_width) // 2, (img_height + crop_height) // 2)) # Crop the largest possible square from a rectangle @Slot() def crop_max_square(self, pil_img): return self.crop_center(pil_img, min(pil_img.size), min(pil_img.size))
def addIssue(self): date = self.dateEntry.text() priority = self.priorityEntry.currentText() observer = self.observerEntry.currentText() revisionTeam = self.revisionTeamEntry.currentText() inspectionName = self.inspectionNameEntry.currentText() observationTheme = self.observationThemeEntry.currentText() facility = self.facilityEntry.currentText() facilitySupervisor = self.facilitySupervisorEntry.currentText() specificLocation = self.specificLocationEntry.toPlainText() inspectedDept = self.inspectedDepartmentEntry.currentText() inspectedContr = self.inspectedContractorEntry.currentText() inspectedSubcontr = self.inspectedSubcontractorEntry.currentText() deadline = self.deadlineEntry.text() # If user selected a file to attach, rename the file and copy it to media folder if self.filePathName != "": self.newFilePath = ShCopy2(self.filePathName, self.attachedFilePath) im = Image.open(self.filePathName) im_resized = self.crop_max_square(im).resize((800, 800), Image.LANCZOS) im_resized.save(self.attachedResizedFilePath) else: self.attachedFilePath = "" self.attachedResizedFilePath = "" if date and priority and observer and revisionTeam and inspectionName and observationTheme and facility \ and facilitySupervisor and specificLocation and inspectedDept and inspectedContr \ and inspectedSubcontr and deadline != "": try: query = "INSERT INTO issues (issue_date, issue_priority, issue_observer, issue_team," \ "issue_inspection, issue_theme, issue_facility, issue_fac_supervisor," \ "issue_spec_loc, issue_insp_dept, issue_insp_contr, issue_insp_subcontr, issue_deadline, " \ "created_on, photo_original_path, photo_resized_path) " \ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" # The purpose of this block is to make created_on timestamp the same format as other dates currentTime = QDateTimeEdit() currentTime.setDateTime(QDateTime.currentDateTime()) now = currentTime.text() db.cur.execute( query, (date, priority, observer, revisionTeam, inspectionName, observationTheme, facility, facilitySupervisor, specificLocation, inspectedDept, inspectedContr, inspectedSubcontr, deadline, now, self.attachedFilePath, self.attachedResizedFilePath)) db.conn.commit() QMessageBox.information(self, "Info", "Issue has been added") self.Parent.funcDisplayIssues() self.close() except: QMessageBox.information(self, "Info", "Issue has not been added") else: QMessageBox.information(self, "Info", "Fields cannot be empty")