Esempio n. 1
0
    def setup_window(self, *args, **kwargs):
        ConverterBase.setup_window(self, *args, **kwargs)

        self.guess_mod2 = tk.IntVar(self, 1)
        self.use_mats = tk.IntVar(self, 1)

        # make the frames
        self.settings_frame = tk.LabelFrame(self, text="Conversion settings")

        # add the buttons
        self.guess_mod2_checkbutton = tk.Checkbutton(
            self.settings_frame, variable=self.guess_mod2,
            text="Locate gbxmodel in directory")
        self.use_mats_checkbutton = tk.Checkbutton(
            self.settings_frame, variable=self.use_mats,
            text="Use collision materials as shaders")

        self.pack_widgets()
        self.apply_style()
Esempio n. 2
0
    def __init__(self, *args, **kwargs):
        data_frame.DataFrame.__init__(self, *args, **kwargs)

        self.checked = tk.IntVar(self)
        self.checkbutton = tk.Checkbutton(
            self,
            variable=self.checked,
            command=self.check,
            text="  ",
            disabledforeground=self.text_disabled_color)

        self.title_label = tk.Label(
            self,
            text=self.gui_name,
            width=self.title_size,
            anchor='w',
            disabledforeground=self.text_disabled_color)

        if self.gui_name != '':
            self.title_label.pack(side='left')
        self.checkbutton.pack(side='left')

        self.populate()
        self._initialized = True
Esempio n. 3
0
    def populate(self):
        bit_opt_map = {}

        desc = self.desc
        for w in (self, self.content, self.check_canvas, self.check_frame,
                  self.title_label):
            w.tooltip_string = self.desc.get('TOOLTIP')

        visible_bits = [
            int(math.log(mask, 2.0)) for mask in sorted(desc['VALUE_MAP'])
        ]
        # create visible bits for all flags that dont have one defined
        if self.all_bools_visible:
            bit_ct = self.field_size * (1 if self.is_bit_based else 8)
            for i in range(bit_ct):
                if len(visible_bits) <= i:
                    visible_bits.extend(range(i, bit_ct))
                    break
                elif visible_bits[i] != i:
                    visible_bits.insert(i, i)

        # make a condensed mapping of all visible flags and their information
        for bit in visible_bits:
            mask = 1 << bit
            opt = desc.get(desc['VALUE_MAP'].get(mask))

            if opt is None or not self.get_visible(opt.get("VISIBLE", True)):
                if not self.all_bools_visible:
                    continue
                name = e_c.UNKNOWN_BOOLEAN % bit
                opt = dict(GUI_NAME=name.replace('_', ' '), NAME=name)
            else:
                opt = dict(opt)
                defname = opt.get('NAME', e_c.UNNAMED_FIELD).replace('_', ' ')
                opt.setdefault('GUI_NAME', defname)

            bit_opt_map[bit] = opt

        if self.bit_opt_map != bit_opt_map:
            self.checkvars = {}
            self.checkbtns = {}

            # destroy all the child widgets of the content
            for c in list(self.check_frame.children.values()):
                c.destroy()

            # loop over each possible boolean(even unused ones)
            for bit in sorted(bit_opt_map):
                opt = bit_opt_map[bit]

                name = opt.get('GUI_NAME', opt['NAME'])
                if opt.get('TOOLTIP'):
                    name += " �"

                self.checkvars[bit] = check_var = tk.IntVar(self.check_frame)
                state = tk.DISABLED
                if opt.get("EDITABLE", not self.disabled):
                    state = tk.NORMAL

                self.checkbtns[bit] = check_btn = tk.Checkbutton(
                    self.check_frame,
                    variable=check_var,
                    padx=0,
                    pady=0,
                    text=name,
                    anchor='nw',
                    justify='left',
                    borderwidth=0,
                    state=state,
                )

                check_btn.config(command=lambda b=check_btn, i=bit, v=
                                 check_var: self._check_bool(b, i, v))

                check_btn.pack(anchor='nw', fill='x', expand=True)
                check_btn.tooltip_string = opt.get('TOOLTIP')

                if e_c.IS_LNX:
                    check_btn.bind('<4>', self.mousewheel_scroll_y)
                    check_btn.bind('<5>', self.mousewheel_scroll_y)
                else:
                    check_btn.bind('<MouseWheel>', self.mousewheel_scroll_y)

            self.apply_style()
            self.bit_opt_map = bit_opt_map

        self.reload()
