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)
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 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)
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)
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)