def __init__(self, parent=None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set invisible self.pushButton_add.setVisible(False) #declare object try: self.clist = Customer_list() except IOError as e: raise IOError(e) self.cprice = Customer_price() #read company list self.m_clist = {} self.m_clist = self.clist.readCompany() #set combo self.setCombo(1, self.m_clist) #set initial one self.comboBox_customer.setCurrentIndex(0) self.on_comboBox_customer_activated(0) #add customer to text browser self.setTextbrowser()
def __init__(self, parent = None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set invisible self.pushButton_add.setVisible(False) #declare object try: self.clist = Customer_list() except IOError as e: raise IOError(e) self.cprice = Customer_price() #read company list self.m_clist={} self.m_clist = self.clist.readCompany() #set combo self.setCombo( 1, self.m_clist ) #set initial one self.comboBox_customer.setCurrentIndex(0) self.on_comboBox_customer_activated(0) #add customer to text browser self.setTextbrowser()
def __init__(self, parent=None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set today ( for file usage) self.qdate = QDate.currentDate() self.dateEdit.setDate(self.qdate) #declare customer list object try: self.cfile = Customer_list() except IOError as e: raise IOError(e) #read company list self.m_clist = {} self.m_clist = self.cfile.readCompany() #set combo box self.setCombo(self.m_clist)
def __init__(self, parent=None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #construct Customer list class self.clist = Customer_list() #construct accounting class self.caccount = Dfile() #construct customer price class self.cprice = Customer_price() #construct standard table self.tablemodel = QStandardItemModel(31, len(PRODUCT_NAME)) self.setTableheader() #save customer list int self.list_customer = self.clist.readCompany() self.setCombo(1, self.list_customer)
def __init__(self, parent = None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set today ( for file usage) self.qdate = QDate.currentDate() self.dateEdit.setDate( self.qdate ) #declare customer list object try: self.cfile = Customer_list() except IOError as e: raise IOError(e) #read company list self.m_clist={} self.m_clist = self.cfile.readCompany() #set combo box self.setCombo(self.m_clist)
def __init__(self, parent = None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #construct Customer list class self.clist = Customer_list() #construct accounting class self.caccount = Dfile() #construct customer price class self.cprice = Customer_price() #construct standard table self.tablemodel = QStandardItemModel(31, len(PRODUCT_NAME) ) self.setTableheader() #save customer list int self.list_customer = self.clist.readCompany() self.setCombo( 1, self.list_customer )
class Dialog_report(QDialog, Ui_Dialog_report): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #construct Customer list class self.clist = Customer_list() #construct accounting class self.caccount = Dfile() #construct customer price class self.cprice = Customer_price() #construct standard table self.tablemodel = QStandardItemModel(31, len(PRODUCT_NAME) ) self.setTableheader() #save customer list int self.list_customer = self.clist.readCompany() self.setCombo( 1, self.list_customer ) def setMode(self, str_mode): if str_mode == 'init': self.clearAllshow() def setCombo(self, comboselect, m_str): """ set combo box """ if comboselect == 1: for i in m_str: self.comboBox_name.addItem(i) elif comboselect == 2: self.comboBox_date.clear() for i in m_str: self.comboBox_date.addItem(i) def clearAllshow(self): #clear all spin box self.setAllspin(0) #clear table self.clearTableview() def setAllspin(self, int_value): self.spinBox_1.setValue(int_value) self.spinBox_2.setValue(int_value) self.spinBox_3.setValue(int_value) self.spinBox_4.setValue(int_value) self.spinBox_5.setValue(int_value) self.spinBox_6.setValue(int_value) self.spinBox_7.setValue(int_value) self.spinBox_8.setValue(int_value) self.spinBox_9.setValue(int_value) self.spinBox_10.setValue(int_value) self.spinBox_11.setValue(int_value) self.spinBox_12.setValue(int_value) self.spinBox_13.setValue(int_value) self.spinBox_14.setValue(int_value) self.spinBox_15.setValue(int_value) self.spinBox_16.setValue(int_value) self.spinBox_17.setValue(int_value) self.spinBox_18.setValue(int_value) self.spinBox_19.setValue(int_value) self.spinBox_19.setValue(0) def setTableheader(self): #set header data self.tablemodel.setHeaderData(0, Qt.Horizontal, PRODUCT_NAME[0] ) self.tablemodel.setHeaderData(1, Qt.Horizontal, PRODUCT_NAME[1] ) self.tablemodel.setHeaderData(2, Qt.Horizontal, PRODUCT_NAME[2] ) self.tablemodel.setHeaderData(3, Qt.Horizontal, PRODUCT_NAME[3] ) self.tablemodel.setHeaderData(4, Qt.Horizontal, PRODUCT_NAME[4] ) self.tablemodel.setHeaderData(5, Qt.Horizontal, PRODUCT_NAME[5] ) def setTableview(self, dlist_data ): """ set data into tableview model """ #show data row = 0 for i in dlist_data: self.tablemodel.setData(self.tablemodel.index(row, 0), QVariant(i[0])) self.tablemodel.setData(self.tablemodel.index(row, 1), QVariant(i[1])) self.tablemodel.setData(self.tablemodel.index(row, 2), QVariant(i[2])) self.tablemodel.setData(self.tablemodel.index(row, 3), QVariant(i[3])) self.tablemodel.setData(self.tablemodel.index(row, 4), QVariant(i[4])) self.tablemodel.setData(self.tablemodel.index(row, 5), QVariant(i[5])) row += 1 #set table into tableview self.tableView.setModel(self.tablemodel) def clearTableview(self): """ clear table """ #show data row = 0 i = [0, 0, 0, 0, 0, 0] for row in range(31): self.tablemodel.setData(self.tablemodel.index(row, 0), QVariant(i[0])) self.tablemodel.setData(self.tablemodel.index(row, 1), QVariant(i[1])) self.tablemodel.setData(self.tablemodel.index(row, 2), QVariant(i[2])) self.tablemodel.setData(self.tablemodel.index(row, 3), QVariant(i[3])) self.tablemodel.setData(self.tablemodel.index(row, 4), QVariant(i[4])) self.tablemodel.setData(self.tablemodel.index(row, 5), QVariant(i[5])) #set table into tableview self.tableView.setModel(self.tablemodel) @pyqtSignature("QString") def on_comboBox_name_currentIndexChanged(self, p0): """ when name index change, set combo date """ #set to initial status self.setMode('init') #read combo text and dict value self.str_customercombo = str( self.comboBox_name.currentText().toUtf8() ) self.i_customercombo = self.clist.readCvalue( self.str_customercombo ) #read all guest accounting data self.list_date = self.caccount.listDatafile( self.i_customercombo ) self.setCombo(2, self.list_date) @pyqtSignature("QString") def on_comboBox_date_currentIndexChanged(self, p0): """ search price data and load accounting into table """ self.str_filename = str( self.comboBox_date.currentText() ) if self.str_filename != '': self.str_datecombo = self.str_filename[3:9] #get price version self.i_priceversion = self.cprice.selectPrice( self.i_customercombo, self.str_datecombo ) #get price dict dict_price = self.cprice.readPrice( self.i_customercombo, self.i_priceversion ) self.list_price = self.cprice.getClist( dict_price ) #show price self.setPricespin( self.list_price ) #show table self.caccount.open_dfile( self.str_filename ) self.table_data = self.caccount.read_alldfile() self.setTableview( self.table_data ) #calculate and show single amount self.eachamount = self.sumEachamount( self.table_data ) self.setEachamount( self.eachamount ) #calculate single price amount self.eachpriceamount = [ self.eachamount[i]*self.list_price[i] for i in range(len(PRODUCT_NAME))] self.setEachpriceamount( self.eachpriceamount ) #show in total income self.spinBox_19.setValue( sum(self.eachpriceamount ) ) def setPricespin( self, list ): self.spinBox_1.setValue( list[0] ) self.spinBox_2.setValue( list[1] ) self.spinBox_3.setValue( list[2] ) self.spinBox_4.setValue( list[3] ) self.spinBox_5.setValue( list[4] ) self.spinBox_6.setValue( list[5] ) def setEachamount( self, list ): self.spinBox_7.setValue( list[0] ) self.spinBox_8.setValue( list[1] ) self.spinBox_9.setValue( list[2] ) self.spinBox_10.setValue( list[3] ) self.spinBox_11.setValue( list[4] ) self.spinBox_12.setValue( list[5] ) def setEachpriceamount(self, list ): self.spinBox_13.setValue( list[0] ) self.spinBox_14.setValue( list[1] ) self.spinBox_15.setValue( list[2] ) self.spinBox_16.setValue( list[3] ) self.spinBox_17.setValue( list[4] ) self.spinBox_18.setValue( list[5] ) #sum each item total amount def sumEachamount(self, duallist ): eachamount = [0, 0, 0, 0, 0, 0] count = 0 for i in duallist: for j in i: eachamount[count] += j count += 1 count = 0 return eachamount
class Dialog_daily(QDialog, Ui_Dialog_daily): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set today ( for file usage) self.qdate = QDate.currentDate() self.dateEdit.setDate( self.qdate ) #declare customer list object try: self.cfile = Customer_list() except IOError as e: raise IOError(e) #read company list self.m_clist={} self.m_clist = self.cfile.readCompany() #set combo box self.setCombo(self.m_clist) def setCombo(self, str): """ set combo box """ for i in str: self.combo_select.addItem(i) def clearSpinbox(self, value=0): """ clear all spin box """ self.spinBox_big.setValue(value) self.spinBox_small.setValue(value) self.spinBox_oil.setValue(value) self.spinBox_tri.setValue(value) self.spinBox_stinky.setValue(value) self.spinBox_milk.setValue(value) @pyqtSignature("") def on_buttonBox_accepted(self): """ save data into file """ i_year = self.qdate.year() i_month = self.qdate.month() i_name = self.cfile.readCvalue( str(self.combo_select.currentText().toUtf8()) ) #declare Dfile object self.dfile = Dfile( i_year, i_month, i_name ) #open file self.dfile.open_dfile() if self.dfile.ischeckRwrite( self.qdate.day() ) == True: #write ui data into file i_big = self.spinBox_big.value() i_small = self.spinBox_small.value() i_oil = self.spinBox_oil.value() i_tri = self.spinBox_tri.value() i_stinky = self.spinBox_stinky.value() i_milk = self.spinBox_milk.value() spindata = [ i_big, i_small, i_oil, i_tri, i_stinky, i_milk] self.dfile.write_dfile(spindata) #close file self.dfile.close_dfile() @pyqtSignature("") def on_buttonBox_rejected(self): """ Clear all value to zero """ self.clearSpinbox() @pyqtSignature("int") def on_horizontalSlider_big_valueChanged(self, value): """ Synchronized with spinBox_big """ self.spinBox_big.setValue(value) @pyqtSignature("int") def on_spinBox_big_valueChanged(self, p0): """ Synchronized with Slider_big """ self.horizontalSlider_big.setValue(p0) @pyqtSignature("int") def on_spinBox_small_valueChanged(self, p0): """ Synchronized with Slider small """ self.horizontalSlider_small.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_small_valueChanged(self, value): """ Synchronized with Spinbox small """ self.spinBox_small.setValue(value) @pyqtSignature("int") def on_spinBox_oil_valueChanged(self, p0): """ Synchronized with Slider oil """ self.horizontalSlider_oil.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_oil_valueChanged(self, value): """ Synchronized with spinBox_oil """ self.spinBox_oil.setValue(value) @pyqtSignature("int") def on_spinBox_tri_valueChanged(self, p0): """ Synchronized with Slider tri """ self.horizontalSlider_tri.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_tri_valueChanged(self, value): """ Synchronized with spinBox_tri """ self.spinBox_tri.setValue(value) @pyqtSignature("int") def on_spinBox_stinky_valueChanged(self, p0): """ Synchronized with Slider stinky """ self.horizontalSlider_stinky.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_stinky_valueChanged(self, value): """ Synchronized with spinBox_stinky """ self.spinBox_stinky.setValue(value) @pyqtSignature("int") def on_spinBox_milk_valueChanged(self, p0): """ Synchronized with Slider milk """ self.horizontalSlider_milk.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_milk_valueChanged(self, value): """ Synchronized with spinBox_milk """ self.spinBox_milk.setValue(value)
class Dialog_cedit(QDialog, Ui_Dialog): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set invisible self.pushButton_add.setVisible(False) #declare object try: self.clist = Customer_list() except IOError as e: raise IOError(e) self.cprice = Customer_price() #read company list self.m_clist = {} self.m_clist = self.clist.readCompany() #set combo self.setCombo(1, self.m_clist) #set initial one self.comboBox_customer.setCurrentIndex(0) self.on_comboBox_customer_activated(0) #add customer to text browser self.setTextbrowser() def setTextbrowser(self): #show company list over text browser for i in self.m_clist: self.textBrowser.append(i) @pyqtSignature("QString") def on_comboBox_customer_activated(self, p0): """ set version combo box """ #set to initial status self.setInitstatus() #read combo text and dict value self.str_customercombo = str( self.comboBox_customer.currentText().toUtf8()) self.i_customercombo = self.clist.readCvalue(self.str_customercombo) #get number of version file self.i_numversion = self.cprice.numGuestprice(self.i_customercombo) #iterate the version number i = 0 m_version = [] self.ultimateversion = 0 while i <= self.i_numversion: m_version.append('v' + str(i)) self.ultimateversion = i i += 1 #set combo box self.setCombo(2, m_version) @pyqtSignature("QString") def on_comboBox_version_activated(self, p0): """ get version start and end date """ #set to initial status self.setInitstatus() if self.comboBox_version.count != 0: #get selected version str_selectversion = self.comboBox_version.currentText() self.i_versioncombo = int(str_selectversion[1]) #set version date, if version equals 0, date shall be 20150101 if self.i_versioncombo != 0: #get start date str_startdate = self.cprice.getStartdate( self.i_customercombo, self.i_versioncombo) self.dateEdit_from.setDate(self.setQdate(str_startdate)) #get end date str_enddate = self.cprice.getEnddate(self.i_customercombo, self.i_versioncombo) self.dateEdit_to.setDate(self.setQdate(str_enddate)) #enable pushButton self.pushButton_load.setEnabled(True) else: self.dateEdit_from.setDate(self.setQdate(self.cprice.INI_DATE)) self.dateEdit_to.setDate(self.setQdate(self.cprice.INI_DATE)) @pyqtSignature("") def on_pushButton_load_clicked(self): """ load data into user interface """ if self.pushButton_load.isEnabled(): dict_loadprice = self.cprice.readPrice(self.i_customercombo, self.i_versioncombo) #set spinbox value self.spinBox_big.setValue(dict_loadprice['big']) self.spinBox_small.setValue(dict_loadprice['small']) self.spinBox_oil.setValue(dict_loadprice['oil']) self.spinBox_tri.setValue(dict_loadprice['tri']) self.spinBox_stinky.setValue(dict_loadprice['stinky']) self.spinBox_milk.setValue(dict_loadprice['milk']) @pyqtSignature("") def on_pushButton_edit_clicked(self): """ change to add mode """ self.setMode('edit') #set next month 1st day if self.ultimateversion != 0: qdate = self.setNextmon(QDate.currentDate()) self.dateEdit_from.setDate(qdate) self.str_qdate = self.getStrdate(qdate) else: self.dateEdit_from.setDate(QDate.currentDate()) self.str_qdate = self.getStrdate(QDate.currentDate()) #set initial date self.dateEdit_to.setDate(self.setQdate(self.cprice.INI_DATE)) @pyqtSignature("") def on_pushButton_add_clicked(self): """ dump value into yaml """ #dump ymal data self.cprice.writePrice(self.i_customercombo, self.str_qdate, self.getSpinboxvalue()) self.setMode('add') @pyqtSignature("") def on_pushButton_addguest_clicked(self): """ add new customer to yaml list """ str_name = str(self.lineEdit_addguest.text().toUtf8()) try: self.clist.writeCompany(str_name.decode('utf8')) except ValueError as e: self.textEdit.append(str(e)) """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """"" self function """ """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" """""" "" def setInitstatus(self, status=False): """ set ui to initial status """ #clear all button status self.clearSpinbox() self.pushButton_load.setEnabled(status) self.dateEdit_from.setDate(self.setQdate(self.cprice.INI_DATE)) self.dateEdit_to.setDate(self.setQdate(self.cprice.INI_DATE)) def setCombo(self, comboselect, m_str): """ set combo box """ if comboselect == 1: for i in m_str: self.comboBox_customer.addItem(i) elif comboselect == 2: self.comboBox_version.clear() for i in m_str: self.comboBox_version.addItem(i) def setMode(self, str_mode): """ set different ui mode """ #set status depends on edit or add mode b_status = True if str_mode == 'edit': b_status = True elif str_mode == 'add': b_status = False self.clearSpinbox() self.pushButton_load.setEnabled(False) self.setreadonlySpinbox(not b_status) self.pushButton_add.setVisible(b_status) self.pushButton_edit.setVisible(not b_status) self.comboBox_version.setEnabled(not b_status) self.comboBox_customer.setEnabled(not b_status) def getStrdate(self, qdate): """ convert qdate to strdate """ #form a string date str_year = str(qdate.year()) if qdate.month() < 10: str_month = '0' + str(qdate.month()) else: str_month = str(qdate.month()) if qdate.day() < 10: str_day = '0' + str(qdate.day()) else: str_day = str(qdate.day()) return str_year + str_month + str_day def setNextmon(self, qdate): """ set import date as next month 1st """ if qdate.month() == 12: qdate.setDate(qdate.year() + 1, 1, 1) else: qdate.setDate(qdate.year(), qdate.month() + 1, 1) return qdate def clearSpinbox(self): """ clean all spin box as zero """ self.spinBox_big.setValue(0) self.spinBox_small.setValue(0) self.spinBox_oil.setValue(0) self.spinBox_tri.setValue(0) self.spinBox_stinky.setValue(0) self.spinBox_milk.setValue(0) def getSpinboxvalue(self): """ get all spin box value in a matrix """ spinboxs_data = [ self.spinBox_big.value(), self.spinBox_small.value(), self.spinBox_oil.value(), self.spinBox_tri.value(), self.spinBox_stinky.value(), self.spinBox_milk.value() ] return spinboxs_data def setreadonlySpinbox(self, status): """ set spin box as read only type """ self.spinBox_big.setReadOnly(status) self.spinBox_small.setReadOnly(status) self.spinBox_oil.setReadOnly(status) self.spinBox_tri.setReadOnly(status) self.spinBox_stinky.setReadOnly(status) self.spinBox_milk.setReadOnly(status) def setQdate(self, str_date): """ set str date (ex:20150201) to Qdate """ i_year = int(str_date[0:4]) i_month = int(str_date[4:6]) i_day = int(str_date[6:9]) return QDate(i_year, i_month, i_day)
class Dialog_cedit(QDialog, Ui_Dialog): """ Class documentation goes here. """ def __init__(self, parent = None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set invisible self.pushButton_add.setVisible(False) #declare object try: self.clist = Customer_list() except IOError as e: raise IOError(e) self.cprice = Customer_price() #read company list self.m_clist={} self.m_clist = self.clist.readCompany() #set combo self.setCombo( 1, self.m_clist ) #set initial one self.comboBox_customer.setCurrentIndex(0) self.on_comboBox_customer_activated(0) #add customer to text browser self.setTextbrowser() def setTextbrowser(self): #show company list over text browser for i in self.m_clist: self.textBrowser.append(i) @pyqtSignature("QString") def on_comboBox_customer_activated(self, p0): """ set version combo box """ #set to initial status self.setInitstatus() #read combo text and dict value self.str_customercombo = str( self.comboBox_customer.currentText().toUtf8() ) self.i_customercombo = self.clist.readCvalue( self.str_customercombo ) #get number of version file self.i_numversion = self.cprice.numGuestprice( self.i_customercombo ) #iterate the version number i = 0 m_version = [] self.ultimateversion = 0 while i <= self.i_numversion: m_version.append('v'+str(i)) self.ultimateversion = i i+=1 #set combo box self.setCombo(2, m_version) @pyqtSignature("QString") def on_comboBox_version_activated(self, p0): """ get version start and end date """ #set to initial status self.setInitstatus() if self.comboBox_version.count != 0: #get selected version str_selectversion = self.comboBox_version.currentText() self.i_versioncombo = int( str_selectversion[1] ) #set version date, if version equals 0, date shall be 20150101 if self.i_versioncombo!=0: #get start date str_startdate = self.cprice.getStartdate( self.i_customercombo, self.i_versioncombo ) self.dateEdit_from.setDate( self.setQdate(str_startdate) ) #get end date str_enddate = self.cprice.getEnddate( self.i_customercombo, self.i_versioncombo ) self.dateEdit_to.setDate( self.setQdate(str_enddate) ) #enable pushButton self.pushButton_load.setEnabled(True) else: self.dateEdit_from.setDate( self.setQdate(self.cprice.INI_DATE) ) self.dateEdit_to.setDate( self.setQdate(self.cprice.INI_DATE) ) @pyqtSignature("") def on_pushButton_load_clicked(self): """ load data into user interface """ if self.pushButton_load.isEnabled(): dict_loadprice = self.cprice.readPrice( self.i_customercombo, self.i_versioncombo ) #set spinbox value self.spinBox_big.setValue( dict_loadprice['big'] ) self.spinBox_small.setValue( dict_loadprice['small'] ) self.spinBox_oil.setValue( dict_loadprice['oil'] ) self.spinBox_tri.setValue( dict_loadprice['tri'] ) self.spinBox_stinky.setValue( dict_loadprice['stinky'] ) self.spinBox_milk.setValue( dict_loadprice['milk'] ) @pyqtSignature("") def on_pushButton_edit_clicked(self): """ change to add mode """ self.setMode('edit') #set next month 1st day if self.ultimateversion != 0: qdate = self.setNextmon( QDate.currentDate() ) self.dateEdit_from.setDate( qdate ) self.str_qdate = self.getStrdate( qdate ) else: self.dateEdit_from.setDate( QDate.currentDate() ) self.str_qdate = self.getStrdate( QDate.currentDate() ) #set initial date self.dateEdit_to.setDate( self.setQdate(self.cprice.INI_DATE) ) @pyqtSignature("") def on_pushButton_add_clicked(self): """ dump value into yaml """ #dump ymal data self.cprice.writePrice( self.i_customercombo, self.str_qdate , self.getSpinboxvalue() ) self.setMode('add') @pyqtSignature("") def on_pushButton_addguest_clicked(self): """ add new customer to yaml list """ str_name = str( self.lineEdit_addguest.text().toUtf8() ) try: self.clist.writeCompany( str_name.decode('utf8') ) except ValueError as e: self.textEdit.append(str(e)) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" self function """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" def setInitstatus(self, status = False): """ set ui to initial status """ #clear all button status self.clearSpinbox() self.pushButton_load.setEnabled(status) self.dateEdit_from.setDate( self.setQdate(self.cprice.INI_DATE) ) self.dateEdit_to.setDate( self.setQdate(self.cprice.INI_DATE) ) def setCombo(self, comboselect, m_str): """ set combo box """ if comboselect == 1: for i in m_str: self.comboBox_customer.addItem(i) elif comboselect == 2: self.comboBox_version.clear() for i in m_str: self.comboBox_version.addItem(i) def setMode(self, str_mode): """ set different ui mode """ #set status depends on edit or add mode b_status = True if str_mode == 'edit': b_status = True elif str_mode == 'add': b_status = False self.clearSpinbox() self.pushButton_load.setEnabled(False) self.setreadonlySpinbox(not b_status) self.pushButton_add.setVisible(b_status) self.pushButton_edit.setVisible(not b_status) self.comboBox_version.setEnabled(not b_status) self.comboBox_customer.setEnabled(not b_status) def getStrdate(self, qdate): """ convert qdate to strdate """ #form a string date str_year = str(qdate.year()) if qdate.month() < 10: str_month = '0'+ str(qdate.month()) else: str_month = str(qdate.month()) if qdate.day() < 10: str_day = '0'+ str(qdate.day()) else: str_day = str(qdate.day()) return str_year + str_month + str_day def setNextmon(self, qdate ): """ set import date as next month 1st """ if qdate.month() == 12: qdate.setDate( qdate.year()+1, 1, 1) else: qdate.setDate( qdate.year(), qdate.month()+1, 1) return qdate def clearSpinbox(self): """ clean all spin box as zero """ self.spinBox_big.setValue( 0 ) self.spinBox_small.setValue( 0 ) self.spinBox_oil.setValue( 0 ) self.spinBox_tri.setValue( 0 ) self.spinBox_stinky.setValue( 0 ) self.spinBox_milk.setValue( 0 ) def getSpinboxvalue(self): """ get all spin box value in a matrix """ spinboxs_data = [ self.spinBox_big.value(), self.spinBox_small.value(), self.spinBox_oil.value(), self.spinBox_tri.value(), self.spinBox_stinky.value(), self.spinBox_milk.value() ] return spinboxs_data def setreadonlySpinbox( self, status ): """ set spin box as read only type """ self.spinBox_big.setReadOnly(status) self.spinBox_small.setReadOnly(status) self.spinBox_oil.setReadOnly(status) self.spinBox_tri.setReadOnly(status) self.spinBox_stinky.setReadOnly(status) self.spinBox_milk.setReadOnly(status) def setQdate(self, str_date): """ set str date (ex:20150201) to Qdate """ i_year = int(str_date[0:4]) i_month = int(str_date[4:6]) i_day = int(str_date[6:9]) return QDate(i_year, i_month, i_day)
class Dialog_daily(QDialog, Ui_Dialog_daily): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #set today ( for file usage) self.qdate = QDate.currentDate() self.dateEdit.setDate(self.qdate) #declare customer list object try: self.cfile = Customer_list() except IOError as e: raise IOError(e) #read company list self.m_clist = {} self.m_clist = self.cfile.readCompany() #set combo box self.setCombo(self.m_clist) def setCombo(self, str): """ set combo box """ for i in str: self.combo_select.addItem(i) def clearSpinbox(self, value=0): """ clear all spin box """ self.spinBox_big.setValue(value) self.spinBox_small.setValue(value) self.spinBox_oil.setValue(value) self.spinBox_tri.setValue(value) self.spinBox_stinky.setValue(value) self.spinBox_milk.setValue(value) @pyqtSignature("") def on_buttonBox_accepted(self): """ save data into file """ i_year = self.qdate.year() i_month = self.qdate.month() i_name = self.cfile.readCvalue( str(self.combo_select.currentText().toUtf8())) #declare Dfile object self.dfile = Dfile(i_year, i_month, i_name) #open file self.dfile.open_dfile() if self.dfile.ischeckRwrite(self.qdate.day()) == True: #write ui data into file i_big = self.spinBox_big.value() i_small = self.spinBox_small.value() i_oil = self.spinBox_oil.value() i_tri = self.spinBox_tri.value() i_stinky = self.spinBox_stinky.value() i_milk = self.spinBox_milk.value() spindata = [i_big, i_small, i_oil, i_tri, i_stinky, i_milk] self.dfile.write_dfile(spindata) #close file self.dfile.close_dfile() @pyqtSignature("") def on_buttonBox_rejected(self): """ Clear all value to zero """ self.clearSpinbox() @pyqtSignature("int") def on_horizontalSlider_big_valueChanged(self, value): """ Synchronized with spinBox_big """ self.spinBox_big.setValue(value) @pyqtSignature("int") def on_spinBox_big_valueChanged(self, p0): """ Synchronized with Slider_big """ self.horizontalSlider_big.setValue(p0) @pyqtSignature("int") def on_spinBox_small_valueChanged(self, p0): """ Synchronized with Slider small """ self.horizontalSlider_small.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_small_valueChanged(self, value): """ Synchronized with Spinbox small """ self.spinBox_small.setValue(value) @pyqtSignature("int") def on_spinBox_oil_valueChanged(self, p0): """ Synchronized with Slider oil """ self.horizontalSlider_oil.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_oil_valueChanged(self, value): """ Synchronized with spinBox_oil """ self.spinBox_oil.setValue(value) @pyqtSignature("int") def on_spinBox_tri_valueChanged(self, p0): """ Synchronized with Slider tri """ self.horizontalSlider_tri.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_tri_valueChanged(self, value): """ Synchronized with spinBox_tri """ self.spinBox_tri.setValue(value) @pyqtSignature("int") def on_spinBox_stinky_valueChanged(self, p0): """ Synchronized with Slider stinky """ self.horizontalSlider_stinky.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_stinky_valueChanged(self, value): """ Synchronized with spinBox_stinky """ self.spinBox_stinky.setValue(value) @pyqtSignature("int") def on_spinBox_milk_valueChanged(self, p0): """ Synchronized with Slider milk """ self.horizontalSlider_milk.setValue(p0) @pyqtSignature("int") def on_horizontalSlider_milk_valueChanged(self, value): """ Synchronized with spinBox_milk """ self.spinBox_milk.setValue(value)
class Dialog_report(QDialog, Ui_Dialog_report): """ Class documentation goes here. """ def __init__(self, parent=None): """ Constructor """ QDialog.__init__(self, parent) self.setupUi(self) #construct Customer list class self.clist = Customer_list() #construct accounting class self.caccount = Dfile() #construct customer price class self.cprice = Customer_price() #construct standard table self.tablemodel = QStandardItemModel(31, len(PRODUCT_NAME)) self.setTableheader() #save customer list int self.list_customer = self.clist.readCompany() self.setCombo(1, self.list_customer) def setMode(self, str_mode): if str_mode == 'init': self.clearAllshow() def setCombo(self, comboselect, m_str): """ set combo box """ if comboselect == 1: for i in m_str: self.comboBox_name.addItem(i) elif comboselect == 2: self.comboBox_date.clear() for i in m_str: self.comboBox_date.addItem(i) def clearAllshow(self): #clear all spin box self.setAllspin(0) #clear table self.clearTableview() def setAllspin(self, int_value): self.spinBox_1.setValue(int_value) self.spinBox_2.setValue(int_value) self.spinBox_3.setValue(int_value) self.spinBox_4.setValue(int_value) self.spinBox_5.setValue(int_value) self.spinBox_6.setValue(int_value) self.spinBox_7.setValue(int_value) self.spinBox_8.setValue(int_value) self.spinBox_9.setValue(int_value) self.spinBox_10.setValue(int_value) self.spinBox_11.setValue(int_value) self.spinBox_12.setValue(int_value) self.spinBox_13.setValue(int_value) self.spinBox_14.setValue(int_value) self.spinBox_15.setValue(int_value) self.spinBox_16.setValue(int_value) self.spinBox_17.setValue(int_value) self.spinBox_18.setValue(int_value) self.spinBox_19.setValue(int_value) self.spinBox_19.setValue(0) def setTableheader(self): #set header data self.tablemodel.setHeaderData(0, Qt.Horizontal, PRODUCT_NAME[0]) self.tablemodel.setHeaderData(1, Qt.Horizontal, PRODUCT_NAME[1]) self.tablemodel.setHeaderData(2, Qt.Horizontal, PRODUCT_NAME[2]) self.tablemodel.setHeaderData(3, Qt.Horizontal, PRODUCT_NAME[3]) self.tablemodel.setHeaderData(4, Qt.Horizontal, PRODUCT_NAME[4]) self.tablemodel.setHeaderData(5, Qt.Horizontal, PRODUCT_NAME[5]) def setTableview(self, dlist_data): """ set data into tableview model """ #show data row = 0 for i in dlist_data: self.tablemodel.setData(self.tablemodel.index(row, 0), QVariant(i[0])) self.tablemodel.setData(self.tablemodel.index(row, 1), QVariant(i[1])) self.tablemodel.setData(self.tablemodel.index(row, 2), QVariant(i[2])) self.tablemodel.setData(self.tablemodel.index(row, 3), QVariant(i[3])) self.tablemodel.setData(self.tablemodel.index(row, 4), QVariant(i[4])) self.tablemodel.setData(self.tablemodel.index(row, 5), QVariant(i[5])) row += 1 #set table into tableview self.tableView.setModel(self.tablemodel) def clearTableview(self): """ clear table """ #show data row = 0 i = [0, 0, 0, 0, 0, 0] for row in range(31): self.tablemodel.setData(self.tablemodel.index(row, 0), QVariant(i[0])) self.tablemodel.setData(self.tablemodel.index(row, 1), QVariant(i[1])) self.tablemodel.setData(self.tablemodel.index(row, 2), QVariant(i[2])) self.tablemodel.setData(self.tablemodel.index(row, 3), QVariant(i[3])) self.tablemodel.setData(self.tablemodel.index(row, 4), QVariant(i[4])) self.tablemodel.setData(self.tablemodel.index(row, 5), QVariant(i[5])) #set table into tableview self.tableView.setModel(self.tablemodel) @pyqtSignature("QString") def on_comboBox_name_currentIndexChanged(self, p0): """ when name index change, set combo date """ #set to initial status self.setMode('init') #read combo text and dict value self.str_customercombo = str(self.comboBox_name.currentText().toUtf8()) self.i_customercombo = self.clist.readCvalue(self.str_customercombo) #read all guest accounting data self.list_date = self.caccount.listDatafile(self.i_customercombo) self.setCombo(2, self.list_date) @pyqtSignature("QString") def on_comboBox_date_currentIndexChanged(self, p0): """ search price data and load accounting into table """ self.str_filename = str(self.comboBox_date.currentText()) if self.str_filename != '': self.str_datecombo = self.str_filename[3:9] #get price version self.i_priceversion = self.cprice.selectPrice( self.i_customercombo, self.str_datecombo) #get price dict dict_price = self.cprice.readPrice(self.i_customercombo, self.i_priceversion) self.list_price = self.cprice.getClist(dict_price) #show price self.setPricespin(self.list_price) #show table self.caccount.open_dfile(self.str_filename) self.table_data = self.caccount.read_alldfile() self.setTableview(self.table_data) #calculate and show single amount self.eachamount = self.sumEachamount(self.table_data) self.setEachamount(self.eachamount) #calculate single price amount self.eachpriceamount = [ self.eachamount[i] * self.list_price[i] for i in range(len(PRODUCT_NAME)) ] self.setEachpriceamount(self.eachpriceamount) #show in total income self.spinBox_19.setValue(sum(self.eachpriceamount)) def setPricespin(self, list): self.spinBox_1.setValue(list[0]) self.spinBox_2.setValue(list[1]) self.spinBox_3.setValue(list[2]) self.spinBox_4.setValue(list[3]) self.spinBox_5.setValue(list[4]) self.spinBox_6.setValue(list[5]) def setEachamount(self, list): self.spinBox_7.setValue(list[0]) self.spinBox_8.setValue(list[1]) self.spinBox_9.setValue(list[2]) self.spinBox_10.setValue(list[3]) self.spinBox_11.setValue(list[4]) self.spinBox_12.setValue(list[5]) def setEachpriceamount(self, list): self.spinBox_13.setValue(list[0]) self.spinBox_14.setValue(list[1]) self.spinBox_15.setValue(list[2]) self.spinBox_16.setValue(list[3]) self.spinBox_17.setValue(list[4]) self.spinBox_18.setValue(list[5]) #sum each item total amount def sumEachamount(self, duallist): eachamount = [0, 0, 0, 0, 0, 0] count = 0 for i in duallist: for j in i: eachamount[count] += j count += 1 count = 0 return eachamount