def createUI(self): self.fsn_text_edit = FSNTextEdit() self.override_date = FormattedDateEdit() self.override_logo = ImageButton( os.path.join(MOSES.getPathToImages(), "override.png"), 64, 64, os.path.join(MOSES.getPathToImages(), "override_mouseover.png")) self.override_logo.setFlat(True) self.override_logo.setToolTip( "If you can't do something once, do it again, and again.") self.override_button = QtGui.QPushButton("Override") self.override_comment_label = QtGui.QLabel("Reason:") self.override_comment_field = QtGui.QLineEdit() self.override_comment_field.setToolTip( "Enter a reason for the override here.") self.data_tabulator = CopiableQTableWidget() column2 = QtGui.QVBoxLayout() column2.addWidget(self.override_logo, 1, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) column2.addWidget(self.override_date, 1) column2.addWidget(self.override_button, 1) column2.addWidget(self.override_comment_label, 1) column2.addWidget(self.override_comment_field, 1) column2.addStretch(2) options_layout = QtGui.QHBoxLayout() options_layout.addWidget(self.fsn_text_edit, 2, QtCore.Qt.AlignTop) options_layout.addLayout(column2, 1) layout = QtGui.QVBoxLayout() layout.addLayout(options_layout, 1) layout.addWidget(self.data_tabulator, 3) self.setLayout(layout) self.setWindowIcon( QtGui.QIcon(os.path.join(MOSES.getPathToImages(), "PORK_Icon.png"))) self.setWindowTitle("Override Tool") self.show()
def createWidgets(self): """Leave Planner: Method to create all the necessary widgets for the leave planner class.""" self.mainLabel = QtGui.QLabel("Apply for Leaves or Relaxation in Work") self.dateLabel1 = QtGui.QLabel("Start Date:") self.start_date_edit = FormattedDateEdit() self.start_date_edit.setMinimumDate(QtCore.QDate(2015,1,1)) self.start_date_edit.setCalendarPopup(True) self.dateLabel2 = QtGui.QLabel("End Date:") self.end_date_edit = FormattedDateEdit() self.end_date_edit.setMinimumDate(QtCore.QDate(2015,1,1)) self.end_date_edit.setCalendarPopup(True) self.statusLabel = QtGui.QLabel("Working Status:") self.statusComboBox = QtGui.QComboBox() self.statusComboBox.addItems(["Working","Leave"]) self.relaxationLabel = QtGui.QLabel("Work Relaxation:") self.relaxationSpinBox = QtGui.QSpinBox() self.relaxationSpinBox.setRange(0,100) self.relaxationSpinBox.setSuffix("%") self.commentLabel = QtGui.QLabel("Comments:") self.commentLineEdit = QtGui.QLineEdit() self.buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok| QtGui.QDialogButtonBox.Cancel) self.work_calendar_table = CopiableQTableWidget(0,0)
def createUI(self): self.date_label = QtGui.QLabel("Date(s):") self.start_date = FormattedDateEdit() self.end_date = FormattedDateEdit() self.employees_label = QtGui.QLabel("Employees:") self.employees_selection_box = CheckableComboBox("Employees") self.all_button = QtGui.QPushButton("Select All") self.clear_button = QtGui.QPushButton("Clear") self.refresh_table_button = QtGui.QPushButton("Refresh Table") self.approve_selected_button = QtGui.QPushButton("Approved") self.approve_selected_button.setCheckable(True) self.reject_selected_button = QtGui.QPushButton("Rejected") self.reject_selected_button.setCheckable(True) self.pending_selected_button = QtGui.QPushButton("Pending") self.pending_selected_button.setCheckable(True) self.button_group = QtGui.QButtonGroup() self.button_group.addButton(self.approve_selected_button) self.button_group.addButton(self.reject_selected_button) self.button_group.addButton(self.pending_selected_button) self.button_group.setExclusive(True) self.approval_comment_label = QtGui.QLabel("Approval\\Rejection Comment:") self.rejection_comment_lineedit = QtGui.QLineEdit() self.leave_table = CopiableQTableWidget(0, 0) self.status_label = QtGui.QLabel("Status") self.status_combobox = QtGui.QComboBox() self.status_combobox.addItems(["Working","Leave"]) self.comment_label = QtGui.QLabel("Comment") self.comment_lineedit = QtGui.QLineEdit() self.save_selected_button = QtGui.QPushButton("Save") self.save_selected_button.setEnabled(False) self.save_all_button = QtGui.QPushButton("Save All") row_1 = QtGui.QHBoxLayout() row_1.addWidget(self.date_label,0) row_1.addWidget(self.start_date,0) row_1.addWidget(self.end_date,0) row_1.addWidget(self.employees_label,0) row_1.addWidget(self.employees_selection_box,0) row_1.addWidget(self.all_button,0) row_1.addWidget(self.clear_button,0) self.relaxation_label = QtGui.QLabel("Relaxation") self.relaxation_spinbox = QtGui.QDoubleSpinBox() self.relaxation_spinbox.setSuffix("%") row_2 = QtGui.QHBoxLayout() row_2.addWidget(self.status_label, 0) row_2.addWidget(self.status_combobox, 0) row_2.addWidget(self.relaxation_label, 0) row_2.addWidget(self.relaxation_spinbox, 0) row_2.addWidget(self.comment_label, 0) row_2.addWidget(self.comment_lineedit, 0) row_3 = QtGui.QHBoxLayout() row_3.addWidget(self.approval_comment_label,0) row_3.addWidget(self.rejection_comment_lineedit,0) row_3.addWidget(self.approve_selected_button,0) row_3.addWidget(self.reject_selected_button,0) row_3.addWidget(self.pending_selected_button,0) row_3.addWidget(self.save_selected_button,0) row_3.addWidget(self.save_all_button,0) row_3.addWidget(self.refresh_table_button,0) layout = QtGui.QVBoxLayout() layout.addLayout(row_1) layout.addLayout(row_2) layout.addLayout(row_3) layout.addWidget(self.leave_table) self.setLayout(layout) self.setWindowTitle("Leaves Manager") self.setWindowIcon(QtGui.QIcon(os.path.join(MOSES.getPathToImages(),"PORK_Icon.png"))) self.show()
class LeaveApproval(QtGui.QWidget): def __init__(self, user_id, password, *args, **kwargs): super(LeaveApproval, self).__init__(*args, **kwargs) self.user_id, self.password = user_id, password self.work_calendar = None self.selected_name = False self.createUI() self.initiate() self.mapEvents() self.applyFilters() def createUI(self): self.date_label = QtGui.QLabel("Date(s):") self.start_date = FormattedDateEdit() self.end_date = FormattedDateEdit() self.employees_label = QtGui.QLabel("Employees:") self.employees_selection_box = CheckableComboBox("Employees") self.all_button = QtGui.QPushButton("Select All") self.clear_button = QtGui.QPushButton("Clear") self.refresh_table_button = QtGui.QPushButton("Refresh Table") self.approve_selected_button = QtGui.QPushButton("Approved") self.approve_selected_button.setCheckable(True) self.reject_selected_button = QtGui.QPushButton("Rejected") self.reject_selected_button.setCheckable(True) self.pending_selected_button = QtGui.QPushButton("Pending") self.pending_selected_button.setCheckable(True) self.button_group = QtGui.QButtonGroup() self.button_group.addButton(self.approve_selected_button) self.button_group.addButton(self.reject_selected_button) self.button_group.addButton(self.pending_selected_button) self.button_group.setExclusive(True) self.approval_comment_label = QtGui.QLabel("Approval\\Rejection Comment:") self.rejection_comment_lineedit = QtGui.QLineEdit() self.leave_table = CopiableQTableWidget(0, 0) self.status_label = QtGui.QLabel("Status") self.status_combobox = QtGui.QComboBox() self.status_combobox.addItems(["Working","Leave"]) self.comment_label = QtGui.QLabel("Comment") self.comment_lineedit = QtGui.QLineEdit() self.save_selected_button = QtGui.QPushButton("Save") self.save_selected_button.setEnabled(False) self.save_all_button = QtGui.QPushButton("Save All") row_1 = QtGui.QHBoxLayout() row_1.addWidget(self.date_label,0) row_1.addWidget(self.start_date,0) row_1.addWidget(self.end_date,0) row_1.addWidget(self.employees_label,0) row_1.addWidget(self.employees_selection_box,0) row_1.addWidget(self.all_button,0) row_1.addWidget(self.clear_button,0) self.relaxation_label = QtGui.QLabel("Relaxation") self.relaxation_spinbox = QtGui.QDoubleSpinBox() self.relaxation_spinbox.setSuffix("%") row_2 = QtGui.QHBoxLayout() row_2.addWidget(self.status_label, 0) row_2.addWidget(self.status_combobox, 0) row_2.addWidget(self.relaxation_label, 0) row_2.addWidget(self.relaxation_spinbox, 0) row_2.addWidget(self.comment_label, 0) row_2.addWidget(self.comment_lineedit, 0) row_3 = QtGui.QHBoxLayout() row_3.addWidget(self.approval_comment_label,0) row_3.addWidget(self.rejection_comment_lineedit,0) row_3.addWidget(self.approve_selected_button,0) row_3.addWidget(self.reject_selected_button,0) row_3.addWidget(self.pending_selected_button,0) row_3.addWidget(self.save_selected_button,0) row_3.addWidget(self.save_all_button,0) row_3.addWidget(self.refresh_table_button,0) layout = QtGui.QVBoxLayout() layout.addLayout(row_1) layout.addLayout(row_2) layout.addLayout(row_3) layout.addWidget(self.leave_table) self.setLayout(layout) self.setWindowTitle("Leaves Manager") self.setWindowIcon(QtGui.QIcon(os.path.join(MOSES.getPathToImages(),"PORK_Icon.png"))) self.show() def mapEvents(self): self.start_date.dateChanged.connect(self.startDateChanged) self.end_date.dateChanged.connect(self.applyFilters) self.refresh_table_button.clicked.connect(self.applyFilters) self.clear_button.clicked.connect(self.employees_selection_box.clearSelection) self.leave_table.currentCellChanged.connect(self.populateForm) self.employees_selection_box.changedSelection.connect(self.applyFilters) self.save_selected_button.clicked.connect(self.saveSelected) self.save_all_button.clicked.connect(self.saveAll) self.all_button.clicked.connect(self.employees_selection_box.selectAll) def saveSelected(self): if self.selected_name: self.saveThese([self.selected_name]) else: self.alertMessage("Select a row","Select a row in the work calendar and then try again.") self.save_selected_button.setEnabled(False) def saveAll(self): self.saveThese(self.employees_selection_box.getCheckedItems()) def saveThese(self, selected_names): selected_employee_ids = [list(self.employees_list[self.employees_list["Name"] == x]["Employee ID"])[0] for x in selected_names] dates = [self.start_date.date().toPyDate(), self.end_date.date().toPyDate()] allow_continue = False if (len(selected_employee_ids)>1) and (dates[0] == dates[1]): ask = QtGui.QMessageBox.question(self, 'Multiple Employees Selected!', "You appear to have chosen the ids of several employees. Click yes if you'd like to continue modifying the work calendar for all their names. If not, click no and select only one employee's name.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if ask == QtGui.QMessageBox.Yes: allow_continue = True elif (len(selected_employee_ids) > 1) and (dates[0] < dates[1]): ask = QtGui.QMessageBox.question(self, 'Multiple Dates and Employees Selected!', "You appear to have chosen the ids of several employees and an entire date range. Are you sure that you want to apply the settings for all of them for all these dates? I'd recommend changing the status of one employee for one date at a time. Click yes if you'd like to continue modifying the work calendar for all their names for those dates. If not, click no and select only one employee's name and one date.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if ask == QtGui.QMessageBox.Yes: allow_continue = True elif (len(selected_employee_ids) == 1) and (dates[0] < dates[1]): ask = QtGui.QMessageBox.question(self, 'Multiple Dates Selected!', "You appear to have chosen an entire date range. Are you sure that you want to apply the settings for the selected employee all these dates? I'd recommend changing the status of one employee for one date at a time. Click yes if you'd like to continue modifying the work calendar for all their names for those dates. If not, click no and select only one date.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if ask == QtGui.QMessageBox.Yes: allow_continue = True elif (len(selected_employee_ids) <= 0): self.alertMessage('No Employees Selected!', "Please select an employee in order to process the work status and relaxation.") else: allow_continue = True if allow_continue: status = str(self.status_combobox.currentText()) relaxation = self.relaxation_spinbox.value()/100 comment = str(self.comment_lineedit.text()) if self.approve_selected_button.isChecked(): approval = "Approved" elif self.reject_selected_button.isChecked(): approval = "Rejected" else: approval = "Pending" approval_comment = str(self.rejection_comment_lineedit.text()) self.alertMessage("Please Wait","This could take a while. Click OK and hold on to your horses.") update = MOSES.updateWorkCalendarFor(self.user_id, self.password, status, relaxation, comment, approval, approval_comment, dates, selected_employee_ids) if update: self.alertMessage("Success","Successfully updated the Work Calendar") self.applyFilters() else: self.alertMessage("Failure","Failed in updating the Work Calendar") else: print "Not allowed to continue" def initiate(self): self.start_date.setDate(datetime.date.today()) self.start_date.setMinimumDate(datetime.date(2015,1,1)) self.end_date.setDate(self.start_date.date()) self.end_date.setMinimumDate(self.start_date.date()) self.employees_list = MOSES.getEmployeesList(self.user_id, self.password, self.end_date.date().toPyDate()) self.employees_selection_box.clear() self.employees_selection_box.addItems(sorted(list(self.employees_list["Name"]))) self.employees_selection_box.selectAll() def applyFilters(self): self.leave_table.showDataFrame(None) selected_employee_ids = [list(self.employees_list[self.employees_list["Name"] == x]["Employee ID"])[0] for x in self.employees_selection_box.getCheckedItems()] if len(selected_employee_ids)<=0: self.alertMessage("No Employees Selected","Select at least one employee!") else: filter_dict = { "Dates": [self.start_date.date().toPyDate(), self.end_date.date().toPyDate()], "Employee IDs": selected_employee_ids } time_diff = (filter_dict["Dates"][1] - filter_dict["Dates"][0]) if datetime.timedelta(days=5) < time_diff < datetime.timedelta(days=30): self.alertMessage("Please Wait","The work calendar is being refreshed. This may take a while since you've selected over a week's worth of data.") elif time_diff >= datetime.timedelta(days=30): self.alertMessage("Please Wait","The work calendar is being refreshed. This will take quite some time longer than usual since you've selected a date range wider than or equal to 30 days.") self.work_calendar = MOSES.getWorkCalendarFor(self.user_id, self.password, filter_dict) self.alertMessage("Success","Retrieved the Work Calendar") yellow = QtGui.QColor(200,200,0) green = QtGui.QColor(0,153,0) red = QtGui.QColor(170,0,0) highlight_rules = [ { "Columns": ["Status","Approval"], "Values": ["Leave","Approved"], "Color":green }, { "Columns": ["Status","Approval"], "Values": ["Leave","Pending"], "Color": yellow }, { "Columns": ["Status","Approval"], "Values": ["Leave","Rejected"], "Color": red }, { "Columns": ["Relaxation","Approval"], "Values": [[0.01,1.00],"Approved"], "Color": green }, { "Columns": ["Relaxation","Approval"], "Values": [[0.01,1.00],"Pending"], "Color": yellow }, { "Columns": ["Relaxation","Approval"], "Values": [[0.01,1.00],"Rejected"], "Color": red } ] self.leave_table.showDataFrame(self.work_calendar,highlight_rules) self.leave_table.setSortingEnabled(False) def startDateChanged(self): self.end_date.setDate(self.start_date.date()) self.end_date.setMinimumDate(self.start_date.date()) self.applyFilters() def populateForm(self, row=None, column=None): if self.work_calendar is not None: #rows = sorted(set(index.row() for index in self.leave_table.selectedIndexes())) try: selected_row = self.work_calendar.loc[row] self.selected_name = selected_row["Employee Name"] status = selected_row["Status"] relaxation = selected_row["Relaxation"] comment = selected_row["Comment"] approval = selected_row["Approval"] rejection_comment = selected_row["Rejection Comment"] date_ = selected_row["Date"] self.save_selected_button.setText("Save %s's entry"%self.selected_name) self.save_selected_button.setEnabled(True) except: self.selected_name = None self.save_selected_button.setText("Save Selected") self.save_selected_button.setEnabled(False) comment = "" relaxation = 0.0 rejection_comment = "" status = "Working" approval = "Pending" self.comment_lineedit.setText(comment if comment is not None else "") self.status_combobox.setCurrentIndex(self.status_combobox.findText(status)) self.rejection_comment_lineedit.setText(rejection_comment if rejection_comment is not None else "") self.relaxation_spinbox.setValue((relaxation*100)) if approval is not None: if approval == "Approved": self.approve_selected_button.setChecked(True) elif approval == "Rejected": self.reject_selected_button.setChecked(True) else: self.pending_selected_button.setChecked(True) else: print "Approval is None!" def alertMessage(self, title, message): QtGui.QMessageBox.about(self, title, message)
class OverrideTool(QtGui.QWidget): """Opens an override dialog.""" def __init__(self, user_id, password): """""" super(OverrideTool, self).__init__() self.user_id = user_id self.password = password self.getOverrideTable() self.createUI() self.mapEvents() self.override_date.setDate(datetime.date.today()) #self.getFSNs() def getOverrideTable(self): self.override_table = MOSES.getOverrideTable(self.user_id, self.password) def createUI(self): self.fsn_text_edit = FSNTextEdit() self.override_date = FormattedDateEdit() self.override_logo = ImageButton( os.path.join(MOSES.getPathToImages(), "override.png"), 64, 64, os.path.join(MOSES.getPathToImages(), "override_mouseover.png")) self.override_logo.setFlat(True) self.override_logo.setToolTip( "If you can't do something once, do it again, and again.") self.override_button = QtGui.QPushButton("Override") self.override_comment_label = QtGui.QLabel("Reason:") self.override_comment_field = QtGui.QLineEdit() self.override_comment_field.setToolTip( "Enter a reason for the override here.") self.data_tabulator = CopiableQTableWidget() column2 = QtGui.QVBoxLayout() column2.addWidget(self.override_logo, 1, QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop) column2.addWidget(self.override_date, 1) column2.addWidget(self.override_button, 1) column2.addWidget(self.override_comment_label, 1) column2.addWidget(self.override_comment_field, 1) column2.addStretch(2) options_layout = QtGui.QHBoxLayout() options_layout.addWidget(self.fsn_text_edit, 2, QtCore.Qt.AlignTop) options_layout.addLayout(column2, 1) layout = QtGui.QVBoxLayout() layout.addLayout(options_layout, 1) layout.addWidget(self.data_tabulator, 3) self.setLayout(layout) self.setWindowIcon( QtGui.QIcon(os.path.join(MOSES.getPathToImages(), "PORK_Icon.png"))) self.setWindowTitle("Override Tool") self.show() def mapEvents(self): """""" self.override_button.clicked.connect(self.createOverride) self.override_date.dateChanged.connect(self.changedDate) def changedDate(self): query_date = self.override_date.date().toPyDate() resultant_data_frame = self.override_table[ self.override_table["Override Date"] == query_date] self.showDataFrame(resultant_data_frame) def showDataFrame(self, data_frame): self.data_tabulator.showDataFrame(data_frame) self.data_tabulator.verticalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.data_tabulator.verticalHeader().setStretchLastSection(False) self.data_tabulator.verticalHeader().setVisible(True) self.data_tabulator.horizontalHeader().setResizeMode( QtGui.QHeaderView.ResizeToContents) self.data_tabulator.horizontalHeader().setStretchLastSection(False) self.data_tabulator.horizontalHeader().setVisible(True) def createOverride(self): """""" fsn_list = self.fsn_text_edit.getFSNs() if len(fsn_list) > 0: comment = str(self.override_comment_field.text()).strip() if len(comment) == 0: self.ask_comment = QtGui.QMessageBox.question( self, 'No reason for override?', "Hi there! You seem to be trying to override an FSN without giving a reason for doing so. Are you sure you want to do that? If you don't want to type a reason, go on ahead. I suggest typing one, because you'll have a neat record of that here.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if self.ask_comment == QtGui.QMessageBox.Yes: allow = True else: allow = False else: allow = True if allow: self.override_button.setEnabled(False) if len(fsn_list) > 1: self.alertMessage( "Please Wait", "Looks like you're trying to override more than one FSN so this step could take a second or a minute, though definitely not more than that. Please wait, and remember, <i>Roma die uno non aedificata est</i>." ) failures = [] for FSN in fsn_list: trial_status = MOSES.addOverride( FSN, self.override_date.date().toPyDate(), self.user_id, self.password, comment) if not trial_status: failures.append(FSN) if len(failures) == 0: self.alertMessage( "Success!", "Successfully overrided the requested %d FSN(s)." % len(fsn_list)) else: self.alertMessage( "Failed!", "Failed in overriding %d of the %d FSN(s)." % (len(failures), len(fsn_list))) self.getOverrideTable() self.changedDate() else: self.alertMessage( "No FSNs Provided", "You don't seem to have pasted any valid FSNs. Could you try that again?" ) self.override_button.setEnabled(True) return True def alertMessage(self, title, message): QtGui.QMessageBox.about(self, title, message)
def createUI(self): self.users_list_label = QtGui.QLabel("Users: ") self.users_list_view = QtGui.QListWidget() self.add_employee_button = ImageButton( os.path.join("Images","add.png"), 48, 48, os.path.join("Images","add_mouseover.png") ) self.edit_employee_button = ImageButton( os.path.join("Images","modify.png"), 48, 48, os.path.join("Images","modify_mouseover.png") ) self.edit_employee_button.setCheckable(True) self.add_employee_button.setCheckable(True) self.button_group = QtGui.QButtonGroup() self.button_group.addButton(self.edit_employee_button) self.button_group.addButton(self.add_employee_button) self.button_group.setExclusive(True) user_list_buttons_layout = QtGui.QHBoxLayout() user_list_buttons_layout.addWidget(self.add_employee_button,0) user_list_buttons_layout.addWidget(self.edit_employee_button,0) users_list_layout = QtGui.QVBoxLayout() users_list_layout.addWidget(self.users_list_label,0) users_list_layout.addWidget(self.users_list_view,3) users_list_layout.addLayout(user_list_buttons_layout,1) users_list_layout.addStretch(1) self.employee_id_label = QtGui.QLabel("Employee ID") self.employee_id_lineedit = QtGui.QLineEdit() self.employee_name_label = QtGui.QLabel("Name") self.employee_name_lineedit = QtGui.QLineEdit() name_id_row = QtGui.QHBoxLayout() name_id_row.addWidget(self.employee_id_label,0) name_id_row.addWidget(self.employee_id_lineedit,2) name_id_row.addWidget(self.employee_name_label,0) name_id_row.addWidget(self.employee_name_lineedit,2) self.email_label = QtGui.QLabel("Email ID:") self.email_lineedit = QtGui.QLineEdit() email_row = QtGui.QHBoxLayout() email_row.addWidget(self.email_label,0) email_row.addWidget(self.email_lineedit,2) self.current_role_label = QtGui.QLabel("Role:") self.current_role_combobox = QtGui.QComboBox() current_role_row = QtGui.QHBoxLayout() current_role_row.addWidget(self.current_role_label,0) current_role_row.addWidget(self.current_role_combobox,1) self.doj_label = QtGui.QLabel("Date of Joining:") self.doj_dateedit = FormattedDateEdit() self.dol_checkbox = QtGui.QCheckBox("Last Working Date:") self.dol_checkbox.setToolTip("Check to mark the LWD of this employee.\nLeave unchecked if the employee is still in the team.") self.dol_dateedit = FormattedDateEdit() self.doj_dateedit.setCalendarPopup(True) self.dol_dateedit.setCalendarPopup(True) doj_dol_row = QtGui.QHBoxLayout() doj_dol_row.addWidget(self.doj_label, 0) doj_dol_row.addWidget(self.doj_dateedit, 0) doj_dol_row.addWidget(self.dol_checkbox, 0) doj_dol_row.addWidget(self.dol_dateedit, 0) self.former_role_label = QtGui.QLabel("Former Role:") self.former_role_combobox = QtGui.QComboBox() self.dop_checkbox = QtGui.QCheckBox("Promoted") self.dop_checkbox.setToolTip("Check this to record a promotion and keep details of the former role.") self.dop_label = QtGui.QLabel("Date of Promotion:") self.dop_dateedit = FormattedDateEdit() self.dop_dateedit.setCalendarPopup(True) promotion_row = QtGui.QHBoxLayout() promotion_row.addWidget(self.dop_checkbox, 0) promotion_row.addWidget(self.dop_label, 0) promotion_row.addWidget(self.dop_dateedit, 1) promotion_row.addWidget(self.former_role_label, 0) promotion_row.addWidget(self.former_role_combobox, 1) self.access_label = QtGui.QLabel("OINK Application Access") self.access_combobox = CheckableComboBox("Applications") self.access_combobox.addItems(["PORK","BACON","VINDALOO"]) access_row = QtGui.QHBoxLayout() access_row.addWidget(self.access_label,0) access_row.addWidget(self.access_combobox,2) access_row.addStretch(1) self.reset_password_button = QtGui.QPushButton("Reset Password") self.save_button = QtGui.QPushButton("Save") self.reset_button = QtGui.QPushButton("Revert") form_buttons_layout = QtGui.QHBoxLayout() form_buttons_layout.addStretch(2) form_buttons_layout.addWidget(self.reset_password_button,0) form_buttons_layout.addWidget(self.save_button,0) form_buttons_layout.addWidget(self.reset_button,0) self.progress_bar = ProgressBar() self.status_label = QtGui.QLabel() self.manager_mapping = CopiableQTableWidget(0,0) self.manager_name_label = QtGui.QLabel("Reporting Manager:") self.manager_name_combobox = QtGui.QComboBox() self.manager_effective_date_label = QtGui.QLabel("Revision Date:") self.manager_effective_dateedit = FormattedDateEdit() self.manager_effective_dateedit.setDate(datetime.date.today()) self.manager_effective_dateedit.setCalendarPopup(True) self.add_new_manager_mapping_row = QtGui.QPushButton("Add or Update") self.remove_manager_mapping_row = QtGui.QPushButton("Remove") manager_mapping_form = QtGui.QHBoxLayout() manager_mapping_form.addWidget(self.manager_name_label,0) manager_mapping_form.addWidget(self.manager_name_combobox,2) manager_mapping_form.addWidget(self.manager_effective_date_label,0) manager_mapping_form.addWidget(self.manager_effective_dateedit,1) manager_mapping_form.addWidget(self.add_new_manager_mapping_row,0) manager_mapping_form.addWidget(self.remove_manager_mapping_row,0) user_data_form_layout = QtGui.QVBoxLayout() user_data_form_layout.addLayout(name_id_row,0) user_data_form_layout.addLayout(email_row,0) user_data_form_layout.addLayout(current_role_row,0) user_data_form_layout.addLayout(doj_dol_row,0) user_data_form_layout.addLayout(promotion_row,0) user_data_form_layout.addLayout(access_row,0) user_data_form_layout.addLayout(form_buttons_layout,0) user_data_form_layout.addWidget(self.manager_mapping,1) user_data_form_layout.addLayout(manager_mapping_form,0) user_data_form_layout.addStretch(1) user_data_form_layout.addWidget(self.progress_bar,0) user_data_form_layout.addWidget(self.status_label,0) user_data_form = QtGui.QGroupBox("User Information:") user_data_form.setLayout(user_data_form_layout) layout = QtGui.QHBoxLayout() layout.addLayout(users_list_layout,1) layout.addWidget(user_data_form,2) self.central_widget = QtGui.QWidget() self.central_widget.setLayout(layout) self.setCentralWidget(self.central_widget) self.setWindowTitle("OINK User Manager") self.setWindowIcon(QtGui.QIcon(os.path.join('Images','PORK_Icon.png'))) self.show()
class UserManager(QtGui.QMainWindow): def __init__(self, user_id, password,*args, **kwargs): super(UserManager, self).__init__(*args, **kwargs) self.user_id, self.password = user_id, password #get the list of users from MOSES. self.refreshData() self.createUI() self.mapEvents() self.initialize() def refreshData(self): self.employees_data = MOSES.getEmployeesList(self.user_id, self.password) self.manager_mapping_data = MOSES.getManagerMappingTable(self.user_id, self.password) def createUI(self): self.users_list_label = QtGui.QLabel("Users: ") self.users_list_view = QtGui.QListWidget() self.add_employee_button = ImageButton( os.path.join("Images","add.png"), 48, 48, os.path.join("Images","add_mouseover.png") ) self.edit_employee_button = ImageButton( os.path.join("Images","modify.png"), 48, 48, os.path.join("Images","modify_mouseover.png") ) self.edit_employee_button.setCheckable(True) self.add_employee_button.setCheckable(True) self.button_group = QtGui.QButtonGroup() self.button_group.addButton(self.edit_employee_button) self.button_group.addButton(self.add_employee_button) self.button_group.setExclusive(True) user_list_buttons_layout = QtGui.QHBoxLayout() user_list_buttons_layout.addWidget(self.add_employee_button,0) user_list_buttons_layout.addWidget(self.edit_employee_button,0) users_list_layout = QtGui.QVBoxLayout() users_list_layout.addWidget(self.users_list_label,0) users_list_layout.addWidget(self.users_list_view,3) users_list_layout.addLayout(user_list_buttons_layout,1) users_list_layout.addStretch(1) self.employee_id_label = QtGui.QLabel("Employee ID") self.employee_id_lineedit = QtGui.QLineEdit() self.employee_name_label = QtGui.QLabel("Name") self.employee_name_lineedit = QtGui.QLineEdit() name_id_row = QtGui.QHBoxLayout() name_id_row.addWidget(self.employee_id_label,0) name_id_row.addWidget(self.employee_id_lineedit,2) name_id_row.addWidget(self.employee_name_label,0) name_id_row.addWidget(self.employee_name_lineedit,2) self.email_label = QtGui.QLabel("Email ID:") self.email_lineedit = QtGui.QLineEdit() email_row = QtGui.QHBoxLayout() email_row.addWidget(self.email_label,0) email_row.addWidget(self.email_lineedit,2) self.current_role_label = QtGui.QLabel("Role:") self.current_role_combobox = QtGui.QComboBox() current_role_row = QtGui.QHBoxLayout() current_role_row.addWidget(self.current_role_label,0) current_role_row.addWidget(self.current_role_combobox,1) self.doj_label = QtGui.QLabel("Date of Joining:") self.doj_dateedit = FormattedDateEdit() self.dol_checkbox = QtGui.QCheckBox("Last Working Date:") self.dol_checkbox.setToolTip("Check to mark the LWD of this employee.\nLeave unchecked if the employee is still in the team.") self.dol_dateedit = FormattedDateEdit() self.doj_dateedit.setCalendarPopup(True) self.dol_dateedit.setCalendarPopup(True) doj_dol_row = QtGui.QHBoxLayout() doj_dol_row.addWidget(self.doj_label, 0) doj_dol_row.addWidget(self.doj_dateedit, 0) doj_dol_row.addWidget(self.dol_checkbox, 0) doj_dol_row.addWidget(self.dol_dateedit, 0) self.former_role_label = QtGui.QLabel("Former Role:") self.former_role_combobox = QtGui.QComboBox() self.dop_checkbox = QtGui.QCheckBox("Promoted") self.dop_checkbox.setToolTip("Check this to record a promotion and keep details of the former role.") self.dop_label = QtGui.QLabel("Date of Promotion:") self.dop_dateedit = FormattedDateEdit() self.dop_dateedit.setCalendarPopup(True) promotion_row = QtGui.QHBoxLayout() promotion_row.addWidget(self.dop_checkbox, 0) promotion_row.addWidget(self.dop_label, 0) promotion_row.addWidget(self.dop_dateedit, 1) promotion_row.addWidget(self.former_role_label, 0) promotion_row.addWidget(self.former_role_combobox, 1) self.access_label = QtGui.QLabel("OINK Application Access") self.access_combobox = CheckableComboBox("Applications") self.access_combobox.addItems(["PORK","BACON","VINDALOO"]) access_row = QtGui.QHBoxLayout() access_row.addWidget(self.access_label,0) access_row.addWidget(self.access_combobox,2) access_row.addStretch(1) self.reset_password_button = QtGui.QPushButton("Reset Password") self.save_button = QtGui.QPushButton("Save") self.reset_button = QtGui.QPushButton("Revert") form_buttons_layout = QtGui.QHBoxLayout() form_buttons_layout.addStretch(2) form_buttons_layout.addWidget(self.reset_password_button,0) form_buttons_layout.addWidget(self.save_button,0) form_buttons_layout.addWidget(self.reset_button,0) self.progress_bar = ProgressBar() self.status_label = QtGui.QLabel() self.manager_mapping = CopiableQTableWidget(0,0) self.manager_name_label = QtGui.QLabel("Reporting Manager:") self.manager_name_combobox = QtGui.QComboBox() self.manager_effective_date_label = QtGui.QLabel("Revision Date:") self.manager_effective_dateedit = FormattedDateEdit() self.manager_effective_dateedit.setDate(datetime.date.today()) self.manager_effective_dateedit.setCalendarPopup(True) self.add_new_manager_mapping_row = QtGui.QPushButton("Add or Update") self.remove_manager_mapping_row = QtGui.QPushButton("Remove") manager_mapping_form = QtGui.QHBoxLayout() manager_mapping_form.addWidget(self.manager_name_label,0) manager_mapping_form.addWidget(self.manager_name_combobox,2) manager_mapping_form.addWidget(self.manager_effective_date_label,0) manager_mapping_form.addWidget(self.manager_effective_dateedit,1) manager_mapping_form.addWidget(self.add_new_manager_mapping_row,0) manager_mapping_form.addWidget(self.remove_manager_mapping_row,0) user_data_form_layout = QtGui.QVBoxLayout() user_data_form_layout.addLayout(name_id_row,0) user_data_form_layout.addLayout(email_row,0) user_data_form_layout.addLayout(current_role_row,0) user_data_form_layout.addLayout(doj_dol_row,0) user_data_form_layout.addLayout(promotion_row,0) user_data_form_layout.addLayout(access_row,0) user_data_form_layout.addLayout(form_buttons_layout,0) user_data_form_layout.addWidget(self.manager_mapping,1) user_data_form_layout.addLayout(manager_mapping_form,0) user_data_form_layout.addStretch(1) user_data_form_layout.addWidget(self.progress_bar,0) user_data_form_layout.addWidget(self.status_label,0) user_data_form = QtGui.QGroupBox("User Information:") user_data_form.setLayout(user_data_form_layout) layout = QtGui.QHBoxLayout() layout.addLayout(users_list_layout,1) layout.addWidget(user_data_form,2) self.central_widget = QtGui.QWidget() self.central_widget.setLayout(layout) self.setCentralWidget(self.central_widget) self.setWindowTitle("OINK User Manager") self.setWindowIcon(QtGui.QIcon(os.path.join('Images','PORK_Icon.png'))) self.show() def mapEvents(self): self.users_list_view.itemSelectionChanged.connect(self.changedCurrentEmployee) self.dop_checkbox.toggled.connect(self.toggleDOP) self.dol_checkbox.toggled.connect(self.toggleDOL) self.reset_password_button.clicked.connect(self.resetPassword) self.manager_mapping.currentCellChanged.connect(self.populateManagerMappingForm) self.add_new_manager_mapping_row.clicked.connect(self.addUpdateManagerMapping) self.remove_manager_mapping_row.clicked.connect(self.removeManagerMapping) self.save_button.clicked.connect(self.saveSelectedEmployee) self.reset_button.clicked.connect(self.changedCurrentEmployee) self.add_employee_button.clicked.connect(self.changeMode) self.edit_employee_button.clicked.connect(self.changeMode) def saveSelectedEmployee(self): #First, build a dictionary with the former values. #Then, build a dictionary with the new values. #pass these dictionaries to a MOSES function. employee_id = str(self.employee_id_lineedit.text()).strip() employee_name = str(self.employee_name_lineedit.text()).strip() employee_email_id = str(self.email_lineedit.text()).strip() employee_role = str(self.current_role_combobox.currentText()).strip() employee_doj = self.doj_dateedit.date().toPyDate() employee_dol = self.dol_dateedit.date().toPyDate() if self.dol_checkbox.isChecked() else "NULL" employee_dop = self.dop_dateedit.date().toPyDate() if self.dop_checkbox.isChecked() else "NULL" employee_former_role = str(self.former_role_combobox.currentText()).strip() if self.dop_checkbox.isChecked() else "NULL" employee_oink_access = str(",".join(self.access_combobox.getCheckedItems())) if len(self.access_combobox.getCheckedItems())>0 else "Pork" if self.add_employee_button.isChecked(): mode = 1 else: mode = 0 if (employee_id in list(self.employees_data["Employee ID"])) and (mode == 1): self.alertMessage("Conflicting User ID","The User ID %s already exists in the system. You can't add another user with that Employee ID."%employee_id) else: employee_dict = { "Employee ID": employee_id, "Name": employee_name, "Email ID": employee_email_id, "Role": employee_role, "DOJ": employee_doj, "DOL": employee_dol, "Date of Promotion": employee_dop, "Former Role": employee_former_role, "OINK Access Level": ",".join(employee_oink_access) if type(employee_oink_access) == list else employee_oink_access } success = MOSES.createOrModifyEmployeeDetails(self.user_id, self.password, employee_dict, mode) if success: self.refreshData() self.initialize() self.populateEmployeesList() self.alertMessage("Success","Successfully completed the operation") else: self.alertMessage("Failure","Revenge is just the beginning.") def changeMode(self): if self.add_employee_button.isChecked(): self.employee_id_lineedit.setEnabled(True) elif self.edit_employee_button.isChecked(): self.employee_id_lineedit.setEnabled(False) def removeManagerMapping(self): failure = True employee_data = self.getEmployeeData(self.getSelectedEmployee()) if employee_data is not None: employee_id = employee_data["Employee ID"] reporting_manager_name = str(self.manager_name_combobox.currentText()) reporting_manager_data = self.getEmployeeData(reporting_manager_name) if reporting_manager_data is not None: reporting_manager_id = reporting_manager_data["Employee ID"] revision_date = self.manager_effective_dateedit.date().toPyDate() MOSES.removeFromManagerMapping(self.user_id, self.password, employee_id, reporting_manager_id, revision_date) self.changedCurrentEmployee() failure = False else: failure = True else: failure = True if failure: self.alertMessage("Failure","Please select a row that you'd like to delete. If you're having problems, select a cell in another row, then select a cell in the row you'd like to delete.") else: self.alertMessage("Success","Successfully removed a row from the Manager Mapping Table with the selected parameters.") def addUpdateManagerMapping(self): employee_id = self.getEmployeeData(self.getSelectedEmployee())["Employee ID"] reporting_manager_name = str(self.manager_name_combobox.currentText()) reporting_manager_id = self.getEmployeeData(reporting_manager_name)["Employee ID"] revision_date = self.manager_effective_dateedit.date().toPyDate() MOSES.addUpdateManagerMapping(self.user_id, self.password, employee_id, reporting_manager_id, revision_date) self.changedCurrentEmployee() self.alertMessage("Success","Successfully added a row into the Manager Mapping Table with the selected parameters.") def populateManagerMappingForm(self, row=None, column=None): rows = sorted(set(index.row() for index in self.manager_mapping.selectedIndexes())) manager = self.manager_mapping_data.loc[row] name = manager["Reporting Manager Name"] date_ = manager["Revision Date"] if name is not None: self.manager_name_combobox.setCurrentIndex(self.manager_name_combobox.findText(name)) else: self.manager_name_combobox.setCurrentIndex(-1) if date_ is not None: self.manager_effective_dateedit.setDate(date_) else: self.manager_effective_dateedit.setDate(datetime.date.today()) def resetPassword(self): current_employee_name = str(self.users_list_view.currentItem().text()) employee_data = self.getEmployeeData(current_employee_name) employee_id = employee_data["Employee ID"] MOSES.resetPassword(self.user_id, self.password, employee_id) self.alertMessage("Reset Password","Successfully reset %s's password to 'password'!"%(current_employee_name)) def alertMessage(self, title, message): QtGui.QMessageBox.about(self, title, message) def toggleDOP(self): if self.dop_checkbox.isChecked(): self.dop_dateedit.setEnabled(True) self.former_role_combobox.setEnabled(True) else: self.former_role_combobox.setCurrentIndex(-1) self.former_role_combobox.setEnabled(False) self.dop_dateedit.setEnabled(False) def toggleDOL(self): if self.dol_checkbox.isChecked(): self.dol_dateedit.setEnabled(True) else: self.dol_dateedit.setEnabled(False) def changedCurrentEmployee(self): self.showPage(self.getSelectedEmployee()) def showPage(self, employee_name): employee_data = self.getEmployeeData(employee_name) if employee_data is not None: self.employee_name_lineedit.setText(employee_data["Name"]) self.employee_id_lineedit.setText(employee_data["Employee ID"]) self.email_lineedit.setText(employee_data["Email ID"]) self.doj_dateedit.setDate(employee_data["DOJ"]) if employee_data["DOL"] is None: self.dol_checkbox.setChecked(False) else: self.dol_checkbox.setChecked(True) self.dol_dateedit.setDate(employee_data["DOL"]) self.current_role_combobox.setCurrentIndex(self.current_role_combobox.findText(employee_data["Role"])) if employee_data["Date of Promotion"] is None: self.dop_checkbox.setChecked(False) self.former_role_combobox.setCurrentIndex(-1) else: self.dop_checkbox.setChecked(True) self.dop_dateedit.setDate(employee_data["Date of Promotion"]) self.former_role_combobox.setCurrentIndex(self.former_role_combobox.findText(employee_data["Former Role"])) self.access_combobox.clearSelection() access_level = employee_data["Access Level"] if "," not in employee_data["Access Level"] else employee_data["Access Level"].split(",") self.access_combobox.select(access_level) self.toggleDOP() self.toggleDOL() self.manager_mapping_data = MOSES.getManagerMappingTable(self.user_id, self.password, employee_data["Employee ID"]) self.manager_mapping.showDataFrame(self.manager_mapping_data) self.manager_mapping.verticalHeader().setStretchLastSection(False) self.manager_mapping.verticalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.manager_mapping.verticalHeader().setVisible(True) self.manager_mapping.horizontalHeader().setStretchLastSection(True) self.manager_mapping.horizontalHeader().setResizeMode(QtGui.QHeaderView.ResizeToContents) self.manager_mapping.horizontalHeader().setResizeMode(QtGui.QHeaderView.Interactive) self.manager_mapping.horizontalHeader().setVisible(True) self.manager_mapping.horizontalHeader().setStretchLastSection(False) self.manager_name_combobox.setCurrentIndex(-1) def getSelectedEmployee(self): return str(self.users_list_view.currentItem().text()) def getEmployeeData(self, employee_name): location_match = self.employees_data["Name"] == employee_name if True in set(location_match): employee_id = list(self.employees_data[location_match]["Employee ID"])[0] employee_name = list(self.employees_data[location_match]["Name"])[0] employee_email_id = list(self.employees_data[location_match]["Email ID"])[0] employee_doj = list(self.employees_data[location_match]["DOJ"])[0] employee_dol = list(self.employees_data[location_match]["DOL"])[0] employee_role = list(self.employees_data[location_match]["Role"])[0] employee_dop = list(self.employees_data[location_match]["Date of Promotion"])[0] employee_former_role = list(self.employees_data[location_match]["Former Role"])[0] employee_oink_access = list(self.employees_data[location_match]["OINK Access Level"])[0] data = { "Employee ID": employee_id, "Name": employee_name, "Email ID": employee_email_id, "DOJ": employee_doj, "DOL": employee_dol, "Role": employee_role, "Date of Promotion": employee_dop, "Former Role": employee_former_role, "Access Level": employee_oink_access } else: data = None return data def initialize(self): employees_list = list(set(self.employees_data["Name"])) employees_list.sort() self.users_list_view.clear() self.users_list_view.addItems(employees_list) self.manager_name_combobox.clear() self.manager_name_combobox.addItems(employees_list) roles = list(set(self.employees_data["Role"])) roles.sort() self.current_role_combobox.addItems(roles) self.former_role_combobox.addItems(roles) self.toggleDOL() self.toggleDOP() self.manager_name_combobox.setCurrentIndex(-1) self.manager_effective_dateedit.setDate(datetime.date.today()) self.edit_employee_button.setChecked(True) self.employee_id_lineedit.setEnabled(False) self.users_list_view.setCurrentRow(0) def populateEmployeesList(self): pass def addEmployee(self): pass def modifyEmployee(self): pass def resetEmployeePassword(self): pass def promoteEmployee(self): pass def populateReportingManagerList(self): pass
class LeavePlanner(QtGui.QWidget): def __init__(self, user_id, password): """Leave Planner.""" super(LeavePlanner, self).__init__() self.user_id = user_id self.password = password self.work_calendar = None self.createWidgets() self.mapTooltips() self.createEvents() self.createLayouts() self.setVisuals() self.start_date_edit.setDate(datetime.date.today()) def createWidgets(self): """Leave Planner: Method to create all the necessary widgets for the leave planner class.""" self.mainLabel = QtGui.QLabel("Apply for Leaves or Relaxation in Work") self.dateLabel1 = QtGui.QLabel("Start Date:") self.start_date_edit = FormattedDateEdit() self.start_date_edit.setMinimumDate(QtCore.QDate(2015,1,1)) self.start_date_edit.setCalendarPopup(True) self.dateLabel2 = QtGui.QLabel("End Date:") self.end_date_edit = FormattedDateEdit() self.end_date_edit.setMinimumDate(QtCore.QDate(2015,1,1)) self.end_date_edit.setCalendarPopup(True) self.statusLabel = QtGui.QLabel("Working Status:") self.statusComboBox = QtGui.QComboBox() self.statusComboBox.addItems(["Working","Leave"]) self.relaxationLabel = QtGui.QLabel("Work Relaxation:") self.relaxationSpinBox = QtGui.QSpinBox() self.relaxationSpinBox.setRange(0,100) self.relaxationSpinBox.setSuffix("%") self.commentLabel = QtGui.QLabel("Comments:") self.commentLineEdit = QtGui.QLineEdit() self.buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok| QtGui.QDialogButtonBox.Cancel) self.work_calendar_table = CopiableQTableWidget(0,0) def createLayouts(self): """Leave Planner: Method to create layouts.""" self.datesLayout = QtGui.QHBoxLayout() self.datesLayout.addWidget(self.dateLabel1) self.datesLayout.addWidget(self.start_date_edit) self.datesLayout.addWidget(self.dateLabel2) self.datesLayout.addWidget(self.end_date_edit) self.statusRelaxLayout = QtGui.QHBoxLayout() self.statusRelaxLayout.addWidget(self.statusLabel) self.statusRelaxLayout.addWidget(self.statusComboBox) self.statusRelaxLayout.addWidget(self.relaxationLabel) self.statusRelaxLayout.addWidget(self.relaxationSpinBox) self.commentsLayout = QtGui.QHBoxLayout() self.commentsLayout.addWidget(self.commentLabel,0) self.commentsLayout.addWidget(self.commentLineEdit,3) self.advice = QtGui.QTextEdit() self.advice.setReadOnly(True) self.advice.setText("This tool can be used to apply for leaves. However, once you apply for a leave, you can't change that. Your TL will have to. After applying for a leave, you'll have to inform your TL to approve them, or the leave won't be considered by the application. Same goes for relaxation, however, you can revert back to 0 with relaxation so long as your TL hasn't approved it yet. Also, if you ask for a relaxation of 10%, the server will record this as 0.1, this is normal.") self.advice.setMaximumHeight(100) self.advice.setStyleSheet("font: 12pt;") self.finalLayout = QtGui.QVBoxLayout() self.finalLayout.addWidget(self.mainLabel) self.finalLayout.addLayout(self.datesLayout) self.finalLayout.addLayout(self.statusRelaxLayout) self.finalLayout.addLayout(self.commentsLayout) self.finalLayout.addWidget(self.buttons) self.finalLayout.addWidget(self.work_calendar_table,3) self.finalLayout.addWidget(self.advice,0) self.setLayout(self.finalLayout) def mapTooltips(self): """Leave Planner: Maps the appropriate tooltips to the input widgets.""" self.start_date_edit.setToolTip("Select the start date for applying for leaves\nor work relaxation.") self.end_date_edit.setToolTip("Select the end date for application.\nIf you want a leave on one day, leave this field as it is.") self.statusComboBox.setToolTip("Select whether you are working on this day or if you'd like a leave.") self.relaxationSpinBox.setToolTip("Set the box to appropriate relaxation you are awarded.\nIf your TL is allowing you to report 80%% for the day, set this box to 20%%.") self.commentLineEdit.setToolTip("Type a reason why you require this leave or relaxation for future record.") def createEvents(self): """Leave Planner: Method to map events.""" self.start_date_edit.dateChanged.connect(self.limitEndDate) self.start_date_edit.dateChanged.connect(self.updateWorkCalendar) self.end_date_edit.dateChanged.connect(self.updateWorkCalendar) self.buttons.accepted.connect(self.submit) self.buttons.rejected.connect(self.reject) def setVisuals(self): """Leave Planner.""" self.resize(300,100) self.center() self.setWindowIcon(QtGui.QIcon('Images\PORK_Icon.png')) self.setWindowTitle("Leave and Work Relaxation") self.show() def center(self): """Leave Planner.""" frameGm = self.frameGeometry() screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos()) centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center() frameGm.moveCenter(centerPoint) self.move(frameGm.topLeft()) def limitEndDate(self): """Leave Planner: Method to limit the end date's minimum value to the start date.""" self.end_date_edit.setMinimumDate(self.start_date_edit.date()) def submit(self): """Leave Planner: Method to send the request to the work calendar table.""" startDate = self.start_date_edit.date().toPyDate() endDate = self.end_date_edit.date().toPyDate() status = str(self.statusComboBox.currentText()) relaxation = self.relaxationSpinBox.value() #Test this. relaxation = float(relaxation)/100.00 comment = str(self.commentLineEdit.text()) dates_list = [startDate, endDate] name = MOSES.getEmpName(self.user_id) self.alertMessage("Please Wait","This process could take a while, and OINK will appear like it has hung. Rest assured that it's running in the background. Please be patient, %s."%name) success = MOSES.askForModWorkCalendar(self.user_id, self.password, dates_list, status, relaxation, comment, name) if success: self.alertMessage("Success", "Your request has been submitted to the server. Ask your TL to approve the request.") else: self.alertMessage("Failed", "Your request could not be submitted. Ask your TL to manually mark your leaves in the server.") def updateWorkCalendar(self): self.work_calendar_table.showDataFrame(None) filter_dict = { "Dates": [self.start_date_edit.date().toPyDate(), self.end_date_edit.date().toPyDate()], "Employee IDs": [self.user_id] } self.work_calendar = MOSES.getWorkCalendarFor(self.user_id, self.password, filter_dict) yellow = QtGui.QColor(200,200,0) green = QtGui.QColor(0,153,0) red = QtGui.QColor(170,0,0) highlight_rules = [ { "Columns": ["Status","Approval"], "Values": ["Leave","Approved"], "Color":green }, { "Columns": ["Status","Approval"], "Values": ["Leave","Pending"], "Color": yellow }, { "Columns": ["Status","Approval"], "Values": ["Leave","Rejected"], "Color": red }, { "Columns": ["Relaxation","Approval"], "Values": [[0.01,1.00],"Approved"], "Color": green }, { "Columns": ["Relaxation","Approval"], "Values": [[0.01,1.00],"Pending"], "Color": yellow }, { "Columns": ["Relaxation","Approval"], "Values": [[0.01,1.00],"Rejected"], "Color": red } ] self.work_calendar_table.showDataFrame(self.work_calendar, highlight_rules) def alertMessage(self, title, message): QtGui.QMessageBox.about(self, title, message) def reject(self): """Leave Planner: Method to close the dialog box.""" self.close()
def createUI(self): self.date_label = QtGui.QLabel("Date(s):") self.start_date = FormattedDateEdit() self.end_date = FormattedDateEdit() self.employees_label = QtGui.QLabel("Employees:") self.employees_selection_box = CheckableComboBox("Employees") self.all_button = QtGui.QPushButton("Select All") self.clear_button = QtGui.QPushButton("Clear") self.refresh_table_button = QtGui.QPushButton("Refresh Table") self.approve_selected_button = QtGui.QPushButton("Approved") self.approve_selected_button.setCheckable(True) self.reject_selected_button = QtGui.QPushButton("Rejected") self.reject_selected_button.setCheckable(True) self.pending_selected_button = QtGui.QPushButton("Pending") self.pending_selected_button.setCheckable(True) self.button_group = QtGui.QButtonGroup() self.button_group.addButton(self.approve_selected_button) self.button_group.addButton(self.reject_selected_button) self.button_group.addButton(self.pending_selected_button) self.button_group.setExclusive(True) self.approval_comment_label = QtGui.QLabel( "Approval\\Rejection Comment:") self.rejection_comment_lineedit = QtGui.QLineEdit() self.leave_table = CopiableQTableWidget(0, 0) self.status_label = QtGui.QLabel("Status") self.status_combobox = QtGui.QComboBox() self.status_combobox.addItems(["Working", "Leave"]) self.comment_label = QtGui.QLabel("Comment") self.comment_lineedit = QtGui.QLineEdit() self.save_selected_button = QtGui.QPushButton("Save") self.save_selected_button.setEnabled(False) self.save_all_button = QtGui.QPushButton("Save All") row_1 = QtGui.QHBoxLayout() row_1.addWidget(self.date_label, 0) row_1.addWidget(self.start_date, 0) row_1.addWidget(self.end_date, 0) row_1.addWidget(self.employees_label, 0) row_1.addWidget(self.employees_selection_box, 0) row_1.addWidget(self.all_button, 0) row_1.addWidget(self.clear_button, 0) self.relaxation_label = QtGui.QLabel("Relaxation") self.relaxation_spinbox = QtGui.QDoubleSpinBox() self.relaxation_spinbox.setSuffix("%") row_2 = QtGui.QHBoxLayout() row_2.addWidget(self.status_label, 0) row_2.addWidget(self.status_combobox, 0) row_2.addWidget(self.relaxation_label, 0) row_2.addWidget(self.relaxation_spinbox, 0) row_2.addWidget(self.comment_label, 0) row_2.addWidget(self.comment_lineedit, 0) row_3 = QtGui.QHBoxLayout() row_3.addWidget(self.approval_comment_label, 0) row_3.addWidget(self.rejection_comment_lineedit, 0) row_3.addWidget(self.approve_selected_button, 0) row_3.addWidget(self.reject_selected_button, 0) row_3.addWidget(self.pending_selected_button, 0) row_3.addWidget(self.save_selected_button, 0) row_3.addWidget(self.save_all_button, 0) row_3.addWidget(self.refresh_table_button, 0) layout = QtGui.QVBoxLayout() layout.addLayout(row_1) layout.addLayout(row_2) layout.addLayout(row_3) layout.addWidget(self.leave_table) self.setLayout(layout) self.setWindowTitle("Leaves Manager") self.setWindowIcon( QtGui.QIcon(os.path.join(MOSES.getPathToImages(), "PORK_Icon.png"))) self.show()
class LeaveApproval(QtGui.QWidget): def __init__(self, user_id, password, *args, **kwargs): super(LeaveApproval, self).__init__(*args, **kwargs) self.user_id, self.password = user_id, password self.work_calendar = None self.selected_name = False self.createUI() self.initiate() self.mapEvents() self.applyFilters() def createUI(self): self.date_label = QtGui.QLabel("Date(s):") self.start_date = FormattedDateEdit() self.end_date = FormattedDateEdit() self.employees_label = QtGui.QLabel("Employees:") self.employees_selection_box = CheckableComboBox("Employees") self.all_button = QtGui.QPushButton("Select All") self.clear_button = QtGui.QPushButton("Clear") self.refresh_table_button = QtGui.QPushButton("Refresh Table") self.approve_selected_button = QtGui.QPushButton("Approved") self.approve_selected_button.setCheckable(True) self.reject_selected_button = QtGui.QPushButton("Rejected") self.reject_selected_button.setCheckable(True) self.pending_selected_button = QtGui.QPushButton("Pending") self.pending_selected_button.setCheckable(True) self.button_group = QtGui.QButtonGroup() self.button_group.addButton(self.approve_selected_button) self.button_group.addButton(self.reject_selected_button) self.button_group.addButton(self.pending_selected_button) self.button_group.setExclusive(True) self.approval_comment_label = QtGui.QLabel( "Approval\\Rejection Comment:") self.rejection_comment_lineedit = QtGui.QLineEdit() self.leave_table = CopiableQTableWidget(0, 0) self.status_label = QtGui.QLabel("Status") self.status_combobox = QtGui.QComboBox() self.status_combobox.addItems(["Working", "Leave"]) self.comment_label = QtGui.QLabel("Comment") self.comment_lineedit = QtGui.QLineEdit() self.save_selected_button = QtGui.QPushButton("Save") self.save_selected_button.setEnabled(False) self.save_all_button = QtGui.QPushButton("Save All") row_1 = QtGui.QHBoxLayout() row_1.addWidget(self.date_label, 0) row_1.addWidget(self.start_date, 0) row_1.addWidget(self.end_date, 0) row_1.addWidget(self.employees_label, 0) row_1.addWidget(self.employees_selection_box, 0) row_1.addWidget(self.all_button, 0) row_1.addWidget(self.clear_button, 0) self.relaxation_label = QtGui.QLabel("Relaxation") self.relaxation_spinbox = QtGui.QDoubleSpinBox() self.relaxation_spinbox.setSuffix("%") row_2 = QtGui.QHBoxLayout() row_2.addWidget(self.status_label, 0) row_2.addWidget(self.status_combobox, 0) row_2.addWidget(self.relaxation_label, 0) row_2.addWidget(self.relaxation_spinbox, 0) row_2.addWidget(self.comment_label, 0) row_2.addWidget(self.comment_lineedit, 0) row_3 = QtGui.QHBoxLayout() row_3.addWidget(self.approval_comment_label, 0) row_3.addWidget(self.rejection_comment_lineedit, 0) row_3.addWidget(self.approve_selected_button, 0) row_3.addWidget(self.reject_selected_button, 0) row_3.addWidget(self.pending_selected_button, 0) row_3.addWidget(self.save_selected_button, 0) row_3.addWidget(self.save_all_button, 0) row_3.addWidget(self.refresh_table_button, 0) layout = QtGui.QVBoxLayout() layout.addLayout(row_1) layout.addLayout(row_2) layout.addLayout(row_3) layout.addWidget(self.leave_table) self.setLayout(layout) self.setWindowTitle("Leaves Manager") self.setWindowIcon( QtGui.QIcon(os.path.join(MOSES.getPathToImages(), "PORK_Icon.png"))) self.show() def mapEvents(self): self.start_date.dateChanged.connect(self.startDateChanged) self.end_date.dateChanged.connect(self.applyFilters) self.refresh_table_button.clicked.connect(self.applyFilters) self.clear_button.clicked.connect( self.employees_selection_box.clearSelection) self.leave_table.currentCellChanged.connect(self.populateForm) self.employees_selection_box.changedSelection.connect( self.applyFilters) self.save_selected_button.clicked.connect(self.saveSelected) self.save_all_button.clicked.connect(self.saveAll) self.all_button.clicked.connect(self.employees_selection_box.selectAll) def saveSelected(self): if self.selected_name: self.saveThese([self.selected_name]) else: self.alertMessage( "Select a row", "Select a row in the work calendar and then try again.") self.save_selected_button.setEnabled(False) def saveAll(self): self.saveThese(self.employees_selection_box.getCheckedItems()) def saveThese(self, selected_names): selected_employee_ids = [ list(self.employees_list[self.employees_list["Name"] == x] ["Employee ID"])[0] for x in selected_names ] dates = [ self.start_date.date().toPyDate(), self.end_date.date().toPyDate() ] allow_continue = False if (len(selected_employee_ids) > 1) and (dates[0] == dates[1]): ask = QtGui.QMessageBox.question( self, 'Multiple Employees Selected!', "You appear to have chosen the ids of several employees. Click yes if you'd like to continue modifying the work calendar for all their names. If not, click no and select only one employee's name.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if ask == QtGui.QMessageBox.Yes: allow_continue = True elif (len(selected_employee_ids) > 1) and (dates[0] < dates[1]): ask = QtGui.QMessageBox.question( self, 'Multiple Dates and Employees Selected!', "You appear to have chosen the ids of several employees and an entire date range. Are you sure that you want to apply the settings for all of them for all these dates? I'd recommend changing the status of one employee for one date at a time. Click yes if you'd like to continue modifying the work calendar for all their names for those dates. If not, click no and select only one employee's name and one date.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if ask == QtGui.QMessageBox.Yes: allow_continue = True elif (len(selected_employee_ids) == 1) and (dates[0] < dates[1]): ask = QtGui.QMessageBox.question( self, 'Multiple Dates Selected!', "You appear to have chosen an entire date range. Are you sure that you want to apply the settings for the selected employee all these dates? I'd recommend changing the status of one employee for one date at a time. Click yes if you'd like to continue modifying the work calendar for all their names for those dates. If not, click no and select only one date.", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No) if ask == QtGui.QMessageBox.Yes: allow_continue = True elif (len(selected_employee_ids) <= 0): self.alertMessage( 'No Employees Selected!', "Please select an employee in order to process the work status and relaxation." ) else: allow_continue = True if allow_continue: status = str(self.status_combobox.currentText()) relaxation = self.relaxation_spinbox.value() / 100 comment = str(self.comment_lineedit.text()) if self.approve_selected_button.isChecked(): approval = "Approved" elif self.reject_selected_button.isChecked(): approval = "Rejected" else: approval = "Pending" approval_comment = str(self.rejection_comment_lineedit.text()) self.alertMessage( "Please Wait", "This could take a while. Click OK and hold on to your horses." ) update = MOSES.updateWorkCalendarFor(self.user_id, self.password, status, relaxation, comment, approval, approval_comment, dates, selected_employee_ids) if update: self.alertMessage("Success", "Successfully updated the Work Calendar") self.applyFilters() else: self.alertMessage("Failure", "Failed in updating the Work Calendar") else: print "Not allowed to continue" def initiate(self): self.start_date.setDate(datetime.date.today()) self.start_date.setMinimumDate(datetime.date(2015, 1, 1)) self.end_date.setDate(self.start_date.date()) self.end_date.setMinimumDate(self.start_date.date()) self.employees_list = MOSES.getEmployeesList( self.user_id, self.password, self.end_date.date().toPyDate()) self.employees_selection_box.clear() self.employees_selection_box.addItems( sorted(list(self.employees_list["Name"]))) self.employees_selection_box.selectAll() def applyFilters(self): self.leave_table.showDataFrame(None) selected_employee_ids = [ list(self.employees_list[self.employees_list["Name"] == x] ["Employee ID"])[0] for x in self.employees_selection_box.getCheckedItems() ] if len(selected_employee_ids) <= 0: self.alertMessage("No Employees Selected", "Select at least one employee!") else: filter_dict = { "Dates": [ self.start_date.date().toPyDate(), self.end_date.date().toPyDate() ], "Employee IDs": selected_employee_ids } time_diff = (filter_dict["Dates"][1] - filter_dict["Dates"][0]) if datetime.timedelta(days=5) < time_diff < datetime.timedelta( days=30): self.alertMessage( "Please Wait", "The work calendar is being refreshed. This may take a while since you've selected over a week's worth of data." ) elif time_diff >= datetime.timedelta(days=30): self.alertMessage( "Please Wait", "The work calendar is being refreshed. This will take quite some time longer than usual since you've selected a date range wider than or equal to 30 days." ) self.work_calendar = MOSES.getWorkCalendarFor( self.user_id, self.password, filter_dict) self.alertMessage("Success", "Retrieved the Work Calendar") yellow = QtGui.QColor(200, 200, 0) green = QtGui.QColor(0, 153, 0) red = QtGui.QColor(170, 0, 0) highlight_rules = [{ "Columns": ["Status", "Approval"], "Values": ["Leave", "Approved"], "Color": green }, { "Columns": ["Status", "Approval"], "Values": ["Leave", "Pending"], "Color": yellow }, { "Columns": ["Status", "Approval"], "Values": ["Leave", "Rejected"], "Color": red }, { "Columns": ["Relaxation", "Approval"], "Values": [[0.01, 1.00], "Approved"], "Color": green }, { "Columns": ["Relaxation", "Approval"], "Values": [[0.01, 1.00], "Pending"], "Color": yellow }, { "Columns": ["Relaxation", "Approval"], "Values": [[0.01, 1.00], "Rejected"], "Color": red }] self.leave_table.showDataFrame(self.work_calendar, highlight_rules) self.leave_table.setSortingEnabled(False) def startDateChanged(self): self.end_date.setDate(self.start_date.date()) self.end_date.setMinimumDate(self.start_date.date()) self.applyFilters() def populateForm(self, row=None, column=None): if self.work_calendar is not None: #rows = sorted(set(index.row() for index in self.leave_table.selectedIndexes())) try: selected_row = self.work_calendar.loc[row] self.selected_name = selected_row["Employee Name"] status = selected_row["Status"] relaxation = selected_row["Relaxation"] comment = selected_row["Comment"] approval = selected_row["Approval"] rejection_comment = selected_row["Rejection Comment"] date_ = selected_row["Date"] self.save_selected_button.setText("Save %s's entry" % self.selected_name) self.save_selected_button.setEnabled(True) except: self.selected_name = None self.save_selected_button.setText("Save Selected") self.save_selected_button.setEnabled(False) comment = "" relaxation = 0.0 rejection_comment = "" status = "Working" approval = "Pending" self.comment_lineedit.setText( comment if comment is not None else "") self.status_combobox.setCurrentIndex( self.status_combobox.findText(status)) self.rejection_comment_lineedit.setText( rejection_comment if rejection_comment is not None else "") self.relaxation_spinbox.setValue((relaxation * 100)) if approval is not None: if approval == "Approved": self.approve_selected_button.setChecked(True) elif approval == "Rejected": self.reject_selected_button.setChecked(True) else: self.pending_selected_button.setChecked(True) else: print "Approval is None!" def alertMessage(self, title, message): QtGui.QMessageBox.about(self, title, message)