Esempio n. 4
0
    def setup_window(self, *args, **kwargs):
        ConverterBase.setup_window(self, *args, **kwargs)

        self.include_weather_polyhedra = tk.IntVar(self, 1)
        self.include_fog_planes = tk.IntVar(self, 1)
        self.include_portals = tk.IntVar(self, 1)
        self.include_collision = tk.IntVar(self, 1)
        self.include_renderable = tk.IntVar(self, 1)
        self.include_mirrors = tk.IntVar(self, 0)
        self.include_lightmaps = tk.IntVar(self, 0)

        self.include_markers = tk.IntVar(self, 1)
        self.include_lens_flares = tk.IntVar(self, 0)

        self.fan_portals = tk.IntVar(self, 1)
        self.fan_weather_polyhedra = tk.IntVar(self, 1)
        self.fan_fog_planes = tk.IntVar(self, 1)
        self.fan_mirrors = tk.IntVar(self, 1)
        self.fan_collision = tk.IntVar(self, 1)

        self.optimize_portals = tk.IntVar(self, 0)
        self.optimize_fog_planes = tk.IntVar(self, 0)
        self.weather_tolerance_string = tk.StringVar(
            self, str(self.weather_tolerance))
        self.weather_tolerance_string.trace(
            "w", lambda *a, s=self: s.set_weather_tolerance())

        # make the frames
        self.include_frame = tk.LabelFrame(self,
                                           text="Geometry/markers to include")
        self.weather_tolerance_frame = tk.LabelFrame(
            self, text="Weather polyhedron tolerance")
        self.topology_frame = tk.LabelFrame(self, text="Topology generation")

        # Generate the important frame and its contents
        include_vars = {
            "Weather polyhedra": self.include_weather_polyhedra,
            "Fog planes": self.include_fog_planes,
            "Portals": self.include_portals,
            "Collidable": self.include_collision,
            "Renderable": self.include_renderable,
            "Mirrors": self.include_mirrors,
            "Lightmaps": self.include_lightmaps,
            "Markers": self.include_markers,
            "Lens flares": self.include_lens_flares
        }
        self.include_buttons = []
        for text in ("Collidable", "Portals", "Renderable",
                     "Weather polyhedra", "Fog planes", "Markers", "Mirrors",
                     "Lens flares", "Lightmaps"):
            self.include_buttons.append(
                tk.Checkbutton(self.include_frame,
                               variable=include_vars[text],
                               text=text))

        # Generate the topology frame and its contents
        topology_vars = {
            "Weather polyhedra": self.fan_weather_polyhedra,
            "Fog planes": self.fan_fog_planes,
            "Mirrors": self.fan_mirrors,
            "Portals": self.fan_portals,
            "Collision": self.fan_collision
        }
        self.topology_frames = []
        self.topology_labels = []
        self.topology_buttons = []
        for text in ("Portals", "Fog planes", "Weather polyhedra", "Mirrors",
                     "Collision"):
            var = topology_vars[text]
            f = tk.Frame(self.topology_frame)
            name_lbl = tk.Label(f, text=text, width=17, anchor="w")
            fan_cbtn = tk.Checkbutton(f, variable=var, text="Triangle fan")
            strip_cbtn = tk.Checkbutton(f,
                                        variable=var,
                                        text="Triangle strip",
                                        onvalue=0,
                                        offvalue=1)
            self.topology_frames.append(f)
            self.topology_labels.append(name_lbl)
            self.topology_buttons.extend((fan_cbtn, strip_cbtn))
            if text == "Portals":
                self.topology_buttons.append(
                    tk.Checkbutton(f,
                                   variable=self.optimize_portals,
                                   text="Optimize"))
            elif text == "Fog planes":
                self.topology_buttons.append(
                    tk.Checkbutton(f,
                                   variable=self.optimize_fog_planes,
                                   text="Optimize"))

        self.weather_tolerance_info = tk.Label(
            self.weather_tolerance_frame,
            justify='left',
            anchor="w",
            text=
            ("Due to how weather polyhedrons work, there is no geometry to extract, so it must be generated. \n"
             "My method for doing this isn't perfect, so sometimes geometry will be missing faces. Adjust this\n"
             "value to find the sweet spot. NEVER set to 0, and be wary of setting to 0.0001 or higher.\n"
             "\tNOTE: You will probably need to manually clean up the generated geometry a bit."
             ))
        self.weather_tolerance_spinbox = tk.Spinbox(
            self.weather_tolerance_frame,
            from_=self.min_weather_tolerance,
            to=100,
            width=25,
            increment=self.weather_tolerance,
            textvariable=self.weather_tolerance_string,
            justify="right")

        self.pack_widgets()
        self.apply_style()
