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 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")
class application(QTabWidget): bot = 0 def __init__(self, parent=None): super(application, self).__init__(parent) self.bot = None self.db = sqlite3.connect('database') # tabs self.tab1 = QWidget() self.tab2 = QWidget() self.tab3 = QWidget() self.tab4 = QWidget() self.tab5 = QWidget() self.resize(640, 400) self.addTab(self.tab1, "Tab 1") self.addTab(self.tab2, "Tab 2") self.addTab(self.tab3, "Tab 3") self.addTab(self.tab4, "Tab 4") self.addTab(self.tab5, "Tab 5") # tab set keys self.h_box_key = QHBoxLayout() self.change_key_b = QPushButton("Edit keys") self.edit_1 = QLineEdit() self.edit_2 = QLineEdit() self.edit_3 = QLineEdit() self.edit_4 = QLineEdit() self.result = QLabel() self.set_button = QPushButton("Set keys") self.handle_info = QLabel() self.follower_info = QLabel() self.ready_lab = QLabel() # tab follow self.box_label = QLabel("Link to tweet") self.combo_label = QLabel("Mode") self.spin_label = QLabel("Limit before sleep") self.prog_bar = QProgressBar() self.combo_box = QComboBox() self.h_box = QHBoxLayout() self.spin_box = QSpinBox() self.link_box = QLineEdit() self.link_result = QLabel() self.follow_button = QPushButton("Follow Retweeters") self.cancel_button = QPushButton("Cancel") self.logger = QPlainTextEdit() self.h_box2 = QHBoxLayout() self.max_box = QSpinBox() self.max_label = QLabel("Max follows before stop") # tab unfollow self.unfollow_button = QPushButton("Unfollow Auto followers") self.unf_logger = QPlainTextEdit() self.unfollow_res = QLabel() self.prog_bar_unf = QProgressBar() self.unfollow_cancel = QPushButton("Cancel") self.unf_confirm = QMessageBox() # tab help self.help_box = QPlainTextEdit() self.help_label = QLabel( "<a href='http://Optumsense.com/'>http://Optumsense.com/</a>") #tab schedule self.tweet_box = QPlainTextEdit() self.date_time = QDateTimeEdit(QDateTime.currentDateTime()) self.schedule_but = QPushButton("Schedule Tweet") self.schedule_info = QLabel() self.schedule_table = QTableView() # threads self.follow_thread = None self.unfollow_thread = None self.schedule_thread = None # tabs self.tab1UI() self.tab2UI() self.tab3UI() self.tab4UI() self.tab5UI() self.setWindowTitle("Optumize") self.setWindowIcon(QtGui.QIcon('assets/oo.png')) # db cursor = self.db.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS keys(one TEXT, two TEXT, three TEXT, four TEXT)''' ) self.db.commit() def tab1UI(self): layout = QFormLayout() layout.addRow(self.h_box) self.h_box.addWidget(self.combo_label) self.combo_label.setAlignment(Qt.AlignRight) self.h_box.addWidget(self.combo_box) self.combo_box.addItem("Follow Retweeters") self.combo_box.addItem("Follow Followers") self.combo_box.currentIndexChanged.connect(self.selection_change) self.h_box.addWidget(self.spin_label) self.spin_label.setAlignment(Qt.AlignRight) self.h_box.addWidget(self.spin_box) self.spin_box.setMinimum(1) self.spin_box.setValue(30) layout.addRow(self.box_label, self.link_box) self.link_result.setAlignment(Qt.AlignCenter) layout.addRow(self.link_result) layout.addRow(self.follow_button) self.follow_button.clicked.connect(self.follow_ret) layout.addRow(self.cancel_button) self.cancel_button.clicked.connect(self.cancel_onclick) layout.addRow(self.h_box2) self.h_box2.addWidget(self.max_label) self.h_box2.addWidget(self.max_box) self.max_box.setFixedWidth(100) self.max_label.setAlignment(Qt.AlignRight) self.max_box.setMaximum(1000000) self.max_box.setValue(100) self.max_label.hide() self.max_box.hide() layout.addRow(self.logger) self.logger.setReadOnly(True) layout.addRow(self.prog_bar) self.prog_bar.setAlignment(Qt.AlignCenter) self.setTabText(0, "Follow") self.setTabIcon(0, QtGui.QIcon('assets/check_mark.png')) self.tab1.setLayout(layout) def selection_change(self, i): if i == 0: self.box_label.setText("Link to tweet") self.follow_button.setText("Follow Retweeters") self.link_result.setText("") self.max_label.hide() self.max_box.hide() self.follow_button.clicked.connect(self.follow_ret) else: self.box_label.setText("Handle of user") self.follow_button.setText("Follow Followers") self.link_result.setText("") self.max_label.show() self.max_box.show() self.max_label.setText("Max follows before stop") self.follow_button.clicked.connect(self.follow_fol) def cancel_onclick(self): if self.follow_thread is None: pass elif self.follow_thread.isRunning(): self.prog_bar.setValue(0) self.logger.appendPlainText("Cancelled script") self.follow_thread.terminate() self.follow_thread = None def follow_ret(self): self.prog_bar.setValue(0) self.follow_button.setEnabled(False) self.link_result.setText("") self.logger.clear() limit = self.spin_box.value() if self.bot is None: self.link_result.setText( "<font color='red'>Configure access keys in set keys tab</font>" ) return if self.follow_thread is not None: return link = self.link_box.text() id_tweet = link.split("/")[-1] try: tweet = self.bot.api.get_status(id_tweet) self.logger.appendPlainText( f"following retweeters from link: {link}...") self.follow_thread = FollowThread(self.bot, id_tweet, limit, 1, 0) self.follow_thread.start() self.connect(self.follow_thread, SIGNAL("finished()"), self.done) self.connect(self.follow_thread, SIGNAL("setup_prog(QString)"), self.setup_prog) self.connect(self.follow_thread, SIGNAL("post_follow(QString)"), self.post_follow) except tweepy.error.TweepError: self.follow_button.setEnabled(True) self.link_result.setText( "<font color='red'>Could not find tweet</font>") def setup_prog(self, msg): self.prog_bar.setMaximum(int(msg)) def follow_fol(self): self.prog_bar.setValue(0) self.follow_button.setEnabled(False) self.link_result.setText("") self.logger.clear() limit = self.spin_box.value() if self.bot is None: self.link_result.setText( "<font color='red'>Configure access keys in set keys tab</font>" ) return if self.follow_thread is not None: return handle = self.link_box.text() if handle == '': self.link_result.setText( "<font color='red'>Enter a handle above</font>") return elif handle[0] == '@': id_user = handle[1:] else: id_user = handle try: man = self.bot.api.get_user(id_user) self.logger.appendPlainText( f"following followers of {man.screen_name}...") self.logger.appendPlainText(f"Collecting") self.follow_thread = FollowThread(self.bot, id_user, limit, 2, self.max_box.value()) self.follow_thread.start() self.connect(self.follow_thread, SIGNAL("finished()"), self.done) self.connect(self.follow_thread, SIGNAL("setup_prog(QString)"), self.setup_prog) self.connect(self.follow_thread, SIGNAL("post_follow(QString)"), self.post_follow) except tweepy.error.TweepError: self.follow_button.setEnabled(True) self.link_result.setText( "<font color='red'>Could not find user</font>") def post_follow(self, message): if message == "bad": self.logger.appendPlainText( "Rate limit exceeded... sleeping for cooldown") else: self.logger.appendPlainText(message) self.prog_bar.setValue(self.prog_bar.value() + 1) def done(self): self.follow_thread = None self.follow_button.setEnabled(True) def tab2UI(self): layout = QFormLayout() layout.addRow(self.unfollow_button) layout.addRow(self.unfollow_cancel) layout.addRow(self.unfollow_res) self.unfollow_res.setAlignment(Qt.AlignCenter) self.unfollow_button.clicked.connect(self.unfollow_fol) self.unfollow_cancel.clicked.connect(self.unfollow_can) layout.addWidget(self.unf_logger) self.unf_logger.setReadOnly(True) layout.addRow(self.prog_bar_unf) self.prog_bar_unf.setAlignment(Qt.AlignCenter) self.setTabText(1, "Unfollow") self.setTabIcon(1, QtGui.QIcon('assets/cross.png')) self.tab2.setLayout(layout) def unfollow_fol(self): self.unfollow_button.setEnabled(False) self.unfollow_thread = UnfollowThread(self.bot) self.unfollow_thread.start() self.connect(self.unfollow_thread, SIGNAL("post_unfol(QString)"), self.post_unfol) self.connect(self.unfollow_thread, SIGNAL("finished()"), self.done_unf) def done_unf(self): self.unfollow_thread = None self.unf_logger.appendPlainText("Done") self.unfollow_button.setEnabled(True) def post_unfol(self, msg): if msg == "bad": self.unf_logger.appendPlainText( "rate limit exceeded, resting for 15 minutes") else: self.unf_logger.appendPlainText(f"Unfollowing {msg}") def unfollow_can(self): if self.unfollow_thread is None: pass elif self.unfollow_thread.isRunning(): self.unf_logger.appendPlainText("Cancelled script") self.unfollow_thread.terminate() self.unfollow_thread = None def tab3UI(self): layout = QFormLayout() layout.addWidget(self.tweet_box) self.tweet_box.setMaximumHeight(150) self.tweet_box.setPlaceholderText("Tweet contents") layout.addRow(self.date_time) self.date_time.setCalendarPopup(True) layout.addRow(self.schedule_info) layout.addRow(self.schedule_but) self.schedule_but.clicked.connect(self.schedule_tweet) layout.addWidget(self.schedule_table) self.setTabText(2, "Schedule Tweet") self.setTabIcon(2, QtGui.QIcon('assets/calendar.png')) self.tab3.setLayout(layout) def schedule_tweet(self): tweet_contents = self.tweet_box.toPlainText() if (len(tweet_contents) == 0): print("length of tweet is 0") self.schedule_info.setText("length of tweet is 0") return elif (len(tweet_contents) >= 280): self.schedule_info.setText("Tweet char limit exceeded") return if self.bot is None: self.schedule_info.setText( "<font color='red'>Configure access keys in set keys tab</font>" ) return datetime = self.date_time.text() try: print("done") self.schedule_thread.start() self.schedule_thread.add_tweet(tweet_contents, datetime) except: self.follow_button.setEnabled(True) self.link_result.setText( "<font color='red'>Could not find user</font>") def done_schedule(self): print("done scheduler") def tab4UI(self): layout = QFormLayout() layout.addRow("API key", self.edit_1) layout.addRow("API key secret", self.edit_2) layout.addRow("Auth token", self.edit_3) layout.addRow("Auth token secret", self.edit_4) self.set_button.clicked.connect(self.set_keys) l = self.read_file() if l is not None: if len(l) == 4: self.edit_1.setText(l[0]) self.edit_2.setText(l[1]) self.edit_3.setText(l[2]) self.edit_4.setText(l[3]) self.set_keys() layout.addRow(self.result) self.result.setAlignment(Qt.AlignCenter) layout.addRow(self.h_box_key) self.h_box_key.addWidget(self.change_key_b) self.h_box_key.addWidget(self.set_button) self.change_key_b.clicked.connect(self.change_keys) layout.addRow(self.handle_info) self.handle_info.setAlignment(Qt.AlignCenter) layout.addRow(self.follower_info) self.follower_info.setAlignment(Qt.AlignCenter) layout.addRow(self.ready_lab) self.ready_lab.setAlignment(Qt.AlignCenter) self.setTabText(3, "Settings") self.setTabIcon(3, QtGui.QIcon('assets/settings.png')) self.tab4.setLayout(layout) def change_keys(self): self.set_button.setEnabled(True) def set_keys(self): self.set_button.setEnabled(False) self.result.setText("") one = self.edit_1.text() two = self.edit_2.text() three = self.edit_3.text() four = self.edit_4.text() try: self.bot = apiconnector.ApiConnector(one, two, three, four) me = self.bot.add_keys(one, two, three, four) self.handle_info.setText("Handle: @" + me.screen_name) self.follower_info.setText("Followers: " + str(me.followers_count)) self.ready_lab.setText("<font color='green'>Ready!</font>") cursor = self.db.cursor() cursor.execute('DELETE FROM keys;', ) cursor.execute( '''INSERT INTO keys(one, two, three, four) VALUES(?,?,?,?)''', (one, two, three, four)) self.db.commit() self.schedule_thread = ScheduleThread(self.bot) except: print("Could not authenticate you") self.result.setText( "<font color='red'>Could not authenticate you</font>") def read_file(self): result = [] try: cursor = self.db.cursor() cursor.execute('''SELECT one, two, three, four FROM keys''') all_rows = cursor.fetchall() for row in all_rows: result.append(row[0]) result.append(row[1]) result.append(row[2]) result.append(row[3]) return result except: return None def tab5UI(self): layout = QFormLayout() layout.addRow("Website", self.help_label) self.help_label.setOpenExternalLinks(True) self.setTabText(4, "Help") self.setTabIcon(4, QtGui.QIcon('assets/help.png')) self.tab5.setLayout(layout)