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 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, 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 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 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 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 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 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 __init__(self, master, **kwargs): super().__init__(master, **kwargs) self.wm_protocol("WM_DELETE_WINDOW", self.close) self.char = master.char self.data = {} editmode = self.editModeSwitcher(self) editmode.pack(fill=tk.BOTH, expand=1) freemode = self.freeModeSwitcher(self) freemode.pack(fill=tk.BOTH, expand=1) switch = tk.Button(self, text=msg.SET_EDIT_SWITCH, command=self.setEditMode) switch.pack(fill=tk.X)
def showRollFrame(self, frame): """ Display an frame to initiate a roll frame: target tk.Frame() The frame will not be cleared, the pack geometry manager is used. """ entry = tk.Entry( frame, font="sans 20 bold", textvariable=self.roll_var, justify=tk.CENTER ) entry.bind("<Return>", self._rollEWT) entry.pack(fill=tk.X, side=tk.LEFT, expand=1) button = tk.Button(frame, text="Würfeln") button.bind("<Button-1>", self._rollEWT) button.pack(fill=tk.Y, side=tk.LEFT)
def _showAspectButtons(self): loaded = self.variant_frame.winfo_children() if loaded: return variants = [(page.ATTRIB_IMAGE, msg.PDF_ATTRIB_IMAGE), (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)] for variant in variants: button = tk.Button( self.variant_frame, text=variant[1], ) button.bind("<Button-1>", self._aspectSelector) button.pack(fill=tk.X) self.variants = variants self.variant_frame.pack(fill=tk.X)
def showToolbar(self): """ Rendering the toolbar """ buttons = [(msg.TOOLBAR_CHAR_DATA, "img/data.png"), (msg.TOOLBAR_CHAR_EQUIP, "img/backpack.png"), (msg.TOOLBAR_CHAR_CONTACTS, "img/contacts.png"), (msg.TOOLBAR_CHAR_NOTES, "img/note.png"), (msg.TOOLBAR_CHAR_IMAGE, "img/char_image.png"), (msg.TOOLBAR_CHAR_LAYOUT, "img/pdf.png")] for i, label in enumerate(buttons): image = ImageTk.PhotoImage(file=label[1]) button = tk.Button(self.toolbar, text=label[0], image=image, compound=tk.TOP) button.image = image button.config( command=lambda label=label[0]: self.switchWindow(label)) button.place(relx=i / 6, relwidth=1 / 6, x=0, relheight=1)
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 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 showNotes(self, canvas): """ display all contacts canvas (tk.Canvas): the canvas to draw on """ # clear canvas canvas.delete("all") # prepare layouting variables row = 0 col = 0 width = canvas.winfo_width() # retrieve notes notes = self.char.getNotes() for note in notes: frame = self.noteFrame(note) x = col * width/self.elements, y = row * self.height, canvas.create_window( x, y, width=width/self.elements, height=self.height, anchor=tk.NW, window=frame ) col += 1 if col >= self.elements: col = 0 row += 1 if self.char.getEditMode() != "view": new_icon = ImageTk.PhotoImage(file="img/note_add.png") new_note = tk.Button( canvas, width=width/self.elements, height=self.height, image=new_icon, command=self.addNote ) new_note.image = new_icon ToolTip(new_note, msg.NS_TT_NEW) x = col * width/self.elements, y = row * self.height, canvas.create_window( x, y, width=width / self.elements, height=self.height, anchor=tk.NW, window=new_note ) self.notes_canvas.config( scrollregion=(0, 0, 1, (row+1)*self.height) )
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 __init__(self, main, app): tk.Frame.__init__(self, main) # localize data ... # create the character instance # # self.app = app self.char = app.char self.skills = app.skills self.traits = app.traits self.itemlist = app.itemlist # stuff that needs to be available across some functions self.global_vars = dict() # defining subwindows to track them! self.open_windows = app.open_windows self.widgets = {} # from here on we are building the screen layout ... # column 1 ... self.frame_1 = frame_1 = tk.Frame(self) frame_1.place(relheight=1, relwidth=1 / 12, relx=0, rely=0, anchor=tk.NW) # starting with the attribute frame ... attr_frame = tk.Frame(frame_1) attr_list = self.char.ATTRIB_LIST attr_names = [ msg.PHY, msg.MEN, msg.SOZ, msg.NK, msg.FK, msg.LP, msg.EP, msg.MP ] edit_mode = self.char.getEditMode() for attr, name in zip(attr_list, attr_names): frame = tk.LabelFrame( attr_frame, font=config.Style.ATTR_LF_FONT, text=name, ) # initiate the IntVars and bind their tcl names to the attributes attrib_values = self.char.attrib_values attrib_values[attr] = tk.IntVar() attrib_values[attr].set(self.char.getAttributeValue(attr)) # in generation mode we have spinboxes ... if edit_mode == cd.GENERATION: self.char.attrib_trace[str(attrib_values[attr])] = attr self.widgets[attr] = tk.Spinbox( frame, from_=core.MIN_ATTRIBUTE, to=core.MAX_ATTRIBUTE, font=config.Style.ATTR_FONT, justify=tk.CENTER, textvariable=attrib_values[attr], width=3) self.widgets[attr].pack(fill=tk.X) self.char.widgets = self.widgets self.char.attrib_values[attr].trace("w", self.char.attributeChange) # in edit mode there are buttons and labels if edit_mode == cd.EDIT: frame.columnconfigure(0, weight=100) value_field = tk.Label(frame, textvariable=attrib_values[attr], font=config.Style.ATTR_FONT, width=3) value_field.grid(row=0, column=0, sticky=tk.EW) plus = ImageTk.PhotoImage(file="img/plus_s.png") self.widgets[attr + "_inc"] = tk.Label( frame, image=plus, ) self.widgets[attr + "_inc"].image = plus self.widgets[attr + "_inc"].bind( "<Button-1>", lambda event, attr=attr: self.increaseAttribute(attr)) self.widgets[attr + "_inc"].grid(row=0, column=1, sticky=tk.EW) # in view and sim mode there is only a label ... if edit_mode in [cd.VIEW, cd.SIMULATION]: value_field = tk.Label(frame, textvariable=attrib_values[attr], font=config.Style.ATTR_FONT, width=3) value_field.pack(fill=tk.X, expand=1) frame.pack(fill=tk.X) attr_frame.pack(fill=tk.X, anchor=tk.N) # this displays the characters XP xp_frame = tk.LabelFrame(frame_1, text=msg.XP) xp_avail = tk.Label(xp_frame, textvariable=self.char.xp_avail) self.char.xp_avail.set(self.char.getAvailableXP()) xp_avail.pack(side=tk.LEFT) xp_total_text = " / " + str(self.char.getTotalXP()) self.xp_total = tk.Label(xp_frame, text=xp_total_text) self.xp_total.pack(side=tk.LEFT) xp_frame.pack(fill=tk.X) # this makes the second block frame_2 = tk.Frame(self) # beginning with the data frame data_frame = tk.LabelFrame( frame_2, font=config.Style.TITLE_LF_FONT, text=msg.CS_BASE_DATA, ) data_list = [[cd.NAME, msg.NAME, 0, 0, 4], [cd.SPECIES, msg.SPECIES, 1, 0, 4], [cd.ORIGIN, msg.ORIGIN, 2, 0, 4], [cd.CONCEPT, msg.CONCEPT, 3, 0, 4], [cd.PLAYER, msg.PLAYER, 4, 0, 4], [cd.HEIGHT, msg.HEIGHT, 5, 0, 1], [cd.WEIGHT, msg.WEIGHT, 5, 1, 1], [cd.AGE, msg.AGE, 5, 2, 1], [cd.GENDER, msg.GENDER, 5, 3, 1], [cd.HAIR, msg.HAIR, 6, 0, 1], [cd.EYES, msg.EYES, 6, 1, 1], [cd.SKIN, msg.SKIN_COLOR, 6, 2, 1], [cd.SKIN_TYPE, msg.SKIN_TYPE, 6, 3, 1]] for data in data_list: frame = tk.LabelFrame(data_frame, text=data[1]) # creating a StringVar() and linking the tcl name value_var = tk.StringVar() self.char.data_values[data[0]] = value_var self.char.data_trace[str(value_var)] = data[0] # retrieve already stored data from character stored_value = self.char.getData(data[0]) if stored_value: value_var.set(stored_value) width = 10 * data[4] entry = tk.Entry(frame, textvariable=value_var, width=width, **config.Style.DATA_STYLE) if edit_mode in [cd.VIEW, cd.SIMULATION]: entry.config(state=tk.DISABLED) else: entry.bind("<FocusOut>", self.dataUpdated) entry.pack(fill=tk.BOTH, expand=1) frame.grid(row=data[2], column=data[3], columnspan=data[4], sticky="NSWE") for row in range(7): data_frame.rowconfigure(row, weight=1) for col in range(4): data_frame.columnconfigure(col, weight=1) data_frame.pack(fill=tk.BOTH, anchor=tk.N, expand=1) # within this frame will be the character traits traits_frame = tk.LabelFrame( frame_2, font=config.Style.TITLE_LF_FONT, text=msg.CS_TRAITS, ) self.traits_text = tk.Text(traits_frame, bg="#eeeeee", font="Arial 10", wrap=tk.WORD, height=5, width=10) self.updateTraitList() # finally pack the field and disable it for editing self.traits_text.pack(fill=tk.BOTH, expand=1) traits_frame.pack(fill=tk.BOTH, expand=1) new_traits_button = tk.Button(frame_2, text=msg.CS_ADD_TRAIT, command=self.showTraitWindow) if edit_mode in [cd.VIEW, cd.SIMULATION]: new_traits_button.config(state=tk.DISABLED) new_traits_button.pack(fill=tk.X) traits_frame.pack(fill=tk.BOTH, expand=1) frame_2.place(relheight=1, relwidth=.4 - 1 / 12, relx=1 / 12, rely=0, anchor=tk.NW) # this frame holds the character skills ... frame_3 = tk.Frame(self) skill_frame = tk.Frame(frame_3) # active skills ... self.active_skill_frame = tk.LabelFrame( skill_frame, font=config.Style.TITLE_LF_FONT, text=msg.CS_ACTIVE_SKILLS, ) self.active_skill_canvas = tk.Canvas(self.active_skill_frame, width=1, height=1) self.active_skill_canvas.bind("<Configure>", lambda event: self.updateSkillList()) self.active_skill_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.active_skill_scroll = tk.Scrollbar(self.active_skill_frame, orient=tk.VERTICAL) self.active_skill_scroll.pack(side=tk.LEFT, fill=tk.Y) self.active_skill_scroll.config(command=self.active_skill_canvas.yview) self.active_skill_canvas.config( yscrollcommand=self.active_skill_scroll.set) # passive skills self.passive_skill_frame = tk.LabelFrame( skill_frame, font=config.Style.TITLE_LF_FONT, text=msg.CS_PASSIVE_SKILLS, ) self.passive_skill_canvas = tk.Canvas(self.passive_skill_frame, width=1, height=1) self.passive_skill_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.passive_skill_scroll = tk.Scrollbar(self.passive_skill_frame, orient=tk.VERTICAL) self.passive_skill_scroll.pack(side=tk.LEFT, fill=tk.Y) self.passive_skill_scroll.config( command=self.passive_skill_canvas.yview) self.passive_skill_canvas.config( yscrollcommand=self.passive_skill_scroll.set) # initialize the list and place it on screen ... self.updateSkillList() self.active_skill_frame.place(relx=0, rely=0, relwidth=.5, relheight=1, anchor=tk.NW) self.passive_skill_frame.place(relx=0.5, rely=0, relwidth=.5, relheight=1, anchor=tk.NW) skill_frame.pack(fill=tk.BOTH, expand=1) # and a button to add skills new_skill_button = tk.Button(frame_3, text=msg.CS_ADD_SKILLS, command=self.showSkillWindow) if edit_mode in ["view", "simulation"]: new_skill_button.config(state=tk.DISABLED) new_skill_button.pack(fill=tk.X) frame_3.place(relheight=1, relwidth=.6, relx=.4, rely=0, anchor=tk.NW)
def __init__(self, main, app): tk.Frame.__init__(self, main) self.app = app self.char = app.char self.itemlist = app.itemlist self.canvas_width = 0 self.account_info = tk.StringVar() self.active_bag_id = -1 self.open_windows = app.open_windows # define the three columns self.left_frame = tk.Frame(self) self.left_frame.place(relx=0, rely=0, relwidth=1 / 3, relheight=1, anchor=tk.NW) # displaying the characters initial account self.initial_account_frame = self.initialAccount(self.left_frame) self.initial_account_frame.pack(fill=tk.X) self.updateInitialAccount() # a button to buy new stuff (opens the InventoryEditor) self.buy_button = tk.Button(self.left_frame, text=msg.ES_BUY_BUTTON, command=self.displayInventoryEditor) self.buy_button.pack(fill=tk.X) # show equipped items self.equipped_frame = tk.LabelFrame(self.left_frame, text=msg.ES_EQUIPPED, font=config.Style.TITLE_LF_FONT) self.equipped_canvas = tk.Canvas(self.equipped_frame, width=1, height=1) self.equipped_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.equipped_scroll = tk.Scrollbar(self.equipped_frame, orient=tk.VERTICAL) self.equipped_scroll.pack(side=tk.LEFT, fill=tk.Y) self.equipped_scroll.config(command=self.equipped_canvas.yview) self.equipped_canvas.config(yscrollcommand=self.equipped_scroll.set) self.equipped_frame.pack(fill=tk.BOTH, expand=1) self.showEquippedItems() # center frame # used for the weapons self.center_frame = tk.Frame(self) self.melee_frame = tk.LabelFrame(self.center_frame, text=msg.ES_MELEE, font=config.Style.TITLE_LF_FONT) self.melee_canvas = tk.Canvas(self.melee_frame, width=1, height=1) self.melee_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.melee_scroll = tk.Scrollbar(self.melee_frame, orient=tk.VERTICAL) self.melee_scroll.pack(side=tk.LEFT, fill=tk.Y) self.melee_scroll.config(command=self.melee_canvas.yview) self.melee_canvas.config(yscrollcommand=self.melee_scroll.set) self.melee_frame.place(relx=0, rely=0, relwidth=1, relheight=.5, anchor=tk.NW) self.guns_frame = tk.LabelFrame(self.center_frame, text=msg.ES_GUNS, font=config.Style.TITLE_LF_FONT) self.guns_canvas = tk.Canvas(self.guns_frame, width=1, height=1) self.guns_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.guns_scroll = tk.Scrollbar(self.guns_frame, orient=tk.VERTICAL) self.guns_scroll.pack(side=tk.LEFT, fill=tk.Y) self.guns_scroll.config(command=self.guns_canvas.yview) self.guns_canvas.config(yscrollcommand=self.guns_scroll.set) self.guns_frame.place(relx=0, rely=0.5, relwidth=1, relheight=.5, anchor=tk.NW) self.center_frame.place(relx=1 / 3, rely=0, relwidth=1 / 3, relheight=1, anchor=tk.NW) self.showEquippedGuns(self.guns_canvas) self.showEquippedMelee(self.melee_canvas) # the right frame is used for unassigned items self.right_frame = tk.Frame(self) self.unassigned_frame = tk.LabelFrame(self.right_frame, text=msg.ES_UNASSIGNED, font=config.Style.TITLE_LF_FONT) self.unassigned_canvas = tk.Canvas(self.unassigned_frame, height=1, width=1) self.unassigned_canvas.bind("<Configure>", self.updateItemList) self.unassigned_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.unassigned_scroll = tk.Scrollbar(self.unassigned_frame, orient=tk.VERTICAL) self.unassigned_scroll.pack(side=tk.LEFT, fill=tk.Y) self.unassigned_scroll.config(command=self.unassigned_canvas.yview) self.unassigned_canvas.config( yscrollcommand=self.unassigned_scroll.set) self.unassigned_frame.place(relx=0, rely=0, relwidth=1, relheight=1, anchor=tk.NW) self.right_frame.place(relx=2 / 3, rely=0, relwidth=1 / 3, relheight=1, anchor=tk.NW) self.showUnassignedItems()
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 __init__(self, main, app): tk.Frame.__init__(self, main) self.app = app self.char = app.char self.width = 0 self.height = 0 self.image = None self.images = [] self.variants = {} self.selected_size = "" self.selected_ratio = 0 self.x = None self.y = None # this checks if there are still operations going on ... self.finished = 0 self.update = 0 # create canvas ... self.edit_frame = tk.Frame(self) self.edit_frame.pack(side=tk.LEFT, fill=tk.X, anchor=tk.N) self.image_canvas = tk.Canvas(self, width=1, height=1) self.image_canvas.bind("<B1-Motion>", self._moveFrame) self.image_canvas.bind("<ButtonRelease-1>", self._stopMotion) self.image_canvas.bind_all("+", self._scaleFrame) self.image_canvas.bind_all("-", self._scaleFrame) self.image_canvas.bind_all("<Left>", self._moveFrame) self.image_canvas.bind_all("<Right>", self._moveFrame) self.image_canvas.bind_all("<Up>", self._moveFrame) self.image_canvas.bind_all("<Down>", self._moveFrame) self.image_canvas.bind("<Configure>", self.resize) self.image_canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.load_button = tk.Button(self.edit_frame) self.load_button.pack() self._checkForImage() # TEST tk.Button( self.edit_frame, text="TESTEXPORT", command=self._test, ).pack(fill=tk.X) self.variant_frame = tk.LabelFrame(self.edit_frame, text=msg.IS_SET_SELECTION) self.img_on_canvas = None self.rect = None # try loading an existing image ... image_tag = self.char.getImage() if image_tag is not None: self.update_idletasks() filename = image_tag.get("file") self.image = Image.open(filename) self._displayImage()
def addMenuIcons(self): widgets = self.item_menu.winfo_children() for widget in widgets: widget.destroy() # reset check ... self.destroy_check = 0 if self.item.get("equipped", "0") == "1": unequip_icon = ImageTk.PhotoImage(file="img/unequip_l.png") unequip_button = tk.Button( self.item_menu, image=unequip_icon, command=self.unequipItem ) unequip_button.image = unequip_icon if self.item.get("type") != it.IMPLANT: unequip_button.pack(side=tk.LEFT) ToolTip(unequip_button, msg.IE_TT_UNEQUIP) else: item_type = self.item.get("type", "") if item_type in self.app.itemlist.EQUIPPABLE: show = True # tools are not always equippable ... if item_type == config.ItemTypes.TOOLS: container = self.item.find("container") damage = self.item.find("damage") if container is None and damage is None: show = False equip_icon = ImageTk.PhotoImage(file="img/equip_l.png") equip_button = tk.Button( self.item_menu, image=equip_icon, command=self.equipItem ) equip_button.image = equip_icon if show: equip_button.pack(side=tk.LEFT) ToolTip(equip_button, msg.IE_TT_EQUIP) if int(self.item_quantity) > 1: self.split_number.set("1") split_scroller = tk.Spinbox( self.item_menu, textvariable=self.split_number, width=2, from_=1, to=int(self.item_quantity) - 1 ) ToolTip(split_scroller, msg.IE_TT_SPLIT_AMOUNT) split_scroller.pack(side=tk.LEFT, fill=tk.Y) split_icon = ImageTk.PhotoImage(file="img/split.png") split_button = tk.Button( self.item_menu, image=split_icon, command=self.split ) split_button.image = split_icon split_button.pack(side=tk.LEFT) ToolTip(split_button, msg.IE_TT_SPLIT) if self.char.getIdenticalItem(self.item) is not None: condense_icon = ImageTk.PhotoImage(file="img/join.png") condense_button = tk.Button( self.item_menu, image=condense_icon, command=self.condense ) condense_button.image = condense_icon condense_button.pack(side=tk.LEFT) ToolTip(condense_button, msg.IE_TT_CONDENSE) sell_icon = ImageTk.PhotoImage(file="img/money.png") sell_button = tk.Button( self.item_menu, image=sell_icon, command=self.sellItem ) sell_button.image = sell_icon sell_button.pack(side=tk.LEFT) ToolTip(sell_button, msg.IE_TT_SELL) destroy_icon = ImageTk.PhotoImage(file="img/cross.png") destroy_button = tk.Button( self.item_menu, image=destroy_icon, command=self.destroyItem ) destroy_button.image = destroy_icon if self.char.getEditMode() == "generation": destroy_button.config(state=tk.DISABLED) destroy_button.pack(side=tk.LEFT) ToolTip(destroy_button, msg.IE_TT_DESTROY)
def noteFrame(self, note): id = note.get("id", "") name = note.get("name", "") update = lambda event, id=id: self._update(event, id) text = note.text if not text: text = "" frame = tk.Frame(self.notes_canvas) title = tk.Entry(frame, width=15, font="Arial 14 bold") title.insert("0", name) title.bind("<KeyRelease>", update) title.place( x=0, y=0, relheight=.1, relwidth=.9, anchor=tk.NW ) del_icon = ImageTk.PhotoImage(file="img/cross_small.png") delete_button = tk.Button( frame, image=del_icon, ) delete_button.bind( "<Button-1>", lambda event, id=id: self._delNote(event, id)) ToolTip(delete_button, msg.NS_TT_DELETE) delete_button.image = del_icon delete_button.place( relx=1, y=0, relheight=.1, relwidth=.1, anchor=tk.NE ) text_widget = tk.Text( frame, width=1, height=1, wrap=tk.WORD, borderwidth=0, highlightthickness=1, highlightbackground="#666666", font="Arial 10" ) text_widget.insert("0.0", text) text_widget.bind("<KeyRelease>", update) text_widget.place( relx=0, rely=.1, relheight=.9, relwidth=1, anchor=tk.NW ) if self.char.getEditMode() == "view": title.config(state=tk.DISABLED) delete_button.config(state=tk.DISABLED) text_widget.config( state=tk.DISABLED, background="#eeeeee", borderwidth=0, highlightthickness=1, highlightbackground="#cccccc", ) return frame
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 showContacts(self, canvas): """ display all contacts canvas (tk.Canvas): the canvas to draw on """ # clear canvas canvas.delete("all") # prepare layouting variables row = 0 col = 0 width = canvas.winfo_width() # retrieve contacts contacts = self.char.getContacts() for contact in contacts: # automatically remove contacts that were created # but never stored ... if contact.get("xp") is None: id = contact.get("id") self.char.removeContactById(id) # render contact to canvas ... else: id = contact.get("id") contact_frame = ContactFrame(canvas, contact=contact) contact_frame.bind("<Button-1>", lambda event, id=id: self.editContact(id)) # draw box to canvas x = col * width / self.elements, y = row * self.height, canvas.create_window(x, y, width=width / self.elements, height=self.height, anchor=tk.NW, window=contact_frame) # set grid location for next box ... col += 1 if col >= self.elements: col = 0 row += 1 # finally add a button to add contacts ... plus_image = ImageTk.PhotoImage(file="img/plus.png") new_button = tk.Button(canvas, image=plus_image, command=self.newContact) new_button.image = plus_image # draw box to canvas x = col * width / self.elements, y = row * self.height, canvas.create_window(x, y, width=width / self.elements, height=self.height, anchor=tk.NW, window=new_button) self.contact_canvas.config(scrollregion=(0, 0, 1, (row + 1) * self.height))
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 __init__(self, app): tk.Toplevel.__init__(self, app) # point to character and skilltree self.char = app.char self.all_skills = app.skills self.app = app self.app.open_windows["skill"] = self self.minspec = 1 self.maxspec = 3 self.origin = "" self.complete_list = [skill[0] for skill in self.all_skills.getList()] # icons: self.unsel_icon = ImageTk.PhotoImage(file="img/unsel.png") self.sel_icon = ImageTk.PhotoImage(file="img/sel.png") # build the window if self.char.getEditMode == "generation": self.title(msg.SS_ADD_REMOVE_SKILLS) else: self.title(msg.SS_ADD_SKILLS) self.protocol("WM_DELETE_WINDOW", self.close) self.search_frame = tk.Frame(self) self.search = tk.StringVar() self.search_gf = tk.Button(self.search_frame, width=3, text=msg.SS_BASE, command=self.toggleMinSpec) self.search_gf.config(relief=tk.SUNKEN) ToolTip(self.search_gf, msg.SS_TT_SHOW_BASE) self.search_gf.pack(side=tk.LEFT) self.search_sp = tk.Button(self.search_frame, width=3, text=msg.SS_SPEC, command=self.toggleMaxSpec) self.search_sp.config(relief=tk.SUNKEN) ToolTip(self.search_sp, msg.SS_TT_SHOW_SPEC) self.search_sp.pack(side=tk.LEFT) self.search_box = tk.Entry(self.search_frame, textvariable=self.search) ToolTip(self.search_box, msg.SS_TT_SEARCH) self.search_box.pack(side=tk.LEFT, fill=tk.X, expand=1) self.search_button = tk.Button( self.search_frame, text=msg.SS_SEARCH, command=lambda: self._showSkills(search=True)) self.search_button.pack(side=tk.RIGHT) self.search_frame.pack(fill=tk.X, expand=1) self.frame = tk.Frame(self) self.scrollbar = tk.Scrollbar(self.frame, orient=tk.VERTICAL) self.list_box = tk.Treeview(self.frame) self.list_box.bind("<<TreeviewSelect>>", self._selectionChanged) self.list_box.config( selectmode=tk.EXTENDED, yscrollcommand=self.scrollbar.set, height=20, show="tree", ) self.scrollbar.config(command=self.list_box.yview) self.list_box.pack(side=tk.LEFT, fill=tk.BOTH, expand=1) self.scrollbar.pack(side=tk.RIGHT, fill=tk.Y) self.frame.pack(fill=tk.BOTH) self.new_skill_name = tk.StringVar() self.new_skill_name.set(msg.SS_NEW_SKILL) self.new_skill_name.trace( "w", lambda name, empty, mode: self._newSkillName()) self.new_skill_check = False self.new_skill_entry = tk.Entry(self, textvariable=self.new_skill_name, state=tk.DISABLED) self.new_skill_entry.bind("<FocusIn>", self._skillEntryFocus) self.new_skill_entry_focus = False self.new_skill_entry.pack(fill=tk.X) self.add_button_text = tk.StringVar() self.add_button = tk.Button(self, textvariable=self.add_button_text, command=self.addSkills, state=tk.DISABLED) if self.char.getEditMode() == "generation": self.add_button_text.set(msg.SS_ADD_REMOVE_SKILLS) else: self.add_button_text.set(msg.SS_ADD_SKILLS) self.add_button.pack(fill=tk.X) self._showSkills() self.focus()
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()