Esempio n. 5
0
    def __init__(self, master, *args, **kwargs):
        BinillaWidget.__init__(self)
        self.temp_root = kwargs.pop('temp_root', self.temp_root)
        textures = kwargs.pop('textures', ())
        app_root = kwargs.pop('app_root', ())

        self.image_canvas_ids = []
        self.textures = []
        self._image_handlers = {}

        temp_name = str(int(random.random() * (1 << 32)))
        self.temp_dir = os.path.join(self.temp_root, temp_name)

        kwargs.update(relief='flat',
                      bd=self.frame_depth,
                      bg=self.default_bg_color)
        tk.Frame.__init__(self, master, *args, **kwargs)

        self.bitmap_index = tk.IntVar(self)
        self.mipmap_index = tk.IntVar(self)
        self.depth_index = tk.IntVar(self)
        self.channel_index = tk.IntVar(self)
        self.cube_display_index = tk.IntVar(self)
        self.root_canvas = tk.Canvas(self, highlightthickness=0)
        self.root_frame = tk.Frame(self.root_canvas, highlightthickness=0)

        # create the root_canvas and the root_frame within the canvas
        self.controls_frame0 = tk.Frame(self.root_frame, highlightthickness=0)
        self.controls_frame1 = tk.Frame(self.root_frame, highlightthickness=0)
        self.controls_frame2 = tk.Frame(self.root_frame, highlightthickness=0)
        self.image_root_frame = tk.Frame(self.root_frame, highlightthickness=0)
        self.image_canvas = tk.Canvas(self.image_root_frame,
                                      highlightthickness=0,
                                      bg=self.bitmap_canvas_bg_color)
        self.depth_canvas = tk.Canvas(self.image_canvas,
                                      highlightthickness=0,
                                      bg=self.bitmap_canvas_bg_color)

        self.bitmap_menu = ScrollMenu(self.controls_frame0,
                                      menu_width=7,
                                      variable=self.bitmap_index,
                                      can_scroll=True)
        self.mipmap_menu = ScrollMenu(self.controls_frame1,
                                      menu_width=7,
                                      variable=self.mipmap_index,
                                      can_scroll=True)
        self.depth_menu = ScrollMenu(self.controls_frame2,
                                     menu_width=7,
                                     variable=self.depth_index,
                                     can_scroll=True)
        self.channel_menu = ScrollMenu(self.controls_frame0,
                                       menu_width=9,
                                       variable=self.channel_index,
                                       can_scroll=True)
        self.cube_display_menu = ScrollMenu(self.controls_frame1,
                                            menu_width=9,
                                            variable=self.cube_display_index,
                                            options=("cross", "linear"),
                                            can_scroll=True)

        self.save_button = ttk.Button(self.controls_frame2,
                                      width=11,
                                      text="Browse",
                                      command=self.save_as)
        self.depth_menu.default_text = self.mipmap_menu.default_text =\
                                       self.bitmap_menu.default_text =\
                                       self.channel_menu.default_text =\
                                       self.cube_display_menu.default_text = ""

        labels = []
        labels.append(tk.Label(self.controls_frame0, text="Bitmap index"))
        labels.append(tk.Label(self.controls_frame1, text="Mipmap level"))
        labels.append(tk.Label(self.controls_frame2, text="Depth level"))
        labels.append(tk.Label(self.controls_frame0, text="Channels"))
        labels.append(tk.Label(self.controls_frame1, text="Cubemap display"))
        labels.append(tk.Label(self.controls_frame2, text="Save to file"))
        for lbl in labels:
            lbl.config(width=15,
                       anchor='w',
                       bg=self.default_bg_color,
                       fg=self.text_normal_color,
                       disabledforeground=self.text_disabled_color)

        self.hsb = tk.Scrollbar(self,
                                orient="horizontal",
                                command=self.root_canvas.xview)
        self.vsb = tk.Scrollbar(self,
                                orient="vertical",
                                command=self.root_canvas.yview)
        self.root_canvas.config(xscrollcommand=self.hsb.set,
                                xscrollincrement=1,
                                yscrollcommand=self.vsb.set,
                                yscrollincrement=1)
        for w in [
                self.root_frame, self.root_canvas, self.image_canvas,
                self.controls_frame0, self.controls_frame1,
                self.controls_frame2
        ] + labels:
            if e_c.IS_LNX:
                w.bind('<Shift-4>', self.mousewheel_scroll_x)
                w.bind('<Shift-5>', self.mousewheel_scroll_x)
                w.bind('<4>', self.mousewheel_scroll_y)
                w.bind('<5>', self.mousewheel_scroll_y)
            else:
                w.bind('<Shift-MouseWheel>', self.mousewheel_scroll_x)
                w.bind('<MouseWheel>', self.mousewheel_scroll_y)

        # pack everything
        # pack in this order so scrollbars aren't shrunk
        self.root_frame_id = self.root_canvas.create_window(
            (0, 0), anchor="nw", window=self.root_frame)
        self.hsb.pack(side='bottom', fill='x', anchor='nw')
        self.vsb.pack(side='right', fill='y', anchor='nw')
        self.root_canvas.pack(fill='both', anchor='nw', expand=True)
        self.controls_frame0.pack(side='top', fill='x', anchor='nw')
        self.controls_frame1.pack(side='top', fill='x', anchor='nw')
        self.controls_frame2.pack(side='top', fill='x', anchor='nw')
        self.image_root_frame.pack(fill='both', anchor='nw', expand=True)
        self.image_canvas.pack(fill='both',
                               side='right',
                               anchor='nw',
                               expand=True)

        padx = self.horizontal_padx
        pady = self.horizontal_pady
        for lbl in labels[:3]:
            lbl.pack(side='left', padx=(25, 0), pady=pady)
        self.bitmap_menu.pack(side='left', padx=padx, pady=pady)
        self.mipmap_menu.pack(side='left', padx=padx, pady=pady)
        self.depth_menu.pack(side='left', padx=padx, pady=pady)
        for lbl in labels[3:]:
            lbl.pack(side='left', padx=(15, 0), pady=pady)
        self.save_button.pack(side='left', padx=padx, pady=pady)
        self.channel_menu.pack(side='left', padx=padx, pady=pady)
        self.cube_display_menu.pack(side='left', padx=padx, pady=pady)

        self.change_textures(textures)

        self.write_trace(self.bitmap_index, self.settings_changed)
        self.write_trace(self.mipmap_index, self.settings_changed)
        self.write_trace(self.depth_index, self.settings_changed)
        self.write_trace(self.cube_display_index, self.settings_changed)
        self.write_trace(self.channel_index, self.settings_changed)

        self.apply_style()
