gnome-specimen r13 - in trunk-from-bzr: . glade



Author: wbolster
Date: Tue Jun 17 18:41:26 2008
New Revision: 13
URL: http://svn.gnome.org/viewvc/gnome-specimen?rev=13&view=rev

Log:
* glade/gnome-specimen.glade:
  - Removed the preview label and put a listbox in its
    place.

* specimenwindow.py
  - Initialize the previews treeview. Each preview uses two
    rows: one shows the font name, the other contains the
    actual preview label.
  - Added add_preview
  - Set a data handler to handle the preview cell rendering


Modified:
   trunk-from-bzr/   (props changed)
   trunk-from-bzr/glade/gnome-specimen.glade
   trunk-from-bzr/specimenwindow.py

Modified: trunk-from-bzr/glade/gnome-specimen.glade
==============================================================================
--- trunk-from-bzr/glade/gnome-specimen.glade	(original)
+++ trunk-from-bzr/glade/gnome-specimen.glade	Tue Jun 17 18:41:26 2008
@@ -391,28 +391,25 @@
 	      </child>
 
 	      <child>
-		<widget class="GtkEventBox" id="eventbox1">
+		<widget class="GtkScrolledWindow" id="previews-treeview-window">
 		  <property name="visible">True</property>
-		  <property name="visible_window">True</property>
-		  <property name="above_child">False</property>
+		  <property name="can_focus">True</property>
+		  <property name="hscrollbar_policy">GTK_POLICY_NEVER</property>
+		  <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+		  <property name="shadow_type">GTK_SHADOW_IN</property>
+		  <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
 
 		  <child>
-		    <widget class="GtkLabel" id="preview-label">
+		    <widget class="GtkTreeView" id="previews-treeview">
 		      <property name="visible">True</property>
-		      <property name="label"></property>
-		      <property name="use_underline">False</property>
-		      <property name="use_markup">False</property>
-		      <property name="justify">GTK_JUSTIFY_CENTER</property>
-		      <property name="wrap">True</property>
-		      <property name="selectable">False</property>
-		      <property name="xalign">0.5</property>
-		      <property name="yalign">0.5</property>
-		      <property name="xpad">0</property>
-		      <property name="ypad">0</property>
-		      <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
-		      <property name="width_chars">-1</property>
-		      <property name="single_line_mode">False</property>
-		      <property name="angle">0</property>
+		      <property name="can_focus">True</property>
+		      <property name="headers_visible">False</property>
+		      <property name="rules_hint">False</property>
+		      <property name="reorderable">False</property>
+		      <property name="enable_search">False</property>
+		      <property name="fixed_height_mode">False</property>
+		      <property name="hover_selection">False</property>
+		      <property name="hover_expand">False</property>
 		    </widget>
 		  </child>
 		</widget>

Modified: trunk-from-bzr/specimenwindow.py
==============================================================================
--- trunk-from-bzr/specimenwindow.py	(original)
+++ trunk-from-bzr/specimenwindow.py	Tue Jun 17 18:41:26 2008
@@ -118,11 +118,76 @@
         self.preview_treeview = glade_tree.get_widget('preview-treeview')
         self.preview_size_spinbutton = glade_tree.get_widget('preview-size-spinbutton')
         self.preview_text_entry = glade_tree.get_widget('preview-text-entry')
-        self.preview_label = glade_tree.get_widget('preview-label')
+        self.previews_treeview = glade_tree.get_widget('previews-treeview')
+        self.previews_treeview_window = glade_tree.get_widget('previews-treeview-window')
 
         self.preview_size_spinbutton.set_value(self.preview_size)
         self.preview_text_entry.set_text(self.preview_text)
 
+        # prepare the tree model
+        self.previews_treestore = gtk.TreeStore(str, pango.FontFamily, pango.FontFace)
+        self.previews_treeview.set_model(self.previews_treestore)
+
+        # we have only one column
+        preview_column = gtk.TreeViewColumn()
+        self.previews_treeview.append_column(preview_column)
+        cell_renderer = gtk.CellRendererText()
+        preview_column.pack_start(cell_renderer, True)
+        preview_column.set_cell_data_func(cell_renderer, self.cell_data_cb)
+        preview_column.add_attribute(cell_renderer, 'text', 0)
+        self.window.show_all()
+
+        # TODO: do sensible stuff with the selection
+        ## setup the treeselection
+        #self.fonts_treeview_selection = self.fonts_treeview.get_selection()
+        #self.fonts_treeview_selection.set_mode(gtk.SELECTION_SINGLE)
+
+    def cell_data_cb(self, column, cell, model, iter, data=None):
+
+        if model.get_path(iter)[0] % 2 == 0:
+            # this is a name row
+            self._set_cell_attributes_for_name_cell(cell)
+
+        else:
+            # this is a preview row
+            (face,) = model.get(iter, 2)
+            self._set_cell_attributes_for_preview_cell(cell, face)
+
+    def _set_cell_attributes_for_name_cell(self, cell):
+        try:
+            # set the values
+            background, foreground, font_desc, size, ellipsize = self.name_cell_properties
+            cell.set_property('background', background)
+            cell.set_property('foreground', foreground)
+            cell.set_property('font-desc', font_desc)
+            cell.set_property('size', size)
+            cell.set_property('ellipsize', ellipsize)
+        except (AttributeError):
+            # store the defaults
+            self.name_cell_properties = (
+                    'white',
+                    'black',
+                    cell.get_property('font-desc'),
+                    cell.get_property('size'),
+                    cell.get_property('ellipsize'))
+
+    def _set_cell_attributes_for_preview_cell(self, cell, face):
+        font_description = face.describe()
+        cell.set_property('background', 'white')
+        cell.set_property('foreground', 'black')
+        cell.set_property('font-desc', font_description)
+        cell.set_property('size', self.preview_size * pango.SCALE)
+        cell.set_property('ellipsize', pango.ELLIPSIZE_END)
+
+    def add_preview(self, family, face):
+        name = '%s %s' % (family.get_name(), face.get_face_name())
+        piter = self.previews_treestore.append(None,
+                [name, family, face])
+        piter = self.previews_treestore.append(None,
+                [self.preview_text, family, face])
+
+        # TODO: make this work
+
     def schedule_update_previews(self):
         'Schedules an update of the previews'
 
@@ -135,7 +200,8 @@
         self.update_timeout = 0
 
         # TODO: update the previews
-        self.update_preview_label()
+        print 'update_previews'
+        #self.update_preview_label()
 
         # Allow this method to be used as a single-run idle timeout
         return False
@@ -187,11 +253,11 @@
 
         else:
             # this is a child row
-            (model, iter) = self.fonts_treeview_selection.get_selected()
+            model = treeview.get_model()
+            iter = model.get_iter(path)
             (family, face) = model.get(iter, 1, 2)
 
-            font_description = face.describe()
-            self.update_preview_label(font_description)
+            self.add_preview(family, face)
 
     def on_preview_size_changed(self, widget, user_data=None):
         'Callback for changed preview point size'



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]