def update_info(self, event=None): s, t, w, h, clean_s, clean_t = sculpty.map_size( self.x_faces.get(), self.y_faces.get(), self.levels.get()) self.info_frame.config(text="Map Size - %d x %d" % (w, h)) self.info_text.set(sculpty.lod_info(w, h)[:-1]) if sculpty.check_clean(w, h, self.x_faces.get(), self.y_faces.get(), self.clean_lods.get()): self.clean_lods_input.configure( background=gui.theme.others['panel'], foreground=gui.theme.defaults['foreground']) pow2 = [2, 4, 8, 16, 32, 64, 128, 256] if self.x_faces.get() in pow2 and self.y_faces.get() in pow2: self.clean_lods_input.configure(state=DISABLED) else: self.clean_lods_input.configure(state=NORMAL) else: self.clean_lods_input.configure( background=gui.theme.defaults['foreground'], foreground=gui.theme.others['panel'], state=NORMAL) if self.shape_name.get() not in ['Plane', 'Hemi']: if self.x_faces.get() < 3: clean_s = False self.create_button.configure(state=DISABLED) if self.y_faces.get() < 3: clean_t = False self.create_button.configure(state=DISABLED) elif self.x_faces.get() > 2: self.create_button.configure(state=NORMAL) else: self.create_button.configure(state=NORMAL) if clean_s and clean_t: self.levels_input.configure( background=gui.hex_color(gui.theme.ui.textfield), foreground=gui.theme.defaults['foreground']) else: self.levels_input.configure( background=gui.theme.defaults['foreground'], foreground=gui.hex_color(gui.theme.ui.textfield)) if clean_s: self.x_faces_input.configure( background=gui.hex_color(gui.theme.ui.textfield), foreground=gui.theme.defaults['foreground']) else: self.x_faces_input.configure( background=gui.theme.defaults['foreground'], foreground=gui.hex_color(gui.theme.ui.textfield)) if clean_t: self.y_faces_input.configure( background=gui.hex_color(gui.theme.ui.textfield), foreground=gui.theme.defaults['foreground']) else: self.y_faces_input.configure( background=gui.theme.defaults['foreground'], foreground=gui.hex_color(gui.theme.ui.textfield))
def update_info(self, event=None): s, t, w, h, clean_s, clean_t = sculpty.map_size(self.x_faces.get(), self.y_faces.get(), self.levels.get()) self.info_frame.config(text="Map Size - %d x %d" % (w, h)) self.info_text.set(sculpty.lod_info(w, h)[:-1]) if sculpty.check_clean(w, h, self.x_faces.get(), self.y_faces.get(), self.clean_lods.get()): self.clean_lods_input.configure( background=gui.theme.others["panel"], foreground=gui.theme.defaults["foreground"] ) pow2 = [2, 4, 8, 16, 32, 64, 128, 256] if self.x_faces.get() in pow2 and self.y_faces.get() in pow2: self.clean_lods_input.configure(state=DISABLED) else: self.clean_lods_input.configure(state=NORMAL) else: self.clean_lods_input.configure( background=gui.theme.defaults["foreground"], foreground=gui.theme.others["panel"], state=NORMAL ) if self.shape_name.get() not in ["Plane", "Hemi"]: if self.x_faces.get() < 3: clean_s = False self.create_button.configure(state=DISABLED) if self.y_faces.get() < 3: clean_t = False self.create_button.configure(state=DISABLED) elif self.x_faces.get() > 2: self.create_button.configure(state=NORMAL) else: self.create_button.configure(state=NORMAL) if clean_s and clean_t: self.levels_input.configure( background=gui.hex_color(gui.theme.ui.textfield), foreground=gui.theme.defaults["foreground"] ) else: self.levels_input.configure( background=gui.theme.defaults["foreground"], foreground=gui.hex_color(gui.theme.ui.textfield) ) if clean_s: self.x_faces_input.configure( background=gui.hex_color(gui.theme.ui.textfield), foreground=gui.theme.defaults["foreground"] ) else: self.x_faces_input.configure( background=gui.theme.defaults["foreground"], foreground=gui.hex_color(gui.theme.ui.textfield) ) if clean_t: self.y_faces_input.configure( background=gui.hex_color(gui.theme.ui.textfield), foreground=gui.theme.defaults["foreground"] ) else: self.y_faces_input.configure( background=gui.theme.defaults["foreground"], foreground=gui.hex_color(gui.theme.ui.textfield) )
def __init__(self, master): self.master = master self.cube_icon = gui.BitmapImage( data="""#define cube_width 16 #define cube_height 16 static unsigned char cube_bits[] = { 0x00, 0x00, 0x80, 0x03, 0x70, 0x1c, 0x8c, 0x62, 0x94, 0x53, 0x64, 0x4c, 0xa4, 0x4b, 0x2c, 0x69, 0x34, 0x59, 0x64, 0x4d, 0xa4, 0x4b, 0x2c, 0x69, 0x30, 0x19, 0x40, 0x05, 0x80, 0x03, 0x00, 0x00 }; """ ) self.file_icon = gui.BitmapImage( data="""#define file_open_width 16 #define file_open_height 16 static unsigned char file_open_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0xfe, 0x01, 0x0c, 0x02, 0x08, 0x04, 0x00, 0x04, 0xf0, 0x00, 0x08, 0x7f, 0xf8, 0x40, 0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0xf8, 0x7f, 0x00, 0x00 }; """ ) # ========================================== # Main window frame # ========================================== top_frame = gui.Frame(self.master, border=4) top_frame.pack() frame = gui.LabelFrame(top_frame, text=LABEL, labelanchor=NW) frame.pack() # ========================================== # Settings frame # ========================================== shape_frame = gui.Frame(frame) shape_frame.pack(fill=X) t = gui.Label(shape_frame, text="Shape", justify=RIGHT, font=("Helvetica", 9, "bold")) t.pack(side=LEFT) self.shape_name = StringVar(self.master) self.shape_name.set(settings["shape_name"]) self.shape_file = settings["shape_file"] self.map_type = gui.Button( shape_frame, textvariable=self.shape_name, command=self.set_map_type, cursor="based_arrow_down", background=gui.hex_color(gui.theme.ui.textfield), relief=SUNKEN, pady=1, anchor=NW, ) self.map_type.pack(expand=True, fill=X, side=LEFT) file_button = gui.Button( shape_frame, image=self.file_icon, compound=LEFT, command=self.set_file, default=ACTIVE ) file_button.pack(side=RIGHT) # ========================================== # Geometry section # ========================================== f = gui.LabelFrame(frame, text="Geometry") f.pack(side=LEFT, fill=Y) fx = gui.Frame(f) fx.pack(expand=True) t = gui.Label(fx, text="X Faces", justify=RIGHT) t.pack(side=LEFT) self.x_faces = IntVar(self.master) self.x_faces.set(settings["x_faces"]) self.x_faces_input = gui.Spinbox( fx, textvariable=self.x_faces, from_=1, to=256, width=3, command=self.update_info ) self.x_faces_input.bind("<Key>", self.update_info) self.x_faces_input.pack(side=RIGHT) fy = gui.Frame(f) fy.pack(expand=True) t = gui.Label(fy, text="Y Faces", justify=RIGHT) t.pack(side=LEFT) self.y_faces = IntVar(self.master) self.y_faces.set(settings["y_faces"]) self.y_faces_input = gui.Spinbox( fy, textvariable=self.y_faces, from_=1, to=256, width=3, command=self.update_info ) self.y_faces_input.bind("<Key>", self.update_info) self.y_faces_input.pack(side=RIGHT) fr = gui.Frame(f) fr.pack(expand=True) t = gui.Label(fr, text="Radius", justify=RIGHT) t.pack(side=LEFT) self.radius = DoubleVar(self.master) self.radius.set(settings["radius"]) self.radius_input = gui.Spinbox( fr, textvariable=self.radius, from_=0.05, to=0.5, increment=0.025, format="%4.3f", width=5 ) self.radius_input.pack(side=RIGHT) self.clean_lods = BooleanVar(self.master) self.clean_lods.set(settings["clean_lods"]) self.clean_lods_input = gui.Checkbutton( f, text="Clean LODs", variable=self.clean_lods, command=self.update_info ) self.clean_lods_input.pack(expand=True) # ========================================== # Subdivision section # ========================================== middle_frame = gui.Frame(frame) middle_frame.pack(side=LEFT, padx=4, fill=BOTH) fs = gui.LabelFrame(middle_frame, text="Subdivision") fs.pack(fill=X) self.levels = IntVar(self.master) self.levels.set(settings["levels"]) fl = gui.Frame(fs) fl.pack() t = gui.Label(fl, text="Levels", justify=RIGHT) t.pack(side=LEFT) self.levels_input = gui.Spinbox(fl, textvariable=self.levels, from_=0, to=6, width=3, command=self.update_info) self.levels_input.bind("<Key>", self.update_info) self.levels_input.pack(side=RIGHT) self.sub_type = IntVar(self.master) self.sub_type.set(settings["sub_type"]) r = gui.Frame(fs) r.pack(side=LEFT) gui.Radiobutton(r, text="Subsurf", variable=self.sub_type, value=1).pack() gui.Radiobutton(r, text="Multires", variable=self.sub_type, value=0).pack() self.subdivision = IntVar(self.master) self.subdivision.set(settings["subdivision"]) r = gui.Frame(fs) r.pack(side=RIGHT) gui.Radiobutton(r, text="Catmull", variable=self.subdivision, value=1).pack() gui.Radiobutton(r, text="Simple", variable=self.subdivision, value=0).pack() # ========================================== # Mesh Type Selection # ========================================== mesh_frame = gui.LabelFrame(middle_frame, text="Mesh Type") mesh_frame.pack(fill=X) self.quads = IntVar(self.master) self.quads.set(settings["quads"]) gui.Radiobutton(mesh_frame, text="Quads", variable=self.quads, value=1).pack(side=LEFT) gui.Radiobutton(mesh_frame, state=DISABLED, text="Triangles", variable=self.quads, value=0).pack(side=LEFT) # ========================================== # LOD display and Create button # ========================================== build_frame = gui.Frame(frame) build_frame.pack(fill=Y, side=LEFT) self.info_text = StringVar(self.master) self.info_frame = gui.LabelFrame(build_frame) self.info_frame.pack() self.lod_display = gui.Label(self.info_frame, textvariable=self.info_text, justify=LEFT) self.lod_display.pack() self.create_button = gui.Button( build_frame, text="Build", image=self.cube_icon, compound=LEFT, command=self.add, default=ACTIVE ) self.create_button.pack(fill=BOTH, expand=True, anchor=SE, pady=5) self.update_info() # ========================================== # Save settings frame # ========================================== self.save_defaults = BooleanVar(self.master) self.save_defaults.set(False) self.save_settings = BooleanVar(self.master) self.save_settings.set(settings["save"]) save_frame = gui.Frame(build_frame) save_frame.pack(fill=Y) t = gui.Checkbutton(save_frame, text="Save", variable=self.save_settings) t.pack(side=LEFT) t = gui.Checkbutton(save_frame, text="Defaults", variable=self.save_defaults) t.pack(side=LEFT) # ========================================== # Popup menu for base mesh shape # ========================================== self.sculpt_menu = gui.Menu(self.master, tearoff=0) for sculpt_type in ["Cylinder", "Hemi", "Plane", "Sphere", "Torus X", "Torus Z"]: def type_command(sculpt_type): def new_command(): self.set_shape(sculpt_type) return new_command self.sculpt_menu.add_command(label=sculpt_type, command=type_command(sculpt_type)) self.sculpt_menu.add_separator() library = sculpty.build_lib(LibDir=MenuDir, LibFile=MenuMap) library.add_to_menu(self, self.sculpt_menu) self.set_shape(settings["shape_name"], settings["shape_file"]) self.master.bind("<Button-1>", self.click_handler)
def __init__(self, master): self.master = master self.cube_icon = gui.BitmapImage(data="""#define cube_width 16 #define cube_height 16 static unsigned char cube_bits[] = { 0x00, 0x00, 0x80, 0x03, 0x70, 0x1c, 0x8c, 0x62, 0x94, 0x53, 0x64, 0x4c, 0xa4, 0x4b, 0x2c, 0x69, 0x34, 0x59, 0x64, 0x4d, 0xa4, 0x4b, 0x2c, 0x69, 0x30, 0x19, 0x40, 0x05, 0x80, 0x03, 0x00, 0x00 }; """) self.file_icon = gui.BitmapImage(data="""#define file_open_width 16 #define file_open_height 16 static unsigned char file_open_bits[] = { 0x00, 0x00, 0x08, 0x00, 0x0c, 0x00, 0xfe, 0x01, 0x0c, 0x02, 0x08, 0x04, 0x00, 0x04, 0xf0, 0x00, 0x08, 0x7f, 0xf8, 0x40, 0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0x08, 0x40, 0xf8, 0x7f, 0x00, 0x00 }; """) # ========================================== # Main window frame # ========================================== top_frame = gui.Frame(self.master, border=4) top_frame.pack() frame = gui.LabelFrame(top_frame, text=LABEL, labelanchor=NW) frame.pack() # ========================================== # Settings frame # ========================================== shape_frame = gui.Frame(frame) shape_frame.pack(fill=X) t = gui.Label(shape_frame, text="Shape", justify=RIGHT, font=('Helvetica', 9, 'bold')) t.pack(side=LEFT) self.shape_name = StringVar(self.master) self.shape_name.set(settings['shape_name']) self.shape_file = settings['shape_file'] self.map_type = gui.Button(shape_frame, textvariable=self.shape_name, command=self.set_map_type, cursor='based_arrow_down', background=gui.hex_color( gui.theme.ui.textfield), relief=SUNKEN, pady=1, anchor=NW) self.map_type.pack(expand=True, fill=X, side=LEFT) file_button = gui.Button(shape_frame, image=self.file_icon, compound=LEFT, command=self.set_file, default=ACTIVE) file_button.pack(side=RIGHT) # ========================================== # Geometry section # ========================================== f = gui.LabelFrame(frame, text="Geometry") f.pack(side=LEFT, fill=Y) fx = gui.Frame(f) fx.pack(expand=True) t = gui.Label(fx, text="X Faces", justify=RIGHT) t.pack(side=LEFT) self.x_faces = IntVar(self.master) self.x_faces.set(settings['x_faces']) self.x_faces_input = gui.Spinbox(fx, textvariable=self.x_faces, from_=1, to=256, width=3, command=self.update_info) self.x_faces_input.bind('<Key>', self.update_info) self.x_faces_input.pack(side=RIGHT) fy = gui.Frame(f) fy.pack(expand=True) t = gui.Label(fy, text="Y Faces", justify=RIGHT) t.pack(side=LEFT) self.y_faces = IntVar(self.master) self.y_faces.set(settings['y_faces']) self.y_faces_input = gui.Spinbox(fy, textvariable=self.y_faces, from_=1, to=256, width=3, command=self.update_info) self.y_faces_input.bind('<Key>', self.update_info) self.y_faces_input.pack(side=RIGHT) fr = gui.Frame(f) fr.pack(expand=True) t = gui.Label(fr, text="Radius", justify=RIGHT) t.pack(side=LEFT) self.radius = DoubleVar(self.master) self.radius.set(settings['radius']) self.radius_input = gui.Spinbox(fr, textvariable=self.radius, from_=0.05, to=0.5, increment=0.025, format="%4.3f", width=5) self.radius_input.pack(side=RIGHT) self.clean_lods = BooleanVar(self.master) self.clean_lods.set(settings['clean_lods']) self.clean_lods_input = gui.Checkbutton(f, text="Clean LODs", variable=self.clean_lods, command=self.update_info) self.clean_lods_input.pack(expand=True) # ========================================== # Subdivision section # ========================================== middle_frame = gui.Frame(frame) middle_frame.pack(side=LEFT, padx=4, fill=BOTH) fs = gui.LabelFrame(middle_frame, text="Subdivision") fs.pack(fill=X) self.levels = IntVar(self.master) self.levels.set(settings['levels']) fl = gui.Frame(fs) fl.pack() t = gui.Label(fl, text="Levels", justify=RIGHT) t.pack(side=LEFT) self.levels_input = gui.Spinbox(fl, textvariable=self.levels, from_=0, to=6, width=3, command=self.update_info) self.levels_input.bind('<Key>', self.update_info) self.levels_input.pack(side=RIGHT) self.sub_type = IntVar(self.master) self.sub_type.set(settings['sub_type']) r = gui.Frame(fs) r.pack(side=LEFT) gui.Radiobutton(r, text="Subsurf", variable=self.sub_type, value=1).pack() gui.Radiobutton(r, text="Multires", variable=self.sub_type, value=0).pack() self.subdivision = IntVar(self.master) self.subdivision.set(settings['subdivision']) r = gui.Frame(fs) r.pack(side=RIGHT) gui.Radiobutton(r, text="Catmull", variable=self.subdivision, value=1).pack() gui.Radiobutton(r, text="Simple", variable=self.subdivision, value=0).pack() # ========================================== # Mesh Type Selection # ========================================== mesh_frame = gui.LabelFrame(middle_frame, text="Mesh Type") mesh_frame.pack(fill=X) self.quads = IntVar(self.master) self.quads.set(settings['quads']) gui.Radiobutton(mesh_frame, text="Quads", variable=self.quads, value=1).pack(side=LEFT) gui.Radiobutton(mesh_frame, state=DISABLED, text="Triangles", variable=self.quads, value=0).pack(side=LEFT) # ========================================== # LOD display and Create button # ========================================== build_frame = gui.Frame(frame) build_frame.pack(fill=Y, side=LEFT) self.info_text = StringVar(self.master) self.info_frame = gui.LabelFrame(build_frame) self.info_frame.pack() self.lod_display = gui.Label(self.info_frame, textvariable=self.info_text, justify=LEFT) self.lod_display.pack() self.create_button = gui.Button(build_frame, text="Build", image=self.cube_icon, compound=LEFT, command=self.add, default=ACTIVE) self.create_button.pack(fill=BOTH, expand=True, anchor=SE, pady=5) self.update_info() # ========================================== # Save settings frame # ========================================== self.save_defaults = BooleanVar(self.master) self.save_defaults.set(False) self.save_settings = BooleanVar(self.master) self.save_settings.set(settings['save']) save_frame = gui.Frame(build_frame) save_frame.pack(fill=Y) t = gui.Checkbutton(save_frame, text="Save", variable=self.save_settings) t.pack(side=LEFT) t = gui.Checkbutton(save_frame, text="Defaults", variable=self.save_defaults) t.pack(side=LEFT) # ========================================== # Popup menu for base mesh shape # ========================================== self.sculpt_menu = gui.Menu(self.master, tearoff=0) for sculpt_type in [ "Cylinder", "Hemi", "Plane", "Sphere", "Torus X", "Torus Z" ]: def type_command(sculpt_type): def new_command(): self.set_shape(sculpt_type) return new_command self.sculpt_menu.add_command(label=sculpt_type, command=type_command(sculpt_type)) self.sculpt_menu.add_separator() library = sculpty.build_lib(LibDir=MenuDir, LibFile=MenuMap) library.add_to_menu(self, self.sculpt_menu) self.set_shape(settings['shape_name'], settings['shape_file']) self.master.bind('<Button-1>', self.click_handler)