Esempio n. 6
0
    def __init__(self, *args, **kwargs):
        BinillaWidget.__init__(self)

        sel_index = kwargs.pop('sel_index', -1)
        disabled = kwargs.pop('disabled', False)

        options = kwargs.pop('options', None)
        self.can_scroll = kwargs.pop('can_scroll', self.can_scroll)
        self.option_getter = kwargs.pop('option_getter', None)
        self.callback = kwargs.pop('callback', None)
        self.variable = kwargs.pop('variable', None)
        self.str_variable = kwargs.pop('str_variable', None)
        self.max_index = kwargs.pop('max_index', self.max_index)
        self.max_height = kwargs.pop('max_height', self.max_height)
        self.f_widget_parent = kwargs.pop('f_widget_parent', None)
        self.menu_width = kwargs.pop('menu_width', 0)
        self.options_volatile = kwargs.pop('options_volatile', False)
        self.default_text = kwargs.pop('default_text', e_c.INVALID_OPTION)

        if self.max_height is None:
            self.max_height = self.scroll_menu_max_height

        kwargs.update(relief='sunken',
                      bd=self.listbox_depth,
                      bg=self.default_bg_color)
        tk.Frame.__init__(self, *args, **kwargs)

        if self.variable is None:
            self.variable = tk.IntVar(self, sel_index)

        self.write_trace(self.variable, lambda *a: self.update_label())

        menu_width = self.menu_width if self.menu_width else self.scroll_menu_width
        self.sel_label = tk.Label(self,
                                  bg=self.enum_normal_color,
                                  fg=self.text_normal_color,
                                  bd=2,
                                  relief='groove',
                                  width=max(
                                      min(menu_width,
                                          self.scroll_menu_max_width), 1))
        # the button_frame is to force the button to be a certain size
        self.button_frame = tk.Frame(self,
                                     relief='flat',
                                     height=18,
                                     width=18,
                                     bd=0)
        self.button_frame.pack_propagate(0)
        self.arrow_button = tk.Button(self.button_frame, text="▼", width=2)
        self.arrow_button.font_type = "fixed_small"
        self.arrow_button.pack()
        #self.arrow_button = ttk.Button(self.button_frame, text="▼", width=2)
        #self.arrow_button.grid(row=1, column=1, sticky='news',
        #                       ipadx=0, ipady=0, padx=0, pady=0)
        self.sel_label.pack(side="left", fill="both", expand=True)
        self.button_frame.pack(side="left", fill="both")

        # make the option box to populate
        option_frame_root = self.winfo_toplevel()
        if hasattr(option_frame_root, "root_frame"):
            option_frame_root = option_frame_root.root_frame

        self.option_frame = tk.Frame(option_frame_root,
                                     highlightthickness=0,
                                     bd=0)
        self.option_frame.pack_propagate(0)
        self.option_bar = tk.Scrollbar(self.option_frame, orient="vertical")
        self.option_box = tk.Listbox(
            self.option_frame,
            highlightthickness=0,
            exportselection=False,
            bg=self.enum_normal_color,
            fg=self.text_normal_color,
            selectbackground=self.enum_highlighted_color,
            selectforeground=self.text_highlighted_color,
            yscrollcommand=self.option_bar.set,
            width=menu_width)
        self.option_bar.config(command=self.option_box.yview)

        # make sure the TagWindow knows these widgets are scrollable
        for w in (self.sel_label, self.button_frame, self.arrow_button,
                  self.option_frame, self.option_bar, self.option_box):
            w.can_scroll = self.can_scroll
            w.f_widget_parent = self.f_widget_parent

        # make bindings so arrow keys can be used to navigate the menu
        self.button_frame.bind('<Up>', self.decrement_sel)
        self.button_frame.bind('<Down>', self.increment_sel)
        self.arrow_button.bind('<Up>', self.decrement_sel)
        self.arrow_button.bind('<Down>', self.increment_sel)
        self.option_bar.bind('<Up>', self.decrement_listbox_sel)
        self.option_bar.bind('<Down>', self.increment_listbox_sel)

        if e_c.IS_LNX:
            self.sel_label.bind('<4>', self._mousewheel_scroll)
            self.sel_label.bind('<5>', self._mousewheel_scroll)
            self.button_frame.bind('<4>', self._mousewheel_scroll)
            self.button_frame.bind('<5>', self._mousewheel_scroll)
            self.arrow_button.bind('<4>', self._mousewheel_scroll)
            self.arrow_button.bind('<5>', self._mousewheel_scroll)
        else:
            self.sel_label.bind('<MouseWheel>', self._mousewheel_scroll)
            self.button_frame.bind('<MouseWheel>', self._mousewheel_scroll)
            self.arrow_button.bind('<MouseWheel>', self._mousewheel_scroll)

        self.sel_label.bind('<Button-1>', self.click_label)
        self.arrow_button.bind('<ButtonRelease-1>', self.select_option_box)
        self.arrow_button.bind('<Return>', self.select_option_box)
        self.arrow_button.bind('<space>', self.select_option_box)
        self.option_bar.bind('<FocusOut>', self.deselect_option_box)
        self.option_bar.bind('<Return>', self.select_menu)
        self.option_bar.bind('<space>', self.select_menu)
        self.option_box.bind('<<ListboxSelect>>', self.select_menu)

        self.set_disabled(disabled)

        if options is not None:
            self.set_options(options)

        if self.str_variable is None:
            self.str_variable = tk.StringVar(self, "")