class DoubleInt(QDialog): def __init__(self, cmd, parent=None, text_left='left', text_right='right', default1=0, default2=0): # cmd is a command which this dialog will call upon OKing. # The arguments are cmd(i1, i2), the two chosen ints. super(DoubleInt, self).__init__(parent) self.tr = text_right self.tl = text_left self.i1 = 0 self.i2 = 0 self.default1 = default1 self.default2 = default2 self.cmd = cmd self.initUI() def initUI(self): mainlay = QVBoxLayout() btns = QHBoxLayout() mainui = QGridLayout() mainlay.addLayout(mainui) mainlay.addLayout(btns) ok = QPushButton('OK') ok.clicked.connect(self.ok) cancel = QPushButton('Cancel') cancel.clicked.connect(self.close) btns.addStretch() btns.addWidget(ok) btns.addWidget(cancel) text1 = QLabel(self.tl) text2 = QLabel(self.tr) self.int1 = QSpinBox() self.int1.setMaximum(2048) self.int1.setMinimum(128) self.int1.setValue(self.default1) self.int2 = QSpinBox() self.int2.setMaximum(2048) self.int2.setMinimum(128) self.int2.setValue(self.default2) mainui.addWidget(text1, 0, 0) mainui.addWidget(text2, 0, 1) mainui.addWidget(self.int1, 1, 0) mainui.addWidget(self.int2, 1, 1) self.setLayout(mainlay) self.setGeometry(340, 340, 200, 100) self.setWindowTitle('MSH Suite - Double Integer') self.show() def ok(self): self.i1 = int(self.int1.text()) self.i2 = int(self.int2.text()) self.cmd(self.i1, self.i2) self.close()
class CalculateSalaryWidget(QWidget): """A PySide widget which provides GUI for selecting employee and calculating salary for a month & year Tis contains boxes for month and year input. Enter the month and year of salary to be calculated here. This is initially automatically set to present month and year. Also contains a ``SearchBox`` for selecting name of employee who's salary needs to be calculated. Selecting the name automatically loads IDs of all employees with that name (in case multiple employees have exact same name) in a dropdown box (``QComboBox``). After selecting the required ID from there, the employee info is automatically loaded. The allowances and deductions are loaded in ``ValueBoxes`` and hence may be edited if required. After selecting everything, user needs to click 'calculate' button. This creates a ``Salary`` object from available info. The actual salary calculation takes place inside ``Salary`` class. This salary object is then passed to ``ShowPaySlipWidget`` which shows the final result and has option to confirm the calculation and print the payslip. Note: To automatically call functions on GUI interaction such as button click, PySide Signal and Slots are used. visit http://zetcode.com/gui/pysidetutorial/eventsandsignals/ for more on PySide Signal and Slots. See Also: - :py:mod:`SearchBox <CustomWidgets.searchBox.SearchBox>` widget from CustomWidgets - :py:mod:`ValueBox <CustomWidgets.valueBox.ValueBox>` widget from CustomWidgets - :py:mod:`Salary <CustomClasses.Salary.Salary>` class from CustomClasses - :py:mod:`ShowPaySlipWidget <ShowPaySlip.ShowPaySlipWidget>` """ def __init__(self, parent=None): QWidget.__init__(self, parent) self.__parent = parent self.title = "Calculate Salary" self.__desig = None self.__emp = None t = datetime.now() self.month = QComboBox() self.month.addItems([ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" ]) self.month.setCurrentIndex(t.month - 1) self.year = QSpinBox() self.year.setRange(1900, 3000) self.year.setValue(t.year) self.name = SearchBox(self) self.name.setPlaceholderText("Enter Name") self.nameList = [] self.nameList = Database.getdb().getEmployeeNameList() self.name.setList(self.nameList) self.id = QComboBox() self.designation = QLineEdit() self.designation.setReadOnly(True) self.originalPay = QLineEdit() self.originalPay.setReadOnly(True) self.originalPayGrade = QLineEdit() self.originalPayGrade.setReadOnly(True) self.DOJ = QLineEdit() self.DOJ.setReadOnly(True) self.pan = QLineEdit() self.pan.setReadOnly(True) self.presentPay = QLineEdit() self.presentPay.setReadOnly(True) self.da_percent = ValueBox() self.hra_percent = ValueBox() self.ta_percent = ValueBox() self.it_percent = ValueBox() self.pt_percent = ValueBox() self.name.editTextChanged.connect(self.clearInfo) self.bttnCalculate = QPushButton("Calculate") self.bttnCalculate.clicked.connect(self.calculate) self.bttnCancel = QPushButton("Back") self.bttnCancel.clicked.connect(self.goBack) self.bttnCalculate.setObjectName("OkButton") self.bttnCancel.setObjectName("CancelButton") self.name.returnPressed.connect(self.setIDList) self.id.currentIndexChanged.connect( lambda: self.loadInfo(self.id.currentText())) self.setupUI() def calculate(self): """Automatically called on clicking calculate button""" if self.__emp is None: QMessageBox(QMessageBox.Information, "Error", "Please select an employee!", parent=self).exec_() else: if self.__parent is not None: self.__desig = Designation(self.__desig.designation, self.da_percent.text(), self.hra_percent.text(), self.ta_percent.text(), self.it_percent.text(), self.pt_percent.text()) salary = Salary(self.__emp, self.__desig, self.month.currentText(), self.year.text()) self.__parent.gotoPage("Result", salary) def clearInfo(self): """Clears the contents of all input/display boxes""" self.id.setCurrentIndex(-1) self.designation.clear() self.originalPay.clear() self.originalPayGrade.clear() self.DOJ.clear() self.pan.clear() self.da_percent.clear() self.hra_percent.clear() self.ta_percent.clear() self.it_percent.clear() self.pt_percent.clear() self.__desig = None self.__emp = None def loadInfo(self, id): """Loads info for given ID in the GUI boxes. This automatically called on selecting an ID from GUI Args: id (str): ID of employee who's info needs to be loaded """ print "id =", id, "...", len(id) if id != '': self.__emp = Database.getdb().getEmployeeInfo(id) self.designation.setText(self.__emp.designation) self.originalPay.setText(str(self.__emp.originalPay)) self.originalPayGrade.setText(str(self.__emp.originalPayGrade)) self.DOJ.setText(self.__emp.getStrDate()) self.pan.setText(self.__emp.pan) self.__desig = Database.getdb().getDesignationInfo( self.__emp.designation) self.da_percent.setText(str(self.__desig.da)) self.hra_percent.setText(str(self.__desig.hra)) self.ta_percent.setText(str(self.__desig.ta)) self.it_percent.setText(str(self.__desig.it)) self.pt_percent.setText(str(self.__desig.pt)) def setIDList(self, name): """Loads IDs of all employees with given name into the ID dropdown box This function is automatically called after selecting a name from the GUI Args: name (str): Name of employee """ self.id.clear() self.id.addItems(Database.getdb().getIdListForName(name)) def goBack(self): if self.__parent is not None: self.__parent.goBack() def setupUI(self): """Arranges GUI elements inside the widget properly""" paneLayout = QHBoxLayout() paneLayout.setContentsMargins(0, 0, 0, 0) leftPane = QFrame() leftPane.setObjectName("leftPane") leftPaneLayout = QVBoxLayout() leftPaneLayout.setContentsMargins(20, 20, 20, 10) heading = QLabel("Select Employee: ") heading.setObjectName("heading") leftPaneLayout.addWidget(heading) leftPaneLayout.addSpacing(10) datelayout = QHBoxLayout() datelayout.addWidget(QLabel("Salary for month of ")) datelayout.addWidget(self.month) datelayout.addWidget(self.year) datelayout.addStretch() leftPaneLayout.addLayout(datelayout) leftForm = QFormLayout() leftForm.setSpacing(10) leftForm.addRow(QLabel("Name"), self.name) leftForm.addRow(QLabel("ID No."), self.id) leftPaneLayout.addLayout(leftForm) leftPaneLayout.addStretch() leftPane.setLayout(leftPaneLayout) paneLayout.addWidget(leftPane) layout = QVBoxLayout() layout.setContentsMargins(20, 20, 20, 10) form = QFormLayout() form.setSpacing(10) form.addRow(QLabel("Designation"), self.designation) form.addRow(QLabel("Original Pay"), self.originalPay) form.addRow(QLabel("Original Pay Grade"), self.originalPayGrade) form.addRow(QLabel("Date of joining"), self.DOJ) form.addRow(QLabel("Pan No."), self.pan) infoGroup = QGroupBox("Basic Info") infoGroup.setLayout(form) layout.addWidget(infoGroup) leftForm = QFormLayout() leftForm.addRow(QLabel("Dearness Allowance"), self.da_percent) leftForm.addRow(QLabel("Housing Rent Allowance"), self.hra_percent) leftForm.addRow(QLabel("Transport Allowance"), self.ta_percent) leftGroup = QGroupBox("Allowances") leftGroup.setLayout(leftForm) rightForm = QFormLayout() rightForm.addRow(QLabel("Income Tax"), self.it_percent) rightForm.addRow(QLabel("Profession Tax"), self.pt_percent) rightGroup = QGroupBox("Deductions") rightGroup.setLayout(rightForm) table = QHBoxLayout() table.addWidget(leftGroup) table.addWidget(rightGroup) layout.addLayout(table) layout.addStretch() bttnLayout = QHBoxLayout() bttnLayout.addStretch() bttnLayout.addWidget(self.bttnCancel) bttnLayout.addWidget(self.bttnCalculate) layout.addLayout(bttnLayout) paneLayout.addLayout(layout) self.setLayout(paneLayout)
class CalculateSalaryWidget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.__parent = parent self.setWindowTitle("Calculate Salary") t = datetime.now() self.month = QComboBox() self.month.addItems([ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" ]) self.month.setCurrentIndex(t.month - 1) self.year = QSpinBox() self.year.setRange(1900, 3000) self.year.setValue(t.year) self.name = SearchBox(self) self.name.setPlaceholderText("Enter Name") self.name.returnPressed.connect(self.setIDList) self.nameList = [] self.nameList = DatabaseManager.db.getEmployeeNameList() self.name.setList(self.nameList) self.name.setCurrentIndex(-1) self.id = QComboBox() self.id.currentIndexChanged.connect( lambda: self.loadInfo(self.id.currentText())) self.designation = QLineEdit() self.designation.setReadOnly(True) self.originalPay = QLineEdit() self.originalPay.setReadOnly(True) self.originalPayGrade = QLineEdit() self.originalPayGrade.setReadOnly(True) self.DOJ = QLineEdit() self.DOJ.setReadOnly(True) self.pan = QLineEdit() self.pan.setReadOnly(True) self.presentPay = QLineEdit() self.presentPay.setReadOnly(True) self.da_percent = ValueBox() self.hra_percent = ValueBox() self.ta_percent = ValueBox() self.it_percent = ValueBox() self.pt_percent = ValueBox() self.name.editTextChanged.connect(self.clearInfo) self.bttnCalculate = QPushButton("Calculate") self.bttnCalculate.clicked.connect(self.calculate) self.bttnCancel = QPushButton("Back") self.bttnCancel.clicked.connect(self.goBack) self.bttnCalculate.setObjectName("OkButton") self.bttnCancel.setObjectName("CancelButton") self.setupUI() def calculate(self): if "" in (self.id.currentText(), self.name.text(), self.designation.text(), self.originalPay.text(), self.originalPayGrade.text(), self.DOJ.text(), self.pan.text(), self.da_percent.text(), self.hra_percent.text(), self.ta_percent.text(), self.it_percent.text(), self.pt_percent.text()): msg = QMessageBox(QMessageBox.Information, "Error", "Please enter all the information!", parent=self) msg.exec_() else: if self.__parent is not None: self.__parent.gotoPage( "Result", (self.id.currentText(), self.name.text(), self.designation.text(), self.originalPay.text(), self.originalPayGrade.text(), self.DOJ.text(), self.pan.text(), self.da_percent.text(), self.hra_percent.text(), self.ta_percent.text(), self.it_percent.text(), self.pt_percent.text(), self.month.currentText(), self.year.text())) def clearInfo(self): self.id.setCurrentIndex(-1) self.designation.clear() self.originalPay.clear() self.originalPayGrade.clear() self.DOJ.clear() self.pan.clear() self.da_percent.clear() self.hra_percent.clear() self.ta_percent.clear() self.it_percent.clear() self.pt_percent.clear() def loadInfo(self, id): print "id =", id, "...", len(id) if id != '': info = DatabaseManager.db.getEmployeeInfo(id) _, _, designation, originalPay, originalPayGrade, doj, pan = info self.designation.setText(str(designation)) self.originalPay.setText(str(originalPay)) self.originalPayGrade.setText(str(originalPayGrade)) self.DOJ.setText("%02d/%02d/%4d" % (doj.day, doj.month, doj.year)) self.pan.setText(str(pan)) _, da, hra, ta, it, pt = DatabaseManager.db.getDesignationInfo( designation) self.da_percent.setText(str(da)) self.hra_percent.setText(str(hra)) self.ta_percent.setText(str(ta)) self.it_percent.setText(str(it)) self.pt_percent.setText(str(pt)) def setIDList(self, name): self.id.clear() self.id.addItems(DatabaseManager.db.getIdListForName(name)) def goBack(self): if self.__parent is not None: self.__parent.goBack() def setupUI(self): layout = QVBoxLayout() layout.setContentsMargins(20, 20, 20, 10) datelayout = QHBoxLayout() datelayout.addWidget(QLabel("Salary for month of ")) datelayout.addWidget(self.month) datelayout.addWidget(self.year) datelayout.addStretch() layout.addLayout(datelayout) form = QFormLayout() form.setSpacing(10) form.addRow(QLabel("Name"), self.name) form.addRow(QLabel("ID No."), self.id) form.addRow(QLabel("Designation"), self.designation) form.addRow(QLabel("Original Pay"), self.originalPay) form.addRow(QLabel("Original Pay Grade"), self.originalPayGrade) form.addRow(QLabel("Date of joining"), self.DOJ) form.addRow(QLabel("Pan No."), self.pan) infoGroup = QGroupBox("Basic Info") infoGroup.setLayout(form) layout.addWidget(infoGroup) leftForm = QFormLayout() leftForm.addRow(QLabel("Dearness Allowance"), self.da_percent) leftForm.addRow(QLabel("Housing Rent Allowance"), self.hra_percent) leftForm.addRow(QLabel("Transport Allowance"), self.ta_percent) leftGroup = QGroupBox("Allowances") leftGroup.setLayout(leftForm) rightForm = QFormLayout() rightForm.addRow(QLabel("Income Tax"), self.it_percent) rightForm.addRow(QLabel("Profession Tax"), self.pt_percent) rightGroup = QGroupBox("Deductions") rightGroup.setLayout(rightForm) table = QHBoxLayout() table.addWidget(leftGroup) table.addWidget(rightGroup) layout.addLayout(table) layout.addStretch() bttnLayout = QHBoxLayout() bttnLayout.addStretch() bttnLayout.addWidget(self.bttnCancel) bttnLayout.addWidget(self.bttnCalculate) layout.addLayout(bttnLayout) self.setLayout(layout)
class UVViewer(QDialog): def __init__(self, model, w, h, parent=None): super(UVViewer, self).__init__(parent) self.w = w self.h = h self.mdl = model self.white_b = QBrush(Qt.white) self.black_b = QBrush(Qt.black) self.pen_width = 2 self.initUI() def initUI(self): mainlay = QVBoxLayout() scn = QGraphicsScene(0, 0, self.w, self.h) self.view = QGraphicsView() self.view.setScene(scn) self.view.setSceneRect(QRectF(0, 0, self.w, self.h)) self.view.setMaximumWidth(self.w) self.view.setMaximumHeight(self.h) mainlay.addWidget(self.view) btns = QHBoxLayout() btns.addStretch() self.pen_w = QSpinBox() self.pen_w.setValue(self.pen_width) redraw = QPushButton('Redraw') redraw.clicked.connect(self.draw_uvs) save = QPushButton('Save') save.clicked.connect(self.save) close = QPushButton('Close') close.clicked.connect(self.close) btns.addWidget(QLabel('Stroke Width')) btns.addWidget(self.pen_w) btns.addWidget(redraw) btns.addWidget(save) btns.addWidget(close) mainlay.addLayout(btns) self.draw_uvs() self.setLayout(mainlay) self.setGeometry(340, 340, 512, 560) self.setWindowTitle('MSH Suite UV Viewer') self.show() def draw_uvs(self): self.img = QPixmap(QSize(self.w, self.h)) pen = QPen() pen.setWidth(int(self.pen_w.text())) pen.setBrush(QBrush(Qt.white)) pen.setColor(QColor('white')) painter = QPainter() painter.begin(self.img) painter.setPen(pen) coords = self.get_coords() for face in coords: for n in xrange(len(face) - 1): print face[n][0], face[n][1], face[n + 1][0], face[n + 1][1] painter.drawLine(face[n][0], face[n][1], face[n + 1][0], face[n + 1][1]) painter.end() self.view.scene().addPixmap(self.img) def get_coords(self): coords = [] for seg in self.mdl.segments: if seg.classname == 'SegmentGeometry': print 'doing stuff' vcoll = seg.vertices for face in seg.faces: face_coords = [] for v in face.SIindices(): face_coords.append((vcoll[v].u * self.w, (1 - vcoll[v].v) * self.h)) face_coords.append((vcoll[face.vertices[0]].u * self.w, (1 - vcoll[face.vertices[0]].v) * self.h)) coords.append(face_coords) #print face_coords return coords def save(self): filename, _ = QFileDialog.getSaveFileName(self, 'Save UV Mesh', os.getcwd(), 'PNG Files (*.png)') if not filename: return self.img.save(filename, 'PNG') self.close()