Exemplo n.º 1
0
    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 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()
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    def editModeSwitcher(self, parent):
        """ create a frame with the edit modes 
        
        Note: 
            registers a tk.StringVar for the selected mode
        
        Args:
            parent (tk.Widget): the master widget
        
        Returns:
            tk.LabelFrame: the selector 
        """

        var = self.data["editmode"] = tk.StringVar()

        frame = tk.LabelFrame(parent, text=msg.SET_EDIT_MODE)
        modes = [(msg.SET_EDIT_GENERATION, cd.GENERATION),
                 (msg.SET_EDIT_EDIT, cd.EDIT), (msg.SET_EDIT_VIEW, cd.VIEW),
                 (msg.SET_EDIT_SIM, cd.SIMULATION)]
        for txt, val in modes:
            button = tk.Radiobutton(
                frame,
                text=txt,
                variable=var,
                value=val,
            )
            button.deselect()
            button.pack(anchor=tk.W)

        var.set(self.char.getEditMode())

        return frame
Exemplo n.º 5
0
    def freeModeSwitcher(self, parent):
        """ displays Checkbuttons for the free modes 
                
        Note: 
            registers a tk.IntVars for the selected modes
        
        Args:
            parent (tk.Widget): the master widget
        
        Returns:
            tk.LabelFrame: the selector 
        """

        free_xp = self.data["free_xp"] = tk.IntVar()
        if self.char.getFreeXP(): free_xp.set(1)
        free_money = self.data["free_money"] = tk.IntVar()
        if self.char.getFreeMoney(): free_money.set(1)

        frame = tk.LabelFrame(parent, text=msg.SET_FREE_MODE)
        free_xp_button = tk.Checkbutton(frame,
                                        text=msg.SET_FREE_XP,
                                        variable=free_xp,
                                        onvalue=1,
                                        offvalue=0)
        free_xp_button.pack()
        free_money_button = tk.Checkbutton(frame,
                                           text=msg.SET_FREE_MONEY,
                                           variable=free_money,
                                           onvalue=1,
                                           offvalue=0)
        free_money_button.pack()
        return frame
Exemplo n.º 6
0
    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))
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    def showContact(self, frame):
        """
        This method creates the information screen, adds respective variables and links the traces ...
        frame: the tkinter content frame in which the data shall be shown
        """

        # clear any old widgets ...
        widgets = self.main_screen.winfo_children()
        for widget in widgets:
            widget.destroy()

        # setup the screen and the variables
        self.vars["name"] = tk.StringVar()
        name_frame = tk.LabelFrame(frame, text=msg.NAME)
        name_entry = tk.Entry(name_frame, textvariable=self.vars["name"])
        name_entry.pack(fill=tk.X)
        name_frame.pack(fill=tk.X)

        self.vars["location"] = tk.StringVar()
        location_frame = tk.LabelFrame(frame, text=msg.SE_LOCATION)
        location_entry = tk.Entry(location_frame,
                                  textvariable=self.vars["location"])
        location_entry.pack(fill=tk.X)
        location_frame.pack(fill=tk.X)

        self.vars["competency"] = tk.StringVar()
        self.vars["competency_level"] = tk.StringVar()
        competency_frame = tk.LabelFrame(frame, text=msg.SE_COMPETENCY)
        competency_entry = tk.Entry(competency_frame,
                                    textvariable=self.vars["competency"])
        competency_level = tk.Spinbox(
            competency_frame,
            from_=1,
            to=9,
            textvariable=self.vars["competency_level"],
            width=2)
        competency_entry.pack(side=tk.LEFT, fill=tk.X, expand=1)
        competency_level.pack(side=tk.LEFT, anchor=tk.E)
        competency_frame.pack(fill=tk.X)

        self.vars["loyality"] = tk.StringVar()
        self.vars["loyality_level"] = tk.StringVar()
        loyality_frame = tk.LabelFrame(frame, text=msg.SE_LOYALITY)
        loyality_label = tk.Label(loyality_frame,
                                  textvariable=self.vars["loyality"])
        loyality_label.pack(fill=tk.X)
        loyality_level = tk.Scale(loyality_frame,
                                  from_=-3,
                                  to=3,
                                  variable=self.vars["loyality_level"],
                                  orient=tk.HORIZONTAL)
        loyality_level.pack(fill=tk.X)
        loyality_frame.pack(fill=tk.X)

        self.vars["frequency"] = tk.StringVar()
        self.vars["frequency_level"] = tk.StringVar()
        frequency_frame = tk.LabelFrame(frame, text=msg.SE_FREQUENCY)
        frequency_label = tk.Label(frequency_frame,
                                   textvariable=self.vars["frequency"])
        frequency_label.pack(fill=tk.X)
        frequency_level = tk.Scale(frequency_frame,
                                   from_=0,
                                   to=5,
                                   variable=self.vars["frequency_level"],
                                   orient=tk.HORIZONTAL)
        frequency_level.pack(fill=tk.X)
        frequency_frame.pack(fill=tk.X)

        description_frame = tk.LabelFrame(frame, text=msg.SE_DESCRIPTION)
        description_text = tk.Text(description_frame,
                                   width=40,
                                   height=10,
                                   wrap=tk.WORD,
                                   font="Arial 9")
        description_text.bind("<KeyRelease>", self.descriptionChanged)
        description_text.pack(fill=tk.X)
        description_frame.pack(fill=tk.X)

        # adding the traces ...
        # needs to be down here to make sure all variables exist
        variables = [
            "name", "location", "competency", "competency_level",
            "loyality_level", "frequency_level"
        ]

        for variable in variables:
            self.vars[variable].trace("w", self.dataChanged)

        # TODO: maybe clean this up ...
        self.vars["name"].set(self.contact.get("name"))
        self.vars["location"].set(self.contact.get("location", ""))
        self.vars["loyality_level"].set(self.contact.get("loyality", "0"))
        stored_frequency = float(self.contact.get("frequency", "1.0"))
        frequencies = {0.25: 0, 0.5: 1, 0.75: 2, 1.0: 3, 1.5: 4, 2.0: 5}
        self.vars["frequency_level"].set(frequencies[stored_frequency])
        self.vars["competency_level"].set(
            self.contact.get("competencylevel", "4"))
        self.vars["competency"].set(self.contact.get("competency", ""))

        self.vars["description"] = None
        description = self.contact.find("description")
        if description is not None:
            self.vars["description"] = description.text
        if self.vars["description"] is None:
            self.vars["description"] = ""
        description_text.insert(tk.END, self.vars["description"])
    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)
Exemplo n.º 11
0
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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()
Exemplo n.º 15
0
    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()
Exemplo n.º 16
0
    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()
Exemplo n.º 17
0
    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()