Пример #1
0
class UnitsPlugin(CtxPlugin):

	name = 'UnitsPlugin'
	update_flag = False
	units = UNIT_MM

	def __init__(self, app, parent):
		CtxPlugin.__init__(self, app, parent)
		events.connect(events.DOC_CHANGED, self.update)
		events.connect(events.DOC_MODIFIED, self.update)

	def build(self):
		bmp = get_bmp(self, icons.CTX_UNITS, _('Document units'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		names = []
		for item in unit_names: names.append(unit_full_names[item])
		self.combo = Combolist(self, items=names, onchange=self.changed)
		self.add(self.combo, 0, LEFT | CENTER, 2)

	def update(self, *args):
		if self.insp.is_doc():
			model = self.app.current_doc.model
			if not model.doc_units == unit_names[self.combo.get_active()]:
				self.units = model.doc_units
				self.combo.set_active(unit_names.index(self.units))

	def changed(self, *args):
		if self.insp.is_doc():
			if not self.units == unit_names[self.combo.get_active()]:
				self.units = unit_names[self.combo.get_active()]
				self.app.current_doc.api.set_doc_units(self.units)
Пример #2
0
    def build(self):
        bmp = get_bmp(self, icons.CTX_UNITS, _('Document units'))
        self.add(bmp, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        names = [unit_full_names[item] for item in unit_names]
        self.combo = Combolist(self, items=names, onchange=self.changed)
        self.add(self.combo, 0, LEFT | CENTER, 2)
Пример #3
0
    def build(self):
        bmp = get_bmp(self, icons.CTX_UNITS, _('Document units'))
        self.pack(bmp, padding=2)

        self.pack((2, 2))

        names = [unit_full_names[item] for item in unit_names]
        self.combo = Combolist(self, items=names, onchange=self.changed)
        self.pack(self.combo, padding=2)
Пример #4
0
	def build(self):
		bmp = get_bmp(self, icons.CTX_UNITS, _('Document units'))
		self.add(bmp, 0, LEFT | CENTER, 2)

		self.add((2, 2))

		names = []
		for item in unit_names: names.append(unit_full_names[item])
		self.combo = Combolist(self, items=names, onchange=self.changed)
		self.add(self.combo, 0, LEFT | CENTER, 2)
Пример #5
0
    def build(self):
        self.formats = [
            _('Custom'),
        ] + PAGE_FORMAT_NAMES
        self.combo = Combolist(self,
                               items=self.formats,
                               onchange=self.combo_changed)
        self.add(self.combo, 0, LEFT | CENTER, 2)
        self.add((3, 3))

        self.width_spin = UnitSpin(self.app,
                                   self,
                                   onchange=self.width_spin_changed)
        self.add(self.width_spin, 0, LEFT | CENTER, 2)

        self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

        self.height_spin = UnitSpin(self.app,
                                    self,
                                    onchange=self.height_spin_changed)
        self.add(self.height_spin, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.portrait = ImageToggleButton(self,
                                          True,
                                          icons.CTX_PAGE_PORTRAIT,
                                          onchange=self.portrait_toggled,
                                          tooltip=ORIENTS_NAMES[0])
        self.add(self.portrait, 0, LEFT | CENTER, 2)

        self.landscape = ImageToggleButton(self,
                                           False,
                                           icons.CTX_PAGE_LANDSCAPE,
                                           onchange=self.landscape_toggled,
                                           tooltip=ORIENTS_NAMES[1])
        self.add(self.landscape, 0, LEFT | CENTER, 2)

        self.width_spin.set_enable(False)
        self.height_spin.set_enable(False)
Пример #6
0
class PagePlugin(CtxPlugin):
    name = 'PagePlugin'
    update_flag = False
    format = []
    formats = None
    combo = None
    width_spin = None
    height_spin = None
    portrait = None
    landscape = None

    def __init__(self, app, parent):
        CtxPlugin.__init__(self, app, parent)
        events.connect(events.DOC_CHANGED, self.update)
        events.connect(events.DOC_MODIFIED, self.update)
        events.connect(events.PAGE_CHANGED, self.update)

    def build(self):
        self.formats = [
            _('Custom'),
        ] + PAGE_FORMAT_NAMES
        self.combo = Combolist(self,
                               items=self.formats,
                               onchange=self.combo_changed)
        self.add(self.combo, 0, LEFT | CENTER, 2)
        self.add((3, 3))

        self.width_spin = UnitSpin(self.app,
                                   self,
                                   onchange=self.width_spin_changed)
        self.add(self.width_spin, 0, LEFT | CENTER, 2)

        self.add(get_bmp(self, icons.CTX_W_ON_H), 0, LEFT | CENTER, 1)

        self.height_spin = UnitSpin(self.app,
                                    self,
                                    onchange=self.height_spin_changed)
        self.add(self.height_spin, 0, LEFT | CENTER, 2)

        self.add((2, 2))

        self.portrait = ImageToggleButton(self,
                                          True,
                                          icons.CTX_PAGE_PORTRAIT,
                                          onchange=self.portrait_toggled,
                                          tooltip=ORIENTS_NAMES[0])
        self.add(self.portrait, 0, LEFT | CENTER, 2)

        self.landscape = ImageToggleButton(self,
                                           False,
                                           icons.CTX_PAGE_LANDSCAPE,
                                           onchange=self.landscape_toggled,
                                           tooltip=ORIENTS_NAMES[1])
        self.add(self.landscape, 0, LEFT | CENTER, 2)

        self.width_spin.set_enable(False)
        self.height_spin.set_enable(False)

    def update(self, *args):
        if self.insp.is_doc():
            self.update_flag = True
            page_format = self.app.current_doc.active_page.page_format
            self.format = page_format
            width, height = page_format[1]
            if page_format[0] in PAGE_FORMAT_NAMES:
                self.combo.set_active(self.formats.index(page_format[0]))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(False)
                self.height_spin.set_enable(False)
            else:
                self.combo.set_active(self.formats.index(_('Custom')))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(True)
                self.height_spin.set_enable(True)
            self.update_flag = False

    def combo_changed(self, *args):
        if self.update_flag:
            return
        if not self.format[0] == self.formats[self.combo.get_active()]:
            self.update_flag = True
            if self.formats[self.combo.get_active()] in PAGE_FORMAT_NAMES:
                w, h = PAGE_FORMATS[self.formats[self.combo.get_active()]]
                if self.portrait.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                elif self.landscape.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                elif self.portrait.get_active() and w < h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                else:
                    self.width_spin.set_point_value(h)
                    self.height_spin.set_point_value(w)
            self.update_flag = False
            self.changes()

    def width_spin_changed(self, *args):
        if self.update_flag:
            return
        if not self.format[1][0] == self.width_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def height_spin_changed(self, *args):
        if self.update_flag:
            return
        if not self.format[1][1] == self.height_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def portrait_toggled(self, *args):
        if self.update_flag:
            return
        if self.portrait.get_active():
            self.update_flag = True
            self.landscape.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.portrait.set_active(True)
            self.update_flag = False

    def landscape_toggled(self, *args):
        if self.update_flag:
            return
        if self.landscape.get_active():
            self.update_flag = True
            self.portrait.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.landscape.set_active(True)
            self.update_flag = False

    def changes(self):
        new_format = [
            self.formats[self.combo.get_active()],
        ]
        new_format += [(self.width_spin.get_point_value(),
                        self.height_spin.get_point_value())]
        if self.portrait.get_active():
            new_format += [
                PORTRAIT,
            ]
        else:
            new_format += [
                LANDSCAPE,
            ]
        self.app.current_doc.api.set_page_format(new_format)
Пример #7
0
class PagePlugin(CtxPlugin):
    name = 'PagePlugin'
    update_flag = False
    format = None
    formats = None
    combo = None
    width_spin = None
    height_spin = None
    portrait = None
    landscape = None

    def __init__(self, app, parent):
        CtxPlugin.__init__(self, app, parent)
        events.connect(events.DOC_CHANGED, self.update)
        events.connect(events.DOC_MODIFIED, self.update)
        events.connect(events.PAGE_CHANGED, self.update)

    def build(self):
        self.formats = [
            _('Custom'),
        ] + PAGE_FORMAT_NAMES
        self.combo = Combolist(self,
                               items=self.formats,
                               onchange=self.combo_changed)
        self.pack(self.combo, padding_all=3)

        self.width_spin = UnitSpin(self.app,
                                   self,
                                   onchange=self.width_spin_changed)
        self.pack(self.width_spin)
        self.pack((3, 3))

        self.pack(get_bmp(self, icons.CTX_W_ON_H))

        self.height_spin = UnitSpin(self.app,
                                    self,
                                    onchange=self.height_spin_changed)
        self.pack(self.height_spin, padding_all=3)

        self.pack((2, 2))

        self.portrait = ImageToggleButton(self,
                                          True,
                                          icons.CTX_PAGE_PORTRAIT,
                                          onchange=self.portrait_toggled,
                                          tooltip=ORIENTS_NAMES[0])
        self.pack(self.portrait, padding=2)

        self.landscape = ImageToggleButton(self,
                                           False,
                                           icons.CTX_PAGE_LANDSCAPE,
                                           onchange=self.landscape_toggled,
                                           tooltip=ORIENTS_NAMES[1])
        self.pack(self.landscape, padding=2)

        self.width_spin.set_enable(False)
        self.height_spin.set_enable(False)

    def update(self, *args):
        if self.insp.is_doc():
            self.update_flag = True
            page_format = self.app.current_doc.active_page.page_format
            self.format = page_format
            width, height = page_format[1]
            if page_format[0] in PAGE_FORMAT_NAMES:
                self.combo.set_active(self.formats.index(page_format[0]))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(False)
                self.height_spin.set_enable(False)
            else:
                self.combo.set_active(self.formats.index(_('Custom')))
                if page_format[2] == PORTRAIT:
                    self.portrait.set_active(True)
                    self.landscape.set_active(False)
                else:
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                self.width_spin.set_point_value(width)
                self.height_spin.set_point_value(height)
                self.width_spin.set_enable(True)
                self.height_spin.set_enable(True)
            self.update_flag = False

    def combo_changed(self, *_args):
        if self.update_flag:
            return
        if not self.format[0] == self.formats[self.combo.get_active()]:
            self.update_flag = True
            if self.formats[self.combo.get_active()] in PAGE_FORMAT_NAMES:
                w, h = PAGE_FORMATS[self.formats[self.combo.get_active()]]
                if self.portrait.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                    self.portrait.set_active(False)
                    self.landscape.set_active(True)
                elif self.landscape.get_active() and w > h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                elif self.portrait.get_active() and w < h:
                    self.width_spin.set_point_value(w)
                    self.height_spin.set_point_value(h)
                else:
                    self.width_spin.set_point_value(h)
                    self.height_spin.set_point_value(w)
            self.update_flag = False
            self.changes()

    def width_spin_changed(self, *_args):
        if self.update_flag:
            return
        if not self.format[1][0] == self.width_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def height_spin_changed(self, *_args):
        if self.update_flag:
            return
        if not self.format[1][1] == self.height_spin.get_point_value():
            self.update_flag = True
            w = self.width_spin.get_point_value()
            h = self.height_spin.get_point_value()
            if w > h and self.portrait.get_active():
                self.portrait.set_active(False)
                self.landscape.set_active(True)
            elif w < h and self.landscape.get_active():
                self.portrait.set_active(True)
                self.landscape.set_active(False)
            self.update_flag = False
            self.changes()

    def portrait_toggled(self, *_args):
        if self.update_flag:
            return
        if self.portrait.get_active():
            self.update_flag = True
            self.landscape.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.portrait.set_active(True)
            self.update_flag = False

    def landscape_toggled(self, *_args):
        if self.update_flag:
            return
        if self.landscape.get_active():
            self.update_flag = True
            self.portrait.set_active(False)
            h = self.width_spin.get_point_value()
            w = self.height_spin.get_point_value()
            self.width_spin.set_point_value(w)
            self.height_spin.set_point_value(h)
            self.update_flag = False
            self.changes()
        else:
            self.update_flag = True
            self.landscape.set_active(True)
            self.update_flag = False

    def changes(self):
        doc = self.app.current_doc
        new_format = [
            self.formats[self.combo.get_active()],
        ]
        new_format += [(self.width_spin.get_point_value(),
                        self.height_spin.get_point_value())]
        if self.portrait.get_active():
            new_format += [
                PORTRAIT,
            ]
        else:
            new_format += [
                LANDSCAPE,
            ]
        current_page_format = deepcopy(doc.active_page.page_format)
        doc.api.set_page_format(new_format)

        pdict = PAGE_FORMATS_MORE
        if new_format[0] in pdict and current_page_format[0] in pdids and \
                pdict[current_page_format[0]] != pdict[new_format[0]]:
            units, jump = pdict[new_format[0]]
            doc.api.set_doc_units(units)
            geom = doc.methods.get_grid_values()[:2] + [jump, jump]
            doc.api.set_grid_values(geom)
            config.obj_jump = jump

        doc.canvas.zoom_fit_to_page()
Пример #8
0
	def build(self):
		flags = LEFT | CENTER
		pflags = ALL | EXPAND
		#---------Labels
		p = HPanel(self)
		props = [
			('Normal font', False, 0),
			('Bold font', True, 0),
			('-1 font', False, -1),
			('+1 font', False, 1),
			('+2 font', False, 2),
			('+2 bold font', True, 2),
			('+2 red bold font', True, 2, (255, 0, 0)),
			]
		for item in props:
			p.pack(Label(p, *item), padding=5)

		self.pack(p, fill=True)
		self.pack(HLine(self), fill=True, padding=5)

		#---------HtmlLabels
		p = HPanel(self)

		p.pack(HtmlLabel(p, 'http://sk1project.org'), padding=5)
		p.pack(HtmlLabel(p, 'Download site', 'http://sk1project.org'), padding=5)

		self.pack(p, fill=True)
		self.pack(HLine(self), fill=True, padding=5)

		#---------Buttons
		p = HPanel(self)

		p.pack(Button(p, 'Native button'), padding=5)
		txt = 'Native default button'
		p.pack(Button(p, 'Native default button', default=True, tooltip=txt), padding=5)
		p.pack(Button(p, 'Native button with callback', onclick=self.test), padding=5)

		self.pack(p, fill=True)
		self.pack(HLine(self), fill=True, padding=5)

		#---------Checkboxes
		p = HPanel(self)

		p.add(Checkbox(p, 'Native checkbox'), 0, flags, 5)
		p.add(Checkbox(p, 'Native checkbox (checked)', True), 0, flags, 5)
		p.add(Checkbox(p, 'Checkbox with callback', onclick=self.test), 0, flags, 5)
		self.pack(p, fill=True, padding=5)
		self.pack(HLine(self), fill=True, padding=5)

		#---------Radiobuttons
		p = HPanel(self, border=BOTTOM, space=2)

		p.add(Radiobutton(p.panel, 'Native radiobutton', group=True), 0, flags, 5)
		p.add(Radiobutton(p.panel, 'Native radiobutton (selected)'), 0, flags, 5)
		p.add(Radiobutton(p.panel, 'Radiobutton with callback', onclick=self.test), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Combolist
		p = HPanel(self, border=BOTTOM, space=2)

		sample = ['zero', 'one', 'two', 'three', 'four five', 'six seven eight']
		p.add(Label(p, 'Native combolist:'), 0, flags, 5)
		p.add(Combolist(p, items=sample), 0, flags, 5)
		p.add(Label(p, 'Native combolist with callback:'), 0, flags, 5)
		p.add(Combolist(p, items=sample, onchange=self.test), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Combobox
		p = HPanel(self, border=BOTTOM, space=2)

		sample = ['zero', 'one', 'two', 'three', 'four five', 'six seven eight']
		p.add(Label(p, 'Native combobox:'), 0, flags, 5)
		p.add(Combobox(p, 'value', items=sample), 0, flags, 5)
		p.add(Label(p, 'Native combobox with callback:'), 0, flags, 5)
		p.add(Combobox(p, items=sample, width=15, onchange=self.test), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Text entry
		p = HPanel(self, border=BOTTOM, space=2)

		p.add(Label(p, 'Native text entry:'), 0, flags, 5)
		p.add(Entry(p, 'value', width=5), 0, flags, 5)
		p.add(Label(p, 'Native text entry with callback:'), 0, flags, 5)
		p.add(Entry(p, 'value', onchange=self.test), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Multiline Text entry
		p = HPanel(self, border=BOTTOM, space=2)

		p.add(Label(p, 'Multiline text entry:'), 0, flags, 5)
		p.add(Entry(p, 'value', size=(150, 50), multiline=True), 0, flags, 5)
		p.add(Label(p, 'Multiline text entry with callback:'), 0, flags, 5)
		p.add(Entry(p, 'value', size=(150, 50), multiline=True,
				onchange=self.test), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Spin
		p = HPanel(self, border=BOTTOM, space=2)

		p.add(Label(p, 'Native spin control:'), 0, flags, 5)
		p.add(Spin(p, 1, (0, 90), onchange=self.test), 0, flags, 5)
		p.add(Label(p, 'Float spin control:'), 0, flags, 5)
		self.spin = FloatSpin(p.panel, 1.3, (0.0, 90.0), 0.01, 3, width=5,
					onchange=self.test)
		p.add(self.spin, 0, flags, 5)
		p.add(Button(p, 'Get value', onclick=self.test_spin), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Slider
		p = HPanel(self, border=BOTTOM, space=2)

		p.add(Label(p, 'Native slider:'), 0, flags, 5)
		p.add(Slider(p.panel, 25, (0, 255), onchange=self.test), 0, flags, 5)

		self.add(p, 0, pflags)

		#---------Labeled panel
		p = HPanel(self)

		panel = LabeledPanel(p, 'The panel')
		panel.add((0, 50), 0, flags, 0)
		panel.add(Label(p, 'Native Labeled Panel'), 0, flags, 0)
		p.box_add(panel.box, 0, flags, 5)


		panel = LabeledPanel(p)
		panel.add((0, 50), 0, flags, 0)
		panel.add(Label(p, 'Headless Labeled Panel'), 0, flags, 0)
		p.box_add(panel.box, 0, flags, 5)

		p.add(VLine(p), 0, ALL | EXPAND, 3)

		nb = Notebook(p)
		page = VPanel(nb)
		page.add((50, 100))
		nb.add_page(page, 'First page')
		page = VPanel(nb)
		page.add((50, 100))
		nb.add_page(page, 'Second page')
		p.add(nb, 1, ALL | EXPAND, 3)

		self.add(p, 0, pflags)