def __init__(self, app, parent): self.app = app self.OrganizationView = parent self.aiv_view = AIVView(self.OrganizationView.frame, self.app) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.aiv_view.Dialog, 'aiv_btnok') btnCancel = xrc.XRCCTRL(self.aiv_view.Dialog, 'aiv_btncancel') # Call the onCancel method when window close self.aiv_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Bind events to the buttons self.aiv_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignEquipmentAIV, self.btnOK) self.aiv_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.aiv_view.Dialog.Bind(wx.EVT_TOOL, self.onEdit, id=xrc.XRCID('aiv_tooledit')) self.aiv_view.Dialog.Bind(wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('aiv_tooldelete')) #Load the widget of check box to know if the total value will be given directly self.aiv_totalok = xrc.XRCCTRL(self.aiv_view.Dialog, 'aiv_checktotal') #Bind events to the checkbox self.aiv_view.Dialog.Bind(wx.EVT_CHECKBOX, self.onCheckBox, self.aiv_totalok) #Bind event when an item of the list of equipments is selected self.aiv_view.Dialog.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEquipmentSelected, self.aiv_view.equipmentList) self.aiv_view.Dialog.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEdit, self.aiv_view.equipmentOrganizationList) #Subscribe to the messages given by the model. In case of any change, the list of elements will be updated Publisher.subscribe(self.aivModified, 'aiv_created') Publisher.subscribe(self.aivModified, 'aiv_updated') Publisher.subscribe(self.aivModified, 'aiv_deleted') #ID of the Organization selected self.idOrganization = self.OrganizationView.getIDItemSelected() #Instance of the AIV, Equipment model self.aiv = AIV() self.equipment = Equipment() #Load the list of equipments in the view self.loadListOfEquipments() self.loadListOfEquipmentsOrganization() #Display the view self.aiv_view.Show()
def decrypt(self, decryption_string): decrypt = decryption_string.split(chr(0)) self.decrypt_name(decrypt[0]) self.available_points = int(decrypt[1], 16) self.character_level = int(decrypt[2], 16) decrypt = decrypt[3:] for stat in range(len(list(Stats))): self.base_stats[Stats.get_stat(ord(decrypt[0][:1]))] = int( decrypt[0][1:], 16) decrypt = decrypt[1:] for item in range(self.EQUIPMENT_SLOTS): if decrypt[0] == chr(1): add = None else: add = Equipment() add.full_import(decrypt[0]) self.worn_equipment[item] = add decrypt = decrypt[1:] for item in range(len(decrypt) - 1): add = Equipment() add.full_import(decrypt[0]) self.worn_equipment[item] = add decrypt = decrypt[1:] return True
def unSerialize(self): """ Transforms a json File containing equipments informations into a list of equipment objects >>> un = UnSerializerEquipment() >>> un.unSerialize("../test/testEquipment.json") >>> un.collection[0].EquNom 'TERRAIN EXTERIEUR DE VOLLEY- BALL' """ if path == None: path = UnSerializerActivity.path try: with open(path) as data: json_data = json.load(data) for item in json_data["data"]: equi = Equipment(item["ComInsee"],item["ComLib"],item["EquipementFiche"],item["EquAnneeService"] ,item["EquNom"],item["EquNomBatiment"]) self.collection.append(equi) except FileNotFoundError: print("fichier inexistant") except KeyError: print("erreur de clé, clé inéxistante ou mal orthographiée")
def onClickEquipment(self, evt): #Check if the frame was already created frame = self.main_frame.FindWindowByName("EquipmentFrame") if not frame: self.Equipment = Equipment() self.EquipmentController = EquipmentController(self) else: frame.Raise() return
def get_equipment(self, key): 'return an equipment given its name' con = lite.connect(os.path.join(self.database_path, 'easybeer.db')) c = con.cursor() c.execute("""select * from equipments where name=:name""", {'name': key}) eq = c.fetchone() equipment = Equipment(eq[0], eq[1], eq[2], eq[3], eq[4], eq[5], eq[6], eq[7], eq[8], eq[9], eq[10]) return equipment
class AIVController: def __init__(self, app, parent): self.app = app self.OrganizationView = parent self.aiv_view = AIVView(self.OrganizationView.frame, self.app) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.aiv_view.Dialog, 'aiv_btnok') btnCancel = xrc.XRCCTRL(self.aiv_view.Dialog, 'aiv_btncancel') # Call the onCancel method when window close self.aiv_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Bind events to the buttons self.aiv_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignEquipmentAIV, self.btnOK) self.aiv_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.aiv_view.Dialog.Bind(wx.EVT_TOOL, self.onEdit, id=xrc.XRCID('aiv_tooledit')) self.aiv_view.Dialog.Bind(wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('aiv_tooldelete')) #Load the widget of check box to know if the total value will be given directly self.aiv_totalok = xrc.XRCCTRL(self.aiv_view.Dialog, 'aiv_checktotal') #Bind events to the checkbox self.aiv_view.Dialog.Bind(wx.EVT_CHECKBOX, self.onCheckBox, self.aiv_totalok) #Bind event when an item of the list of equipments is selected self.aiv_view.Dialog.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEquipmentSelected, self.aiv_view.equipmentList) self.aiv_view.Dialog.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEdit, self.aiv_view.equipmentOrganizationList) #Subscribe to the messages given by the model. In case of any change, the list of elements will be updated Publisher.subscribe(self.aivModified, 'aiv_created') Publisher.subscribe(self.aivModified, 'aiv_updated') Publisher.subscribe(self.aivModified, 'aiv_deleted') #ID of the Organization selected self.idOrganization = self.OrganizationView.getIDItemSelected() #Instance of the AIV, Equipment model self.aiv = AIV() self.equipment = Equipment() #Load the list of equipments in the view self.loadListOfEquipments() self.loadListOfEquipmentsOrganization() #Display the view self.aiv_view.Show() def aivModified(self, mensaje): self.loadListOfEquipments() self.loadListOfEquipmentsOrganization() def loadListOfEquipments(self): (error, list) = self.equipment.read_all() if error: msg = "Error reading the list of Equipments: \n" + list wx.MessageBox(msg) self.onCancel() else: self.aiv_view.loadListOfEquipments(list) def loadListOfEquipmentsOrganization(self): list_equ = [] self.aiv.FK_Organization = self.idOrganization (error, list) = self.aiv.read_by_organization() if error: msg = "Error reading the list of equipments of the Organization: \n" + list wx.MessageBox(msg) self.onCancel() else: for aiv_entry in list: #Grab the FK_Equipment value from the query row self.equipment.id = aiv_entry[8] (error, value) = self.equipment.read() if error: msg = "Error reading the values of the Equipment: \n" + value wx.MessageBox(msg) self.onCancel() else: list_equ.append(value[0]) self.aiv_view.loadListOfOrganizationEquipments(list_equ) return def onCheckBox(self, evt): if self.aiv_totalok.IsChecked(): self.aiv_view.changeTextsInputs(True) else: self.aiv_view.changeTextsInputs(False) return def onEquipmentSelected(self, evt): #Change to the default value the OK button self.aiv_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignEquipmentAIV, self.btnOK) self.btnOK.SetLabel('Assign') #Reset the text fields self.aiv_view.clearTextsInputs() #And establish the default input mode (Total value will not be given) self.aiv_view.changeTextsInputs(False) self.aiv_totalok.SetValue(False) return def onAssignEquipmentAIV(self, evt): #Check if there is selected any item in the equipment list count = self.aiv_view.getItemCount(self.aiv_view.equipmentList) if (count == 0): wx.MessageBox("Please select an Equipment to assign an AIV value!") elif (count > 1): wx.MessageBox( "Please select just one Equipment to assign an AIV value!") else: #Grab the id of the Equipment selected idEquipment = self.aiv_view.getIDItemSelected( self.aiv_view.equipmentList) self.aiv.FK_Equipment = idEquipment self.aiv.FK_Organization = self.idOrganization #Check if the Equipment is already assigned to the Organization (error, value) = self.aiv.read_by_equipment_organization() if error: msg = "Error reading the AIV value of the equipment: \n" + value wx.MessageBox(msg) self.onCancel() else: if not value: if self.getAIVValuesFromView(): self.aiv.create() else: wx.MessageBox( "Equipment already assigned to the Organization!") return def getAIVValuesFromView(self): #Check if the user will give the Total Value or each single cost if self.aiv_totalok.GetValue(): self.aiv.EC = self.aiv.SC = self.aiv.PC = self.aiv.RV = self.aiv.OC = 0 self.aiv.Total = self.aiv_view.aiv_total.GetValue() #Check if the values provided have a valid format #------------------------------------ list_val = [self.aiv.Total] if not checkStringInputType(list_val, "decimal"): wx.MessageBox("One of the inputs has an incorrect format") return False else: self.aiv.Total = Decimal(self.aiv.Total) else: self.aiv.EC = 0 if self.aiv_view.aiv_equipmentCost.GetValue( ) == "" else self.aiv_view.aiv_equipmentCost.GetValue() self.aiv.SC = 0 if self.aiv_view.aiv_serviceCost.GetValue( ) == "" else self.aiv_view.aiv_serviceCost.GetValue() self.aiv.PC = 0 if self.aiv_view.aiv_personnelCost.GetValue( ) == "" else self.aiv_view.aiv_personnelCost.GetValue() self.aiv.RV = 0 if self.aiv_view.aiv_resellCost.GetValue( ) == "" else self.aiv_view.aiv_resellCost.GetValue() self.aiv.OC = 0 if self.aiv_view.aiv_otherCost.GetValue( ) == "" else self.aiv_view.aiv_otherCost.GetValue() #Check if the values provided have a valid format #------------------------------------ list_val = [ self.aiv.EC, self.aiv.SC, self.aiv.PC, self.aiv.RV, self.aiv.OC ] if not checkStringInputType(list_val, "decimal"): wx.MessageBox("One of the inputs has an incorrect format") return False else: self.aiv.EC = Decimal(self.aiv.EC) self.aiv.SC = Decimal(self.aiv.SC) self.aiv.PC = Decimal(self.aiv.PC) self.aiv.RV = Decimal(self.aiv.RV) self.aiv.OC = Decimal(self.aiv.OC) #AIV Calculation Following the given in Gustavo's Thesis self.aiv.Total = (self.aiv.EC + self.aiv.PC + self.aiv.SC + self.aiv.OC) - self.aiv.RV if self.aiv.Total == 0: wx.MessageBox("The value of AIV could not be zero!!") return False return True def onEdit(self, evt): #Check if any item in the list of equipments of the current organization is selected count = self.aiv_view.getItemCount( self.aiv_view.equipmentOrganizationList) if (count == 0): wx.MessageBox( "Please select an Equipment of the Organization to edit the AIV value!" ) elif (count > 1): wx.MessageBox( "Please select just one Equipment of the Organization to edit the AIV value!" ) else: #Grab the id of the Equipment selected idEquipment = self.aiv_view.getIDItemSelected( self.aiv_view.equipmentOrganizationList) self.aiv.FK_Equipment = idEquipment self.aiv.FK_Organization = self.idOrganization #Read the AIV values of the Equipment (error, value) = self.aiv.read_by_equipment_organization() if error: msg = "Error reading the AIV value of the equipment: \n" + value wx.MessageBox(msg) self.onCancel() else: #Change the behaviour of the OK button to call the method that will load the changes to the database self.btnOK.SetLabel('Edit AIV') self.aiv_view.Dialog.Bind(wx.EVT_BUTTON, self.editAIVValues, self.btnOK) self.aiv_view.loadAIVValues(value[0]) self.aiv.id = value[0][0] return def editAIVValues(self, evt): #Load the Values from the View if self.getAIVValuesFromView(): (error, values) = self.aiv.update() if error: msg = "Error editing the AIV values: \n" + values wx.MessageBox(msg) self.onCancel() return def onDelete(self, evt): count = self.aiv_view.getItemCount( self.aiv_view.equipmentOrganizationList) if (count == 0): wx.MessageBox( "Please select an Equipment of the Organization to be deleted!" ) else: msg = "Proceed to delete " + str(count) + " elements?" del_confirm = wx.MessageDialog(None, msg, 'Delete Confirmation', wx.YES_NO | wx.ICON_QUESTION) if del_confirm.ShowModal() == wx.ID_NO: return item_list = self.aiv_view.getSetItemsSelected( self.aiv_view.equipmentOrganizationList) for id_equipment in item_list: self.aiv.FK_Equipment = id_equipment self.aiv.FK_Organization = self.idOrganization (error, values) = self.aiv.delete_by_organization_equipment() if error: msg = "There was an error deleting the equipment of the organization: \n" + values wx.MessageBox(msg) self.onCancel() self.aiv_view.clearTextsInputs() return def onCancel(self, evt): self.aiv_view.Dialog.Destroy()
def read_input(self): typ = None mash_tun_size = None mash_tun_dead_space = None mash_tun_heat_losses = None v_unit = self.model.get_unit('water_volume') t_unit = self.model.get_unit('temperature') delta_t_unit = self.model.get_unit('delta_temperature') name = self.util.check_input(self.name_edit, True, self.tr('Name'), False) if not name: return brewing_efficiency = self.util.check_input( self.brewing_efficiency_edit, False, self.tr('Brewing Efficiency'), False, 0, 100) if not brewing_efficiency: return boiler_size = self.util.check_input(self.boiler_size_edit, False, self.tr('Boiler Size'), False, 0, vcst.MAX_MASH_TUN_SIZE, None, v_unit) if not boiler_size: return boiler_dead_space = self.util.check_input(self.boiler_dead_space_edit, False, self.tr('Boiler Dead Space'), False, 0, vcst.MAX_MASH_TUN_SIZE, None, v_unit) if not boiler_dead_space: return 'as evaporation is always calculated per hour, the ratio is the same as the ratio between °C and °F' boiler_evaporation_rate = self.util.check_input( self.boiler_evaporation_rate_edit, False, self.tr('Boiler Evaporation Rate'), False, 0, 20, None, v_unit) if not boiler_evaporation_rate: return fermentor_size = self.util.check_input(self.fermentor_size_edit, False, self.tr('Fermentor Size'), False, 0, vcst.MAX_MASH_TUN_SIZE, None, v_unit) if not fermentor_size: return fermentor_dead_space = self.util.check_input( self.fermentor_dead_space_edit, False, self.tr('Boiler Size'), False, 0, vcst.MAX_MASH_TUN_SIZE, None, v_unit) if not fermentor_dead_space: return if self.basic_type_radiobutton.isChecked(): typ = 0 elif self.all_in_one_type_radiobutton.isChecked(): typ = 1 else: typ = 0 try: if typ == 0: mash_tun_size = self.util.check_input(self.mash_tun_size_edit, False, self.tr('Mash Tun Size'), False, 0, vcst.MAX_MASH_TUN_SIZE, None, v_unit) if not mash_tun_size: return mash_tun_dead_space = self.util.check_input(self.mash_tun_dead_space_edit,\ False, self.tr('Mash Tun Dead Space'), False,0,vcst.MAX_MASH_TUN_SIZE/10,None,v_unit) if not mash_tun_dead_space: return 'as heat losses are always calculates per hour, the ratio is the same as the ratio between °C and °F' mash_tun_heat_losses = self.util.check_input(self.mash_tun_heat_losses_edit,\ False,self.tr('Mash Tun Heat Losses'),False,0,vcst.MAX_MASH_TUN_HEAT_LOSSES,None,delta_t_unit) if not mash_tun_heat_losses: return elif typ == 1: mash_tun_size = None mash_tun_dead_space = None mash_tun_heat_losses = None equipment=Equipment(name,brewing_efficiency,boiler_size,boiler_dead_space, boiler_evaporation_rate,\ fermentor_size,fermentor_dead_space,typ,mash_tun_size,mash_tun_dead_space,mash_tun_heat_losses) self.add_button.hide() return (equipment) except ValueError: self.alerte( self. tr('Could not read inputs. Please check all input values are correct' ))
def calc_player_dmg(self, character, monster): weapon = character.worn_equipment[0] if character.worn_equipment[0] is None: dmg = 2 else: dmg = weapon.get_equipment_type().base_damage(weapon.get_equipment_level()) return dmg def fight_monster(self, zone_level): monster = Monsters.get_monster(zone_level) character = self.player.get_current_character() character_life = character.max_life monster_life = monster.value[2] finished = False while not finished: print(self.calc_player_dmg(character, monster)) finished = True p = Player("058859595") p.create_character("jos") p.set_current_character("jos") e = Equipment(100) e.equipment_type = EquipmentType.Two_handed_axe p.get_current_character().equip_item(e) f = Fight(p, None) f.fight_monster(85)
class AEVController: def __init__(self, app, parent): self.app = app self.OrganizationView = parent self.aev_view = AEVView(self.OrganizationView.frame, self.app) #Load the buttons of the view self.btnOK = xrc.XRCCTRL(self.aev_view.Dialog, 'aev_btnok') btnCancel = xrc.XRCCTRL(self.aev_view.Dialog, 'aev_btncancel') # Call the onCancel method when window close self.aev_view.Dialog.Bind(wx.EVT_CLOSE, self.onCancel) #Bind events to the buttons self.aev_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignEquipmentAEV, self.btnOK) self.aev_view.Dialog.Bind(wx.EVT_BUTTON, self.onCancel, btnCancel) #Bind Events to the items in the ToolBar self.aev_view.Dialog.Bind(wx.EVT_TOOL, self.onEdit, id=xrc.XRCID('aev_tooledit')) self.aev_view.Dialog.Bind(wx.EVT_TOOL, self.onDelete, id=xrc.XRCID('aev_tooldelete')) #Load the widget of check box to know if the total value will be given directly self.aev_totalok = xrc.XRCCTRL(self.aev_view.Dialog, 'aev_checktotal') #Bind events to the checkbox self.aev_view.Dialog.Bind(wx.EVT_CHECKBOX, self.onCheckBox, self.aev_totalok) #Bind event when an item of the list of equipments is selected self.aev_view.Dialog.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEquipmentSelected, self.aev_view.equipmentList) self.aev_view.Dialog.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onEdit, self.aev_view.equipmentOrganizationList) #Subscribe to the messages given by the model. In case of any change, the list of elements will be updated Publisher.subscribe(self.aevModified, 'aev_created') Publisher.subscribe(self.aevModified, 'aev_updated') Publisher.subscribe(self.aevModified, 'aev_deleted') #ID of the Organization selected self.idOrganization = self.OrganizationView.getIDItemSelected() #Instance of the AEV, Equipment model self.aev = AEV() self.equipment = Equipment() #Filters self.GUIequipments = [] self.GUIorg_equipments = [] self.txtFilter1 = xrc.XRCCTRL(self.aev_view.Dialog, 'AEV_txtfilter1') self.btnFilter1 = xrc.XRCCTRL(self.aev_view.Dialog, 'AEV_btnfilter1') self.txtFilter2 = xrc.XRCCTRL(self.aev_view.Dialog, 'AEV_txtfilter2') self.btnFilter2 = xrc.XRCCTRL(self.aev_view.Dialog, 'AEV_btnfilter2') self.aev_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter1, self.btnFilter1) self.aev_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter1, self.txtFilter1) self.aev_view.Dialog.Bind(wx.EVT_BUTTON, self.onFilter2, self.btnFilter2) self.aev_view.Dialog.Bind(wx.EVT_TEXT_ENTER, self.onFilter2, self.txtFilter2) #Load the list of equipments in the view self.loadListOfEquipments() self.loadListOfEquipmentsOrganization() #Display the view self.aev_view.Show() #------------------------------------------------------------------------------------------------------------ def aevModified(self, msg): self.loadListOfEquipments() self.loadListOfEquipmentsOrganization() #------------------------------------------------------------------------------------------------------------ def loadListOfEquipments(self): (equ_error, equ_list) = self.equipment.read_all() if equ_error: msg = "Error reading the list of PEPs: \n" + equ_list wx.MessageBox(msg) self.onCancel(True) else: #Exclude from the list of equipments those already assigned to the Organization list_equ = [] self.txtFilter1.SetValue("") self.aev.FK_Organization = self.idOrganization (aev_error, aev_list) = self.aev.read_by_organization() if aev_error: msg = "Error reading the list of PEPs assigned to the Organization: \n" + aev_list wx.MessageBox(msg) self.onCancel(True) else: equ_org = [ ] #list to save the IDs of the Equipments assigned to the Organization for aev_entry in aev_list: # self.aev.read_by_organization() returns a sequence of tuples, each tuple has the following form: # (idAEV, EC, SC, PC, RV, OC, NEquipments, Total, FK_Organization, FK_Equipment) equ_org.append( aev_entry[9]) #Append to the list the Equipment ID for equ_entry in equ_list: # self.equipment.read_all() returns a sequence of tuples, each tuple has the following form: # (idEquipment, Name, Type) if not equ_entry[ 0] in equ_org: # Don't include the equipments already assigned list_equ.append(equ_entry) self.GUIequipments = list_equ self.aev_view.loadListOfEquipments(list_equ) #------------------------------------------------------------------------------------------------------------ def loadListOfEquipmentsOrganization(self): list_equ = [] self.aev.FK_Organization = self.idOrganization (error, list) = self.aev.read_by_organization() if error: msg = "Error reading the list of PEPs of the Organization: \n" + list wx.MessageBox(msg) self.onCancel(True) else: self.txtFilter2.SetValue("") for aev_entry in list: #Grab the FK_Equipment value from the query row self.equipment.id = aev_entry[9] (error, value) = self.equipment.read() if error: msg = "Error reading the values of the PEP: \n" + value wx.MessageBox(msg) self.onCancel(True) else: if value: list_equ.append(value[0]) self.GUIorg_equipments = list_equ self.aev_view.loadListOfOrganizationEquipments(list_equ) return #------------------------------------------------------------------------------------------------------- def onFilter1(self, event): new_list = [] string = self.txtFilter1.GetValue().upper() if string != "": for item in self.GUIequipments: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.aev_view.loadListOfEquipments(new_list) else: self.aev_view.loadListOfEquipments(self.GUIequipments) #------------------------------------------------------------------------------------------------------- def onFilter2(self, event): new_list = [] string = self.txtFilter2.GetValue().upper() if string != "": for item in self.GUIorg_equipments: for sub_item in item: if type(sub_item) is str: if any([string in sub_item.upper()]): new_list.append(item) break self.aev_view.loadListOfOrganizationEquipments(new_list) else: self.aev_view.loadListOfOrganizationEquipments( self.GUIorg_equipments) #------------------------------------------------------------------------------------------------------------ def onCheckBox(self, evt): if self.aev_totalok.IsChecked(): self.aev_view.changeTextsInputs(True) else: self.aev_view.changeTextsInputs(False) return #------------------------------------------------------------------------------------------------------------ def onEquipmentSelected(self, evt): #Change to the default value the OK button self.aev_view.Dialog.Bind(wx.EVT_BUTTON, self.onAssignEquipmentAEV, self.btnOK) self.btnOK.SetLabel('Assign') self.aev_totalok.Enable() self.btnOK.Enable() #Reset the text fields self.aev_view.clearTextsInputs() #And establish the default input mode (Total value will not be given) self.aev_view.changeTextsInputs(False) self.aev_totalok.SetValue(False) self.aev_view.aev_totalok.Enable() return #------------------------------------------------------------------------------------------------------------ def onAssignEquipmentAEV(self, evt): #Check if there is selected any item in the equipment list count = self.aev_view.getItemCount(self.aev_view.equipmentList) if (count == 0): wx.MessageBox("Please select a PEP to assign an AEV value!") elif (count > 1): wx.MessageBox("Please select just one PEP to assign an AEV value!") else: #Grab the id of the Equipment selected idEquipment = self.aev_view.getIDItemSelected( self.aev_view.equipmentList) self.aev.FK_Equipment = idEquipment self.aev.FK_Organization = self.idOrganization #Check if the Equipment is already assigned to the Organization (error, value) = self.aev.read_by_equipment_organization() if error: msg = "Error reading the AEV value of the PEP: \n" + value wx.MessageBox(msg) self.onCancel(True) else: if not value: if self.getAEVValuesFromView(): self.aev.create() else: wx.MessageBox("PEP already assigned to the Organization!") #Send a message to update the view of list of organizations Publisher.sendMessage("organization_updated", None) return #------------------------------------------------------------------------------------------------------------ def getAEVValuesFromView(self): #Check if the user will give the Total Value or each single cost if self.aev_totalok.GetValue(): self.aev.EC = self.aev.SC = self.aev.PC = self.aev.RV = self.aev.OC = 0 self.aev.NEquipments = self.aev_view.aev_number.GetValue() self.aev.Total = self.aev_view.aev_total.GetValue() #Check if the values provided have a valid format #------------------------------------ list_val = [self.aev.Total, self.aev.NEquipments] if not checkStringInputType(list_val, "decimal"): wx.MessageBox("One of the inputs has an incorrect format") return False else: self.aev.NEquipments = Decimal(self.aev.NEquipments) self.aev.Total = Decimal(self.aev.Total) * self.aev.NEquipments else: self.aev.EC = 0 if self.aev_view.aev_equipmentCost.GetValue( ) == "" else self.aev_view.aev_equipmentCost.GetValue() self.aev.SC = 0 if self.aev_view.aev_serviceCost.GetValue( ) == "" else self.aev_view.aev_serviceCost.GetValue() self.aev.PC = 0 if self.aev_view.aev_personnelCost.GetValue( ) == "" else self.aev_view.aev_personnelCost.GetValue() self.aev.RV = 0 if self.aev_view.aev_resellCost.GetValue( ) == "" else self.aev_view.aev_resellCost.GetValue() self.aev.OC = 0 if self.aev_view.aev_otherCost.GetValue( ) == "" else self.aev_view.aev_otherCost.GetValue() self.aev.NEquipments = 0 if self.aev_view.aev_number.GetValue( ) == "" else self.aev_view.aev_number.GetValue() #Check if the values provided have a valid format #------------------------------------ list_val = [ self.aev.EC, self.aev.SC, self.aev.PC, self.aev.RV, self.aev.OC, self.aev.NEquipments ] if not checkStringInputType(list_val, "decimal"): wx.MessageBox("One of the inputs has an incorrect format") return False else: self.aev.EC = Decimal(self.aev.EC) self.aev.SC = Decimal(self.aev.SC) self.aev.PC = Decimal(self.aev.PC) self.aev.RV = Decimal(self.aev.RV) self.aev.OC = Decimal(self.aev.OC) self.aev.NEquipments = Decimal(self.aev.NEquipments) #AEV Calculation Following the given in Gustavo's Thesis self.aev.Total = ( (self.aev.EC + self.aev.PC + self.aev.SC + self.aev.OC) - self.aev.RV) * self.aev.NEquipments if self.aev.NEquipments == 0: wx.MessageBox("The number of PEPs could not be zero!!") return False if self.aev.Total == 0: wx.MessageBox("The value of AEV could not be zero!!") return False return True #------------------------------------------------------------------------------------------------------------ def onEdit(self, evt): #Check if any item in the list of equipments of the current organization is selected count = self.aev_view.getItemCount( self.aev_view.equipmentOrganizationList) if (count == 0): wx.MessageBox( "Please select a PEP of the Organization to edit the AEV value!" ) elif (count > 1) and not isinstance(evt, wx.ListEvent): wx.MessageBox( "Please select just one PEP of the Organization to edit the AEV value!" ) else: #Grab the id of the Equipment selected idEquipment = self.aev_view.getIDItemSelected( self.aev_view.equipmentOrganizationList) self.aev.FK_Equipment = idEquipment self.aev.FK_Organization = self.idOrganization #Read the AEV values of the Equipment (error, value) = self.aev.read_by_equipment_organization() if error: msg = "Error reading the AEV value of the PEP: \n" + value wx.MessageBox(msg) self.onCancel(True) else: self.aev_view.loadAEVValues(value[0]) self.aev.id = value[0][0] #When Called from the Edit button,change the behaviour of the OK button # to call the method that will load the changes to the database # If is called from the list just show the results and disable the button self.btnOK.SetLabel('Edit AEV') if isinstance(evt, wx.ListEvent): self.btnOK.Disable() self.aev_view.aev_equipmentCost.Disable() self.aev_view.aev_serviceCost.Disable() self.aev_view.aev_personnelCost.Disable() self.aev_view.aev_resellCost.Disable() self.aev_view.aev_otherCost.Disable() self.aev_view.aev_number.Disable() self.aev_view.aev_total.Disable() self.aev_view.aev_totalok.Disable() else: self.btnOK.Enable() self.aev_view.aev_totalok.Enable() self.aev_view.Dialog.Bind(wx.EVT_BUTTON, self.editAEVValues, self.btnOK) #Send a message to update the view of list of organizations Publisher.sendMessage("organization_updated", None) return #------------------------------------------------------------------------------------------------------------ def editAEVValues(self, evt): #Load the Values from the View if self.getAEVValuesFromView(): (error, values) = self.aev.update() if error: msg = "Error editing the AEV values: \n" + values wx.MessageBox(msg) self.onCancel(True) return #------------------------------------------------------------------------------------------------------------ def onDelete(self, evt): count = self.aev_view.getItemCount( self.aev_view.equipmentOrganizationList) if (count == 0): wx.MessageBox( "Please select a PEP of the Organization to be deleted!") else: msg = "Proceed to delete " + str(count) + " elements?" del_confirm = wx.MessageDialog(None, msg, 'Delete Confirmation', wx.YES_NO | wx.ICON_QUESTION) if del_confirm.ShowModal() == wx.ID_NO: return item_list = self.aev_view.getSetItemsSelected( self.aev_view.equipmentOrganizationList) for id_equipment in item_list: self.aev.FK_Equipment = id_equipment self.aev.FK_Organization = self.idOrganization (error, values) = self.aev.delete_by_organization_equipment() if error: msg = "There was an error deleting the PEP of the organization: \n" + values wx.MessageBox(msg) self.onCancel(True) self.aev_view.clearTextsInputs() #Send a message to update the view of list of organizations Publisher.sendMessage("organization_updated", None) return #------------------------------------------------------------------------------------------------------------ def onCancel(self, evt): self.aev_view.Dialog.Destroy()