def _get_position(self): "Return the element positioning settings." el = self.get_selected_element() if el is False: return position = gtk.Expander(_("Element Position")) # Positional elements that are in all `theme._RenderableSection`s. table = gui.ESTable(5, 2) self._p = {} help_ = gtk.image_new_from_stock(gtk.STOCK_HELP, gtk.ICON_SIZE_BUTTON) helppos = _("Positions are relative, with values between 0 and 1. \ A value of 0 is on the far left or top, and a value of 1 is on the far right or bottom.") help_.set_tooltip_text(helppos) table.attach_widget(help_, None, x=2, y=0) adjust = gtk.Adjustment(el.pos[0], 0.0, 1.0, 0.01, 0.10) self._p['lf'] = table.attach_spinner(adjust, 0.02, 2, label=_('Left:')) self._p['lf'].set_numeric(True) self._p['lf'].connect('changed', self._on_change_pos) adjust = gtk.Adjustment(el.pos[2], 0.0, 1.0, 0.01, 0.10) self._p['rt'] = table.attach_spinner(adjust, 0.02, 2, label=_('Right:'), x=1) self._p['rt'].set_numeric(True) self._p['rt'].connect('changed', self._on_change_pos) adjust = gtk.Adjustment(el.pos[1], 0.0, 1.0, 0.01, 0.10) self._p['tp'] = table.attach_spinner(adjust, 0.02, 2, label=_('Top:'), y=1) self._p['tp'].set_numeric(True) self._p['tp'].connect('changed', self._on_change_pos) adjust = gtk.Adjustment(el.pos[3], 0.0, 1.0, 0.01, 0.10) self._p['bt'] = table.attach_spinner(adjust, 0.02, 2, label=_('Bottom:'), x=1, y=1) self._p['bt'].set_numeric(True) self._p['bt'].connect('changed', self._on_change_pos) adjust = gtk.Adjustment(el.margin, 0.0, 1.0, 0.01, 0.05) self._p['mg'] = table.attach_spinner(adjust, 0.01, 2, label=_('Margin:'), y=2, w=2) self._p['mg'].set_numeric(True) self._p['mg'].connect('changed', self._on_change_mg) self._p['al'] = table.attach_combo(map(theme.get_align_text, (theme.LEFT, theme.CENTER, theme.RIGHT)), None, label=_('Alignment:'), y=3, w=2) gui.set_active_text(self._p['al'], theme.get_align_text(el.align)) self._p['al'].connect('changed', self._on_change_al) self._p['va'] = table.attach_combo(map(theme.get_valign_text, (theme.TOP, theme.MIDDLE, theme.BOTTOM)), None, label=_('Vertical Alignment:'), y=4, w=2) gui.set_active_text(self._p['va'], theme.get_valign_text(el.valign)) self._p['va'].connect('changed', self._on_change_va) position.add(table) return position
def _element_changed(self, sel): "Sets the editing area when the selection changes." self.__updating = True self._ctbl.foreach(lambda w: self._ctbl.remove(w)) el = self.get_selected_element() if el is False: st = _("Select or add an item from the left to edit.") label = self._ctbl.attach_label(st, h=4, xoptions=gtk.EXPAND|gtk.FILL, yoptions=gtk.EXPAND|gtk.FILL) label.set_line_wrap(True) label.set_alignment(0.5, 0.5) elif isinstance(el, theme.Text): buffer_ = undobuffer.UndoableBuffer() # Toolbar toolbar = gtk.Toolbar() undo = gtk.ToolButton(gtk.STOCK_UNDO) undo.connect('clicked', self._undo, buffer_) undo.set_sensitive(False) toolbar.insert(undo, -1) redo = gtk.ToolButton(gtk.STOCK_REDO) redo.connect('clicked', self._redo, buffer_) redo.set_sensitive(False) toolbar.insert(redo, -1) self._ctbl.attach_widget(toolbar, yoptions=gtk.FILL) text = gtk.TextView() text.set_wrap_mode(gtk.WRAP_NONE) buffer_.begin_not_undoable_action() buffer_.set_text(el.markup) buffer_.end_not_undoable_action() buffer_.set_modified(False) buffer_.connect("changed", self._on_text_buffer_changed, undo, redo) text.set_buffer(buffer_) try: gtkspell.Spell(text) except Exception: pass scroll = gtk.ScrolledWindow() scroll.add(text) scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scroll.set_size_request(250, -1) scroll.set_shadow_type(gtk.SHADOW_IN) self._ctbl.attach_widget(scroll, y=1, h=3, yoptions=gtk.FILL|gtk.EXPAND) elif isinstance(el, theme.Image): fc = gtk.FileChooserButton("Select Image") fc.set_size_request(250, -1) fc.set_action(gtk.FILE_CHOOSER_ACTION_OPEN) if el.src: fc.set_filename(el.src) filt = gtk.FileFilter() filt.add_pixbuf_formats() fc.set_filter(filt) preview = gtk.Image() fc.set_preview_widget(preview) fc.connect("update-preview", gui.filechooser_preview, preview) fc.connect("file-set", self._on_image_changed) self._ctbl.attach_widget(fc) self._image_preview = gtk.Image() self._ctbl.attach_widget(self._image_preview, y=1) gui.update_image_preview(self._image_preview, el.src) options = map(theme.get_aspect_text, (theme.ASPECT_FIT, theme.ASPECT_FILL)) aspect = self._ctbl.attach_combo(options, None, y=2, label=_('Resize to:')) gui.set_active_text(aspect, theme.get_aspect_text(el.aspect)) aspect.connect('changed', self._on_change_aspect) if el is not False: self._ctbl.attach_widget(self._get_position(), y=6) # TODO Custom Theme self._ctbl.show_all() self.__updating = False