def __init__(self, master=None, contact=None, **kwargs): super().__init__(master, **kwargs) contact_frame = tk.LabelFrame(self, text=msg.SE_CONTACT_TITLE) contact_frame.place(relx=0, rely=0, relwidth=1, relheight=1, anchor=tk.NW) name = contact.get("name", "") name_label = tk.Label(self, text=name, font=config.Style.ATTR_FONT, anchor=tk.E) name_label.place(relx=.5, rely=.3, anchor=tk.CENTER) competency = "{name} ({lvl})".format( name=contact.get("competency", ""), lvl=contact.get("competencylevel", "")) comp_label = tk.Label(contact_frame, text=competency) comp_label.place(relx=.5, rely=.6, anchor=tk.CENTER) location = contact.get("location", "") loc_label = tk.Label(contact_frame, text=location) loc_label.place(relx=.5, rely=.8, anchor=tk.CENTER) # the contacts loyality is used to recolor the name ... loyality = float(contact.get("loyality", "0")) if loyality >= 1: name_label.config(foreground=config.Colors.DARK_GREEN) if loyality < 0: name_label.config(foreground=config.Colors.DARK_RED) if 0 <= loyality < 1: name_label.config(foreground=config.Colors.BLACK)
def showBagContents(self, bag, frame): bag_id = int(bag.get("id")) # if no bag is the active bag - this bag becomes the active bag ... if self.active_bag_id == -1: self.active_bag_id = bag_id bag_tag = bag.find("container") bag_frame = tk.LabelFrame(frame, text=bag_tag.get("name")) if self.active_bag_id == bag_id: bag_frame.config(font=config.Style.BAG_LF_FONT, ) ToolTip(bag_frame, msg.ES_TT_ACTIVE_BAG) else: ToolTip(bag_frame, msg.ES_TT_INACTIVE_BAG) # retrieve bag content and display ... item_ids = bag.get("content") if item_ids is not None: entries = item_ids.split() for item_id in entries: item = self.char.getItemById(item_id) if item is not None: item_line = tk.Frame(bag_frame) quantity_label = tk.Label(item_line, text=item.get("quantity") + msg.MULTIPLY) quantity_label.pack(side=tk.LEFT) item_label = tk.Label(item_line, text=item.get("name")) item_label.bind("<Button-1>", lambda event, id=item_id: self. displayItemEditor(event, id)) item_label.pack(side=tk.LEFT, fill=tk.X, expand=1) unpack_icon = ImageTk.PhotoImage(file="img/unpack.png") item_unpack = tk.Button(item_line, image=unpack_icon) ToolTip(item_unpack, msg.ES_TT_UNPACK) item_unpack.image = unpack_icon item_unpack.bind( "<Button-1>", lambda event, id=item_id: self.unpackItem(event, id)) item_unpack.pack(side=tk.RIGHT, anchor=tk.E) item_line.pack(fill=tk.X, expand=1) children = bag_frame.winfo_children() # for empty bag ... if not children: tk.Label(bag_frame, text=" ").pack() bag_frame.pack(fill=tk.BOTH, expand=1) bag_frame.bind( "<Button-1>", lambda event, bag_id=bag_id: self.setActiveBag(event, bag_id))
def showContent(self, frame): content_ids = self.item.get("content", "") content_ids = content_ids.split(" ") content_frame = tk.LabelFrame(frame, text=msg.IE_CONTENT) for content_id in content_ids: sub_item = self.char.getItemById(content_id) if sub_item is not None: sub_item_id = sub_item.get("id") line = tk.Frame(content_frame) label_text = sub_item.get("quantity") + "x - " + sub_item.get("name") label = tk.Label(line, text=label_text) label.bind( "<Button-1>", lambda event, load_item=sub_item: self.close(load=load_item) ) label.pack(side=tk.LEFT) unpack_icon = ImageTk.PhotoImage(file="img/unpack.png") unpack_button = tk.Button(line, image=unpack_icon) unpack_button.image = unpack_icon ToolTip(unpack_button, msg.IE_TT_UNPACK) unpack_button.bind( "<Button-1>", lambda event, sub=sub_item, line_widget=line: self.unpackItem(event, sub, line_widget) ) unpack_button.pack(side=tk.RIGHT, anchor=tk.E) line.pack(fill=tk.X, expand=1) content_frame.pack(fill=tk.X, expand=1)
def __init__(self, app): tk.Toplevel.__init__(self) self.app = app self.char = app.char # tk variables ... self.xp_var = tk.StringVar() self.event_name = tk.StringVar() self.money_amount = tk.StringVar() self.selected_account = tk.StringVar() # build screen self.title(msg.IW_TITLE) # event name self.event_frame = tk.LabelFrame(self, text=msg.IW_EVENT) self.event_text = tk.Entry(self.event_frame, textvariable=self.event_name, width=50) self.event_text.pack(fill=tk.X) self.event_frame.pack(fill=tk.X) # xp frame self.xp_frame = tk.LabelFrame(self, text=msg.IW_XP) self.xp_spinbox = tk.Spinbox(self.xp_frame, textvariable=self.xp_var, from_=-100, to=100, width=4, font="Arial 12 bold") self.xp_var.set("0") self.xp_spinbox.pack(fill=tk.X) self.xp_frame.pack(fill=tk.X) # money frame self.money_frame = tk.LabelFrame(self, text=msg.IW_MONEY) self.money_amount.set("0") self.money_entry = tk.Entry(self.money_frame, textvariable=self.money_amount, font="Arial 12 bold") self.money_entry.pack(fill=tk.X) self.account_label = tk.Label(self.money_frame, text=msg.IW_ACCOUNT) accounts = self.buildAccountList() width = 0 for account in accounts: if len(account) >= width: width = len(account) self.selected_account.set(accounts[0]) account_selector = tk.OptionMenu(self.money_frame, self.selected_account, *accounts) account_selector.config(width=width) account_selector.pack(fill=tk.X) self.money_frame.pack(fill=tk.X) # submit button self.submit = tk.Button(self, text=msg.IW_ADD, command=self._addEvent) self.submit.pack(fill=tk.X) self.event_name.trace("w", self._check) self.money_amount.trace("w", self._check) self.xp_var.trace("w", self._check) self.event_name.set("")
def getClipInfo(self, frame): self.showContent(frame) search = "option[@name='" + it.OPTION_CALIBER + "']" caliber = self.item.find(search).get("value") size = self.item.find("container").get("size") items = self.getMatchingAmmo(caliber) for item in items: line = tk.Frame(frame) item_id = item.get("id") name_label = tk.Label(line, text=item.get("name")) name_label.pack(side=tk.LEFT) button_fill = tk.Button(line, text=msg.IE_FILL_CLIP) button_fill.bind( "<Button-1>", lambda event, item=item: self.loadRoundInClip(event, item, fill=True) ) button_fill.pack(side=tk.RIGHT) button_plus1 = tk.Button(line, text=msg.IE_ADD_ONE) button_plus1.bind( "<Button-1>", lambda event, item=item: self.loadRoundInClip(event, item, fill=False) ) button_plus1.pack(side=tk.RIGHT) line.pack()
def getAmmoInfo(self, frame): search = "option[@name='"+it.OPTION_CALIBER+"']" caliber = self.item.find(search).get("value") items = self.char.getItems() guns = [] for item in items: # try to get the caliber of the item ... item_caliber = item.find("option[@name='"+it.OPTION_CALIBER+"']") if item_caliber is not None: # make sure it is a weapon ... if (item_caliber.get("value") == caliber and item.get("type") not in [it.AMMO, it.CLIP] ): # add the item to the list of guns ... guns.append(item) if guns: info = tk.Label(frame, text=msg.IE_INSERT_CARTRIDGE) info.pack() for gun in guns: button = tk.Button(frame, text=gun.get("name")) button.pack(fill=tk.X, expand=1) button.bind( "<Button-1>", lambda event, item=gun: self.reloadChamber(event, item, variant="bullet") )
def initialAccount(self, parent): frame = tk.Frame(parent) frame.columnconfigure(1, weight=100) minus = ImageTk.PhotoImage(file="img/minus.png") reduce_account = tk.Button( frame, image=minus, command=lambda: self.updateInitialAccount(-1)) reduce_account.image = minus img = ImageTk.PhotoImage(file="img/money.png") account_label = tk.Label( frame, textvariable=self.account_info, compound=tk.LEFT, image=img, ) account_label.image = img account_label.grid(row=0, column=1) plus = ImageTk.PhotoImage(file="img/plus.png") increase_account = tk.Button( frame, image=plus, command=lambda: self.updateInitialAccount(+1)) increase_account.image = plus mode = self.char.getEditMode() if mode == "generation": reduce_account.grid(row=0, column=0) increase_account.grid(row=0, column=2) return frame
def __init__(self, main): tk.Frame.__init__(self, main) self.char = main.char self.xp_label = tk.Label(self, text=msg.SB_XP_AVAIL) self.xp_label.pack(side=tk.LEFT) self.xp_info = tk.Label(self, anchor=tk.W, textvariable=self.char.xp_avail) self.xp_info.pack(side=tk.LEFT) tk.Label(self, text=" ").pack(side=tk.LEFT) self.money_label = tk.Label(self, text=msg.SB_MONEY_AVAIL) self.money_label.pack(side=tk.LEFT) self.money_info = tk.Label(self, textvariable=self.char.account_balance) self.money_info.pack(side=tk.LEFT) self.freeMode()
def showEquippedMelee(self, canvas): """ show the equipped melee weapons canvas: tk.Canvas - where to display the stuff ... """ # clear the frame canvas.delete(tk.ALL) # get the items items = self.char.getItems() y = 0 for item in items: if item.get("equipped", "0") == "1": item_type = item.get("type") weapons = [ it.CLUB, it.BLADE, it.STAFF, it.OTHER_MELEE, it.TOOLS, it.NATURAL ] if item_type in weapons: item_name = item.get("name") item_id = item.get("id") damage = item.find("damage") if damage is not None: damage_value = damage.get("value") item_frame = tk.Frame(canvas, borderwidth=2, relief=tk.RIDGE) name_label = tk.Label(item_frame, text=item_name) name_label.bind("<Button-1>", lambda event, item_id=item_id: self. displayItemEditor(event, item_id)) name_label.pack(side=tk.LEFT) damage_label = tk.Label(item_frame, text=damage_value) damage_label.pack(side=tk.RIGHT, anchor=tk.E) canvas.create_window( 0, y, # x, y window=item_frame, anchor=tk.NW, width=self.canvas_width) self.update_idletasks() y += item_frame.winfo_height()
def showEWT(self, frame): """ This method draws the EWT using graphics frame: tk.Frame() target to draw in ... The frame will not be cleared! This method uses the grid geometry manager on 11 rows and 17 columns! """ rolls = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] columns = [-7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7] for column in columns: label = tk.Label(frame, text=column, font="sans 12 bold") label.grid(row=0, column=column + 8) for roll in rolls: label = tk.Label(frame, text=roll, font="sans 12 bold") label.grid(row=roll, column=0) label = tk.Label(frame, text=roll, font="sans 12 bold") label.grid(row=roll, column=16) label = tk.Label(frame, text=roll) for column in columns: rowindex = roll - 1 colindex = column + 7 effect = config.EWT[rowindex][colindex] image = None if effect == 0.0: image = self.ewt00 elif effect == 0.5: image = self.ewt05 elif effect == 1.0: image = self.ewt10 elif effect == 2.0: image = self.ewt20 label = tk.Label( frame, image=image ) if rowindex%2: label.config(background="#eeeeee") else: label.config(background="#cccccc") label.image = image label.grid(row=rowindex + 1, column=colindex + 1)
def showMenu(self, frame): widgets = frame.winfo_children() for widget in widgets: widget.destroy() close = tk.Button(frame, text=msg.SE_CLOSE, command=self.close) close.pack(side=tk.LEFT) save = tk.Button(frame, text=msg.SE_SAVE, command=self.updateContact) save.pack(side=tk.LEFT) delete = tk.Button(frame, text=msg.SE_DELETE, command=self.deleteContact) delete.pack(side=tk.LEFT) xp = tk.Label(frame, text=msg.XP + ": ") xp.pack(side=tk.LEFT, anchor=tk.E) xp_val = tk.Label(frame, textvariable=self.xp_cost) xp_val.pack(side=tk.LEFT, anchor=tk.E)
def showEquippedItems(self): canvas = self.equipped_canvas # clear contents canvas.delete(tk.ALL) y = 0 # display weight ... weight = tk.Label(canvas, text=self.updateWeight()) canvas.create_window(0, y, anchor=tk.NW, window=weight) y += 25 # armor and clothing armor_frame = tk.LabelFrame(canvas, text=msg.ES_CLOTHING_ARMOR, width=self.canvas_width) lines = self.showEquippedClothing(armor_frame) if lines > 1: armor = canvas.create_window( 0, y, # x, y window=armor_frame, anchor=tk.NW, width=self.canvas_width) self.update_idletasks() y += armor_frame.winfo_height() cyber_frame = tk.LabelFrame(canvas, text=msg.ES_BIOTECH, width=250) lines = self.showEquippedBiotech(cyber_frame) if lines > 1: armor = canvas.create_window( 0, y, # x, y window=cyber_frame, anchor=tk.NW, width=self.canvas_width) self.update_idletasks() y += cyber_frame.winfo_height() # carried bags bags = self.char.getContainers() for bag in bags: bag_frame = tk.Frame(canvas) self.showBagContents(bag, bag_frame) canvas.create_window( 0, y, # x, y window=bag_frame, anchor=tk.NW, width=self.canvas_width) self.update_idletasks() y += bag_frame.winfo_height()
def showEquippedBiotech(self, frame): frame.columnconfigure(0, weight=100) items = self.char.getItems(item_type=it.IMPLANT) row = 0 name_label = tk.Label(frame, text=msg.ES_ITEMNAME) name_label.grid(row=row, column=0, sticky=tk.W) qual_label = tk.Label(frame, text=msg.ES_QUALITY_S) qual_label.grid(row=row, column=1, sticky=tk.EW) row = 1 for item in items: if item.get("equipped", "0") == "1": item_id = item.get("id") name = item.get("name") name_label = tk.Label(frame, text=name) name_label.grid(row=row, column=0, sticky=tk.W) name_label.bind("<Button-1>", lambda event, item_id=item_id: self. displayItemEditor(event, item_id)) quality = item.get("quality") qual_label = tk.Label(frame, text=quality) qual_label.grid(row=row, column=1, sticky=tk.EW) row += 1 return row
def showEquippedClothing(self, frame): items = self.char.getItems() row = 0 frame.columnconfigure(0, weight=100) name_label = tk.Label(frame, text=msg.ES_ITEMNAME) name_label.grid(row=row, column=0, sticky=tk.W) sd_label = tk.Label(frame, text=msg.ES_DAMAGE_S) sd_label.grid(row=row, column=1, sticky=tk.EW) qual_label = tk.Label(frame, text=msg.ES_QUALITY_S) qual_label.grid(row=row, column=2, sticky=tk.EW) row = 1 clothing_and_bags = [ it.CLOTHING, it.ARMOR, it.HARNESS, it.BAG, it.CONTAINER, it.TOOLS ] for item in items: if (item.get("equipped", "0") == "1" and item.get("type") in clothing_and_bags): # only show tools that are containers ... if item.get("type") == it.TOOLS: container = item.find("container") if container is None: continue name = item.get("name") item_id = item.get("id") name_label = tk.Label(frame, text=name) name_label.bind("<Button-1>", lambda event, item_id=item_id: self. displayItemEditor(event, item_id)) name_label.grid(row=row, column=0, sticky=tk.W) sd = "" damage = item.find("damage") if damage is not None: sd = damage.get("value", "") sd_label = tk.Label(frame, text=sd) sd_label.grid(row=row, column=1, sticky=tk.EW) quality = item.get("quality") qual_label = tk.Label(frame, text=quality) qual_label.grid(row=row, column=2, sticky=tk.EW) unequip_icon = ImageTk.PhotoImage(file="img/unequip.png") unequip_button = tk.Button(frame, image=unequip_icon) ToolTip(unequip_button, msg.ES_TT_UNEQUIP) unequip_button.image = unequip_icon item_id = item.get("id") unequip_button.bind("<Button-1>", lambda event, item_id=item_id: self. unequipItem(event, item_id)) unequip_button.grid(row=row, column=3, sticky=tk.EW) row += 1 return row
def _newModule(self, frame): tk.Label(frame, text=msg.ME_NEW).pack(fill=tk.X, expand=1) mod_types = ( msg.PDF_ATTRIBUTES, msg.PDF_TRAITS, msg.PDF_SKILLS, msg.PDF_EQUIPMENT, msg.PDF_WEAPONS, msg.PDF_CONTACTS, msg.PDF_EWT, msg.PDF_IMAGE, msg.PDF_NOTES) # this will be the frame for the option selection ... selected_type = tk.StringVar() selected_type.trace("w", self._modTypeChanged) self.vars[str(selected_type)] = selected_type self.var_names["module"] = str(selected_type) select_button = tk.OptionMenu( frame, selected_type, *mod_types) selected_type.set(mod_types[0]) select_button.pack(fill=tk.X, expand=1) row = str(self.row) col = str(self.col) id = str(self.main.getHighestModuleId()+1) sub_frame = tk.Frame(frame) self.widgets["options"] = option_frame = tk.Frame(sub_frame) option_frame.pack(fill=tk.X) selected_type.set(mod_types[0]) sub_frame.pack(fill=tk.BOTH, expand=1) add_button = tk.Button(frame, text=msg.ME_ADD, command=self._addModule) add_button.pack(fill=tk.X)
def drawText(self, text, font="Arial 9"): """ Helper method to draw text to the canvas Args: text (str): the text to draw font (str): the font used """ label = tk.Label( self.canvas, text=text, font=font, wrap=290, justify=tk.LEFT ) self.canvas.create_window( 5, self.y, width=290, window=label, anchor=tk.NW, ) self.y += label.winfo_reqheight()
def startScreenImage(self): photo = ImageTk.PhotoImage(file="img/logo.png") label = tk.Label(self.main_frame, image=photo) label.image = photo label.pack()
def drawTitle(self): """ Renders the title of the window """ x = 2 title_width = 250 edit_mode = self.char.getEditMode() i_xp = int(self.trait_xp) if i_xp > 0: trait_type = msg.TI_ADVANTAGE else: trait_type = msg.TI_DISADVANTAGE if edit_mode == "generation": icon = ImageTk.PhotoImage(file="img/del_s.png") remove_button = tk.Label( self.canvas, image=icon, ) remove_button.image = icon ToolTip(remove_button, msg.TI_REMOVE.format(type=trait_type)) remove_button.bind( "<Button-1>", self.removeTrait ) self.canvas.create_window( x, 0, window=remove_button, anchor=tk.NW ) x += remove_button.winfo_reqwidth() + 2 if edit_mode != "view": minus = ImageTk.PhotoImage(file="img/minus_s.png") plus = ImageTk.PhotoImage(file="img/plus_s.png") m_button = tk.Label( self.canvas, image=minus, ) m_button.image = minus m_button.bind( "<Button-1>", lambda event: self.modTrait(event, -1) ) ToolTip(m_button, msg.TI_LESSEN.format(type=trait_type)) self.canvas.create_window( x, 0, window=m_button, anchor=tk.NW ) x += m_button.winfo_reqwidth() + 2 p_button = tk.Label( self.canvas, image=plus, ) p_button.image = plus ToolTip(p_button, msg.TI_INTENSIFY.format(type=trait_type)) p_button.bind( "<Button-1>", self.modTrait ) self.canvas.create_window( x, 0, window=p_button, anchor=tk.NW ) x += p_button.winfo_reqwidth() + 2 title_width -= x title = tk.Label( self.canvas, font="Arial 12 bold", text=self.trait_name, wraplength=title_width, justify=tk.LEFT ) xp = tk.Label( self.canvas, font="Arial 12 bold", text="("+self.trait_xp+")", justify=tk.RIGHT ) if int(self.trait_xp) > 0: xp.config(foreground=config.Colors.DARK_GREEN) else: xp.config(foreground=config.Colors.DARK_RED) self.canvas.create_window( x, 0, window=title, width=title_width, anchor=tk.NW ) self.y += title.winfo_reqheight() self.canvas.create_window( 298, 0, window=xp, anchor=tk.NE )
def getBiotechInfo(self, frame, item_type): implanted = int(self.item.get("equipped", "0")) inside = self.item.get("inside", "-1") if inside != -1: parent = self.char.getItemById(inside) if parent is not None: name = parent.get("name") parent_type = parent.get("type") if parent_type in [it.IMPLANT, it.PROSTHESIS]: if item_type == it.PROSTHESIS: status = msg.IE_ATTACHED_TO else: status = msg.IE_BUILT_INTO label = tk.Label( frame, text=status+name ) label.bind( "<Button-1>", lambda item=parent: self.close(load=parent) ) label.pack() content = self.item.get("content", "") if content != "": content_list = content.split() else: content_list = [] content_frame = tk.LabelFrame(frame, text=msg.IE_IMPLANT_ADDONS) for item_id in content_list: sub_item = self.char.getItemById(item_id) if sub_item is not None: item_frame = tk.Frame(content_frame) sub_name = sub_item.get("name") sub_type = sub_item.get("type") label = tk.Label( item_frame, text=sub_name ) label.bind( "<Button-1>", lambda event, sub_item=sub_item: self.close(load=sub_item) ) label.pack(side=tk.LEFT, anchor=tk.W) button = tk.Button( item_frame, text=msg.IE_UNEQUIP, command=lambda sub_item=sub_item: self.unpackProsthesis(sub_item) ) if sub_type == it.PROSTHESIS: button.pack(side=tk.RIGHT, anchor=tk.E) item_frame.pack(fill=tk.X) if content_list: content_frame.pack(fill=tk.X) if item_type != it.IMPLANT_PART: add_ons = (self.char.getItems(item_type=it.IMPLANT_PART) + self.char.getItems(item_type=it.PROSTHESIS)) for sub_item in add_ons: inside = sub_item.get("inside", "-1") sub_id = sub_item.get("id") if (inside != "-1" or self.item.get("id") in sub_item.get("content", "").split() or sub_id == self.item.get("id") ): continue sub_name = sub_item.get("name") if sub_id not in content_list: sub_frame = tk.Frame(frame) label = tk.Label( sub_frame, text=sub_name ) label.pack(side=tk.LEFT, anchor=tk.W) button = tk.Button( sub_frame, text="einbauen", command=lambda sub_item=sub_item: self.packItem(sub_item) ) button.pack(side=tk.RIGHT, anchor=tk.E) sub_frame.pack(fill=tk.X) if item_type == it.IMPLANT and not implanted: tk.Button( frame, text=msg.IE_IMPLANT, command=self.equipItem ).pack(fill=tk.X) items = self.char.getItems(item_type=it.IMPLANT_PART) for item in items: pass
def showUnassignedItems(self): # clear the list ... canvas = self.unassigned_canvas canvas.delete(tk.ALL) # get all items items = self.char.getItems() equippable_types = self.itemlist.EQUIPPABLE y = 0 canvas.update() for item in items: # is the item currently packed or assigned as carried item? unassigned = True inside = int(item.get("inside", "-1")) if inside > 0: unassigned = False equipped = int(item.get("equipped", "0")) if equipped == 1: unassigned = False # display unassigned items if unassigned: quantity = int(item.get("quantity")) item_id = item.get("id") item_frame = tk.Frame(canvas) item_frame.columnconfigure(1, weight=100) amount_label = tk.Label(item_frame, text=str(quantity) + msg.MULTIPLY, justify=tk.LEFT, width=4) amount_label.grid(row=0, column=0, sticky=tk.EW) name_label = tk.Label(item_frame, text=item.get("name"), justify=tk.LEFT) name_label.bind("<Button-1>", lambda event, item_id=item_id: self. displayItemEditor(event, item_id)) name_label.grid(row=0, column=1, sticky=tk.EW) item_type = item.get("type") if item_type in equippable_types: show = True if item_type == it.TOOLS: container = item.find("container") damage = item.find("damage") if damage is None and container is None: show = False equip_icon = ImageTk.PhotoImage(file="img/equip.png") equip_button = tk.Button(item_frame, image=equip_icon) ToolTip(equip_button, msg.ES_TT_EQUIP) equip_button.image = equip_icon equip_button.bind("<Button-1>", lambda event, item_id=item_id: self. equipItem(event, item_id)) if show: equip_button.grid(row=0, column=2, sticky=tk.EW) else: empty = tk.Label(item_frame, text=" ", width=2) empty.grid(row=0, column=2) else: empty = tk.Label(item_frame, text=" ", width=2) empty.grid(row=0, column=2, sticky=tk.EW) if self.active_bag_id >= 0: pack_icon = ImageTk.PhotoImage(file="img/pack.png") pack_button = tk.Button(item_frame, image=pack_icon) ToolTip(pack_button, msg.ES_TT_PACK) pack_button.image = pack_icon pack_button.bind("<Button-1>", lambda event, item_id=item_id: self. packItem(event, item_id)) pack_button.grid(row=0, column=3, sticky=tk.EW) else: empty = tk.Label(item_frame, text=" ", width=2) empty.grid(row=0, column=3, sticky=tk.EW) canvas.create_window( 0, y, # x, y width=self.canvas_width, window=item_frame, anchor=tk.NW, ) y += name_label.winfo_reqheight() + 5
def getPistolInfo(self, frame): chambered_id = self.item.find("ammo").get("loaded", "-1") chambered_item = self.char.getItemById(str(chambered_id)) first_round = None chamber_frame = tk.LabelFrame(frame, text=msg.IE_LOADED) chamber_frame.pack(fill=tk.X, expand=1) if chambered_item is not None: chamber_info = tk.Label( chamber_frame, text=chambered_item.get("name") ) chamber_info.pack(fill=tk.X, expand=1) else: chamber_frame.config(text=msg.IE_NOT_LOADED) loaded_clip = None content = self.item.get("content", "-1").split() for item_id in content: item = self.char.getItemById(item_id) if item is not None: if item.get("type") == it.CLIP: loaded_clip = item break if loaded_clip is None: label = tk.Label( frame, text=msg.IE_NO_CLIP_LOADED, borderwidth=2, relief=tk.RIDGE ) label.pack(fill=tk.X) else: loaded_clip_frame = tk.LabelFrame( frame, text=msg.IE_CLIP_LOADED ) loaded_rounds = 0 loaded_clip_content = loaded_clip.get("content", "-1").split() try: first_round = self.char.getItemById(loaded_clip_content[0]) except IndexError: pass if first_round is not None: loaded_rounds = len(loaded_clip_content) capacity = loaded_clip.find("container").get("size") info = msg.IE_CLIP_STATUS + str(loaded_rounds)+" / "+str(capacity) content_label = tk.Label(loaded_clip_frame, text=info) content_label.pack(fill=tk.X, expand=1) eject_button = tk.Button(loaded_clip_frame, text=msg.IE_EJECT) eject_button.bind( "<Button-1>", lambda event, clip=loaded_clip: self.ejectClip(event, clip) ) eject_button.pack(fill=tk.X, expand=1) loaded_clip_frame.pack(fill=tk.X, expand=1) fire_button = tk.Button( chamber_frame, text=msg.IE_FIRE_WEAPON, command=self.fireWeapon ) if chambered_item is None or self.char.getEditMode() == "generation": fire_button.config(state=tk.DISABLED) fire_button.pack(fill=tk.X) reload_button = tk.Button(chamber_frame, text=msg.IE_CYCLE_WEAPON) reload_button.bind( "<Button-1>", lambda event, item=first_round: self.reloadChamber(event, item)) reload_button.pack(fill=tk.X) search = "option[@name='"+it.OPTION_CALIBER+"']" caliber = self.item.find(search).get("value") clips = self.getMatchingAmmo(caliber, it.CLIP) if clips: clips_label = tk.Label(frame, text=msg.IE_COMPATIBLE_CLIPS) clips_label.pack() for clip in clips: clip_frame = tk.Frame(frame, borderwidth="1", relief=tk.RIDGE) name_frame = tk.Label(clip_frame) name_frame.pack(fill=tk.X, expand=1) clip_capacity = clip.find("container").get("size") clip_contents = "0" content = clip.get("content", "-1").split() try: first_round = self.char.getItemById(content[0]) except IndexError: first_round = None if first_round is not None: clip_contents = str(len(content)) info = first_round.get("name") + " [" + first_round.find("damage").get("value") + "]" first_round_label = tk.Label(clip_frame, text=info) first_round_label.pack(fill=tk.X, expand=1) if loaded_clip is None: load_button = tk.Button(clip_frame, text=msg.IE_LOAD_WEAPON) load_button.bind( "<Button-1>", lambda event, item=clip: self.loadClip(event, item) ) load_button.pack(fill=tk.X, expand=1) name = clip.get("name") + " ("+clip_contents+"/"+clip_capacity+")" name_frame.config(text=name) clip_frame.pack(fill=tk.X, expand=1)
def showEffectiveMovement(self): """ Calculate and show effective character movement This takes into account the encumberence of equipment as well as the effects of relevant character traits """ phy_val = int(self.char.getAttributeValue(config.CharData.PHY)) # check if the character has a modified strength or speed spd_mod = 0 str_mod = 0 traits = self.char.getTraits() for trait in traits: trait_name = trait.get("name") print(trait_name) effects = trait.findall("effect") if not effects: continue factor = 0 for effect in effects: name = effect.get("name", "none") if name not in ["strength", "movement"]: continue factor = int(effect.get("factor", "1")) rank_value = 1 ranks = trait.findall("rank") for rank in ranks: rank_value = int(rank.get("value", "1")) if name == "strength": str_mod += factor * rank_value elif name == "movement": spd_mod += factor * rank_value lift_base = phy_val + str_mod speed_base = phy_val + spd_mod weights = [ lift_base * config.Core.WEIGHT_LIGHT, lift_base * config.Core.WEIGHT_MARCH, lift_base * config.Core.WEIGHT_HEAVY, lift_base * config.Core.WEIGHT_LIMIT ] range_light = msg.MV_WEIGHT_RANGE.format(low=0, high=weights[0]) range_march = msg.MV_WEIGHT_RANGE.format(low=weights[0], high=weights[1]) range_heavy = msg.MV_WEIGHT_RANGE.format(low=weights[1], high=weights[2]) range_limit = msg.MV_WEIGHT_RANGE.format(low=weights[2], high=weights[3]) # retrieve the current encumberance items = self.char.getItems() equipment_weight = 0 clothing_weight = 0 excess_weight = 0 for item in items: if item.get("equipped", "0") == "1": if item.get("type", "item") == "clothing": clothing_weight += self.char.getWeight(item) if clothing_weight > range_light: excess_weight += clothing_weight - range_light clothing_weight = range_light else: equipment_weight += self.char.getWeight(item) weight_list = [ (msg.MV_WEIGHT_LIGHT, range_light), (msg.MV_WEIGHT_MARCH, range_march), (msg.MV_WEIGHT_HEAVY, range_heavy), (msg.MV_WEIGHT_LIMIT, range_limit) ] gross_weight = equipment_weight + excess_weight encumberance = 0 weight_table = tk.LabelFrame(self, text=msg.MV_WEIGHT_CLASSES) for row, data in enumerate(weight_list): active = False if gross_weight >= weights[row] * 1000: encumberance += 1 if encumberance == row: active = True label = tk.Label(weight_table, text=data[0]) value = tk.Label(weight_table, text=data[1]) if active: label.config(config.Style.RED) value.config(config.Style.RED) label.grid(row=row, column=0, sticky=tk.W) value.grid(row=row, column=1, sticky=tk.W) weight_table.pack() hex_img = ImageTk.PhotoImage(file="img/hex.png") hex_start = ImageTk.PhotoImage(file="img/hex_start.png") hex_jump_start = ImageTk.PhotoImage(file="img/hex_jump_start.png") hex_jump_start_1 = ImageTk.PhotoImage(file="img/hex_jump_start_1.png") hex_jump = ImageTk.PhotoImage(file="img/hex_jump.png") hex_jump_land = ImageTk.PhotoImage(file="img/hex_start.png") hex_light = ImageTk.PhotoImage(file="img/hex_light.png") hex_march = ImageTk.PhotoImage(file="img/hex_march.png") hex_heavy = ImageTk.PhotoImage(file="img/hex_heavy.png") hex_limit = ImageTk.PhotoImage(file="img/hex_limit.png") running_table = tk.LabelFrame(self, text=msg.MV_RUNNING) for i in range(0, speed_base + 1): img = None if i == speed_base: img = hex_light elif i == speed_base - 1: img = hex_march elif i == speed_base - 3: img = hex_heavy else: img = hex_img if i == 0: img = hex_start if i == 1: img = hex_limit if not img: img = hex_img label = tk.Label( running_table, padx=0, pady=0, border=0, image=img ) label.image = img label.pack(side=tk.LEFT, padx=0, pady=0) running_table.pack() jumping_table = tk.LabelFrame(self, text=msg.MV_JUMPING) jump_distance = int(round(speed_base / 2)) start_distance = int(round(jump_distance / 2)) if start_distance < 1: start_distance = 1 if jump_distance < 1: jump_distance = 1 for i in range(start_distance + jump_distance + 1): if i < start_distance: if i == 0: if start_distance == 1: img = hex_jump_start_1 else: img = hex_start elif i < start_distance - 1: img = hex_img else: img = hex_jump_start else: if i == start_distance + jump_distance: img = hex_jump_land else: i = hex_jump label = tk.Label( jumping_table, padx=0, pady=0, border=0, image=img ) label.image = img label.pack(anchor = tk.S, side=tk.LEFT, padx=0, pady=0) jumping_table.pack() info = "Kleidung: {clothing}g, Ausrüstung: {equipment}g\nPHY: {phy}\nLIFT_BASE: {lift}".format( clothing=clothing_weight, equipment=equipment_weight, phy=phy_val, lift=lift_base ) a = tk.Label(self) a.config(text=str(info)) a.pack()
def showResults(self, frame, results): """ display the results of an EWT roll using graphics Args: frame: a tk.Frame() to display the results in (will be cleared on each call) results: expects the results of rollEWT(..,transparent=True)! """ # clear frame widgets = frame.winfo_children() for widget in widgets: widget.destroy() # load images from disk d = {} ewt = {} try: d[1] = ImageTk.PhotoImage(file="img/d1.png") d[2] = ImageTk.PhotoImage(file="img/d2.png") d[3] = ImageTk.PhotoImage(file="img/d3.png") d[4] = ImageTk.PhotoImage(file="img/d4.png") d[5] = ImageTk.PhotoImage(file="img/d5.png") d[6] = ImageTk.PhotoImage(file="img/d6.png") d[7] = ImageTk.PhotoImage(file="img/d7.png") d[8] = ImageTk.PhotoImage(file="img/d8.png") d[9] = ImageTk.PhotoImage(file="img/d9.png") d[10] = ImageTk.PhotoImage(file="img/d0.png") ewt["0"] = ImageTk.PhotoImage(file="img/ewt_00.png") ewt["/"] = ImageTk.PhotoImage(file="img/ewt_05.png") ewt["x"] = ImageTk.PhotoImage(file="img/ewt_10.png") ewt["x+"] = ImageTk.PhotoImage(file="img/ewt_20.png") except IOError: d = {1: "1"} ewt = {"0": "O", "/": "/", "x": "x", "X+": "X+"} # last roll header ... last_roll = self.roll_var.get() parts = last_roll.split("/") if int(parts[1]) > 0: parts[1] = "+"+str(parts[1]) if parts[1] == "0": parts[1] = "±0" tk.Label( frame, text="Letzter Wurf: "+parts[0]+"/"+parts[1], justify=tk.LEFT, font="sans 10 bold" ).pack(anchor=tk.W) roll = 1 sum = 0 for result in results: roll_frame = tk.Frame(frame) if result[1] == 0.0: effect = ewt["0"] if result[1] == 0.5: effect = ewt["/"] if result[1] == 1.0: effect = ewt["x"] if result[2]: text = effect = ewt["x+"] else: roll += 1 # if graphics exist ... if d[1] != "1" and ewt["0"] != "O": dice = d[result[0]] dice_img = tk.Label(roll_frame, image=dice) dice_img.image = dice dice_img.pack(side=tk.LEFT) colon = tk.Label(roll_frame, text=" : ", font="sans 16 bold") colon.pack(side=tk.LEFT) effect_img = tk.Label(roll_frame, image=effect) effect_img.image = effect effect_img.pack(side=tk.LEFT) else: text = "Wurf: "+str(result[0]) + " - Effekt: "+effect roll_frame.pack() sum += result[1] tk.Label( frame, text="Gesamteffekt: "+str(sum), justify=tk.LEFT, font="sans 10 bold" ).pack(anchor=tk.W)
def showControl(self, frame): tpl_ops = [(msg.SL_TT_NEW, "img/tpl_new.png", self._newTemplate), (msg.SL_TT_LOAD, "img/tpl_load.png", self._loadTemplate), (msg.SL_TT_SAVE, "img/tpl_save.png", self._saveTemplate)] tpl = tk.LabelFrame(frame, text="Template") for op in tpl_ops: img = ImageTk.PhotoImage(file=op[1]) button = tk.Button( tpl, text=op[0], image=img, command=op[2], ) tt = ToolTip(button, op[0]) button.image = img button.pack(side=tk.LEFT) tpl.pack(side=tk.LEFT) tk.Label(frame, text=" ").pack(side=tk.LEFT) flip = tk.LabelFrame(frame, text="blättern") icon = ImageTk.PhotoImage(file="img/book_previous.png") self.widgets["last_page"] = tk.Button( flip, image=icon, command=lambda: self._switchPage(-1)) ToolTip(self.widgets["last_page"], msg.SL_TT_LAST) self.widgets["last_page"].image = icon self.widgets["last_page"].pack(side=tk.LEFT, fill=tk.X) self.widgets["cur_page"] = tk.Label(flip, textvariable=self.cur_page) self.widgets["cur_page"].pack(side=tk.LEFT, fill=tk.X) icon = ImageTk.PhotoImage(file="img/book_next.png") self.widgets["next_page"] = tk.Button( flip, image=icon, command=lambda: self._switchPage(+1)) self.widgets["next_page"].image = icon ToolTip(self.widgets["next_page"], msg.SL_TT_NEXT) self.widgets["next_page"].pack(side=tk.LEFT, fill=tk.X) flip.pack(side=tk.LEFT) tk.Label(frame, text=" ").pack(side=tk.LEFT) pages = tk.LabelFrame(frame, text="Seiten") icon = ImageTk.PhotoImage(file="img/page_new.png") self.widgets["new_page"] = tk.Button(pages, image=icon, command=self._newPage) self.widgets["new_page"].image = icon ToolTip(self.widgets["new_page"], msg.SL_TT_NEW_PAGE) self.widgets["new_page"].pack(side=tk.LEFT) icon = ImageTk.PhotoImage(file="img/page_up.png") self.widgets["page_up"] = tk.Button( pages, image=icon, command=lambda: self._movePage(self.active_page - 1)) self.widgets["page_up"].image = icon ToolTip(self.widgets["page_up"], msg.SL_TT_MOVE_UP) self.widgets["page_up"].pack(side=tk.LEFT) icon = ImageTk.PhotoImage(file="img/page_down.png") self.widgets["page_down"] = tk.Button( pages, image=icon, command=lambda: self._movePage(self.active_page + 1)) self.widgets["page_down"].image = icon ToolTip(self.widgets["page_down"], msg.SL_TT_MOVE_DOWN) self.widgets["page_down"].pack(side=tk.LEFT) icon = ImageTk.PhotoImage(file="img/page_del.png") self.widgets["del_page"] = tk.Button(pages, image=icon, command=self._deletePage) self.widgets["del_page"].image = icon ToolTip(self.widgets["del_page"], msg.SL_TT_DEL_PAGE) self.widgets["del_page"].pack(side=tk.LEFT) pages.pack(side=tk.LEFT) tk.Label(frame, text=" ").pack(side=tk.LEFT) style_frame = tk.LabelFrame(frame, text=msg.SL_STYLE) s_icon = ImageTk.PhotoImage(file="img/style_straight.png") if self.template.getroot().get("style") == "straight": s_icon = ImageTk.PhotoImage(file="img/style_straight_sel.png") self.widgets["straight"] = straight_button = tk.Button( style_frame, image=s_icon, command=lambda: self._setStyle("straight")) ToolTip(straight_button, msg.SL_TT_STYLE_STRAIGHT) straight_button.image = s_icon straight_button.pack(side=tk.LEFT) r_icon = ImageTk.PhotoImage(file="img/style_round.png") if self.template.getroot().get("style") == "round": r_icon = ImageTk.PhotoImage(file="img/style_round_sel.png") self.widgets["round"] = round_button = tk.Button( style_frame, image=r_icon, command=lambda: self._setStyle("round")) ToolTip(round_button, msg.SL_TT_STYLE_ROUND) round_button.image = r_icon round_button.pack(side=tk.LEFT) style_frame.pack(side=tk.LEFT) img = ImageTk.PhotoImage(file="img/pdf.png") export = tk.Button(frame, text=msg.SL_EXPORT, image=img, compound=tk.LEFT, command=self._exportPDF) export.image = img export.pack(fill=tk.BOTH, expand=1)
def _showItemInfo(self): """ Display the item info in the main screen section """ item_title = self.item_title item_body = self.item_body # clear the frames (if necessary) widgets = item_title.winfo_children() for widget in widgets: widget.destroy() widgets = item_body.winfo_children() for widget in widgets: widget.destroy() quant_label = tk.Label( item_title, text=str(self.item_quantity) + "x - ", font="Helvetica 12 bold") quant_label.pack(side=tk.LEFT) name_label = tk.Entry( item_title, font="Helvetica 12 bold", ) name_label.insert(0, self.item_name) name_label.config(**config.Style.HIDDEN_ENTRY) name_label.pack(side=tk.LEFT, expand=1) name_label.bind("<Double-Button-1>", self._activateEntryField) name_label.bind( "<Return>", lambda event: self._updateAttribute(event, attribute="name") ) weight = self.getWeight() if weight > 500: weight_str = str(round(weight/1000.0, 2)) weight_str = weight_str.replace(".", ",") + msg.IE_KG else: weight_str = str(weight) + msg.IE_G weight_str = msg.IE_WEIGHT + weight_str # check for limit: limit = 0 container = self.item.find("container") if container is not None: limit = int(container.get("limit", "0")) weight_label = tk.Label(item_body, text=weight_str, anchor=tk.W) if weight > limit > 0: weight_label.config(**config.Style.RED) weight_label.pack(fill=tk.X) price = round(self.item_price * self.item_quantity, 2) price = str(price) if "." in price: price = price.split(".") price[1] = price[1] + "0000" price[1] = price[1][0:2] price = msg.MONEYSPLIT.join(price) price_str = msg.IE_PRICE_VALUE + price price_label = tk.Label(item_body, text=price_str, anchor=tk.W) price_label.pack(fill=tk.X) qualtities = { 1: msg.IE_QUALITY_1, 2: msg.IE_QUALITY_2, 3: msg.IE_QUALITY_3, 4: msg.IE_QUALITY_4, 5: msg.IE_QUALITY_5, 6: msg.IE_QUALITY_6, 7: msg.IE_QUALITY_7, 8: msg.IE_QUALITY_8, 9: msg.IE_QUALITY_9, } quality_str = msg.IE_QUALITY + ": " + qualtities[self.item_quality] quality_frame = tk.Frame(item_body) quality_label = tk.Label( quality_frame, text=quality_str, ) quality_label.pack(side=tk.LEFT) rep_icon = ImageTk.PhotoImage(file="img/repair.png") rep_label = tk.Label(quality_frame, image=rep_icon) rep_label.bind("<Button-1>", self.repair) rep_label.image = rep_icon ToolTip(rep_label, msg.IE_TT_REPAIR) if self.item_quality >= 9: rep_label.config(state=tk.DISABLED) rep_label.pack(side=tk.RIGHT, anchor=tk.W) dmg_icon = ImageTk.PhotoImage(file="img/damage.png") dmg_label = tk.Label(quality_frame, image=dmg_icon) dmg_label.bind("<Button-1>", self.damage) dmg_label.image = dmg_icon dmg_label.pack(side=tk.RIGHT, anchor=tk.W) ToolTip(dmg_label, msg.IE_TT_DAMAGE_ITEM) if self.item_quality <= 1: dmg_label.config(state=tk.DISABLED) quality_frame.pack(fill=tk.X) options = self.item.findall("option") for option in options: name = option.get("name", "") value = option.get("value", "") frame = tk.Frame(self.item_body) display_name = "" if name == it.OPTION_CALIBER: display_name = msg.IE_CALIBER elif name == it.OPTION_COLOR: display_name = msg.IE_CE_FABRIC_COLOR else: display_name = name tk.Label( frame, text=display_name ).pack(side=tk.LEFT, anchor=tk.W) entry = tk.Entry( frame, width=len(value)+2, ) entry.delete(0, tk.END) entry.insert(0, value) entry.config(**config.Style.HIDDEN_ENTRY) entry.bind("<Double-Button-1>", self._activateEntryField) entry.bind( "<Return>", lambda event, name=name: self._updateTag(event, tagname="option", name=name) ) entry.pack(side=tk.RIGHT, anchor=tk.E, fill=tk.X, expand=1) frame.pack(fill=tk.X, expand=1, anchor=tk.W) # display stuff according to item type ... self.showMore(item_body) # display the description Window ... description_text = tk.Text( item_body, width=30, height=8, wrap=tk.WORD, font="Helvetica 9" ) description_text.bind("<KeyRelease>", self.descriptionEdited) description_text.pack(fill=tk.X) description = self.item.find("description") if description is not None: description_text.insert(tk.END, description.text)
def showEquippedGuns(self, canvas): """ This method fills a frame with data about equipped guns canvas: tk.Canvas() where to display the data """ # clear the frame canvas.delete(tk.ALL) # go for the items items = self.char.getItems() y = 0 for item in items: if item.get("equipped", "0") == "1": item_type = item.get("type") weapons = [ it.PISTOL, it.REVOLVER, it.RIFLE, it.SHOT_GUN, it.RIFLE_SA, it.SHOT_GUN_SA, it.AUTOMATIC_WEAPON, ] if item_type in weapons: item_name = item.get("name") damage = item.find("damage").get("value") # retrieve the loaded round chambered_item = None chambers = 1 loaded_chambers = 0 ammo_tag = item.find("ammo") if ammo_tag is not None: active_chamber = int(ammo_tag.get("active", "1")) chambers = int(ammo_tag.get("chambers", "1")) loaded_ammo = ammo_tag.get("loaded", "-1") ammo_list = loaded_ammo.split() chambered_id = ammo_list[active_chamber - 1] chambered_item = self.char.getItemById(chambered_id) for chamber in ammo_list: if chamber != "-1": loaded_chambers += 1 # get other content loaded_clip = None content = item.get("content", "x") if content != "x": content_list = content.split() for content_id in content_list: content_item = self.char.getItemById(content_id) if content_item is not None: content_type = content_item.get("type") if content_type == it.CLIP: loaded_clip = content_item # building the display ... item_id = item.get("id") weapon_frame = tk.Frame(canvas, borderwidth=2, relief=tk.RIDGE) name_line = tk.Frame(weapon_frame) name_label = tk.Label(name_line, text=item_name, justify=tk.LEFT) name_label.bind("<Button-1>", lambda event, item_id=item_id: self. displayItemEditor(event, item_id)) name_label.pack(side=tk.LEFT, fill=tk.X, expand=1) chambered_line = tk.Frame(weapon_frame) if chambered_item is None: damage_label = tk.Label(name_line, text=damage) damage_label.pack(side=tk.RIGHT, anchor=tk.E) chamber_label = tk.Label(chambered_line, text=msg.ES_NOT_LOADED) chamber_label.pack() else: chambered_name = chambered_item.get("name") damage = chambered_item.find("damage").get("value") chamber_label = tk.Label(chambered_line, text=chambered_name) chamber_label.pack(side=tk.LEFT, fill=tk.X, anchor=tk.W) damage_label = tk.Label(chambered_line, text=damage) damage_label.pack(side=tk.RIGHT, anchor=tk.E) ammo_line = tk.Frame(weapon_frame) if loaded_clip is None: ammo_text = msg.ES_CHAMBERED_AMMO.format( chambers=chambers, loaded=loaded_chambers) ammo_label = tk.Label(ammo_line, text=ammo_text) ammo_label.pack(fill=tk.X, expand=1) else: clip_name = loaded_clip.get("name") clip_size = loaded_clip.find("container").get("size") clip_content = loaded_clip.get("content", "x").split() ammo_in_clip = 0 if len(clip_content) == 1 and clip_content[0] == "x": pass else: ammo_in_clip = len(clip_content) ammo_text = msg.ES_CLIP.format(name=clip_name, number=ammo_in_clip, capacity=clip_size) ammo_label = tk.Label(ammo_line, text=ammo_text) ammo_label.pack(fill=tk.X, expand=1) name_line.pack(fill=tk.X, expand=1) chambered_line.pack(fill=tk.X, expand=1) ammo_line.pack(fill=tk.X, expand=1) canvas.create_window( 0, y, # x, y window=weapon_frame, anchor=tk.NW, width=self.canvas_width) self.update_idletasks() y += weapon_frame.winfo_height()
def _modTypeChanged(self, name, e, m): selected = self.vars[name].get() try: frame = self.widgets["options"] except KeyError: frame = None if frame: # cleanup ... widgets = frame.winfo_children() for widget in widgets: widget.destroy() row = str(self.row) col = str(self.col) sizes = self._potentialSizes() if selected == msg.PDF_ATTRIBUTES: if msg.PDF_DOUBLE in sizes: sizes = [msg.PDF_DOUBLE] else: sizes = [""] if selected == msg.PDF_EWT: if msg.PDF_SINGLE in sizes: sizes = [msg.PDF_SINGLE] else: sizes = [""] size = tk.StringVar() self.vars[str(size)] = size self.var_names["size"] = str(size) size_button = tk.OptionMenu( frame, size, *sizes ) size.set(sizes[0]) size_button.pack(fill=tk.X) if selected == msg.PDF_TRAITS: """ trait_type = "all", info_lines = 1, start_index = 0 """ trait_types = [ msg.PDF_ALL_TRAITS, msg.PDF_POSITIVE_TRAITS, msg.PDF_NEGATIVE_TRAITS ] trait_type = tk.StringVar() self.vars[str(trait_type)] = trait_type self.var_names["trait_type"] = str(trait_type) trait_type_button = tk.OptionMenu( frame, trait_type, *trait_types ) trait_type.set(trait_types[0]) trait_type_button.pack(fill=tk.X) info_lines = tk.StringVar() self.vars[str(info_lines)] = info_lines self.var_names["info_lines"] = str(info_lines) info_lines.set("0") info_lines_frame = tk.Frame(frame) info_lines_label = tk.Label( info_lines_frame, text=msg.ME_TEXTLINES ) info_lines_label.pack(side=tk.LEFT) info_lines_spinner = tk.Spinbox( frame, from_=0, to=5, textvariable=info_lines, width=2) info_lines_spinner.pack(side=tk.LEFT) info_lines_frame.pack(fill=tk.X, expand=1) pass if selected == msg.PDF_SKILLS: skill_types = [ msg.PDF_SKILLS_ALL, msg.PDF_SKILLS_ACTIVE, msg.PDF_SKILLS_PASSIVE, msg.PDF_SKILLS_KNOWLEDGE, msg.PDF_SKILLS_LANGUAGE ] skill_type = tk.StringVar() self.vars[str(skill_type)] = skill_type self.var_names["skill_type"] = str(skill_type) skill_type_button = tk.OptionMenu( frame, skill_type, *skill_types ) skill_type.set(skill_types[0]) skill_type_button.pack(fill=tk.X) if selected == msg.PDF_WEAPONS: variants = [ msg.PDF_ALL_WEAPONS, msg.PDF_MELEE, msg.PDF_GUNS, msg.PDF_AMMO ] variant = tk.StringVar() self.vars[str(variant)] = variant self.var_names["variant"] = str(variant) variant_button = tk.OptionMenu( frame, variant, *variants) variant.set(variants[0]) variant_button.pack(fill=tk.X) equipped = tk.IntVar() self.vars[str(equipped)] = equipped self.var_names["equipped"] = str(equipped) equipped.set(0) tk.Checkbutton( frame, text=msg.ME_EQUIPPED_WEAPONS, variable=equipped, offvalue=0, onvalue=1 ).pack(fill=tk.X) amount = tk.IntVar() self.vars[str(amount)] = amount self.var_names["amount"] = str(amount) amount.set(0) tk.Checkbutton( frame, text=msg.ME_SHOW_QUANTITY, variable=amount, offvalue=0, onvalue=1 ).pack(fill=tk.X) info_lines = tk.StringVar() self.vars[str(info_lines)] = info_lines self.var_names["info_lines"] = str(info_lines) info_lines.set("0") info_lines_frame = tk.Frame(frame) info_lines_label = tk.Label( info_lines_frame, text=msg.ME_TEXTLINES ) info_lines_label.pack(side=tk.LEFT) info_lines_spinner = tk.Spinbox( frame, from_=0, to=5, textvariable=info_lines, width=2 ) info_lines_spinner.pack(side=tk.LEFT) info_lines_frame.pack(fill=tk.X, expand=1) if selected == msg.PDF_EQUIPMENT: item_group = tk.StringVar() groups = [ msg.PDF_EQUIPMENT_ALL, msg.PDF_EQUIPMENT_CLOTHING, msg.PDF_EQUIPMENT_TOOLS, msg.PDF_EQUIPMENT_BIOTECH, msg.PDF_EQUIPMENT_MONEY ] self.vars[str(item_group)] = item_group self.var_names["item_group"] = str(item_group) item_group.set(groups[0]) labelframe = tk.LabelFrame(frame, text="Gruppe wählen") tk.OptionMenu( labelframe, item_group, *groups ).pack(fill=tk.X) labelframe.pack(fill=tk.X) # condense items selection ... condensed = tk.IntVar() self.vars[str(condensed)] = condensed self.var_names["condensed"] = str(condensed) condensed.set(0) tk.Checkbutton( frame, text=msg.ME_CONDENSE, variable=condensed, offvalue=0, onvalue=1, ).pack(fill=tk.X, expand=1) # show only equipped stuff selection equipped = tk.IntVar() self.vars[str(equipped)] = equipped self.var_names["equipped"] = str(equipped) equipped.set(0) tk.Checkbutton( frame, text=msg.ME_EQUIPPED_STUFF, variable=equipped, offvalue=0, onvalue=1, ).pack(fill=tk.X, expand=1) # display content selection content = tk.IntVar() self.vars[str(content)] = content self.var_names["content"] = str(content) content.set(0) tk.Checkbutton( frame, text=msg.ME_BAG_CONTENTS, variable=content, offvalue=0, onvalue=1, ).pack(fill=tk.X, expand=1) # display weapons selection display_weapons = tk.IntVar() self.vars[str(display_weapons)] = display_weapons self.var_names["display_weapons"] = str(display_weapons) display_weapons.set(0) tk.Checkbutton( frame, text=msg.ME_SHOW_WEAPONS, variable=display_weapons, offvalue=0, onvalue=1, ).pack(fill=tk.X, expand=1) # use item_id selector use_item_id = tk.IntVar() self.vars[str(use_item_id)] = use_item_id self.var_names["use_item_id"] = str(use_item_id) use_item_id.set(0) use_item_id_button = tk.Checkbutton( frame, text=msg.ME_ONLY_BAG, variable=use_item_id, offvalue=0, onvalue=1, ) use_item_id_button.pack(fill=tk.X, expand=1) # select items that are bags/containers ... items = self.main.char.getItems() containers = [ it.CLOTHING, it.BAG, it.CONTAINER, it.BOX, it.TOOLS, it.HARNESS] self.vars["bags"] = [] for item in items: if item.get("type") in containers: container = item.find("container") if container is not None: item_id = item.get("id") item_name = item.get("name") self.vars["bags"].append(item_id+": "+item_name) if len(self.vars["bags"]) == 0: use_item_id_button.config(state=tk.DISABLED) else: bag_lists = self.vars["bags"] bag_list = tk.StringVar() self.vars[str(bag_list)] = bag_list self.var_names["bag_list"] = str(bag_list) bag_list_button = tk.OptionMenu( frame, bag_list, *bag_lists ) bag_list.set(bag_lists[0]) bag_list_button.pack() # how many info_lines info_lines = tk.StringVar() self.vars[str(info_lines)] = info_lines self.var_names["info_lines"] = str(info_lines) info_lines.set("0") info_lines_frame = tk.Frame(frame) info_lines_label = tk.Label( info_lines_frame, text=msg.ME_TEXTLINES ) info_lines_label.pack(side=tk.LEFT) info_lines_spinner = tk.Spinbox( frame, from_=0, to=5, textvariable=info_lines, width=2 ) info_lines_spinner.pack(side=tk.LEFT) # show weight show_weight = tk.IntVar() self.vars[str(show_weight)] = show_weight self.var_names["show_weight"] = str(show_weight) show_weight.set(0) tk.Checkbutton( info_lines_frame, text=msg.ME_SHOW_WEIGHT, variable=show_weight, offvalue=0, onvalue=1 ).pack(side=tk.LEFT) # show value show_value = tk.IntVar() self.vars[str(show_value)] = show_value self.var_names["show_value"] = str(show_value) show_value.set(0) tk.Checkbutton( info_lines_frame, text=msg.ME_SHOW_VALUE, variable=show_value, offvalue=0, onvalue=1 ).pack(side=tk.LEFT) info_lines_frame.pack(fill=tk.X, expand=1) # add traces (when everything exists) ... condensed.trace("w", self._equipmentOptions) equipped.trace("w", self._equipmentOptions) content.trace("w", self._equipmentOptions) use_item_id.trace("w", self._equipmentOptions) if selected == msg.PDF_CONTACTS: contact_types = [ msg.PDF_ALL_CONTACTS, msg.PDF_FRIENDS, msg.PDF_ENEMIES ] contact_type = tk.StringVar() self.vars[str(contact_type)] = contact_type self.var_names["contact_type"] = str(contact_type) contact_type_button = tk.OptionMenu( frame, contact_type, *contact_types ) contact_type.set(contact_types[0]) contact_type_button.pack(fill=tk.X) info_lines = tk.StringVar() self.vars[str(info_lines)] = info_lines self.var_names["info_lines"] = str(info_lines) info_lines.set("0") info_lines_frame = tk.Frame(frame) info_lines_label = tk.Label( info_lines_frame, text=msg.ME_TEXTLINES ) info_lines_label.pack(side=tk.LEFT) info_lines_spinner = tk.Spinbox( frame, from_=0, to=5, textvariable=info_lines, width=2 ) info_lines_spinner.pack(side=tk.LEFT) info_lines_frame.pack(fill=tk.X, expand=1) if selected == msg.PDF_NOTES: notes = self.main.char.getNotes() entries = [] for note in notes: id = note.get("id", "") name = note.get("name", "") entries.append(id+": "+name) if entries: var = tk.StringVar() var.set(msg.ME_NOT_SELECTED) var.trace("w", self._notesEdited) self.vars["id"] = var sub_frame = tk.LabelFrame(frame, text=msg.ME_NOTES) button = tk.OptionMenu( sub_frame, var, *entries ) button.pack(fill=tk.X) sub_frame.pack(fill=tk.X) title = tk.StringVar() self.vars["title"] = title title_frame = tk.LabelFrame(frame, text=msg.ME_NOTES_TITLE) entry = tk.Entry(title_frame, textvariable=title) entry.pack(fill=tk.X) title_frame.pack(fill=tk.X) title.trace("w", self._notesEdited) if selected == msg.PDF_IMAGE: pass
def getMeleeInfo(self, frame): damage_tag = self.item.find("damage") if damage_tag is not None: damage = damage_tag.get("value") text = msg.IE_DAMAGE.format(value=damage) tk.Label(frame,text=text).pack(fill=tk.X)
def getRevolverInfo(self, frame): number_chambers = int(self.item.find("ammo").get("chambers")) active_chamber = int(self.item.find("ammo").get("active", "1")) loaded_ammo = self.item.find("ammo").get("loaded", "-1") ammo_list = loaded_ammo.split() while len(ammo_list) < number_chambers: ammo_list.append("-1") chamber_frame = tk.LabelFrame(frame, text=msg.IE_CHAMBERS) i = 0 self.widgets["chambers"] = chamber_frame while i < number_chambers: loaded_item = None if len(ammo_list) > i: loaded_item = self.char.getItemById(str(ammo_list[i])) text = msg.IE_EMPTY if loaded_item is not None: text = loaded_item.get("name") chamber_button = tk.Button(chamber_frame, text=text) self.widgets["chamber"+str(i+1)] = chamber_button chamber_button.bind( "<Button-1>", lambda event, chamber=i+1: self.selectChamber(event, chamber) ) chamber_button.pack(fill=tk.X, expand=1) if i == active_chamber - 1: chamber_button.state(["pressed"]) i += 1 chamber_frame.pack(fill=tk.X, expand=1) chambered_item = self.char.getItemById(ammo_list[active_chamber-1]) if chambered_item is not None: if chambered_item.get("name") == msg.IE_SHELL_CASING: chambered_item = None fire_button = tk.Button( chamber_frame, text=msg.IE_FIRE_WEAPON, command=self.fireWeapon ) if chambered_item is None or self.char.getEditMode() == "generation": fire_button.config(state=tk.DISABLED) fire_button.pack(fill=tk.X) eject_button = tk.Button( chamber_frame, text=msg.IE_CLEAR, command=self.ejectBullets ) eject_button.pack(fill=tk.X) select_label = tk.Label(frame, text=msg.IE_AVAILABLE_AMMO) search = "option[@name='"+it.OPTION_CALIBER+"']" caliber = self.item.find(search).get("value") items = self.getMatchingAmmo(caliber) if items: select_label.pack() for item in items: line = tk.Frame(frame) item_id = item.get("id") ammo_button = tk.Button(line, text=item.get("name")) ammo_button.bind( "<Button-1>", lambda event, item=item, line=line: self.loadRoundInChamber(event, item)) ammo_button.pack(side=tk.RIGHT) line.pack()
def _editModule(self, frame): tk.Label(frame, text=msg.ME_EDIT).pack() mod_type = self.module.get("type") # change size ... self.space = self._getSpace() sizes = self._potentialSizes() if mod_type == page.MOD_ATTRIBUTES: if msg.PDF_DOUBLE in sizes: sizes = [msg.PDF_DOUBLE] else: sizes = [""] if mod_type == page.MOD_EWT: if msg.PDF_SINGLE in sizes: sizes = [msg.PDF_SINGLE] else: sizes = [""] tk.Label(frame, text=msg.ME_CHANGE_SIZE).pack() size = tk.StringVar() self.vars[str(size)] = size self.var_names["size"] = str(size) cur_size = self.module.get("size") size_names = { page.SINGLE: msg.PDF_SINGLE, page.WIDE: msg.PDF_WIDE, page.DOUBLE: msg.PDF_DOUBLE, page.QUART: msg.PDF_QUART, page.TRIPLE: msg.PDF_TRIPLE, page.BIG: msg.PDF_BIG, page.FULL: msg.PDF_FULL, page.HALF: msg.PDF_HALF } cur_size = size_names[cur_size] size_button = tk.OptionMenu( frame, size, *sizes ) size.set(cur_size) size_button.pack(fill=tk.X) if mod_type in [ page.MOD_TRAITS, page.MOD_WEAPONS, page.MOD_EQUIPMENT, page.MOD_CONTACTS ]: info_lines = tk.StringVar() self.vars[str(info_lines)] = info_lines self.var_names["info_lines"] = str(info_lines) info_lines_tag = self.module.find("param[@name='info_lines']") if info_lines_tag is not None: info_lines.set(info_lines_tag.get("value", "0")) else: info_lines.set("0") sub_frame = tk.Frame(frame) tk.Label(sub_frame, text=msg.ME_TEXTLINES).pack(side=tk.LEFT) tk.Spinbox( sub_frame, textvariable=info_lines, from_=0, to=5, width=2 ).pack(side=tk.LEFT) sub_frame.pack() tk.Button(frame, text=msg.ME_SAVE, command=self._updateModule).pack() tk.Button(frame, text=msg.ME_DELETE, command=self._removeModule).pack()