def build_dlg(self): top = self.top var_number = DoubleVar(top) var_unit = StringVar(top) self.var_pos = LengthVar(1.0, config.preferences.default_unit, var_number, var_unit, command = self.set_pos) pos_frame = Frame(top) pos_frame.pack(side = TOP, fill = X, expand = 0) self.var_label = StringVar(top) self.var_label.set('X:') label = Label(pos_frame, textvariable = self.var_label) label.pack(side = LEFT, expand = 1, anchor = E) entry = MyEntry(pos_frame, textvariable = var_number, justify = RIGHT, width = 4, command = self.var_pos.UpdateNumber) entry.pack(side = LEFT, expand = 1, fill = X, anchor = E) scroll = MiniScroller(pos_frame, variable = var_number, min = 0, max = None, step = 1) scroll.pack(side = LEFT, fill = Y) optmenu = create_unit_menu(pos_frame, self.set_unit, variable = var_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W) list_frame = Frame(top) list_frame.pack(side = TOP, expand = 1, fill = BOTH) sb_vert = Scrollbar(list_frame, takefocus = 0) sb_vert.pack(side = RIGHT, fill = Y) guides = UpdatedListbox(list_frame, name = 'list') guides.pack(expand = 1, fill = BOTH) guides.Subscribe(SELECTION, self.select_guide) sb_vert['command'] = (guides, 'yview') guides['yscrollcommand'] = (sb_vert, 'set') self.guides = guides self.selected = None frame = Frame(top) frame.pack(side = BOTTOM, fill = X) button = UpdatedButton(frame, text = _("Add H"), command = self.add_guide, args = 1) button.pack(side = LEFT) button = UpdatedButton(frame, text = _("Add V"), command = self.add_guide, args = 0) button.pack(side = LEFT) button = UpdatedButton(frame, text = _("Delete"), command = self.del_guide) button.pack(side = LEFT) button = UpdatedButton(frame, text = _("Close"), command = self.close_dlg) button.pack(side = RIGHT)
def __init__(self, master=None, **kw): apply(PatternFrame.__init__, (self, master), kw) frame = Frame(self) frame.pack(side = TOP, fill = X, expand = 1) self.colors = [None, None] self.colors[0] = ColorButton(frame, height = 1, command = self.set_color, args = 0) self.colors[0].pack(side = LEFT, fill = X, expand = 1) self.colors[1] = ColorButton(frame, height = 1, command = self.set_color, args = 1) self.colors[1].pack(side = LEFT, fill = X, expand = 1) var_spacing_number = DoubleVar(self) var_unit = StringVar(self) self.var_spacing = LengthVar(1.0, config.preferences.default_unit, var_spacing_number, var_unit, command = self.set_spacing) width_frame = Frame(self) width_frame.pack(side = TOP, fill = X, expand = 1) #label = Label(width_frame, text = 'Spacing') #label.pack(side = LEFT, expand = 1, anchor = E) entry = MyEntry(width_frame, textvariable = var_spacing_number, justify = RIGHT, width = 6, command = self.var_spacing.UpdateNumber) entry.pack(side = LEFT, expand = 1, fill = X) scroll = MiniScroller(width_frame, variable = var_spacing_number, min = 0.0, max = None, step = 1.0, command = self.var_spacing.UpdateNumber) scroll.pack(side = LEFT, fill = Y) optmenu = create_unit_menu(width_frame, self.var_spacing.UpdateUnit, variable = var_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W) self.SetPattern(HatchingPattern(StandardColors.red))
def build_dlg(self): top = self.top # # Undo # undo_frame = self.make_frame() label = Label(undo_frame, text=_("# Undo Levels:"), anchor=E) label.pack(side=LEFT, expand=1, fill=X) self.var_undo = IntVar(top) self.undo_entry = Entry(undo_frame, textvariable=self.var_undo, width=4) self.undo_entry.pack(side=LEFT) self.var_unlimited = IntVar(top) check = UpdatedCheckbutton(undo_frame, text=_("unlimited"), variable=self.var_unlimited, command=self.unlimited_undo) check.pack(side=RIGHT, expand=1, anchor=W) limit = preferences.undo_limit if limit == None: self.var_undo.set(10) self.var_unlimited.set(1) else: if limit < 0: limit = 0 self.var_undo.set(limit) self.var_unlimited.set(0) # # Duplication # off_frame = self.make_frame() var_off_x_number = DoubleVar(top) var_off_y_number = DoubleVar(top) var_off_x_unit = StringVar(top) var_off_y_unit = StringVar(top) x, y = preferences.duplicate_offset unit = config.preferences.default_unit self.var_off_x = LengthVar(x, unit, var_off_x_number, var_off_x_unit) self.var_off_y = LengthVar(y, unit, var_off_y_number, var_off_y_unit) label = Label(off_frame, text=_("Duplication Offset")) label.pack(side=TOP, anchor=W) label = Label(off_frame, text=_("Hor.")) label.pack(side=LEFT, expand=1, anchor=E) entry = MyEntry(off_frame, textvariable=var_off_x_number, width=6, command=self.var_off_x.UpdateNumber) entry.pack(side=LEFT, fill=X, anchor=E) label = Label(off_frame, text=_("Vert.")) label.pack(side=LEFT, anchor=E) entry = MyEntry(off_frame, textvariable=var_off_y_number, width=6, command=self.var_off_y.UpdateNumber) entry.pack(side=LEFT, fill=X, anchor=E) def CallBoth(arg, x=self.var_off_x, y=self.var_off_y): x.UpdateUnit(arg) y.UpdateUnit(arg) optmenu = create_unit_menu(off_frame, CallBoth, variable=var_off_x_unit, indicatoron=0, width=3) optmenu.pack(side=LEFT, expand=1, anchor=W) # # Default Unit # self.default_unit = config.preferences.default_unit frame = self.make_frame() label = Label(frame, text=_("Default Unit")) label.pack(side=LEFT, expand=1) menu = create_unit_menu(frame, self.set_unit, indicatoron=0, width=3, text=self.default_unit) menu.pack(side=RIGHT, expand=1) # # Gradient Patterns # #self.var_steps = IntVar(top) #self.var_steps.set(preferences.gradient_steps) #frame = self.make_frame() #label = Label(frame, text = 'Gradient Steps') # # Standard Buttons (OK, Cancel) # but_frame = Frame(top) but_frame.pack(side=BOTTOM, fill=BOTH, expand=1, padx=4, pady=4) button = UpdatedButton(but_frame, text=_("OK"), command=self.ok) button.pack(side=LEFT, expand=1) button = UpdatedButton(but_frame, text=_("Cancel"), command=self.close_dlg) button.pack(side=RIGHT, expand=1)
class OptionDialog: def __init__(self, master, main_window): self.master = master self.main_window = main_window top = Toplevel(master) top.title(_("Global Options")) top.transient(master) top.protocol('WM_DELETE_WINDOW', self.close_dlg) top.geometry('%+d%+d' % (master.winfo_rootx() + 100, master.winfo_rooty() + 100)) self.top = top self.build_dlg() def make_frame(self): frame = Frame(self.top, relief=GROOVE, bd=2) frame.pack(side=TOP, expand=1, fill=X, padx=4, pady=4) return frame def build_dlg(self): top = self.top # # Undo # undo_frame = self.make_frame() label = Label(undo_frame, text=_("# Undo Levels:"), anchor=E) label.pack(side=LEFT, expand=1, fill=X) self.var_undo = IntVar(top) self.undo_entry = Entry(undo_frame, textvariable=self.var_undo, width=4) self.undo_entry.pack(side=LEFT) self.var_unlimited = IntVar(top) check = UpdatedCheckbutton(undo_frame, text=_("unlimited"), variable=self.var_unlimited, command=self.unlimited_undo) check.pack(side=RIGHT, expand=1, anchor=W) limit = preferences.undo_limit if limit == None: self.var_undo.set(10) self.var_unlimited.set(1) else: if limit < 0: limit = 0 self.var_undo.set(limit) self.var_unlimited.set(0) # # Duplication # off_frame = self.make_frame() var_off_x_number = DoubleVar(top) var_off_y_number = DoubleVar(top) var_off_x_unit = StringVar(top) var_off_y_unit = StringVar(top) x, y = preferences.duplicate_offset unit = config.preferences.default_unit self.var_off_x = LengthVar(x, unit, var_off_x_number, var_off_x_unit) self.var_off_y = LengthVar(y, unit, var_off_y_number, var_off_y_unit) label = Label(off_frame, text=_("Duplication Offset")) label.pack(side=TOP, anchor=W) label = Label(off_frame, text=_("Hor.")) label.pack(side=LEFT, expand=1, anchor=E) entry = MyEntry(off_frame, textvariable=var_off_x_number, width=6, command=self.var_off_x.UpdateNumber) entry.pack(side=LEFT, fill=X, anchor=E) label = Label(off_frame, text=_("Vert.")) label.pack(side=LEFT, anchor=E) entry = MyEntry(off_frame, textvariable=var_off_y_number, width=6, command=self.var_off_y.UpdateNumber) entry.pack(side=LEFT, fill=X, anchor=E) def CallBoth(arg, x=self.var_off_x, y=self.var_off_y): x.UpdateUnit(arg) y.UpdateUnit(arg) optmenu = create_unit_menu(off_frame, CallBoth, variable=var_off_x_unit, indicatoron=0, width=3) optmenu.pack(side=LEFT, expand=1, anchor=W) # # Default Unit # self.default_unit = config.preferences.default_unit frame = self.make_frame() label = Label(frame, text=_("Default Unit")) label.pack(side=LEFT, expand=1) menu = create_unit_menu(frame, self.set_unit, indicatoron=0, width=3, text=self.default_unit) menu.pack(side=RIGHT, expand=1) # # Gradient Patterns # #self.var_steps = IntVar(top) #self.var_steps.set(preferences.gradient_steps) #frame = self.make_frame() #label = Label(frame, text = 'Gradient Steps') # # Standard Buttons (OK, Cancel) # but_frame = Frame(top) but_frame.pack(side=BOTTOM, fill=BOTH, expand=1, padx=4, pady=4) button = UpdatedButton(but_frame, text=_("OK"), command=self.ok) button.pack(side=LEFT, expand=1) button = UpdatedButton(but_frame, text=_("Cancel"), command=self.close_dlg) button.pack(side=RIGHT, expand=1) def unlimited_undo(self): unlimited = self.var_unlimited.get() if unlimited: self.undo_entry['state'] = DISABLED else: self.undo_entry['state'] = NORMAL def set_unit(self, unit): self.default_unit = unit def ok(self): # undo unlimited = self.var_unlimited.get() if unlimited: preferences.undo_limit = None else: preferences.undo_limit = self.var_undo.get() # offset x = self.var_off_x.get() y = self.var_off_y.get() preferences.duplicate_offset = (x, y) # default unit preferences.default_unit = self.default_unit # self.close_dlg() def close_dlg(self): self.main_window = None self.top.destroy() def deiconify_and_raise(self): self.top.deiconify() self.top.tkraise()
class GuidePanel(SketchPanel): title = _("Guide Lines") receivers = SketchPanel.receivers[:] def __init__(self, master, canvas, doc): SketchPanel.__init__(self, master, canvas, doc, name = 'guidedlg') def build_dlg(self): top = self.top var_number = DoubleVar(top) var_unit = StringVar(top) self.var_pos = LengthVar(1.0, config.preferences.default_unit, var_number, var_unit, command = self.set_pos) pos_frame = Frame(top) pos_frame.pack(side = TOP, fill = X, expand = 0) self.var_label = StringVar(top) self.var_label.set('X:') label = Label(pos_frame, textvariable = self.var_label) label.pack(side = LEFT, expand = 1, anchor = E) entry = MyEntry(pos_frame, textvariable = var_number, justify = RIGHT, width = 4, command = self.var_pos.UpdateNumber) entry.pack(side = LEFT, expand = 1, fill = X, anchor = E) scroll = MiniScroller(pos_frame, variable = var_number, min = 0, max = None, step = 1) scroll.pack(side = LEFT, fill = Y) optmenu = create_unit_menu(pos_frame, self.set_unit, variable = var_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W) list_frame = Frame(top) list_frame.pack(side = TOP, expand = 1, fill = BOTH) sb_vert = Scrollbar(list_frame, takefocus = 0) sb_vert.pack(side = RIGHT, fill = Y) guides = UpdatedListbox(list_frame, name = 'list') guides.pack(expand = 1, fill = BOTH) guides.Subscribe(SELECTION, self.select_guide) sb_vert['command'] = (guides, 'yview') guides['yscrollcommand'] = (sb_vert, 'set') self.guides = guides self.selected = None frame = Frame(top) frame.pack(side = BOTTOM, fill = X) button = UpdatedButton(frame, text = _("Add H"), command = self.add_guide, args = 1) button.pack(side = LEFT) button = UpdatedButton(frame, text = _("Add V"), command = self.add_guide, args = 0) button.pack(side = LEFT) button = UpdatedButton(frame, text = _("Delete"), command = self.del_guide) button.pack(side = LEFT) button = UpdatedButton(frame, text = _("Close"), command = self.close_dlg) button.pack(side = RIGHT) def set_unit(self, *rest): apply(self.var_pos.UpdateUnit, rest) self.update_list() receivers.append((GUIDE_LINES, 'init_from_doc')) def init_from_doc(self, *rest): self.guide_lines = self.document.GuideLines() self.guide_lines.reverse() self.update_list() def update_list(self): strings = [] factor = self.var_pos.Factor() unit = self.var_pos.UnitName() if unit in ('in', 'cm'): prec = 2 else: prec = 1 for line in self.guide_lines: pos, horizontal = line.Coordinates() if horizontal: format = _("% 6.*f %s horizontal") else: format = _("% 6.*f %s vertical") strings.append(format % (prec, pos / factor, unit)) self.guides.SetList(strings) self.select_index(self.selected) def select_index(self, index): if index is not None and index < len(self.guide_lines): self.guides.Select(index) self.select_guide() else: self.selected = None def set_pos(self, *rest): if self.selected is not None: self.document.MoveGuideLine(self.guide_lines[self.selected], self.var_pos.get()) def select_guide(self, *rest): sel = self.guides.curselection() if sel: self.selected = atoi(sel[0]) pos, horizontal = self.guide_lines[self.selected].Coordinates() self.var_pos.set(pos) if horizontal: self.var_label.set(_("Y:")) else: self.var_label.set(_("X:")) else: self.selected = None def del_guide(self, *rest): if self.selected is not None: line = self.guide_lines[self.selected] self.document.RemoveGuideLine(line) def add_guide(self, horizontal): length = len(self.guide_lines) self.document.AddGuideLine(Point(0, 0), horizontal) self.select_index(length)
class HatchingPatternFrame(PatternFrame): def __init__(self, master=None, **kw): apply(PatternFrame.__init__, (self, master), kw) frame = Frame(self) frame.pack(side = TOP, fill = X, expand = 1) self.colors = [None, None] self.colors[0] = ColorButton(frame, height = 1, command = self.set_color, args = 0) self.colors[0].pack(side = LEFT, fill = X, expand = 1) self.colors[1] = ColorButton(frame, height = 1, command = self.set_color, args = 1) self.colors[1].pack(side = LEFT, fill = X, expand = 1) var_spacing_number = DoubleVar(self) var_unit = StringVar(self) self.var_spacing = LengthVar(1.0, config.preferences.default_unit, var_spacing_number, var_unit, command = self.set_spacing) width_frame = Frame(self) width_frame.pack(side = TOP, fill = X, expand = 1) #label = Label(width_frame, text = 'Spacing') #label.pack(side = LEFT, expand = 1, anchor = E) entry = MyEntry(width_frame, textvariable = var_spacing_number, justify = RIGHT, width = 6, command = self.var_spacing.UpdateNumber) entry.pack(side = LEFT, expand = 1, fill = X) scroll = MiniScroller(width_frame, variable = var_spacing_number, min = 0.0, max = None, step = 1.0, command = self.var_spacing.UpdateNumber) scroll.pack(side = LEFT, fill = Y) optmenu = create_unit_menu(width_frame, self.var_spacing.UpdateUnit, variable = var_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W) self.SetPattern(HatchingPattern(StandardColors.red)) def set_color(self, idx): self.pattern = self.pattern.Duplicate() self.pattern.SetForeground(self.__get_color(0)) self.pattern.SetBackground(self.__get_color(1)) self.issue(CHANGED) def __get_color(self, idx): return self.colors[idx].Color() def set_spacing(self, *rest): spacing = self.var_spacing.get() self.pattern = self.pattern.Duplicate() self.pattern.SetSpacing(spacing) self.issue(CHANGED) def SetPattern(self, pattern): PatternFrame.SetPattern(self, pattern) self.colors[0].SetColor(pattern.Foreground()) self.colors[1].SetColor(pattern.Background()) self.var_spacing.set(pattern.Spacing()) def SetDirection(self, dir): dir = apply(Point, dir) self.pattern = self.pattern.Duplicate() self.pattern.SetDirection(dir) self.issue(CHANGED) def EditModes(self): return (0, 1)
def build_dlg(self): top = self.top var_number = DoubleVar(top) var_unit = StringVar(top) self.var_pos = LengthVar(1.0, config.preferences.default_unit, var_number, var_unit, command=self.set_pos) pos_frame = Frame(top) pos_frame.pack(side=TOP, fill=X, expand=0) self.var_label = StringVar(top) self.var_label.set('X:') label = Label(pos_frame, textvariable=self.var_label) label.pack(side=LEFT, expand=1, anchor=E) entry = MyEntry(pos_frame, textvariable=var_number, justify=RIGHT, width=4, command=self.var_pos.UpdateNumber) entry.pack(side=LEFT, expand=1, fill=X, anchor=E) scroll = MiniScroller(pos_frame, variable=var_number, min=0, max=None, step=1) scroll.pack(side=LEFT, fill=Y) optmenu = create_unit_menu(pos_frame, self.set_unit, variable=var_unit, indicatoron=0, width=3) optmenu.pack(side=LEFT, expand=1, fill=X, anchor=W) list_frame = Frame(top) list_frame.pack(side=TOP, expand=1, fill=BOTH) sb_vert = Scrollbar(list_frame, takefocus=0) sb_vert.pack(side=RIGHT, fill=Y) guides = UpdatedListbox(list_frame, name='list') guides.pack(expand=1, fill=BOTH) guides.Subscribe(SELECTION, self.select_guide) sb_vert['command'] = (guides, 'yview') guides['yscrollcommand'] = (sb_vert, 'set') self.guides = guides self.selected = None frame = Frame(top) frame.pack(side=BOTTOM, fill=X) button = UpdatedButton(frame, text=_("Add H"), command=self.add_guide, args=1) button.pack(side=LEFT) button = UpdatedButton(frame, text=_("Add V"), command=self.add_guide, args=0) button.pack(side=LEFT) button = UpdatedButton(frame, text=_("Delete"), command=self.del_guide) button.pack(side=LEFT) button = UpdatedButton(frame, text=_("Close"), command=self.close_dlg) button.pack(side=RIGHT)
class GuidePanel(SketchPanel): title = _("Guide Lines") receivers = SketchPanel.receivers[:] def __init__(self, master, canvas, doc): SketchPanel.__init__(self, master, canvas, doc, name='guidedlg') def build_dlg(self): top = self.top var_number = DoubleVar(top) var_unit = StringVar(top) self.var_pos = LengthVar(1.0, config.preferences.default_unit, var_number, var_unit, command=self.set_pos) pos_frame = Frame(top) pos_frame.pack(side=TOP, fill=X, expand=0) self.var_label = StringVar(top) self.var_label.set('X:') label = Label(pos_frame, textvariable=self.var_label) label.pack(side=LEFT, expand=1, anchor=E) entry = MyEntry(pos_frame, textvariable=var_number, justify=RIGHT, width=4, command=self.var_pos.UpdateNumber) entry.pack(side=LEFT, expand=1, fill=X, anchor=E) scroll = MiniScroller(pos_frame, variable=var_number, min=0, max=None, step=1) scroll.pack(side=LEFT, fill=Y) optmenu = create_unit_menu(pos_frame, self.set_unit, variable=var_unit, indicatoron=0, width=3) optmenu.pack(side=LEFT, expand=1, fill=X, anchor=W) list_frame = Frame(top) list_frame.pack(side=TOP, expand=1, fill=BOTH) sb_vert = Scrollbar(list_frame, takefocus=0) sb_vert.pack(side=RIGHT, fill=Y) guides = UpdatedListbox(list_frame, name='list') guides.pack(expand=1, fill=BOTH) guides.Subscribe(SELECTION, self.select_guide) sb_vert['command'] = (guides, 'yview') guides['yscrollcommand'] = (sb_vert, 'set') self.guides = guides self.selected = None frame = Frame(top) frame.pack(side=BOTTOM, fill=X) button = UpdatedButton(frame, text=_("Add H"), command=self.add_guide, args=1) button.pack(side=LEFT) button = UpdatedButton(frame, text=_("Add V"), command=self.add_guide, args=0) button.pack(side=LEFT) button = UpdatedButton(frame, text=_("Delete"), command=self.del_guide) button.pack(side=LEFT) button = UpdatedButton(frame, text=_("Close"), command=self.close_dlg) button.pack(side=RIGHT) def set_unit(self, *rest): apply(self.var_pos.UpdateUnit, rest) self.update_list() receivers.append((GUIDE_LINES, 'init_from_doc')) def init_from_doc(self, *rest): self.guide_lines = self.document.GuideLines() self.guide_lines.reverse() self.update_list() def update_list(self): strings = [] factor = self.var_pos.Factor() unit = self.var_pos.UnitName() if unit in ('in', 'cm'): prec = 2 else: prec = 1 for line in self.guide_lines: pos, horizontal = line.Coordinates() if horizontal: format = _("% 6.*f %s horizontal") else: format = _("% 6.*f %s vertical") strings.append(format % (prec, pos / factor, unit)) self.guides.SetList(strings) self.select_index(self.selected) def select_index(self, index): if index is not None and index < len(self.guide_lines): self.guides.Select(index) self.select_guide() else: self.selected = None def set_pos(self, *rest): if self.selected is not None: self.document.MoveGuideLine(self.guide_lines[self.selected], self.var_pos.get()) def select_guide(self, *rest): sel = self.guides.curselection() if sel: self.selected = atoi(sel[0]) pos, horizontal = self.guide_lines[self.selected].Coordinates() self.var_pos.set(pos) if horizontal: self.var_label.set(_("Y:")) else: self.var_label.set(_("X:")) else: self.selected = None def del_guide(self, *rest): if self.selected is not None: line = self.guide_lines[self.selected] self.document.RemoveGuideLine(line) def add_guide(self, horizontal): length = len(self.guide_lines) self.document.AddGuideLine(Point(0, 0), horizontal) self.select_index(length)
def build_dlg(self): top = self.top # # Undo # undo_frame = self.make_frame() label = Label(undo_frame, text = _("# Undo Levels:"), anchor = E) label.pack(side = LEFT, expand = 1, fill = X) self.var_undo = IntVar(top) self.undo_entry = Entry(undo_frame, textvariable = self.var_undo, width = 4) self.undo_entry.pack(side = LEFT) self.var_unlimited = IntVar(top) check = UpdatedCheckbutton(undo_frame, text = _("unlimited"), variable = self.var_unlimited, command = self.unlimited_undo) check.pack(side = RIGHT, expand = 1, anchor = W) limit = preferences.undo_limit if limit == None: self.var_undo.set(10) self.var_unlimited.set(1) else: if limit < 0: limit = 0 self.var_undo.set(limit) self.var_unlimited.set(0) # # Duplication # off_frame = self.make_frame() var_off_x_number = DoubleVar(top) var_off_y_number = DoubleVar(top) var_off_x_unit = StringVar(top) var_off_y_unit = StringVar(top) x, y = preferences.duplicate_offset unit = config.preferences.default_unit self.var_off_x = LengthVar(x, unit, var_off_x_number, var_off_x_unit) self.var_off_y = LengthVar(y, unit, var_off_y_number, var_off_y_unit) label = Label(off_frame, text = _("Duplication Offset")) label.pack(side = TOP, anchor = W) label = Label(off_frame, text = _("Hor.")) label.pack(side = LEFT, expand = 1, anchor = E) entry = MyEntry(off_frame, textvariable = var_off_x_number, width = 6, command = self.var_off_x.UpdateNumber) entry.pack(side = LEFT, fill = X, anchor = E) label = Label(off_frame, text = _("Vert.")) label.pack(side = LEFT, anchor = E) entry = MyEntry(off_frame, textvariable = var_off_y_number, width = 6, command = self.var_off_y.UpdateNumber) entry.pack(side = LEFT, fill = X, anchor = E) def CallBoth(arg, x = self.var_off_x, y = self.var_off_y): x.UpdateUnit(arg) y.UpdateUnit(arg) optmenu = create_unit_menu(off_frame, CallBoth, variable = var_off_x_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, anchor = W) # # Default Unit # self.default_unit = config.preferences.default_unit frame = self.make_frame() label = Label(frame, text = _("Default Unit")) label.pack(side = LEFT, expand = 1) menu = create_unit_menu(frame, self.set_unit, indicatoron = 0, width = 3, text = self.default_unit) menu.pack(side = RIGHT, expand = 1) # # Gradient Patterns # #self.var_steps = IntVar(top) #self.var_steps.set(preferences.gradient_steps) #frame = self.make_frame() #label = Label(frame, text = 'Gradient Steps') # # Standard Buttons (OK, Cancel) # but_frame = Frame(top) but_frame.pack(side = BOTTOM, fill = BOTH, expand = 1, padx = 4, pady = 4) button = UpdatedButton(but_frame, text = _("OK"), command = self.ok) button.pack(side = LEFT, expand = 1) button = UpdatedButton(but_frame, text = _("Cancel"), command = self.close_dlg) button.pack(side = RIGHT, expand = 1)
class OptionDialog: def __init__(self, master, main_window): self.master = master self.main_window = main_window top = Toplevel(master) top.title(_("Global Options")) top.transient(master) top.protocol('WM_DELETE_WINDOW', self.close_dlg) top.geometry('%+d%+d' % (master.winfo_rootx() + 100, master.winfo_rooty() + 100)) self.top = top self.build_dlg() def make_frame(self): frame = Frame(self.top, relief = GROOVE, bd = 2) frame.pack(side = TOP, expand = 1, fill = X, padx = 4, pady = 4) return frame def build_dlg(self): top = self.top # # Undo # undo_frame = self.make_frame() label = Label(undo_frame, text = _("# Undo Levels:"), anchor = E) label.pack(side = LEFT, expand = 1, fill = X) self.var_undo = IntVar(top) self.undo_entry = Entry(undo_frame, textvariable = self.var_undo, width = 4) self.undo_entry.pack(side = LEFT) self.var_unlimited = IntVar(top) check = UpdatedCheckbutton(undo_frame, text = _("unlimited"), variable = self.var_unlimited, command = self.unlimited_undo) check.pack(side = RIGHT, expand = 1, anchor = W) limit = preferences.undo_limit if limit == None: self.var_undo.set(10) self.var_unlimited.set(1) else: if limit < 0: limit = 0 self.var_undo.set(limit) self.var_unlimited.set(0) # # Duplication # off_frame = self.make_frame() var_off_x_number = DoubleVar(top) var_off_y_number = DoubleVar(top) var_off_x_unit = StringVar(top) var_off_y_unit = StringVar(top) x, y = preferences.duplicate_offset unit = config.preferences.default_unit self.var_off_x = LengthVar(x, unit, var_off_x_number, var_off_x_unit) self.var_off_y = LengthVar(y, unit, var_off_y_number, var_off_y_unit) label = Label(off_frame, text = _("Duplication Offset")) label.pack(side = TOP, anchor = W) label = Label(off_frame, text = _("Hor.")) label.pack(side = LEFT, expand = 1, anchor = E) entry = MyEntry(off_frame, textvariable = var_off_x_number, width = 6, command = self.var_off_x.UpdateNumber) entry.pack(side = LEFT, fill = X, anchor = E) label = Label(off_frame, text = _("Vert.")) label.pack(side = LEFT, anchor = E) entry = MyEntry(off_frame, textvariable = var_off_y_number, width = 6, command = self.var_off_y.UpdateNumber) entry.pack(side = LEFT, fill = X, anchor = E) def CallBoth(arg, x = self.var_off_x, y = self.var_off_y): x.UpdateUnit(arg) y.UpdateUnit(arg) optmenu = create_unit_menu(off_frame, CallBoth, variable = var_off_x_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, anchor = W) # # Default Unit # self.default_unit = config.preferences.default_unit frame = self.make_frame() label = Label(frame, text = _("Default Unit")) label.pack(side = LEFT, expand = 1) menu = create_unit_menu(frame, self.set_unit, indicatoron = 0, width = 3, text = self.default_unit) menu.pack(side = RIGHT, expand = 1) # # Gradient Patterns # #self.var_steps = IntVar(top) #self.var_steps.set(preferences.gradient_steps) #frame = self.make_frame() #label = Label(frame, text = 'Gradient Steps') # # Standard Buttons (OK, Cancel) # but_frame = Frame(top) but_frame.pack(side = BOTTOM, fill = BOTH, expand = 1, padx = 4, pady = 4) button = UpdatedButton(but_frame, text = _("OK"), command = self.ok) button.pack(side = LEFT, expand = 1) button = UpdatedButton(but_frame, text = _("Cancel"), command = self.close_dlg) button.pack(side = RIGHT, expand = 1) def unlimited_undo(self): unlimited = self.var_unlimited.get() if unlimited: self.undo_entry['state'] = DISABLED else: self.undo_entry['state'] = NORMAL def set_unit(self, unit): self.default_unit = unit def ok(self): # undo unlimited = self.var_unlimited.get() if unlimited: preferences.undo_limit = None else: preferences.undo_limit = self.var_undo.get() # offset x = self.var_off_x.get() y = self.var_off_y.get() preferences.duplicate_offset = (x, y) # default unit preferences.default_unit = self.default_unit # self.close_dlg() def close_dlg(self): self.main_window = None self.top.destroy() def deiconify_and_raise(self): self.top.deiconify() self.top.tkraise()
def build_dlg(self): top = self.top format_frame = Frame(top) format_frame.pack(side = TOP, expand = 1, fill = X, padx = 4, pady = 4) format_label = Label(format_frame, text = _("Paper format:")) format_label.pack(side = LEFT, expand = 1, fill = X) format_names = map(lambda t: t[0], PapersizesList) format_names.append(USER_SPECIFIC) self.var_format_name = StringVar(top) format_menu = MyOptionMenu(format_frame, format_names, variable = self.var_format_name, command = self.choose_format) format_menu.configure(width = max(map(len, format_names))) format_menu.pack(side = RIGHT, expand = 1, fill = X) orientation_frame = Frame(top) orientation_frame.pack(side = TOP, expand = 1, fill = X) self.var_orientation = IntVar(top) radio = UpdatedRadiobutton(orientation_frame, text = _("Portrait"), variable = self.var_orientation, value = Portrait, command = self.choose_orientation) radio.pack(side = LEFT, expand = 1, fill = X) radio = UpdatedRadiobutton(orientation_frame, text = _("Landscape"), variable = self.var_orientation, value = Landscape, command = self.choose_orientation) radio.pack(side = RIGHT, expand = 1, fill = X) size_frame = Frame(top) size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4) var_width_number = DoubleVar(top) var_height_number = DoubleVar(top) var_width_unit = StringVar(top) var_height_unit = StringVar(top) unit = config.preferences.default_unit self.var_width = LengthVar(10, unit, var_width_number, var_width_unit) self.var_height = LengthVar(10, unit,var_height_number,var_height_unit) label = Label(size_frame, text = _("Page size:")) label.pack(side = TOP, anchor = W) label = Label(size_frame, text = _("Width")) label.pack(side = LEFT, anchor = E) self.widthentry = MyEntry(size_frame, textvariable = var_width_number, command = self.var_width.UpdateNumber, width = 6) self.widthentry.pack(side = LEFT, expand = 1, fill = X, anchor = E) label = Label(size_frame, text = _("Height")) label.pack(side = LEFT, anchor = E) self.heightentry = MyEntry(size_frame, textvariable =var_height_number, command = self.var_height.UpdateNumber, width = 6) self.heightentry.pack(side = LEFT, expand = 1, fill = X, anchor = E) def CallBoth(arg, x = self.var_width, y = self.var_height): x.UpdateUnit(arg) y.UpdateUnit(arg) optmenu = create_unit_menu(size_frame, CallBoth, variable = var_width_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W) button_frame = Frame(top) button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1, padx = 4, pady = 4) button = UpdatedButton(button_frame, text = _("Apply"), command = self.apply_settings) button.pack(side = LEFT, expand = 1) button = UpdatedButton(button_frame, text = _("Close"), command = self.close_dlg) button.pack(side = RIGHT, expand = 1)
class LayoutPanel(SketchPanel): title = _("Layout") class_name = 'SKLayout' receivers = SketchPanel.receivers[:] def __init__(self, master, main_window, doc): SketchPanel.__init__(self, master, main_window, doc, name = 'layoutdlg') def build_dlg(self): top = self.top format_frame = Frame(top) format_frame.pack(side = TOP, expand = 1, fill = X, padx = 4, pady = 4) format_label = Label(format_frame, text = _("Paper format:")) format_label.pack(side = LEFT, expand = 1, fill = X) format_names = map(lambda t: t[0], PapersizesList) format_names.append(USER_SPECIFIC) self.var_format_name = StringVar(top) format_menu = MyOptionMenu(format_frame, format_names, variable = self.var_format_name, command = self.choose_format) format_menu.configure(width = max(map(len, format_names))) format_menu.pack(side = RIGHT, expand = 1, fill = X) orientation_frame = Frame(top) orientation_frame.pack(side = TOP, expand = 1, fill = X) self.var_orientation = IntVar(top) radio = UpdatedRadiobutton(orientation_frame, text = _("Portrait"), variable = self.var_orientation, value = Portrait, command = self.choose_orientation) radio.pack(side = LEFT, expand = 1, fill = X) radio = UpdatedRadiobutton(orientation_frame, text = _("Landscape"), variable = self.var_orientation, value = Landscape, command = self.choose_orientation) radio.pack(side = RIGHT, expand = 1, fill = X) size_frame = Frame(top) size_frame.pack(side = TOP, fill = X, expand = 1, padx = 4, pady = 4) var_width_number = DoubleVar(top) var_height_number = DoubleVar(top) var_width_unit = StringVar(top) var_height_unit = StringVar(top) unit = config.preferences.default_unit self.var_width = LengthVar(10, unit, var_width_number, var_width_unit) self.var_height = LengthVar(10, unit,var_height_number,var_height_unit) label = Label(size_frame, text = _("Page size:")) label.pack(side = TOP, anchor = W) label = Label(size_frame, text = _("Width")) label.pack(side = LEFT, anchor = E) self.widthentry = MyEntry(size_frame, textvariable = var_width_number, command = self.var_width.UpdateNumber, width = 6) self.widthentry.pack(side = LEFT, expand = 1, fill = X, anchor = E) label = Label(size_frame, text = _("Height")) label.pack(side = LEFT, anchor = E) self.heightentry = MyEntry(size_frame, textvariable =var_height_number, command = self.var_height.UpdateNumber, width = 6) self.heightentry.pack(side = LEFT, expand = 1, fill = X, anchor = E) def CallBoth(arg, x = self.var_width, y = self.var_height): x.UpdateUnit(arg) y.UpdateUnit(arg) optmenu = create_unit_menu(size_frame, CallBoth, variable = var_width_unit, indicatoron = 0, width = 3) optmenu.pack(side = LEFT, expand = 1, fill = X, anchor = W) button_frame = Frame(top) button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1, padx = 4, pady = 4) button = UpdatedButton(button_frame, text = _("Apply"), command = self.apply_settings) button.pack(side = LEFT, expand = 1) button = UpdatedButton(button_frame, text = _("Close"), command = self.close_dlg) button.pack(side = RIGHT, expand = 1) def init_from_doc(self): self.Update() def update_size_from_name(self, formatname): width, height = Papersize[formatname] if self.var_orientation.get() == Landscape: width, height = height, width self.update_size(width, height) def update_size(self, width, height): self.var_width.set(width) self.var_height.set(height) receivers.append((LAYOUT, 'Update')) def Update(self): layout = self.document.Layout() formatname = layout.FormatName() self.var_orientation.set(layout.Orientation()) if formatname and formatname != USER_SPECIFIC: self.update_size_from_name(formatname) else: formatname = USER_SPECIFIC self.update_size(layout.Width(), layout.Height()) self.var_format_name.set(formatname) self.set_entry_sensitivity() def set_entry_sensitivity(self): formatname = self.var_format_name.get() if formatname != USER_SPECIFIC: self.widthentry.config(state = DISABLED) self.heightentry.config(state = DISABLED) else: self.widthentry.config(state = NORMAL) self.heightentry.config(state = NORMAL) def choose_format(self, formatname): self.var_format_name.set(formatname) if formatname != USER_SPECIFIC: self.update_size_from_name(formatname) self.set_entry_sensitivity() def choose_orientation(self): name = self.var_format_name.get() if name != USER_SPECIFIC: self.update_size_from_name(name) def apply_settings(self): formatname = self.var_format_name.get() if formatname == USER_SPECIFIC: layout = PageLayout(width = self.var_width.get(), height = self.var_height.get(), orientation = self.var_orientation.get()) else: layout = PageLayout(formatname, orientation = self.var_orientation.get()) self.document.SetLayout(layout)