def __init__(self, parent, mainwindow): self.parent=parent self.mainwindow=mainwindow TFrame.__init__(self, self.parent, name = 'pagerPanel', style='FlatFrame', borderwidth=0) top_border=TLabel(self, style='FlatLabel', image='space_1') top_border.pack(side=TOP, fill=X) self.container=TFrame(self, style='FlatFrame', borderwidth=0) space=TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.home_but=TButton(self.container, style='PagerHome', command=self.PageHome) self.home_but.pack(side=LEFT) self.home_but=TButton(self.container, style='PagerPrevious', command=self.PagePrevious) self.home_but.pack(side=LEFT) self.text=TLabel(self.container, style='FlatLabel', text=' '+_('Page 2 of 2')+' ') self.text.pack(side=LEFT) self.home_but=TButton(self.container, style='PagerNext', command=self.PageNext) self.home_but.pack(side=LEFT) self.home_but=TButton(self.container, style='PagerEnd', command=self.PageEnd) self.home_but.pack(side=LEFT) space=TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.mainwindow.Subscribe(DOCUMENT, self.Resubscribe) self.Resubscribe() self.doc_paged() self.text.bind('<Double-Button-1>', self.GoToPage)
def init(self, master): self.master = master self.mw = app.mw self.pcontainer = self.master.master self.document = self.mw.document TFrame.__init__(self, self.master, style='FlatFrame', borderwidth=0) self.top = TFrame(self, style='PWinHead', borderwidth=3) self.panel = TFrame(self, style='PWinBody', borderwidth=3) self.activated = 1 self.visible = 1 self.packed = 1 for item in self.pcontainer.loaded: if not item.collapsed: item.collapse_panel() self.pack(side=TOP, fill=self.fill, expand=self.expand, padx=1, pady=1) self.top.pack(side=TOP, fill=X) self.panel.pack(side=TOP, fill=BOTH, expand=1) self.iconlabel = TLabel(self.top, style='PWLabel', image=self.icon) self.textlabel = TLabel(self.top, style='PWLabel', text=self.title, anchor=W) if not 'bold' in self.textlabel['font'].split(): self.textlabel['font'] += ' bold' self.closebut = TButton(self.top, style='PWButton', image='close_pw', command=self.close_panel) self.collapsebut = TButton(self.top, style='PWButton', image='minimize_pw', command=self.click) self.iconlabel.pack(side=LEFT, padx=2) self.textlabel.pack(side=LEFT, fill=BOTH, expand=1, padx=3) self.closebut.pack(side=RIGHT) self.collapsebut.pack(side=RIGHT) self.textlabel.bind("<Button-1>", self.click) self.mw.Subscribe(DOCUMENT, self.doc_changed)
def __init__(self, master=None, min=0, max=100, step=1, textvariable=None, var=0, vartype=0, command=None, state=NORMAL, width=5, args=(), **kw): '''vartype=0 - integer vartype=1 - float ''' self.min_value = min self.max_value = max self.step = step self.variable = var self.vartype = vartype if textvariable: self.text_var = textvariable else: self.text_var = StringVar() self.command = command self.state = state self.width = width apply(TFrame.__init__, (self, master), kw) self["style"] = "FlatFrame" self.entry = TEntryExt(self, textvariable=self.text_var, width=self.width, style='SpinEntry') self.entry.pack(side=LEFT, expand=1, fill=BOTH) self.button_frame = TFrame(self, style="FlatFrame") self.button_frame.pack(side=LEFT, fill=Y) self.up_button = TButton(self.button_frame, class_='Repeater', command=self.increase, image='pal_arrow_up', style='SpinUpButton', takefocus=0) self.up_button.pack(side=TOP) self.down_button = TButton(self.button_frame, class_='Repeater', command=self.decrease, image='pal_arrow_down', style='SpinDownButton', takefocus=0) self.down_button.pack(side=TOP) if self.vartype == 1: self.variable = float(self.variable) else: self.variable = int(self.variable) self.text_var.set(str(self.variable)) self.entry.bind('<Button-4>', self.wheel_increase) self.entry.bind('<Button-5>', self.wheel_decrease) self.entry.bind('<Key-Up>', self.wheel_increase) self.entry.bind('<Key-Down>', self.wheel_decrease) self.entry.bind('<Key-Return>', self.apply_command) self.entry.bind('<Key-KP_Enter>', self.apply_command)
def __init__(self, master, dialog, **kw): apply(TFrame.__init__, (self, master), kw) self.prev_btn = TButton(self, image='fd-go-previous', style="Toolbutton") self.prev_btn.pack(side=LEFT) self.up_btn = TButton(self, image='fd-go-up', style="Toolbutton") self.up_btn.pack(side=LEFT) self.next_btn = TButton(self, image='fd-go-next', style="Toolbutton") self.next_btn.pack(side=LEFT)
def init(self, master): PluginPanel.init(self, master) self.initial_color = self.default_color self.current_color = copy.copy(self.initial_color) top = TFrame(self.panel, style='FlatFrame', borderwidth=5) top.pack(side=TOP, fill=BOTH) self.selector = ColorSpaceSelector(top, self.refresh_widgets, self.current_color, self.sign) self.selector.pack(side=TOP, expand=1, fill=X) self.picker = ColorChooserWidget(top, self.refresh_widgets, self.current_color) self.picker.pack(side=TOP, expand=1, fill=X) self.digitizer = ColorDigitizer(top, self.refresh_widgets, self.current_color) self.digitizer.pack(side=TOP, expand=1, fill=X) button = UpdatedButton(top, text=_("Apply"), command=self.apply_pattern, sensitivecb=self.is_selection) button.pack(side=BOTTOM, expand=1, fill=X) self.Subscribe(SELECTION, button.Update) button_frame = TFrame(top, style='FlatFrame', borderwidth=1) button_frame.pack(side=BOTTOM, fill=X, pady=5) button = TButton(button_frame, style='TSmallbutton', text=' ', image='small_colorpicker', command=self.copy_from) button.pack(side=LEFT) tooltips.AddDescription(button, _("Copy From...")) button = TButton(button_frame, style='TSmallbutton', text=' ', image='restore_color', command=self.restore_color) button.pack(side=LEFT, padx=5) tooltips.AddDescription(button, _("Restore color")) self.var_autoupdate = IntVar(top) self.var_autoupdate.set(1) self.autoupdate_check = TCheckbutton(button_frame, text=_("Auto Update"), variable=self.var_autoupdate, command=self.init_from_doc) self.autoupdate_check.pack(side=RIGHT, anchor=W, padx=10) self.init_from_doc() self.subscribe_receivers()
def __init__(self, parent, name, document=None, state=0): self.parent = parent self.name = name self.document = document if state: self.isActive = 1 self.style = 'DocTabActive' TButton.__init__(self, self.parent, style=NORMAL_TAB, image=DOC_ICON, text=self.name.ljust(20), command=self.action) self.bind('<ButtonPress-3>', self.popup_context_menu)
def build_dlg(self): root = TFrame(self.top, style='FlatFrame', borderwidth = 10) root.pack(side = TOP, fill = BOTH, expand = 1) middle = TFrame(root, style='FlatFrame', borderwidth = 5) middle.pack(side = TOP, fill = X, expand = 1) label = TLabel(middle, text = _("Delete page No.:")+" ", style='FlatLabel') label.pack(side = LEFT) self.pagenum_spin = TSpinbox(middle, var=app.mw.document.active_page+1, vartype=0, textvariable = self.pagenum, min = 1, max = len(app.mw.document.pages), step = 1, width = 6, command = self.ok) self.pagenum_spin.pack(side = LEFT) if len(app.mw.document.pages)==1: self.pagenum_spin.set_state('disabled') bottom = TFrame(root, style='FlatFrame', borderwidth = 5) bottom.pack(side = BOTTOM, fill = X, expand = 1) cancel = TButton(bottom, text=_("Cancel"), command=self.cancel) cancel.pack(side = RIGHT) label = TLabel(bottom, text = ' ', style='FlatLabel') label.pack(side = RIGHT) ok = TButton(bottom, text=_("OK"), command=self.ok) ok.pack(side = RIGHT) self.focus_widget = ok self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.top.resizable (width=0, height=0)
def __init__(self, parent, toplevel, size=300, orient=LEFT, min=200, max=500, cnf={}, **kw): TFrame.__init__(self, parent, style='FlatFrame', **kw) self.parent = parent self.panel = TFrame(self, style='FlatFrame') self.orient = orient self.min = min self.max = max self.size = size self.toplevel = toplevel self.canv_size = 0 self.counter = 0 if orient in [LEFT, RIGHT]: self.spacer = Frame(self, width=size, height=1) self.grip = TButton(self, style='VGrip', cursor=appconst.CurHResize) if orient == LEFT: self.spacer.pack(side=TOP) self.grip.pack(side=LEFT, fill=Y) self.panel.pack(side=RIGHT, fill=BOTH, expand=1) else: self.spacer.pack(side=TOP) self.grip.pack(side=RIGHT, fill=Y) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.spacer = Frame(self, width=1, height=size) self.grip = TButton(self, style='HGrip', cursor=appconst.CurVResize) if orient == BOTTOM: self.grip.pack(side=BOTTOM, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.grip.pack(side=TOP, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) self.grip.bind("<Button-1>", self.start) self.grip.bind("<ButtonRelease-1>", self.stop)
def __init__(self, master, dialog, **kw): self.dialog = dialog apply(TFrame.__init__, (self, master), kw) cancel_bt = TButton(self, text=_("Cancel"), command=self.dialog.cancel) cancel_bt.pack(side=RIGHT) ok_bt = TButton(self, text=_("OK"), command=self.dialog.ok) ok_bt.pack(side=RIGHT, padx=5)
def __init__(self, parent): CtxSubPanel.__init__(self, parent) b = TButton(self.panel, command=self.flip, style='Toolbutton', image='context_hflip') tooltips.AddDescription(b, _('Flip Horizontal')) b.pack(side = LEFT) b = TButton(self.panel, command=self.flop, style='Toolbutton', image='context_vflip') tooltips.AddDescription(b, _('Flip Vertical')) b.pack(side = LEFT)
def build_dlg(self): root = self.top top = TFrame(root, borderwidth=5, style='FlatFrame') top.pack(side=TOP, expand=0, fill=BOTH) top2 = TFrame(top, style='FlatFrame') top2.pack(side=TOP, expand=0, fill=X) format_label = TLabel(top2, text=_('Style name:'), borderwidth=0) format_label.pack(side=LEFT, pady=3) self.entry_name = TEntrybox(top, command=self.ok, width=15) self.entry_name.pack(side=TOP, fill=X) top2 = TFrame(top, height=5, style='FlatFrame') top2.pack(side=TOP, expand=0, fill=X) prop_cont = TLabelframe(top, text=_('Style properties'), padding=10) prop_cont.pack(side=TOP, fill=X) properties = self.object.Properties() self.flags = {} for prop in property_names: type = property_types[prop] if type == FillProperty: state = self.object.has_fill and NORMAL or DISABLED elif type == LineProperty: state = self.object.has_line and NORMAL or DISABLED elif type == FontProperty: state = self.object.has_font and NORMAL or DISABLED else: # unknown property type! continue long, short = property_titles[prop] self.flags[prop] = var = IntVar(root) var.set(state == NORMAL) radio = TCheckbutton(prop_cont, text=long, state=state, variable=var) radio.pack(side=TOP, anchor=W) top2 = TFrame(top, height=3, style='FlatFrame') top2.pack(side=TOP, expand=0, fill=X) but_frame = Frame(top) but_frame.pack(side=TOP, fill=X) button = TButton(but_frame, text=_("Cancel"), command=self.cancel) button.pack(side=RIGHT, padx=5) button = TButton(but_frame, text=_("OK"), command=self.ok) button.pack(side=RIGHT, padx=5) root.resizable (width=0, height=0) self.entry_name.set_focus()
def build_dlg(self): self.root = TFrame(self.top, style='FlatFrame', borderwidth=5) self.root.pack(side=TOP, fill=BOTH, expand=1) panel = TFrame(self.root, style='FlatFrame', borderwidth=5) panel.pack(side=TOP, fill=X) icon = TLabel(panel, style='FlatLabel', image='icon_sk1_48') icon.pack(side=LEFT, padx=5, pady=5) panel = TFrame(panel, style='FlatFrame', borderwidth=5) panel.pack(side=LEFT) text = TLabel(panel, style='FlatLabel', text='sK1 v.%s' % app.sKVersion, font=app.config.preferences.large_font + ' bold') text.pack(side=TOP, anchor=W) text = TLabel( panel, style='FlatLabel', text=_('Uses libraries: Tcl/Tk %s; Python %s; LCMS %s') % (TclVersion, string.split(sys.version)[0], cms.get_version())) text.pack(side=TOP, anchor=W) self.nb = TNotebook(self.root, height=150, width=500, padding=5) self.nb.pack(side=TOP, fill=BOTH, expand=1) self.build_tab_about() self.build_tab_authors() self.build_tab_localization() self.build_tab_license() ok = TButton(self.root, text=_("Close"), command=self.ok) ok.pack(side=RIGHT, padx=5, pady=5) self.focus_widget = ok self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.top.resizable(width=0, height=0)
def build_dlg(self): root = TFrame(self.top, style='FlatFrame', borderwidth = 10) root.pack(side = TOP, fill = BOTH, expand = 1) middle = TFrame(root, style='FlatFrame', borderwidth = 5) middle.pack(side = TOP, fill = X, expand = 1) label = TLabel(middle, text = _("Go to page No.:")+" ", style='FlatLabel') label.pack(side = LEFT) self.pagenum_spin = TSpinbox(middle, var=app.mw.document.active_page+1, vartype=0, textvariable = self.pagenum, min = 1, max = len(app.mw.document.pages), step = 1, width = 6, command = self.ok) self.pagenum_spin.pack(side = LEFT) if len(app.mw.document.pages)==1: self.pagenum_spin.set_state('disabled') bottom = TFrame(root, style='FlatFrame', borderwidth = 5) bottom.pack(side = BOTTOM, fill = X, expand = 1) cancel = TButton(bottom, text=_("Cancel"), command=self.cancel) cancel.pack(side = RIGHT) label = TLabel(bottom, text = ' ', style='FlatLabel') label.pack(side = RIGHT) ok = TButton(bottom, text=_("OK"), command=self.ok) ok.pack(side = RIGHT) self.focus_widget = ok self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.top.resizable (width=0, height=0)
def build_dlg(self): self.root = TFrame(self.top, style='FlatFrame', borderwidth=5) self.root.pack(side=TOP, fill=BOTH, expand=1) panel = TFrame(self.root, style='FlatFrame', borderwidth=5) panel.pack(side=TOP, fill=X) icon = TLabel(panel, style='FlatLabel', image='icon_sk1_48') icon.pack(side=LEFT, padx=5, pady=5) panel = TFrame(panel, style='FlatFrame', borderwidth=5) panel.pack(side=LEFT) text = TLabel(panel, style='FlatLabel', text='sK1 v.%s' % app.sKVersion, font=app.config.preferences.large_font + ' bold') text.pack(side=TOP, anchor=W) text = TLabel(panel, style='FlatLabel', text=_('Uses libraries: Tcl/Tk %s; Python %s; LCMS %s') % (TclVersion, string.split(sys.version)[0], cms.get_version())) text.pack(side=TOP, anchor=W) self.nb = TNotebook(self.root, height=150, width=500, padding=5) self.nb.pack(side=TOP, fill=BOTH, expand=1) self.build_tab_about() self.build_tab_authors() self.build_tab_localization() self.build_tab_license() ok = TButton(self.root, text=_("Close"), command=self.ok) ok.pack(side=RIGHT, padx=5, pady=5) self.focus_widget = ok self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.top.resizable (width=0, height=0)
def __init__(self, master=None, min=0, max=100, step=1, textvariable=None, var=0, vartype=0, command=None, state=NORMAL, width=5, args=(), **kw): '''vartype=0 - integer vartype=1 - float ''' self.min_value=min self.max_value=max self.step=step self.variable=var self.vartype=vartype if textvariable: self.text_var=textvariable else: self.text_var=StringVar() self.command=command self.state=state self.width=width apply(TFrame.__init__, (self, master), kw) self["style"]="FlatFrame" self.entry=TEntryExt(self, textvariable=self.text_var, width=self.width, style='SpinEntry') self.entry.pack(side = LEFT, expand = 1, fill = BOTH) self.button_frame=TFrame(self,style="FlatFrame") self.button_frame.pack(side = LEFT,fill = Y) self.up_button=TButton(self.button_frame, class_='Repeater', command=self.increase, image='pal_arrow_up', style='SpinUpButton', takefocus=0) self.up_button.pack(side = TOP) self.down_button=TButton(self.button_frame, class_='Repeater', command=self.decrease, image='pal_arrow_down', style='SpinDownButton', takefocus=0) self.down_button.pack(side = TOP) if self.vartype==1: self.variable=float(self.variable) else: self.variable=int(self.variable) self.text_var.set(str(self.variable)) self.entry.bind('<Button-4>', self.wheel_increase) self.entry.bind('<Button-5>', self.wheel_decrease) self.entry.bind('<Key-Up>', self.wheel_increase) self.entry.bind('<Key-Down>', self.wheel_decrease) self.entry.bind('<Key-Return>', self.apply_command) self.entry.bind('<Key-KP_Enter>', self.apply_command)
def __init__(self, parent, toplevel, size=300, orient=LEFT, min=200, max=500, cnf={}, **kw): TFrame.__init__(self, parent, style='FlatFrame', **kw) self.parent = parent self.panel = TFrame(self, style='FlatFrame') self.orient = orient self.min = min self.max = max self.size = size self.toplevel = toplevel self.canv_size = 0 self.counter = 0 if orient in [LEFT, RIGHT]: self.spacer = Frame(self, width=size, height=1) self.grip = TButton(self, style='VGrip', cursor=appconst.CurHResize) if orient == LEFT: self.spacer.pack(side=TOP) self.grip.pack(side=LEFT, fill=Y) self.panel.pack(side=RIGHT, fill=BOTH, expand=1) else: self.spacer.pack(side=TOP) self.grip.pack(side=RIGHT, fill=Y) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.spacer = Frame(self, width=1, height=size) self.grip = TButton(self, style='HGrip', cursor=appconst.CurVResize) if orient == BOTTOM: self.grip.pack(side=BOTTOM, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.grip.pack(side=TOP, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) self.grip.bind ("<Button-1>", self.start) self.grip.bind ("<ButtonRelease-1>", self.stop)
def build_dlg(self): root = self.top top = TFrame(root, style='FlatFrame', borderwidth=13) top.pack(side=TOP) label = TLabel(top, text=_("Please select the object categories whose\n default properties you want to change")) label.pack(side=TOP, anchor=W) frame = TFrame(top, style='FlatFrame', borderwidth=10) frame.pack(side=TOP) self.var_graphics_style = IntVar(top) self.var_graphics_style.set(0) if self.category != 'font': self.var_graphics_style.set(1) button = TCheckbutton(frame, text=_("Graphics Objects"), state=(self.category == 'font' and DISABLED or NORMAL), variable=self.var_graphics_style) button.pack(side=TOP, anchor=W) self.var_text_style = IntVar(top) self.var_text_style.set(0) if self.category == 'font': self.var_text_style.set(1) button = TCheckbutton(frame, text=_("Text Objects"), state=(self.category == 'line' and DISABLED or NORMAL), variable=self.var_text_style) button.pack(side=TOP, anchor=W) label = TLabel(top, style="HLine") label.pack(side=TOP, fill=BOTH) but_frame = TFrame(top, style='FlatFrame') but_frame.pack(side=TOP, fill=BOTH, expand=1) button = TButton(but_frame, text=_("Cancel"), command=self.cancel) button.pack(side=RIGHT, expand=1) button = TButton(but_frame, text=_("OK"), command=self.ok) button.pack(side=RIGHT, expand=1) root.resizable (width=0, height=0)
def __init__(self, parent): CtxSubPanel.__init__(self, parent) self.angle=DoubleVar(self.mw.root) self.angle.set(0) label = TLabel(self.panel, image='context_R') label.pack(side = LEFT) self.entry_width = TSpinbox(self.panel, var=0, vartype=1, textvariable = self.angle, min = -360, max = 360, step = 1, width = 6, command = self.applyRotate) tooltips.AddDescription(self.entry_width, _('Rotation angle')) self.entry_width.pack(side = LEFT, padx=5) b = TButton(self.panel, command=self.rotLeft, style='Toolbutton', image='context_rotate_ccw') tooltips.AddDescription(b, _(u'Rotate -90°')) b.pack(side = LEFT) b = TButton(self.panel, command=self.rot180, style='Toolbutton', image='context_rotate') tooltips.AddDescription(b, _(u'Rotate 180°')) b.pack(side = LEFT) b = TButton(self.panel, command=self.rotRight, style='Toolbutton', image='context_rotate_cw') tooltips.AddDescription(b, _(u'Rotate 90°')) b.pack(side = LEFT)
def build_dlg(self): root = TFrame(self.top, style='FlatFrame', borderwidth = 10) root.pack(side = TOP, fill = BOTH, expand = 1) top = TFrame(root, style='FlatFrame', borderwidth = 5) top.pack(side = TOP, fill = X, expand = 1) label = TLabel(top, text = _("Insert:")+" ", style='FlatLabel') label.pack(side = LEFT) self.numpages_spin = TSpinbox(top, var=1, vartype=0, textvariable = self.numpages, min = 1, max = 1000, step = 1, width = 6, command = self.ok) self.numpages_spin.pack(side = LEFT) label = TLabel(top, text = " "+_("page(s)"), style='FlatLabel') label.pack(side = LEFT) middle = TFrame(root, style='FlatFrame', borderwidth = 5) middle.pack(side = TOP, fill = X, expand = 1) rbframe = TFrame(middle, style='FlatFrame', borderwidth = 5) rbframe.pack(side = LEFT) self.var_reference = StringVar(self.master) if self.is_before: self.var_reference.set('before') else: self.var_reference.set('after') radio = UpdatedRadiobutton(rbframe, value = 'before', text = _("Before")+" ", variable = self.var_reference) radio.pack(side=TOP, anchor=W) radio = UpdatedRadiobutton(rbframe, value = 'after', text = _("After")+" ", variable = self.var_reference) radio.pack(side=TOP, anchor=W) label = TLabel(middle, text = " "+_("page No.:")+" ", style='FlatLabel') label.pack(side = LEFT) self.pagenum_spin = TSpinbox(middle, var=app.mw.document.active_page+1, vartype=0, textvariable = self.pagenum, min = 1, max = len(app.mw.document.pages), step = 1, width = 6, command = self.ok) self.pagenum_spin.pack(side = LEFT) if len(app.mw.document.pages)==1: self.pagenum_spin.set_state('disabled') bottom = TFrame(root, style='FlatFrame', borderwidth = 5) bottom.pack(side = BOTTOM, fill = X, expand = 1) cancel = TButton(bottom, text=_("Cancel"), command=self.cancel) cancel.pack(side = RIGHT) label = TLabel(bottom, text = ' ', style='FlatLabel') label.pack(side = RIGHT) ok = TButton(bottom, text=_("OK"), command=self.ok) ok.pack(side = RIGHT) self.focus_widget = ok self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.top.resizable (width=0, height=0)
def __init__(self, parent, mainwindow): self.parent = parent self.mainwindow = mainwindow TFrame.__init__(self, self.parent, name='pagerPanel', style='FlatFrame', borderwidth=0) top_border = TLabel(self, style='FlatLabel', image='space_1') top_border.pack(side=TOP, fill=X) self.container = TFrame(self, style='FlatFrame', borderwidth=0) space = TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.home_but = TButton(self.container, style='PagerHome', command=self.PageHome) self.home_but.pack(side=LEFT) self.home_but = TButton(self.container, style='PagerPrevious', command=self.PagePrevious) self.home_but.pack(side=LEFT) self.text = TLabel(self.container, style='FlatLabel', text=' ' + _('Page 2 of 2') + ' ') self.text.pack(side=LEFT) self.home_but = TButton(self.container, style='PagerNext', command=self.PageNext) self.home_but.pack(side=LEFT) self.home_but = TButton(self.container, style='PagerEnd', command=self.PageEnd) self.home_but.pack(side=LEFT) space = TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.mainwindow.Subscribe(DOCUMENT, self.Resubscribe) self.Resubscribe() self.doc_paged() self.text.bind('<Double-Button-1>', self.GoToPage)
class DistributePlugin(PluginPanel): name = 'Distribute' title = _("Distribution") def init(self, master): PluginPanel.init(self, master) root = self.mw.root self.var_reference = StringVar(root) self.var_reference.set(SELECT) #--------------------------------------------------------- top = TFrame(self.panel, style='FlatFrame') top.pack(side=TOP, fill=BOTH) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Relative to") + " ", style="FlatLabel") label.pack(side=TOP, fill=BOTH, padx=5) rel_frame = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4) rel_frame.pack(side=TOP, fill=X, padx=5, pady=2) button_frame = TFrame(rel_frame, style='FlatFrame') button_frame.pack(side=TOP, fill=BOTH, padx=5) self.reference = TCombobox(button_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal', width=14, textvariable=self.var_reference, postcommand=self.set_cs) self.reference.pack(side=TOP) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Distribute type") + " ", style="FlatLabel") label.pack(side=TOP, fill=BOTH, padx=5) framec = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) framec.pack(side=TOP, fill=X, padx=5, pady=2) framex = TFrame(framec, style='FlatFrame') framex.pack(side=TOP, expand=0, padx=5, pady=5) framey = TFrame(framec, style='FlatFrame') framey.pack(side=TOP, expand=0, padx=5, pady=5) x_pixmaps = ['doleft', 'docenterh', 'dospacingh', 'doright'] y_pixmaps = ['dotop', 'docenterv', 'dospacingv', 'dobottom'] x_tooltips = [ _('Distribute left sides equidistantly'), _('Distribute centers equidistantly horizontally'), _('Make horizontal gaps between objects equal'), _('Distribute right sides equidistantly') ] y_tooltips = [ _('Distribute tops sides equidistantly'), _('Distribute centers equidistantly vertically'), _('Make vertical gaps between objects equal'), _('Distribute bottoms sides equidistantly') ] self.var_x = IntVar(top) self.var_x.set(0) self.value_x = 0 self.var_y = IntVar(top) self.var_y.set(0) self.value_y = 0 for i in range(1, 5): button = make_button(framex, image=x_pixmaps[i - 1], value=i, variable=self.var_x, command=self.apply_x) tooltips.AddDescription(button, x_tooltips[i - 1]) button.pack(side=LEFT, padx=3) button = make_button(framey, image=y_pixmaps[i - 1], value=i, variable=self.var_y, command=self.apply_y) tooltips.AddDescription(button, y_tooltips[i - 1]) button.pack(side=LEFT, padx=3) #--------------------------------------------------------- # Auto Apply Check self.var_auto_apply = IntVar(top) self.var_auto_apply.set(0) self.auto_apply_check = TCheckbutton(top, text=_("Auto Apply"), variable=self.var_auto_apply, command=self.reset) self.auto_apply_check.pack(side=TOP, anchor=W, padx=5, pady=5) #--------------------------------------------------------- # Button frame self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5) self.button_frame.pack(side=BOTTOM, fill=BOTH) self.update_buttons = [] self.button_apply = TButton(self.button_frame, text=_("Apply"), command=self.apply_distribute) self.apply_button_show(1) self.init_from_doc() self.subscribe_receivers() ############################################################################### def subscribe_receivers(self): self.document.Subscribe(SELECTION, self.Update) def unsubscribe_receivers(self): self.document.Unsubscribe(SELECTION, self.Update) def init_from_doc(self): self.Update() def Update(self, *arg): reference = self.var_reference.get() if self.is_selection(reference): state = NORMAL else: state = DISABLED self.button_apply['state'] = state def apply_button_show(self, state): if not state: self.button_apply.pack_forget() else: self.button_apply.pack(side=BOTTOM, expand=1, fill=X, pady=3) def make_cs_list(self): cs = () cs += (SELECT, PAGE, EDGE) return cs def set_cs(self): self.Update() def is_selection(self, reference=SELECT): if not self.var_auto_apply.get( ) and self.value_x == 0 and self.value_y == 0: return 0 if reference == SELECT: return (len(self.document.selection) > 2) else: return (len(self.document.selection) > 1) def HDistributeSelection(self, x, reference=SELECT): if self.is_selection(reference) and x: self.document.begin_transaction(TRANSACTION) try: try: add_undo = self.document.add_undo objects = self.document.selection.GetObjects() if reference == PAGE: brleft, brbottom, brright, brtop = self.document.PageRect( ) else: brleft, brbottom, brright, brtop = self.document.selection.coord_rect posh = [] total_width = 0 for obj in objects: rect = obj.coord_rect posh.append((rect.left, rect.right - rect.left, obj)) total_width += rect.right - rect.left posh.sort() first_obj_left, first_obj_width, first_obj = posh[0] last_obj_left, last_obj_width, last_obj = posh[-1] # how much influence of the width. 1-no, 0-full part_obj_dict = [None, 1.0, 0.5, 1.0, 0] # influence the width last object first_obj_dict = [ None, 0, first_obj_width * 0.5, 0, first_obj_width ] # influence the width last object last_obj_dict = [ None, last_obj_width, last_obj_width * 0.5, 0, 0 ] # influence the width. 0-no , 1-yes width_obj_dict = [None, 0, 0, 1, 0] brleft += first_obj_dict[x] brright -= last_obj_dict[x] brwidth = (brright - brleft - total_width * width_obj_dict[x]) if reference == EDGE: step = config.preferences.handle_jump else: step = brwidth / (len(posh) - 1) part = part_obj_dict[x] next = 0 for left, width, obj in posh[0:]: off = Point( next - left + brleft - width + width * part, 0) self.document.add_undo(obj.Translate(off)) next += step + width * width_obj_dict[x] add_undo(self.document.queue_edited()) except: self.document.abort_transaction() finally: self.document.end_transaction() def VDistributeSelection(self, y, reference=SELECT): if self.is_selection(reference) and y: self.document.begin_transaction(TRANSACTION) try: try: add_undo = self.document.add_undo objects = self.document.selection.GetObjects() if reference == PAGE: brleft, brbottom, brright, brtop = self.document.PageRect( ) else: brleft, brbottom, brright, brtop = self.document.selection.coord_rect posv = [] total_height = 0 for obj in objects: rect = obj.coord_rect posv.append((rect.top, rect.bottom - rect.top, obj)) total_height += rect.bottom - rect.top posv.sort() posv.reverse() first_obj_top, first_obj_height, first_obj = posv[0] last_obj_top, last_obj_height, last_obj = posv[-1] # how much influence of the height. 1-no, 0-full part_obj_dict = [None, 1.0, 0.5, 1.0, 0] # influence the height last object first_obj_dict = [ None, 0, first_obj_height * 0.5, 0, first_obj_height ] # influence the height last object last_obj_dict = [ None, last_obj_height, last_obj_height * 0.5, 0, 0 ] # influence the height. 0-no , 1-yes height_obj_dict = [None, 0, 0, 1, 0] brtop += first_obj_dict[y] brbottom -= last_obj_dict[y] brwidth = (brbottom - brtop - total_height * height_obj_dict[y]) if reference == EDGE: step = -1 * config.preferences.handle_jump else: step = brwidth / (len(posv) - 1) part = part_obj_dict[y] next = 0 for top, height, obj in posv[0:]: off = Point( 0, next - top + brtop - height + height * part) self.document.add_undo(obj.Translate(off)) next += step + height * height_obj_dict[y] add_undo(self.document.queue_edited()) except: self.document.abort_transaction() finally: self.document.end_transaction() def apply_x(self): x = self.var_x.get() reference = self.var_reference.get() if self.var_auto_apply.get(): self.reset() self.HDistributeSelection(x, reference=reference) else: if self.value_x == x: self.var_x.set(0) self.value_x = 0 else: self.value_x = x self.Update() def apply_y(self): y = self.var_y.get() reference = self.var_reference.get() if self.var_auto_apply.get(): self.reset() self.VDistributeSelection(y, reference=reference) else: if self.value_y == y: self.var_y.set(0) self.value_y = 0 else: self.value_y = y self.Update() def apply_distribute(self): if self.var_auto_apply.get(): return self.document.begin_transaction(TRANSACTION) try: try: reference = self.var_reference.get() x = self.value_x y = self.value_y self.HDistributeSelection(x, reference=reference) self.VDistributeSelection(y, reference=reference) except: self.document.abort_transaction() finally: self.document.end_transaction() def reset(self): self.var_x.set(0) self.value_x = 0 self.var_y.set(0) self.value_y = 0 ## self.apply_button_show(not self.var_auto_apply.get()) self.Update()
def __init__(self, parent): CtxSubPanel.__init__(self, parent) b = TButton(self.panel, command=self.makePageFrame, style='Toolbutton', image='context_add_page_frame') tooltips.AddDescription(b, _('Add page frame')) b.pack(side=LEFT) b = TButton(self.panel, command=self.addCenteredGuides, style='Toolbutton', image='context_add_centered_guides') tooltips.AddDescription(b, _('Add guides for page center')) b.pack(side=LEFT) ############# b = TLabel(self.panel, image="toolbar_sep") b.pack(side=LEFT) b = TButton(self.panel, command=self.addGuidesFrame, style='Toolbutton', image='context_add_guides_frame') tooltips.AddDescription(b, _('Add guides across page border')) b.pack(side=LEFT) self.var_jump_number = DoubleVar(self.mw.root) unit = config.preferences.default_unit var_jump_unit = StringVar(self.mw.root) self.var_jump = LengthVar(10, unit, self.var_jump_number, var_jump_unit) self.entry_jump = TSpinbox(self.panel, var=0, vartype=1, textvariable=self.var_jump_number, min=-1000, max=1000, step=5, width=6, command=self.addGuidesFrame) self.entry_jump.pack(side=LEFT, padx=2) config.preferences.Subscribe(CHANGED, self.update) self.var_jump.set(0) self.update(0, 0) b = TLabel(self.panel, image="toolbar_sep") b.pack(side=LEFT) ############## b = TButton(self.panel, command=self.removeAllGuides, style='Toolbutton', image='context_remove_all_guides') tooltips.AddDescription(b, _('Remove all guides')) b.pack(side=LEFT)
def build_dlg(self): super = self.top top = TFrame(super, borderwidth=10, style='FlatFrame') top.pack(side=TOP, fill=BOTH, expand=1) frame = TFrame(top, style='FlatFrame') frame.pack(side=BOTTOM, fill=BOTH, expand=0) label = TLabel(top, style="HLine") label.pack(side=BOTTOM, fill=BOTH, expand=0) button = TButton(frame, text=_("Cancel"), command=self.cancel) button.pack(side=RIGHT, expand=0) label = TLabel(frame, image="space_6", style="FlatLabel") label.pack(side=RIGHT) button = TButton(frame, text=_("OK"), command=self.ok) button.pack(side=RIGHT, expand=0) button = TButton(frame, image='colorpicker', state='disabled') button.pack(side=LEFT, expand=0) # RGBlabel_frame = TFrame(top, borderwidth = 1, style='FlatFrame') # RGBlabel_frame.pack(side = BOTTOM, fill = BOTH) # # self.label = TLabel(RGBlabel_frame, style="FlatLabel") # self.label.pack(side = LEFT) frame = TFrame(top, style="RoundedFrame", borderwidth=5) frame.pack(side=LEFT) viewxy = ChooseRGBXY(frame, xyramp_size[0], xyramp_size[1], 0, 1) viewxy.pack(side=LEFT) frame = TFrame(top, style="RoundedFrame", borderwidth=5) frame.pack(side=LEFT) viewz = ChooseRGBZ(frame, zramp_size[0], zramp_size[1], 2) viewz.pack(side=LEFT) frame1 = TFrame(top, borderwidth=3, style='FlatFrame') frame1.pack(side=RIGHT) CS_frame = TFrame(frame1, borderwidth=1, style='FlatFrame') CS_frame.pack(side=TOP) label = TLabel(CS_frame, text="Old color: \nNew color: ", justify='right') label.pack(side=LEFT) frame = TFrame(CS_frame, style="RoundedFrame", borderwidth=5) frame.pack(side=LEFT) self.sample = ColorSample(frame, self.color, width=60, height=20) self.sample.pack(side=BOTTOM) sample = ColorSample(frame, self.color, width=60, height=20) sample.pack(side=TOP) label = TLabel(frame1, style="HLine") label.pack(side=TOP, fill=BOTH, expand=0) spin_frame = TFrame(frame1, borderwidth=1, style='FlatFrame') spin_frame.pack(side=TOP) hsv_frame = TFrame(spin_frame, borderwidth=2, style='FlatFrame') hsv_frame.pack(side=LEFT) frame = TFrame(hsv_frame, borderwidth=2, style='FlatFrame') frame.pack(side=TOP) label = TLabel(frame, text="H: ") label.pack(side=LEFT) self.var1 = TSpinbox(frame, min=0, max=1.0, step=0.01, vartype=1, command=self.component_changed) self.var1.pack(side=RIGHT) frame = TFrame(hsv_frame, borderwidth=2, style='FlatFrame') frame.pack(side=TOP) label = TLabel(frame, text="S: ") label.pack(side=LEFT) self.var2 = TSpinbox(frame, min=0, max=1.0, step=0.01, vartype=1, command=self.component_changed) self.var2.pack(side=RIGHT) frame = TFrame(hsv_frame, borderwidth=2, style='FlatFrame') frame.pack(side=TOP) label = TLabel(frame, text="V: ") label.pack(side=LEFT) self.var3 = TSpinbox(frame, min=0, max=1.0, step=0.01, vartype=1, command=self.component_changed) self.var3.pack(side=RIGHT) rgb_frame = TFrame(spin_frame, borderwidth=2, style='FlatFrame') rgb_frame.pack(side=LEFT) frame = TFrame(rgb_frame, borderwidth=2, style='FlatFrame') frame.pack(side=TOP) label = TLabel(frame, text="R: ") label.pack(side=LEFT) self.var4 = TSpinbox(frame, min=0, max=255, step=1, vartype=0, command=self.rgb_component_changed) self.var4.pack(side=RIGHT) frame = TFrame(rgb_frame, borderwidth=2, style='FlatFrame') frame.pack(side=TOP) label = TLabel(frame, text="G: ") label.pack(side=LEFT) self.var5 = TSpinbox(frame, min=0, max=255, step=1, vartype=0, command=self.rgb_component_changed) self.var5.pack(side=RIGHT) frame = TFrame(rgb_frame, borderwidth=2, style='FlatFrame') frame.pack(side=TOP) label = TLabel(frame, text="B: ") label.pack(side=LEFT) self.var6 = TSpinbox(frame, min=0, max=255, step=1, vartype=0, command=self.rgb_component_changed) self.var6.pack(side=RIGHT) HTML_frame = TFrame(frame1, borderwidth=3, style='FlatFrame') HTML_frame.pack(side=TOP) label = TLabel(HTML_frame, text="HTML: ") label.pack(side=LEFT) self.html = TEntrybox(HTML_frame, text='#000000', width=10, command=self.html_component_changed) self.html.pack(side=LEFT) viewxy.Subscribe(CHANGED, self.color_changed) viewz.Subscribe(CHANGED, self.color_changed) self.viewxy = viewxy self.viewz = viewz super.resizable(width=0, height=0) self.color_changed(self.color)
class DistributePlugin(PluginPanel): name='Distribute' title = _("Distribution") def init(self, master): PluginPanel.init(self, master) root=self.mw.root self.var_reference = StringVar(root) self.var_reference.set(SELECT) #--------------------------------------------------------- top = TFrame(self.panel, style='FlatFrame') top.pack(side = TOP, fill=BOTH) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel") label.pack(side = TOP, fill = BOTH, padx=5) rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4) rel_frame.pack(side = TOP, fill=X, padx=5, pady=2) button_frame=TFrame(rel_frame, style='FlatFrame') button_frame.pack(side = TOP, fill = BOTH, padx=5) self.reference = TCombobox(button_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14, textvariable=self.var_reference, postcommand = self.set_cs) self.reference.pack(side = TOP) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Distribute type")+" ", style="FlatLabel") label.pack(side = TOP, fill = BOTH, padx=5) framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) framec.pack(side = TOP, fill=X, padx=5, pady=2) framex = TFrame(framec, style='FlatFrame') framex.pack(side = TOP, expand = 0, padx = 5, pady = 5) framey = TFrame(framec, style='FlatFrame') framey.pack(side = TOP, expand = 0, padx = 5, pady = 5) x_pixmaps = ['doleft', 'docenterh', 'dospacingh', 'doright'] y_pixmaps = ['dotop', 'docenterv', 'dospacingv', 'dobottom'] x_tooltips = [_('Distribute left sides equidistantly'), _('Distribute centers equidistantly horizontally'), _('Make horizontal gaps between objects equal'), _('Distribute right sides equidistantly')] y_tooltips = [_('Distribute tops sides equidistantly'), _('Distribute centers equidistantly vertically'), _('Make vertical gaps between objects equal'), _('Distribute bottoms sides equidistantly')] self.var_x = IntVar(top) self.var_x.set(0) self.value_x = 0 self.var_y = IntVar(top) self.var_y.set(0) self.value_y = 0 for i in range(1, 5): button = make_button(framex, image = x_pixmaps[i - 1], value = i, variable = self.var_x, command = self.apply_x) tooltips.AddDescription(button, x_tooltips[i - 1]) button.pack(side = LEFT, padx = 3) button = make_button(framey, image = y_pixmaps[i - 1], value = i, variable = self.var_y, command = self.apply_y) tooltips.AddDescription(button, y_tooltips[i - 1]) button.pack(side = LEFT, padx = 3) #--------------------------------------------------------- # Auto Apply Check self.var_auto_apply = IntVar(top) self.var_auto_apply.set(0) self.auto_apply_check = TCheckbutton(top, text = _("Auto Apply"), variable = self.var_auto_apply, command = self.reset) self.auto_apply_check.pack(side = TOP, anchor=W, padx=5,pady=5) #--------------------------------------------------------- # Button frame self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5) self.button_frame.pack(side = BOTTOM, fill = BOTH) self.update_buttons = [] self.button_apply = TButton(self.button_frame, text = _("Apply"), command = self.apply_distribute) self.apply_button_show(1) self.init_from_doc() self.subscribe_receivers() ############################################################################### def subscribe_receivers(self): self.document.Subscribe(SELECTION, self.Update) def unsubscribe_receivers(self): self.document.Unsubscribe(SELECTION, self.Update) def init_from_doc(self): self.Update() def Update(self, *arg): reference = self.var_reference.get() if self.is_selection(reference): state=NORMAL else: state=DISABLED self.button_apply['state']=state def apply_button_show(self, state): if not state: self.button_apply.pack_forget() else: self.button_apply.pack(side = BOTTOM, expand = 1, fill = X, pady=3) def make_cs_list(self): cs=() cs+=(SELECT,PAGE,EDGE) return cs def set_cs(self): self.Update() def is_selection(self, reference = SELECT): if not self.var_auto_apply.get() and self.value_x==0 and self.value_y==0: return 0 if reference == SELECT: return (len(self.document.selection) > 2) else: return (len(self.document.selection) > 1) def HDistributeSelection(self, x, reference = SELECT): if self.is_selection(reference) and x: self.document.begin_transaction(TRANSACTION) try: try: add_undo = self.document.add_undo objects = self.document.selection.GetObjects() if reference == PAGE: brleft, brbottom, brright, brtop = self.document.PageRect() else: brleft, brbottom, brright, brtop = self.document.selection.coord_rect posh = [] total_width=0 for obj in objects: rect = obj.coord_rect posh.append((rect.left, rect.right - rect.left, obj)) total_width += rect.right - rect.left posh.sort() first_obj_left, first_obj_width, first_obj = posh[0] last_obj_left, last_obj_width, last_obj = posh[-1] # how much influence of the width. 1-no, 0-full part_obj_dict=[None, 1.0, 0.5, 1.0, 0] # influence the width last object first_obj_dict = [None, 0, first_obj_width*0.5, 0, first_obj_width] # influence the width last object last_obj_dict = [None, last_obj_width, last_obj_width*0.5, 0, 0] # influence the width. 0-no , 1-yes width_obj_dict = [None, 0,0,1,0] brleft += first_obj_dict[x] brright -= last_obj_dict[x] brwidth = (brright-brleft - total_width*width_obj_dict[x]) if reference == EDGE: step = config.preferences.handle_jump else: step = brwidth / (len(posh)-1) part=part_obj_dict[x] next = 0 for left, width, obj in posh[0:]: off = Point(next - left +brleft - width + width*part, 0) self.document.add_undo(obj.Translate(off)) next += step+width*width_obj_dict[x] add_undo(self.document.queue_edited()) except: self.document.abort_transaction() finally: self.document.end_transaction() def VDistributeSelection(self, y, reference = SELECT): if self.is_selection(reference) and y: self.document.begin_transaction(TRANSACTION) try: try: add_undo = self.document.add_undo objects = self.document.selection.GetObjects() if reference == PAGE: brleft, brbottom, brright, brtop = self.document.PageRect() else: brleft, brbottom, brright, brtop = self.document.selection.coord_rect posv = [] total_height=0 for obj in objects: rect = obj.coord_rect posv.append((rect.top, rect.bottom - rect.top, obj)) total_height += rect.bottom - rect.top posv.sort() posv.reverse() first_obj_top, first_obj_height, first_obj = posv[0] last_obj_top, last_obj_height, last_obj = posv[-1] # how much influence of the height. 1-no, 0-full part_obj_dict=[None, 1.0, 0.5, 1.0, 0] # influence the height last object first_obj_dict = [None, 0, first_obj_height*0.5, 0, first_obj_height] # influence the height last object last_obj_dict = [None, last_obj_height, last_obj_height*0.5, 0, 0] # influence the height. 0-no , 1-yes height_obj_dict = [None, 0,0,1,0] brtop += first_obj_dict[y] brbottom -= last_obj_dict[y] brwidth = (brbottom-brtop - total_height*height_obj_dict[y]) if reference == EDGE: step = -1*config.preferences.handle_jump else: step = brwidth / (len(posv)-1) part=part_obj_dict[y] next = 0 for top, height, obj in posv[0:]: off = Point(0, next - top +brtop - height + height*part) self.document.add_undo(obj.Translate(off)) next += step+height*height_obj_dict[y] add_undo(self.document.queue_edited()) except: self.document.abort_transaction() finally: self.document.end_transaction() def apply_x(self): x = self.var_x.get() reference = self.var_reference.get() if self.var_auto_apply.get(): self.reset() self.HDistributeSelection(x, reference = reference) else: if self.value_x==x: self.var_x.set(0) self.value_x = 0 else: self.value_x = x self.Update() def apply_y(self): y = self.var_y.get() reference = self.var_reference.get() if self.var_auto_apply.get(): self.reset() self.VDistributeSelection(y, reference = reference) else: if self.value_y==y: self.var_y.set(0) self.value_y = 0 else: self.value_y = y self.Update() def apply_distribute(self): if self.var_auto_apply.get(): return self.document.begin_transaction(TRANSACTION) try: try: reference = self.var_reference.get() x = self.value_x y = self.value_y self.HDistributeSelection(x, reference = reference) self.VDistributeSelection(y, reference = reference) except: self.document.abort_transaction() finally: self.document.end_transaction() def reset(self): self.var_x.set(0) self.value_x = 0 self.var_y.set(0) self.value_y = 0 ## self.apply_button_show(not self.var_auto_apply.get()) self.Update()
class TSpinbox(TFrame): def __init__(self, master=None, min=0, max=100, step=1, textvariable=None, var=0, vartype=0, command=None, state=NORMAL, width=5, args=(), **kw): '''vartype=0 - integer vartype=1 - float ''' self.min_value = min self.max_value = max self.step = step self.variable = var self.vartype = vartype if textvariable: self.text_var = textvariable else: self.text_var = StringVar() self.command = command self.state = state self.width = width apply(TFrame.__init__, (self, master), kw) self["style"] = "FlatFrame" self.entry = TEntryExt(self, textvariable=self.text_var, width=self.width, style='SpinEntry') self.entry.pack(side=LEFT, expand=1, fill=BOTH) self.button_frame = TFrame(self, style="FlatFrame") self.button_frame.pack(side=LEFT, fill=Y) self.up_button = TButton(self.button_frame, class_='Repeater', command=self.increase, image='pal_arrow_up', style='SpinUpButton', takefocus=0) self.up_button.pack(side=TOP) self.down_button = TButton(self.button_frame, class_='Repeater', command=self.decrease, image='pal_arrow_down', style='SpinDownButton', takefocus=0) self.down_button.pack(side=TOP) if self.vartype == 1: self.variable = float(self.variable) else: self.variable = int(self.variable) self.text_var.set(str(self.variable)) self.entry.bind('<Button-4>', self.wheel_increase) self.entry.bind('<Button-5>', self.wheel_decrease) self.entry.bind('<Key-Up>', self.wheel_increase) self.entry.bind('<Key-Down>', self.wheel_decrease) self.entry.bind('<Key-Return>', self.apply_command) self.entry.bind('<Key-KP_Enter>', self.apply_command) #self.entry.bind ( '<KeyPress>', self.check_input) def check_input(self, event): event = None def apply_command(self, *args): if self.state == NORMAL: text = self.entry.get() text = text.replace(',', '.') text = text.replace('/', '*1./') if text and not expression.search(text): try: variable = eval(text) except: pass else: self.set_value(variable) self.command(*args) def set_state(self, state): self.state = state self.entry.configure(state=state) self.up_button.configure(state=state) self.down_button.configure(state=state) def get_state(self): return self.state def wheel_increase(self, event): self.increase() def wheel_decrease(self, event): self.decrease() def increase(self): if self.state == NORMAL: try: self.variable = float(self.text_var.get()) except: self.text_var.set('0') self.variable = float(self.text_var.get()) self.variable = self.variable + self.step self.set_value(self.variable) def decrease(self): if self.state == NORMAL: try: self.variable = float(self.text_var.get()) except: self.text_var.set('0') self.variable = float(self.text_var.get()) self.variable = self.variable - self.step self.set_value(self.variable) def set_value(self, value=0): try: value = float(value) except: value = 0 value = min(self.max_value, value) value = max(self.min_value, value) if self.vartype == 1: self.variable = float(value) else: self.variable = int(round(value)) self.text_var.set(str(self.variable)) def get_value(self): try: self.variable = float(self.text_var.get()) except: self.text_var.set('0') self.variable = float(self.text_var.get()) if self.vartype == 1: self.variable = float(self.variable) else: self.variable = int(round(self.variable)) return self.variable def destroy(self): self.entry.unbind_all(self.entry) self.entry.destroy() self.button_frame.destroy() self.up_button.destroy() self.down_button.destroy() self.command = self.args = None TFrame.destroy(self)
class Pager(TFrame, Publisher): hidden=1 def __init__(self, parent, mainwindow): self.parent=parent self.mainwindow=mainwindow TFrame.__init__(self, self.parent, name = 'pagerPanel', style='FlatFrame', borderwidth=0) top_border=TLabel(self, style='FlatLabel', image='space_1') top_border.pack(side=TOP, fill=X) self.container=TFrame(self, style='FlatFrame', borderwidth=0) space=TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.home_but=TButton(self.container, style='PagerHome', command=self.PageHome) self.home_but.pack(side=LEFT) self.home_but=TButton(self.container, style='PagerPrevious', command=self.PagePrevious) self.home_but.pack(side=LEFT) self.text=TLabel(self.container, style='FlatLabel', text=' '+_('Page 2 of 2')+' ') self.text.pack(side=LEFT) self.home_but=TButton(self.container, style='PagerNext', command=self.PageNext) self.home_but.pack(side=LEFT) self.home_but=TButton(self.container, style='PagerEnd', command=self.PageEnd) self.home_but.pack(side=LEFT) space=TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.mainwindow.Subscribe(DOCUMENT, self.Resubscribe) self.Resubscribe() self.doc_paged() self.text.bind('<Double-Button-1>', self.GoToPage) def stub(self): pass def doc_paged(self): current_page=self.mainwindow.document.active_page+1 num_pages=len(self.mainwindow.document.pages) if self.hidden and num_pages>1: self.container.pack(side=LEFT, fill=Y) self.hidden=0 if not self.hidden and num_pages==1: self.container.forget() self.hidden=1 self.text['text']=' '+_('Page %u of %u')%(current_page,num_pages)+' ' def Resubscribe(self, *arg): self.mainwindow.document.Subscribe(PAGE, self.doc_paged) self.doc_paged() def PageHome(self): self.mainwindow.document.GoToPage(0) self.mainwindow.document.SelectNone() self.mainwindow.canvas.ForceRedraw() def PageEnd(self): self.mainwindow.document.GoToPage(len(self.mainwindow.document.pages)-1) self.mainwindow.document.SelectNone() self.mainwindow.canvas.ForceRedraw() def PagePrevious(self): self.mainwindow.PreviousPage() def PageNext(self): self.mainwindow.NextPage() def GoToPage(self, *args): self.mainwindow.GotoPage()
class ResizableTFrame(TFrame): def __init__(self, parent, toplevel, size=300, orient=LEFT, min=200, max=500, cnf={}, **kw): TFrame.__init__(self, parent, style='FlatFrame', **kw) self.parent = parent self.panel = TFrame(self, style='FlatFrame') self.orient = orient self.min = min self.max = max self.size = size self.toplevel = toplevel self.canv_size = 0 self.counter = 0 if orient in [LEFT, RIGHT]: self.spacer = Frame(self, width=size, height=1) self.grip = TButton(self, style='VGrip', cursor=appconst.CurHResize) if orient == LEFT: self.spacer.pack(side=TOP) self.grip.pack(side=LEFT, fill=Y) self.panel.pack(side=RIGHT, fill=BOTH, expand=1) else: self.spacer.pack(side=TOP) self.grip.pack(side=RIGHT, fill=Y) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.spacer = Frame(self, width=1, height=size) self.grip = TButton(self, style='HGrip', cursor=appconst.CurVResize) if orient == BOTTOM: self.grip.pack(side=BOTTOM, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.grip.pack(side=TOP, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) self.grip.bind("<Button-1>", self.start) self.grip.bind("<ButtonRelease-1>", self.stop) def start(self, *args): self.toplevel.bind("<Motion>", self.resize) def stop(self, *args): self.toplevel.unbind("<Motion>") def resize(self, args): self.counter += 1 if self.counter < 5: return self.counter = 0 if self.orient in [LEFT, RIGHT]: self.canv_size = args.x else: self.canv_size = args.y if self.orient in [LEFT, RIGHT]: cw = string.atoi(self.spacer['width']) if self.orient == LEFT: cw -= self.canv_size else: cw += self.canv_size if cw < self.min: cw = self.min if cw > self.max: cw = self.max self.spacer['width'] = cw else: cw = string.atoi(self.spacer['height']) if self.orient == TOP: cw -= self.canv_size else: cw += self.canv_size if cw < self.min: cw = self.min if cw > self.max: cw = self.max self.spacer['height'] = cw
def destroy(self): self.command.Unsubscribe(CHANGED, self._update) pax.unregister_object(self.command) self.command = self.args = None TButton.destroy(self) pax.unregister_object(self)
def destroy(self): AutoUpdate.clean_up(self) WidgetWithCommand.clean_up(self) TButton.destroy(self)
def __init__(self, parent): CtxSubPanel.__init__(self, parent) self.angle = DoubleVar(self.mw.root) self.angle.set(0) label = TLabel(self.panel, image='context_R') label.pack(side=LEFT) self.entry_width = TSpinbox(self.panel, var=0, vartype=1, textvariable=self.angle, min=-360, max=360, step=1, width=6, command=self.applyRotate) tooltips.AddDescription(self.entry_width, _('Rotation angle')) self.entry_width.pack(side=LEFT, padx=5) b = TButton(self.panel, command=self.rotLeft, style='Toolbutton', image='context_rotate_ccw') tooltips.AddDescription(b, _(u'Rotate -90°')) b.pack(side=LEFT) b = TButton(self.panel, command=self.rot180, style='Toolbutton', image='context_rotate') tooltips.AddDescription(b, _(u'Rotate 180°')) b.pack(side=LEFT) b = TButton(self.panel, command=self.rotRight, style='Toolbutton', image='context_rotate_cw') tooltips.AddDescription(b, _(u'Rotate 90°')) b.pack(side=LEFT)
def build_dlg(self): root = TFrame(self.top, style='FlatFrame', borderwidth=10) root.pack(side=TOP, fill=BOTH, expand=1) top = TFrame(root, style='FlatFrame', borderwidth=5) top.pack(side=TOP, fill=X, expand=1) label = TLabel(top, text=_("Insert:") + " ", style='FlatLabel') label.pack(side=LEFT) self.numpages_spin = TSpinbox(top, var=1, vartype=0, textvariable=self.numpages, min=1, max=1000, step=1, width=6, command=self.ok) self.numpages_spin.pack(side=LEFT) label = TLabel(top, text=" " + _("page(s)"), style='FlatLabel') label.pack(side=LEFT) middle = TFrame(root, style='FlatFrame', borderwidth=5) middle.pack(side=TOP, fill=X, expand=1) rbframe = TFrame(middle, style='FlatFrame', borderwidth=5) rbframe.pack(side=LEFT) self.var_reference = StringVar(self.master) if self.is_before: self.var_reference.set('before') else: self.var_reference.set('after') radio = UpdatedRadiobutton(rbframe, value='before', text=_("Before") + " ", variable=self.var_reference) radio.pack(side=TOP, anchor=W) radio = UpdatedRadiobutton(rbframe, value='after', text=_("After") + " ", variable=self.var_reference) radio.pack(side=TOP, anchor=W) label = TLabel(middle, text=" " + _("page No.:") + " ", style='FlatLabel') label.pack(side=LEFT) self.pagenum_spin = TSpinbox(middle, var=app.mw.document.active_page + 1, vartype=0, textvariable=self.pagenum, min=1, max=len(app.mw.document.pages), step=1, width=6, command=self.ok) self.pagenum_spin.pack(side=LEFT) if len(app.mw.document.pages) == 1: self.pagenum_spin.set_state('disabled') bottom = TFrame(root, style='FlatFrame', borderwidth=5) bottom.pack(side=BOTTOM, fill=X, expand=1) cancel = TButton(bottom, text=_("Cancel"), command=self.cancel) cancel.pack(side=RIGHT) label = TLabel(bottom, text=' ', style='FlatLabel') label.pack(side=RIGHT) ok = TButton(bottom, text=_("OK"), command=self.ok) ok.pack(side=RIGHT) self.focus_widget = ok self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.top.resizable(width=0, height=0)
class AlignPlugin(PluginPanel): name = 'Alignment' title = _("Alignment") def init(self, master): PluginPanel.init(self, master) root = self.mw.root self.var_reference = StringVar(root) self.var_reference.set(SELECT) #--------------------------------------------------------- top = TFrame(self.panel, style='FlatFrame') top.pack(side=TOP, fill=BOTH) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Relative to") + " ", style="FlatLabel") label.pack(side=TOP, fill=BOTH, padx=5) rel_frame = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) rel_frame.pack(side=TOP, fill=X, padx=5, pady=2) self.reference = TCombobox(rel_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal', width=14, textvariable=self.var_reference, postcommand=self.set_cs) self.reference.pack(side=TOP) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Alignment type") + " ", style="FlatLabel") label.pack(side=TOP, fill=BOTH, padx=5) framec = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) framec.pack(side=TOP, fill=X, padx=5, pady=2) framex = TFrame(framec, style='FlatFrame') framex.pack(side=TOP, expand=0, padx=5, pady=5) framey = TFrame(framec, style='FlatFrame') framey.pack(side=TOP, expand=0, padx=5, pady=5) x_pixmaps = ['aoleft', 'aocenterh', 'aoright'] y_pixmaps = ['aotop', 'aocenterv', 'aobottom'] x_tooltips = [ _('Align left sides'), _('Center on vertical axis'), _('Align right sides') ] y_tooltips = [ _('Align tops'), _('Center on horizontal axis'), _('Align bottoms') ] self.var_x = IntVar(top) self.var_x.set(0) self.value_x = 0 self.var_y = IntVar(top) self.var_y.set(0) self.value_y = 0 for i in range(1, 4): button = make_button(framex, image=x_pixmaps[i - 1], value=i, variable=self.var_x, command=self.apply_x) tooltips.AddDescription(button, x_tooltips[i - 1]) button.pack(side=LEFT, padx=3) button = make_button(framey, image=y_pixmaps[i - 1], value=i, variable=self.var_y, command=self.apply_y) tooltips.AddDescription(button, y_tooltips[i - 1]) button.pack(side=LEFT, padx=3) #--------------------------------------------------------- # Auto Apply Check self.var_auto_apply = IntVar(top) self.var_auto_apply.set(0) self.auto_apply_check = TCheckbutton(top, text=_("Auto Apply"), variable=self.var_auto_apply, command=self.reset) self.auto_apply_check.pack(side=TOP, anchor=W, padx=5, pady=5) #--------------------------------------------------------- # Button frame self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5) self.button_frame.pack(side=BOTTOM, fill=BOTH) self.update_buttons = [] self.button_apply = TButton(self.button_frame, text=_("Apply"), command=self.apply) self.apply_button_show(1) self.init_from_doc() self.subscribe_receivers() ############################################################################### def subscribe_receivers(self): self.document.Subscribe(SELECTION, self.Update) def unsubscribe_receivers(self): self.document.Unsubscribe(SELECTION, self.Update) def init_from_doc(self): self.Update() self.issue(SELECTION) def Update(self, *arg): reference = self.var_reference.get() if self.is_selection(reference): state = NORMAL else: state = DISABLED self.button_apply['state'] = state def apply_button_show(self, state): if not state: self.button_apply.pack_forget() else: self.button_apply.pack(side=BOTTOM, expand=1, fill=X, pady=3) def make_cs_list(self): cs = () cs += (SELECT, LOWERMOST, PAGE) return cs def set_cs(self): self.Update() def is_selection(self, reference=SELECT): if not self.var_auto_apply.get( ) and self.value_x == 0 and self.value_y == 0: return 0 if reference == PAGE: return (len(self.document.selection) > 0) else: return (len(self.document.selection) > 1) def apply_x(self): x = self.var_x.get() if self.var_auto_apply.get(): self.reset() self.apply(x=x) else: if self.value_x == x: self.var_x.set(0) self.value_x = 0 else: self.value_x = x self.Update() def apply_y(self): y = self.var_y.get() if self.var_auto_apply.get(): self.reset() self.apply(y=y) else: if self.value_y == y: self.var_y.set(0) self.value_y = 0 else: self.value_y = y self.Update() def apply(self, x=None, y=None, reference=None): reference = self.var_reference.get() if not self.is_selection(reference): return if x is None: x = self.var_x.get() if y is None: y = self.var_y.get() if reference is None: reference = self.var_reference.get() reference = self.reference_command(reference) self.document.AlignSelection(x, y, reference=reference) def reference_command(self, reference): if reference == SELECT: return 'selection' if reference == LOWERMOST: return 'lowermost' if reference == PAGE: return 'page' def reset(self): self.var_x.set(0) self.value_x = 0 self.var_y.set(0) self.value_y = 0 ## self.apply_button_show(not self.var_auto_apply.get()) self.Update()
def init(self, master): PluginPanel.init(self, master) root = self.mw.root self.var_reference = StringVar(root) self.var_reference.set(SELECT) #--------------------------------------------------------- top = TFrame(self.panel, style='FlatFrame') top.pack(side=TOP, fill=BOTH) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Relative to") + " ", style="FlatLabel") label.pack(side=TOP, fill=BOTH, padx=5) rel_frame = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) rel_frame.pack(side=TOP, fill=X, padx=5, pady=2) self.reference = TCombobox(rel_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal', width=14, textvariable=self.var_reference, postcommand=self.set_cs) self.reference.pack(side=TOP) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Alignment type") + " ", style="FlatLabel") label.pack(side=TOP, fill=BOTH, padx=5) framec = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) framec.pack(side=TOP, fill=X, padx=5, pady=2) framex = TFrame(framec, style='FlatFrame') framex.pack(side=TOP, expand=0, padx=5, pady=5) framey = TFrame(framec, style='FlatFrame') framey.pack(side=TOP, expand=0, padx=5, pady=5) x_pixmaps = ['aoleft', 'aocenterh', 'aoright'] y_pixmaps = ['aotop', 'aocenterv', 'aobottom'] x_tooltips = [ _('Align left sides'), _('Center on vertical axis'), _('Align right sides') ] y_tooltips = [ _('Align tops'), _('Center on horizontal axis'), _('Align bottoms') ] self.var_x = IntVar(top) self.var_x.set(0) self.value_x = 0 self.var_y = IntVar(top) self.var_y.set(0) self.value_y = 0 for i in range(1, 4): button = make_button(framex, image=x_pixmaps[i - 1], value=i, variable=self.var_x, command=self.apply_x) tooltips.AddDescription(button, x_tooltips[i - 1]) button.pack(side=LEFT, padx=3) button = make_button(framey, image=y_pixmaps[i - 1], value=i, variable=self.var_y, command=self.apply_y) tooltips.AddDescription(button, y_tooltips[i - 1]) button.pack(side=LEFT, padx=3) #--------------------------------------------------------- # Auto Apply Check self.var_auto_apply = IntVar(top) self.var_auto_apply.set(0) self.auto_apply_check = TCheckbutton(top, text=_("Auto Apply"), variable=self.var_auto_apply, command=self.reset) self.auto_apply_check.pack(side=TOP, anchor=W, padx=5, pady=5) #--------------------------------------------------------- # Button frame self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5) self.button_frame.pack(side=BOTTOM, fill=BOTH) self.update_buttons = [] self.button_apply = TButton(self.button_frame, text=_("Apply"), command=self.apply) self.apply_button_show(1) self.init_from_doc() self.subscribe_receivers()
class Pager(TFrame, Publisher): hidden = 1 def __init__(self, parent, mainwindow): self.parent = parent self.mainwindow = mainwindow TFrame.__init__(self, self.parent, name='pagerPanel', style='FlatFrame', borderwidth=0) top_border = TLabel(self, style='FlatLabel', image='space_1') top_border.pack(side=TOP, fill=X) self.container = TFrame(self, style='FlatFrame', borderwidth=0) space = TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.home_but = TButton(self.container, style='PagerHome', command=self.PageHome) self.home_but.pack(side=LEFT) self.home_but = TButton(self.container, style='PagerPrevious', command=self.PagePrevious) self.home_but.pack(side=LEFT) self.text = TLabel(self.container, style='FlatLabel', text=' ' + _('Page 2 of 2') + ' ') self.text.pack(side=LEFT) self.home_but = TButton(self.container, style='PagerNext', command=self.PageNext) self.home_but.pack(side=LEFT) self.home_but = TButton(self.container, style='PagerEnd', command=self.PageEnd) self.home_but.pack(side=LEFT) space = TLabel(self.container, style='FlatLabel', image='space_3') space.pack(side=LEFT, fill=Y) self.mainwindow.Subscribe(DOCUMENT, self.Resubscribe) self.Resubscribe() self.doc_paged() self.text.bind('<Double-Button-1>', self.GoToPage) def stub(self): pass def doc_paged(self): current_page = self.mainwindow.document.active_page + 1 num_pages = len(self.mainwindow.document.pages) if self.hidden and num_pages > 1: self.container.pack(side=LEFT, fill=Y) self.hidden = 0 if not self.hidden and num_pages == 1: self.container.forget() self.hidden = 1 self.text['text'] = ' ' + _('Page %u of %u') % (current_page, num_pages) + ' ' def Resubscribe(self, *arg): self.mainwindow.document.Subscribe(PAGE, self.doc_paged) self.doc_paged() def PageHome(self): self.mainwindow.document.GoToPage(0) self.mainwindow.document.SelectNone() self.mainwindow.canvas.ForceRedraw() def PageEnd(self): self.mainwindow.document.GoToPage( len(self.mainwindow.document.pages) - 1) self.mainwindow.document.SelectNone() self.mainwindow.canvas.ForceRedraw() def PagePrevious(self): self.mainwindow.PreviousPage() def PageNext(self): self.mainwindow.NextPage() def GoToPage(self, *args): self.mainwindow.GotoPage()
def init(self, master): PluginPanel.init(self, master) root = self.mw.root top = TFrame(self.panel, style='FlatFrame', borderwidth=5) top.pack(side=TOP, fill=BOTH) ########### APPLY BUTTON ################################################ button = UpdatedButton(top, text=_("Apply"), command=self.apply_properties, sensitivecb=self.is_correct_selection) button.pack(side=BOTTOM, expand=1, fill=X) self.Subscribe(SELECTION, button.Update) ########### COLOR BUTTON ################################################ color_frame = TFrame(top, style='FlatFrame', borderwidth=3) color_frame.pack(side=TOP) label = TLabel(color_frame, style='FlatLabel', text=_('Color:')) label.pack(side=LEFT, padx=5) self.color_button = TColorButton(color_frame, command=self.show_outline_color) self.color_button.pack(side=LEFT, padx=5) self.color_button.set_color((255, 0, 0)) ########### LINE WIDTH ################################################## self.var_width_number = DoubleVar(root) self.var_width_base = DoubleVar(root) var_width_unit = StringVar(root) unit = config.preferences.default_unit self.var_width = LengthVar(10, unit, self.var_width_number, var_width_unit) line_width_frame = TFrame(top, style='FlatFrame', borderwidth=3) line_width_frame.pack(side=TOP, fill=BOTH) self.labelwunit = TLabel(line_width_frame, style='FlatLabel', text=self.var_width.unit) self.labelwunit.pack(side=RIGHT, padx=5) self.entry_width = TSpinbox(line_width_frame, var=0, vartype=1, textvariable=self.var_width_number, min=0, max=50000, step=.1, width=8, command=self.update_pattern) self.entry_width.pack(side=RIGHT) label = TLabel(line_width_frame, style='FlatLabel', text=_('Line width:')) label.pack(side=RIGHT, padx=5) ########### LINE STYLE ################################################# style_frame = TFrame(top, style='FlatFrame', borderwidth=5) style_frame.pack(side=TOP, fill=X) for item in range(1, 12): self.dashlist.append("dash%d" % (item)) self.style_button = TOptionMenu(style_frame, self.dashlist, command=self.set_dash, entry_type='image', style='TComboSmall') self.style_button.pack(side=RIGHT, fill=X) label = TLabel(style_frame, style='FlatLabel', text=_('Style:')) label.pack(side=RIGHT, padx=5) ######################################################################## selection_frame = TFrame(top, style='FlatFrame', borderwidth=1) selection_frame.pack(side=TOP) ########### CORNERS ##################################################### label = TLabel(selection_frame, text=" " + _("Corners:") + " ", style="FlatLabel") label.pack() corners_frame = TLabelframe(selection_frame, labelwidget=label, style='Labelframe', borderwidth=8) corners_frame.pack(side=LEFT, fill=Y, pady=1, padx=1) self.var_corner = IntVar(root) radio = UpdatedRadiobutton(corners_frame, image="join_miter", variable=self.var_corner, value=const.JoinMiter, command=self.update_pattern) radio.pack(side=TOP, anchor=W, pady=2) radio = UpdatedRadiobutton(corners_frame, image="join_round", variable=self.var_corner, value=const.JoinRound, command=self.update_pattern) radio.pack(side=TOP, anchor=W, pady=2) radio = UpdatedRadiobutton(corners_frame, image="join_bevel", variable=self.var_corner, value=const.JoinBevel, command=self.update_pattern) radio.pack(side=TOP, anchor=W, pady=2) ########### LINE CAPS ################################################### label = TLabel(selection_frame, text=" " + _("Line caps:") + " ", style="FlatLabel") label.pack() caps_frame = TLabelframe(selection_frame, labelwidget=label, style='Labelframe', borderwidth=8) caps_frame.pack(side=RIGHT, fill=Y, pady=1, padx=1) self.var_caps = IntVar(root) radio = UpdatedRadiobutton(caps_frame, image="cap_butt", variable=self.var_caps, value=const.CapButt, command=self.update_pattern) radio.pack(side=TOP, anchor=W, pady=2) radio = UpdatedRadiobutton(caps_frame, image="cap_round", variable=self.var_caps, value=const.CapRound, command=self.update_pattern) radio.pack(side=TOP, anchor=W, pady=2) radio = UpdatedRadiobutton(caps_frame, image="cap_projecting", variable=self.var_caps, value=const.CapProjecting, command=self.update_pattern) radio.pack(side=TOP, anchor=W, pady=2) self.var_caps.set(0) ############ BOTTOM BUTTONS ############################################# button_frame = TFrame(top, style='FlatFrame', borderwidth=1) button_frame.pack(side=BOTTOM, fill=X, pady=5) button = TButton(button_frame, style='TSmallbutton', text=' ', image='small_colorpicker', command=self.copy_from) button.pack(side=LEFT) tooltips.AddDescription(button, _("Copy From...")) button = TButton(button_frame, style='TSmallbutton', text=' ', image='restore_color', command=self.restore_properties) button.pack(side=LEFT, padx=5) tooltips.AddDescription(button, _("Restore properties")) self.var_autoupdate = IntVar(top) self.var_autoupdate.set(1) self.autoupdate_check = TCheckbutton(button_frame, text=_("Auto Update"), variable=self.var_autoupdate, command=self.init_from_doc) self.autoupdate_check.pack(side=RIGHT, anchor=W, padx=10) ####################################################################### self.set_default_style() self.init_from_doc() self.subscribe_receivers()
def init(self, master): PluginPanel.init(self, master) top = self.panel top = TFrame(top, borderwidth=2, style='FlatFrame') top.pack(side = TOP, expand = 1, fill = X) button_frame = TFrame(top, borderwidth=2, style='FlatFrame') button_frame.pack(side = BOTTOM, fill = BOTH, expand = 1) button=TButton(button_frame,text=_('Apply'), command=self.replace) button.pack(side = TOP) #---------------------------------------------------------- main_frame = TFrame(top, style='FlatFrame', borderwidth=3) main_frame.pack(side = TOP, fill=X) self.find_var = StringVar(top); self.find_var.set('') findField = TEntryExt(main_frame, textvariable=self.find_var) findField.pack(side = RIGHT) label = TLabel(main_frame, style='FlatLabel', text = _("Find:")+" ") label.pack(side = RIGHT, anchor = E) #--------------------------------------------------------- main_frame = TFrame(top, style='FlatFrame', borderwidth=3) main_frame.pack(side = TOP, fill=X) self.replace_var = StringVar(top); self.replace_var.set('') replaceField = TEntryExt(main_frame, textvariable=self.replace_var) replaceField.pack(side = RIGHT) label = TLabel(main_frame, style='FlatLabel', text = _("Replace to:")+" ") label.pack(side = RIGHT, anchor = E) main_frame = TFrame(top, style='FlatFrame', borderwidth=3) main_frame.pack(side = TOP) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Parameters")+" ", style="FlatLabel") label.pack() parametersFrameLabel=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4) parametersFrameLabel.pack(side = TOP, fill=X, pady=4, padx=4) parametersFrame = TFrame(parametersFrameLabel, style='FlatFrame') self.var_case_sensitive = BooleanVar(top) self.var_case_sensitive.set(False) self.case_sensitive_check = TCheckbutton(parametersFrame, text = _("Case sensitive"), variable = self.var_case_sensitive) self.case_sensitive_check.pack(side = TOP, anchor=W, padx=5) self.var_whole_word = BooleanVar(top) self.var_whole_word.set(False) self.whole_word_check = TCheckbutton(parametersFrame, text = _("Whole word"), variable = self.var_whole_word) self.whole_word_check.pack(side = TOP, anchor=W, padx=5) self.var_regexp = BooleanVar(top) self.var_regexp.set(False) self.regexpCheck = TCheckbutton(parametersFrame, text = _("RegExp search"), variable = self.var_regexp, command=self.disable_enable_action) self.regexpCheck.pack(side = TOP, anchor=W, padx=5) parametersFrame.pack(side=TOP, fill=X, pady=2)
class PluginPanel(TFrame, Publisher): receivers = [(SELECTION, 'issue', SELECTION)] name = '' category = '' title = '' icon = 'strip_dialog' contents = [] category = '' category_title = '' activated = 0 collapsed = 0 visible = 0 packed = 0 fill = X expand = 0 def init(self, master): self.master = master self.mw = app.mw self.pcontainer = self.master.master self.document = self.mw.document TFrame.__init__(self, self.master, style='FlatFrame', borderwidth=0) self.top = TFrame(self, style='PWinHead', borderwidth=3) self.panel = TFrame(self, style='PWinBody', borderwidth=3) self.activated = 1 self.visible = 1 self.packed = 1 for item in self.pcontainer.loaded: if not item.collapsed: item.collapse_panel() self.pack(side=TOP, fill=self.fill, expand=self.expand, padx=1, pady=1) self.top.pack(side=TOP, fill=X) self.panel.pack(side=TOP, fill=BOTH, expand=1) self.iconlabel = TLabel(self.top, style='PWLabel', image=self.icon) self.textlabel = TLabel(self.top, style='PWLabel', text=self.title, anchor=W) if not 'bold' in self.textlabel['font'].split(): self.textlabel['font'] += ' bold' self.closebut = TButton(self.top, style='PWButton', image='close_pw', command=self.close_panel) self.collapsebut = TButton(self.top, style='PWButton', image='minimize_pw', command=self.click) self.iconlabel.pack(side=LEFT, padx=2) self.textlabel.pack(side=LEFT, fill=BOTH, expand=1, padx=3) self.closebut.pack(side=RIGHT) self.collapsebut.pack(side=RIGHT) self.textlabel.bind("<Button-1>", self.click) self.mw.Subscribe(DOCUMENT, self.doc_changed) def click(self, *args): if self.collapsed: self.decollapse_panel() else: self.collapse_panel() def close_panel(self): self.packed = 0 self.forget() self.pcontainer.remove_plugin(self) def restore_panel(self): for item in self.pcontainer.loaded: if not item.collapsed: item.collapse_panel() self.forget() self.packed = 1 self.pack(side=TOP, fill=self.fill, expand=self.expand, padx=1, pady=1) self.decollapse_panel() def decollapse_panel(self, *arg): if self.collapsed: for item in self.pcontainer.loaded: if not item.collapsed: item.collapse_panel() self.forget() self.pack(side=TOP, fill=X, padx=1, pady=1) self.panel.pack(side=TOP, fill=BOTH, expand=1) self.collapsebut['image'] = 'minimize_pw' self.collapsed = 0 self.textlabel['foreground'] = app.uimanager.currentColorTheme.foreground self.forget() self.pack(side=TOP, fill=self.fill, expand=self.expand, padx=1, pady=1) def collapse_panel(self, *arg): if not self.collapsed: self.panel.forget() self.collapsebut['image'] = 'restore_pw' self.collapsed = 1 self.textlabel['foreground'] = app.uimanager.currentColorTheme.menudisabledforeground self.forget() self.pack(side=TOP, fill=X, expand=0, padx=1, pady=1) def doc_changed(self, *arg): self.SetDocument(self.mw.document) def doc_has_selection(self): return self.document.HasSelection() def subscribe_receivers(self): pass def unsubscribe_receivers(self): pass def SetDocument(self, doc): if self.document: self.unsubscribe_receivers() self.document = doc self.init_from_doc() self.subscribe_receivers() def init_from_doc(self): # Called whenever the document changes and from __init__ pass def Update(self): # Called when the selection changes. pass def do_apply(self): # called by the `Apply' standard button to apply the settings pass def can_apply(self): return 1 def create_std_buttons(self, master): frame = TFrame(master, style='FlatFrame', borderwidth=2) button = UpdatedButton(frame, text=_("Apply"), command=self.do_apply, sensitivecb=self.can_apply) button.pack(side=TOP) return frame
def build_dlg(self): if not self.builded: cmds = self.mw.canvas.commands.PolyBezierEditor b = TButton(self.panel, command=cmds.InsertNodes.Invoke, style='Toolbutton', image='context_node_add') tooltips.AddDescription(b, _('Insert node')) b.pack(side = LEFT) b = TButton(self.panel, command=cmds.DeleteNodes.Invoke, style='Toolbutton', image='context_node_remove') tooltips.AddDescription(b, _('Remove nodes')) b.pack(side = LEFT) ############# b = TLabel(self.panel, image = "toolbar_sep") b.pack(side = LEFT) b = TButton(self.panel, command=cmds.CloseNodes.Invoke, style='Toolbutton', image='context_node_join') tooltips.AddDescription(b, _('Join selected nodes')) b.pack(side = LEFT) b = TButton(self.panel, command=cmds.OpenNodes.Invoke, style='Toolbutton', image='context_node_break') tooltips.AddDescription(b, _('Break path at selected nodes')) b.pack(side = LEFT) ############# b = TLabel(self.panel, image = "toolbar_sep") b.pack(side = LEFT) b = TButton(self.panel, command=cmds.ContAngle.Invoke, style='Toolbutton', image='context_node_corner') tooltips.AddDescription(b, _('Make selected nodes corner')) b.pack(side = LEFT) b = TButton(self.panel, command=cmds.ContSmooth.Invoke, style='Toolbutton', image='context_node_smooth') tooltips.AddDescription(b, _('Make selected nodes smooth')) b.pack(side = LEFT) b = TButton(self.panel, command=cmds.ContSymmetrical.Invoke, style='Toolbutton', image='context_node_symm') tooltips.AddDescription(b, _('Make selected nodes symmetric')) b.pack(side = LEFT) ############# b = TLabel(self.panel, image = "toolbar_sep") b.pack(side = LEFT) b = TButton(self.panel, command=cmds.SegmentsToLines.Invoke, style='Toolbutton', image='context_node_line') tooltips.AddDescription(b, _('Make selected segments lines')) b.pack(side = LEFT) b = TButton(self.panel, command=cmds.SegmentsToCurve.Invoke, style='Toolbutton', image='context_node_curve') tooltips.AddDescription(b, _('Make selected segments curves')) b.pack(side = LEFT) ############# b = TLabel(self.panel, image = "toolbar_sep") b.pack(side = LEFT) b = TButton(self.panel, command=cmds.SelectAllNodes.Invoke, style='Toolbutton', image='context_node_all') tooltips.AddDescription(b, _('Select all nodes in path')) b.pack(side = LEFT) self.builded=1
def init(self, master): PluginPanel.init(self, master) root=self.mw.root self.var_reference = StringVar(root) self.var_reference.set(SELECT) #--------------------------------------------------------- top = TFrame(self.panel, style='FlatFrame') top.pack(side = TOP, fill=BOTH) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel") label.pack(side = TOP, fill = BOTH, padx=5) rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4) rel_frame.pack(side = TOP, fill=X, padx=5, pady=2) button_frame=TFrame(rel_frame, style='FlatFrame') button_frame.pack(side = TOP, fill = BOTH, padx=5) self.reference = TCombobox(button_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14, textvariable=self.var_reference, postcommand = self.set_cs) self.reference.pack(side = TOP) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Distribute type")+" ", style="FlatLabel") label.pack(side = TOP, fill = BOTH, padx=5) framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) framec.pack(side = TOP, fill=X, padx=5, pady=2) framex = TFrame(framec, style='FlatFrame') framex.pack(side = TOP, expand = 0, padx = 5, pady = 5) framey = TFrame(framec, style='FlatFrame') framey.pack(side = TOP, expand = 0, padx = 5, pady = 5) x_pixmaps = ['doleft', 'docenterh', 'dospacingh', 'doright'] y_pixmaps = ['dotop', 'docenterv', 'dospacingv', 'dobottom'] x_tooltips = [_('Distribute left sides equidistantly'), _('Distribute centers equidistantly horizontally'), _('Make horizontal gaps between objects equal'), _('Distribute right sides equidistantly')] y_tooltips = [_('Distribute tops sides equidistantly'), _('Distribute centers equidistantly vertically'), _('Make vertical gaps between objects equal'), _('Distribute bottoms sides equidistantly')] self.var_x = IntVar(top) self.var_x.set(0) self.value_x = 0 self.var_y = IntVar(top) self.var_y.set(0) self.value_y = 0 for i in range(1, 5): button = make_button(framex, image = x_pixmaps[i - 1], value = i, variable = self.var_x, command = self.apply_x) tooltips.AddDescription(button, x_tooltips[i - 1]) button.pack(side = LEFT, padx = 3) button = make_button(framey, image = y_pixmaps[i - 1], value = i, variable = self.var_y, command = self.apply_y) tooltips.AddDescription(button, y_tooltips[i - 1]) button.pack(side = LEFT, padx = 3) #--------------------------------------------------------- # Auto Apply Check self.var_auto_apply = IntVar(top) self.var_auto_apply.set(0) self.auto_apply_check = TCheckbutton(top, text = _("Auto Apply"), variable = self.var_auto_apply, command = self.reset) self.auto_apply_check.pack(side = TOP, anchor=W, padx=5,pady=5) #--------------------------------------------------------- # Button frame self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5) self.button_frame.pack(side = BOTTOM, fill = BOTH) self.update_buttons = [] self.button_apply = TButton(self.button_frame, text = _("Apply"), command = self.apply_distribute) self.apply_button_show(1) self.init_from_doc() self.subscribe_receivers()
class ResizableTFrame(TFrame): def __init__(self, parent, toplevel, size=300, orient=LEFT, min=200, max=500, cnf={}, **kw): TFrame.__init__(self, parent, style='FlatFrame', **kw) self.parent = parent self.panel = TFrame(self, style='FlatFrame') self.orient = orient self.min = min self.max = max self.size = size self.toplevel = toplevel self.canv_size = 0 self.counter = 0 if orient in [LEFT, RIGHT]: self.spacer = Frame(self, width=size, height=1) self.grip = TButton(self, style='VGrip', cursor=appconst.CurHResize) if orient == LEFT: self.spacer.pack(side=TOP) self.grip.pack(side=LEFT, fill=Y) self.panel.pack(side=RIGHT, fill=BOTH, expand=1) else: self.spacer.pack(side=TOP) self.grip.pack(side=RIGHT, fill=Y) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.spacer = Frame(self, width=1, height=size) self.grip = TButton(self, style='HGrip', cursor=appconst.CurVResize) if orient == BOTTOM: self.grip.pack(side=BOTTOM, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) else: self.grip.pack(side=TOP, fill=X) self.spacer.pack(side=RIGHT) self.panel.pack(side=LEFT, fill=BOTH, expand=1) self.grip.bind ("<Button-1>", self.start) self.grip.bind ("<ButtonRelease-1>", self.stop) def start(self, *args): self.toplevel.bind ("<Motion>", self.resize) def stop(self, *args): self.toplevel.unbind ("<Motion>") def resize(self, args): self.counter += 1 if self.counter < 5: return self.counter = 0 if self.orient in [LEFT, RIGHT]: self.canv_size = args.x else: self.canv_size = args.y if self.orient in [LEFT, RIGHT]: cw = string.atoi(self.spacer['width']) if self.orient == LEFT: cw -= self.canv_size else: cw += self.canv_size if cw < self.min:cw = self.min if cw > self.max:cw = self.max self.spacer['width'] = cw else: cw = string.atoi(self.spacer['height']) if self.orient == TOP: cw -= self.canv_size else: cw += self.canv_size if cw < self.min:cw = self.min if cw > self.max:cw = self.max self.spacer['height'] = cw
def build_dlg(self): self.root = TFrame(self.top, style='FlatFrame', borderwidth=10) self.root.pack(side=TOP, fill=BOTH, expand=1) ##### top panel #########################RoundedFrame toppanel = TFrame(self.root, style='FlatFrame') toppanel.pack(side=TOP, fill=BOTH, expand=1) rpanel = ResizableTFrame(toppanel, self.top, size=220, orient=RIGHT) rpanel.pack(side=LEFT, fill=Y) panel = TFrame(rpanel.panel, style='RoundedFrame', borderwidth=5) panel.pack(side=LEFT, fill=BOTH, expand=1) ctheme = app.uimanager.currentColorTheme self.scanvas = ScrolledCanvas(panel, bg=ctheme.editfieldbackground, height=420, width=200) self.scanvas.frame.pack(side=LEFT, fill=BOTH, expand=1) self.plugpanel = TFrame(toppanel, style='FlatFrame') self.plugpanel.pack(side=RIGHT, fill=BOTH, expand=1) # lab=TLabel(self.plugpanel, style='FlatLabel', text='Test label') # lab.pack(side = LEFT) ##### line ######################### line = TLabel(self.root, style='HLine2') line.pack(side=TOP, fill=X) ##### bottom panel ######################### botpanel = TFrame(self.root, style='FlatFrame') botpanel.pack(side=BOTTOM, fill=X, expand=0) cancel_bt = TButton(botpanel, text=_("Cancel"), command=self.cancel) cancel_bt.pack(side=RIGHT) apply_bt = TButton(botpanel, text=_("Apply"), command=self.do_apply) apply_bt.pack(side=RIGHT, padx=10) ok_bt = TButton(botpanel, text=_("OK"), command=self.ok) ok_bt.pack(side=RIGHT) help_bt = TButton(botpanel, text=_("Help"), state='disabled') help_bt.pack(side=LEFT) rdefs_bt = TButton(botpanel, text=_("Restore Defaults"), command=self.do_restore) rdefs_bt.pack(side=LEFT, padx=10) self.focus_widget = cancel_bt self.top.bind('<Escape>', self.cancel) self.top.protocol('WM_DELETE_WINDOW', self.cancel) self.width = 700 self.height = 500 self.build_plugins_tree() item = PluginsTreeItem(self.root_cat, self) node = TreeNode(self.scanvas.canvas, None, item, ctheme, 26) node.expand() self.loadByName('general')
def build_dlg(self): if not self.builded: cmds = self.mw.canvas.commands.Ellipse label = TLabel(self.panel, text=_("Start:")) label.pack(side=LEFT, padx=2) self.entry_start = TSpinbox(self.panel, var=0, vartype=1, textvariable=self.start, min=-360, max=360, step=5, width=6, command=self.applyAngle) self.entry_start.pack(side=LEFT, padx=2) tooltips.AddDescription(self.entry_start, _('Arc start point angle')) #-------------- sep = FlatFrame(self.panel, width=5, height=2) sep.pack(side=LEFT) #-------------- label = TLabel(self.panel, text=_("End:")) label.pack(side=LEFT, padx=2) self.entry_end = TSpinbox(self.panel, var=0, vartype=1, textvariable=self.end, min=-360, max=360, step=5, width=6, command=self.applyAngle) self.entry_end.pack(side=LEFT, padx=2) tooltips.AddDescription(self.entry_end, _('Arc end point angle')) b = TButton(self.panel, command=self.ResetAngle, style='Toolbutton', image='context_arc_reset') tooltips.AddDescription(b, _('Reset angles')) b.pack(side=LEFT) b = TButton(self.panel, command=self.SwapAngle, style='Toolbutton', image='context_arc_swap') tooltips.AddDescription(b, _('Swap angles')) b.pack(side=LEFT) b = TLabel(self.panel, image="toolbar_sep") b.pack(side=LEFT) b = TButton(self.panel, command=cmds.EllipseArc.Invoke, style='Toolbutton', image='context_arc') tooltips.AddDescription(b, _('to Arc')) b.pack(side=LEFT) b = TButton(self.panel, command=cmds.EllipseChord.Invoke, style='Toolbutton', image='context_chord') tooltips.AddDescription(b, _('to Chord')) b.pack(side=LEFT) b = TButton(self.panel, command=cmds.EllipsePieSlice.Invoke, style='Toolbutton', image='context_pie') tooltips.AddDescription(b, _('to Pie')) b.pack(side=LEFT) self.builded = 1 else: obj = self.mw.document.CurrentObject() if obj and obj.is_Ellipse: start_angle = round(obj.start_angle / degrees, 2) end_angle = round(obj.end_angle / degrees, 2) self.entry_start.set_value(start_angle) self.entry_end.set_value(end_angle)
def init(self, master): PluginPanel.init(self, master) top = self.panel top = TFrame(top, borderwidth=2, style='FlatFrame') top.pack(side=TOP, expand=1, fill=X) button_frame = TFrame(top, borderwidth=2, style='FlatFrame') button_frame.pack(side=BOTTOM, fill=BOTH, expand=1) button = TButton(button_frame, text=_('Apply'), command=self.replace) button.pack(side=TOP) #---------------------------------------------------------- main_frame = TFrame(top, style='FlatFrame', borderwidth=3) main_frame.pack(side=TOP, fill=X) self.find_var = StringVar(top) self.find_var.set('') findField = TEntryExt(main_frame, textvariable=self.find_var) findField.pack(side=RIGHT) label = TLabel(main_frame, style='FlatLabel', text=_("Find:") + " ") label.pack(side=RIGHT, anchor=E) #--------------------------------------------------------- main_frame = TFrame(top, style='FlatFrame', borderwidth=3) main_frame.pack(side=TOP, fill=X) self.replace_var = StringVar(top) self.replace_var.set('') replaceField = TEntryExt(main_frame, textvariable=self.replace_var) replaceField.pack(side=RIGHT) label = TLabel(main_frame, style='FlatLabel', text=_("Replace to:") + " ") label.pack(side=RIGHT, anchor=E) main_frame = TFrame(top, style='FlatFrame', borderwidth=3) main_frame.pack(side=TOP) #--------------------------------------------------------- label = TLabel(top, text=" " + _("Parameters") + " ", style="FlatLabel") label.pack() parametersFrameLabel = TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=4) parametersFrameLabel.pack(side=TOP, fill=X, pady=4, padx=4) parametersFrame = TFrame(parametersFrameLabel, style='FlatFrame') self.var_case_sensitive = BooleanVar(top) self.var_case_sensitive.set(False) self.case_sensitive_check = TCheckbutton( parametersFrame, text=_("Case sensitive"), variable=self.var_case_sensitive) self.case_sensitive_check.pack(side=TOP, anchor=W, padx=5) self.var_whole_word = BooleanVar(top) self.var_whole_word.set(False) self.whole_word_check = TCheckbutton(parametersFrame, text=_("Whole word"), variable=self.var_whole_word) self.whole_word_check.pack(side=TOP, anchor=W, padx=5) self.var_regexp = BooleanVar(top) self.var_regexp.set(False) self.regexpCheck = TCheckbutton(parametersFrame, text=_("RegExp search"), variable=self.var_regexp, command=self.disable_enable_action) self.regexpCheck.pack(side=TOP, anchor=W, padx=5) parametersFrame.pack(side=TOP, fill=X, pady=2)
class TSpinbox(TFrame): def __init__(self, master=None, min=0, max=100, step=1, textvariable=None, var=0, vartype=0, command=None, state=NORMAL, width=5, args=(), **kw): '''vartype=0 - integer vartype=1 - float ''' self.min_value=min self.max_value=max self.step=step self.variable=var self.vartype=vartype if textvariable: self.text_var=textvariable else: self.text_var=StringVar() self.command=command self.state=state self.width=width apply(TFrame.__init__, (self, master), kw) self["style"]="FlatFrame" self.entry=TEntryExt(self, textvariable=self.text_var, width=self.width, style='SpinEntry') self.entry.pack(side = LEFT, expand = 1, fill = BOTH) self.button_frame=TFrame(self,style="FlatFrame") self.button_frame.pack(side = LEFT,fill = Y) self.up_button=TButton(self.button_frame, class_='Repeater', command=self.increase, image='pal_arrow_up', style='SpinUpButton', takefocus=0) self.up_button.pack(side = TOP) self.down_button=TButton(self.button_frame, class_='Repeater', command=self.decrease, image='pal_arrow_down', style='SpinDownButton', takefocus=0) self.down_button.pack(side = TOP) if self.vartype==1: self.variable=float(self.variable) else: self.variable=int(self.variable) self.text_var.set(str(self.variable)) self.entry.bind('<Button-4>', self.wheel_increase) self.entry.bind('<Button-5>', self.wheel_decrease) self.entry.bind('<Key-Up>', self.wheel_increase) self.entry.bind('<Key-Down>', self.wheel_decrease) self.entry.bind('<Key-Return>', self.apply_command) self.entry.bind('<Key-KP_Enter>', self.apply_command) #self.entry.bind ( '<KeyPress>', self.check_input) def check_input(self, event): event=None def apply_command(self, *args): if self.state==NORMAL: text = self.entry.get() text = text.replace(',', '.') text = text.replace('/', '*1./') if text and not expression.search(text): try: variable = eval(text) except: pass else: self.set_value(variable) self.command(*args) def set_state(self, state): self.state=state self.entry.configure(state = state) self.up_button.configure(state = state) self.down_button.configure(state = state) def get_state(self): return self.state def wheel_increase(self, event): self.increase() def wheel_decrease(self, event): self.decrease() def increase(self): if self.state==NORMAL: try: self.variable=float(self.text_var.get()) except: self.text_var.set('0') self.variable=float(self.text_var.get()) self.variable=self.variable+self.step self.set_value(self.variable) def decrease(self): if self.state==NORMAL: try: self.variable=float(self.text_var.get()) except: self.text_var.set('0') self.variable=float(self.text_var.get()) self.variable=self.variable-self.step self.set_value(self.variable) def set_value(self, value=0): try: value = float(value) except: value = 0 value = min(self.max_value, value) value = max(self.min_value, value) if self.vartype == 1: self.variable = float(value) else: self.variable = int(round(value)) self.text_var.set(str(self.variable)) def get_value(self): try: self.variable=float(self.text_var.get()) except: self.text_var.set('0') self.variable=float(self.text_var.get()) if self.vartype==1: self.variable=float(self.variable) else: self.variable = int(round(self.variable)) return self.variable def destroy(self): self.entry.unbind_all(self.entry) self.entry.destroy() self.button_frame.destroy() self.up_button.destroy() self.down_button.destroy() self.command = self.args = None TFrame.destroy(self)
class AlignPlugin(PluginPanel): name='Alignment' title = _("Alignment") def init(self, master): PluginPanel.init(self, master) root=self.mw.root self.var_reference = StringVar(root) self.var_reference.set(SELECT) #--------------------------------------------------------- top = TFrame(self.panel, style='FlatFrame') top.pack(side = TOP, fill=BOTH) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Relative to")+" ", style="FlatLabel") label.pack(side = TOP, fill = BOTH, padx=5) rel_frame=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) rel_frame.pack(side = TOP, fill=X, padx=5, pady=2) self.reference = TCombobox(rel_frame, state='readonly', values=self.make_cs_list(), style='ComboNormal',width=14, textvariable=self.var_reference, postcommand = self.set_cs) self.reference.pack(side = TOP) #--------------------------------------------------------- label=TLabel(top, text=" "+_("Alignment type")+" ", style="FlatLabel") label.pack(side = TOP, fill = BOTH, padx=5) framec=TLabelframe(top, labelwidget=label, style='Labelframe', borderwidth=3) framec.pack(side = TOP, fill=X, padx=5, pady=2) framex = TFrame(framec, style='FlatFrame') framex.pack(side = TOP, expand = 0, padx = 5, pady = 5) framey = TFrame(framec, style='FlatFrame') framey.pack(side = TOP, expand = 0, padx = 5, pady = 5) x_pixmaps = ['aoleft', 'aocenterh', 'aoright'] y_pixmaps = ['aotop', 'aocenterv', 'aobottom'] x_tooltips = [_('Align left sides'), _('Center on vertical axis'), _('Align right sides')] y_tooltips = [_('Align tops'), _('Center on horizontal axis'), _('Align bottoms')] self.var_x = IntVar(top) self.var_x.set(0) self.value_x = 0 self.var_y = IntVar(top) self.var_y.set(0) self.value_y = 0 for i in range(1, 4): button = make_button(framex, image = x_pixmaps[i - 1], value = i, variable = self.var_x, command = self.apply_x) tooltips.AddDescription(button, x_tooltips[i - 1]) button.pack(side = LEFT, padx = 3) button = make_button(framey, image = y_pixmaps[i - 1], value = i, variable = self.var_y, command = self.apply_y) tooltips.AddDescription(button, y_tooltips[i - 1]) button.pack(side = LEFT, padx = 3) #--------------------------------------------------------- # Auto Apply Check self.var_auto_apply = IntVar(top) self.var_auto_apply.set(0) self.auto_apply_check = TCheckbutton(top, text = _("Auto Apply"), variable = self.var_auto_apply, command = self.reset) self.auto_apply_check.pack(side = TOP, anchor=W, padx=5,pady=5) #--------------------------------------------------------- # Button frame self.button_frame = TFrame(top, style='FlatFrame', borderwidth=5) self.button_frame.pack(side = BOTTOM, fill = BOTH) self.update_buttons = [] self.button_apply = TButton(self.button_frame, text = _("Apply"), command = self.apply) self.apply_button_show(1) self.init_from_doc() self.subscribe_receivers() ############################################################################### def subscribe_receivers(self): self.document.Subscribe(SELECTION, self.Update) def unsubscribe_receivers(self): self.document.Unsubscribe(SELECTION, self.Update) def init_from_doc(self): self.Update() self.issue(SELECTION) def Update(self, *arg): reference = self.var_reference.get() if self.is_selection(reference): state=NORMAL else: state=DISABLED self.button_apply['state']=state def apply_button_show(self, state): if not state: self.button_apply.pack_forget() else: self.button_apply.pack(side = BOTTOM, expand = 1, fill = X, pady=3) def make_cs_list(self): cs=() cs+=(SELECT,LOWERMOST,PAGE) return cs def set_cs(self): self.Update() def is_selection(self, reference = SELECT): if not self.var_auto_apply.get() and self.value_x==0 and self.value_y==0: return 0 if reference == PAGE: return (len(self.document.selection) > 0) else: return (len(self.document.selection) > 1) def apply_x(self): x = self.var_x.get() if self.var_auto_apply.get(): self.reset() self.apply(x=x) else: if self.value_x==x: self.var_x.set(0) self.value_x = 0 else: self.value_x = x self.Update() def apply_y(self): y = self.var_y.get() if self.var_auto_apply.get(): self.reset() self.apply(y=y) else: if self.value_y==y: self.var_y.set(0) self.value_y = 0 else: self.value_y = y self.Update() def apply(self, x=None, y=None, reference = None): reference = self.var_reference.get() if not self.is_selection(reference): return if x is None: x = self.var_x.get() if y is None: y = self.var_y.get() if reference is None: reference = self.var_reference.get() reference = self.reference_command(reference) self.document.AlignSelection(x, y, reference = reference) def reference_command(self, reference): if reference == SELECT: return 'selection' if reference == LOWERMOST: return 'lowermost' if reference == PAGE: return 'page' def reset(self): self.var_x.set(0) self.value_x = 0 self.var_y.set(0) self.value_y = 0 ## self.apply_button_show(not self.var_auto_apply.get()) self.Update()