Beispiel #1
0
 def _on_image_changed(self, filechooser):
     "The user chose another image."
     el = self.get_selected_element()
     el.src = filechooser.get_filename()
     gui.update_image_preview(self._image_preview, el.src)
     self._set_changed()
Beispiel #2
0
 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