gnome-specimen r8 - in trunk-from-bzr: . glade
- From: wbolster svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-specimen r8 - in trunk-from-bzr: . glade
- Date: Tue, 17 Jun 2008 18:41:21 +0000 (UTC)
Author: wbolster
Date: Tue Jun 17 18:41:20 2008
New Revision: 8
URL: http://svn.gnome.org/viewvc/gnome-specimen?rev=8&view=rev
Log:
* glade/gnome-specimen.glade, specimenwindow.py:
- Replaced the right pane treeview with a label for
testing purposes.
- Changing the preview text and the font size update the
label size and content.
- Add hacks that succesfully set the font for the label,
which means the preview label actually works!
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:20 2008
@@ -327,7 +327,7 @@
</child>
<child>
- <widget class="GtkEntry" id="entry1">
+ <widget class="GtkEntry" id="preview-text-entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
@@ -337,6 +337,7 @@
<property name="has_frame">True</property>
<property name="invisible_char">*</property>
<property name="activates_default">False</property>
+ <signal name="changed" handler="on_preview_text_changed" last_modification_time="Sat, 29 Apr 2006 20:02:32 GMT"/>
</widget>
<packing>
<property name="left_attach">1</property>
@@ -348,7 +349,7 @@
</child>
<child>
- <widget class="GtkSpinButton" id="spinbutton1">
+ <widget class="GtkSpinButton" id="preview-size-spinbutton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="climb_rate">1</property>
@@ -358,6 +359,7 @@
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">16 0 100 1 10 10</property>
+ <signal name="changed" handler="on_preview_size_changed" last_modification_time="Sat, 29 Apr 2006 20:02:21 GMT"/>
</widget>
<packing>
<property name="left_attach">1</property>
@@ -404,32 +406,28 @@
</child>
<child>
- <widget class="GtkScrolledWindow" id="scrolledwindow2">
+ <widget class="GtkLabel" id="preview-label">
<property name="visible">True</property>
<property name="can_focus">True</property>
- <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</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="GtkTreeView" id="preview-treeview">
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="headers_visible">False</property>
- <property name="rules_hint">True</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>
+ <property name="label" translatable="yes">This is some sample text.</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">True</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>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
- <property name="fill">True</property>
+ <property name="fill">False</property>
</packing>
</child>
</widget>
Modified: trunk-from-bzr/specimenwindow.py
==============================================================================
--- trunk-from-bzr/specimenwindow.py (original)
+++ trunk-from-bzr/specimenwindow.py Tue Jun 17 18:41:20 2008
@@ -7,11 +7,14 @@
class SpecimenWindow:
- # list of pango.FontFamily objects
+ update_timeout = 0
families = []
+ preview_size = 16
+ preview_text = 'This is preview text'
+
def __init__(self):
- "Initializes the application"
+ 'Initializes the application'
# load glade interface description
import os.path
@@ -22,24 +25,36 @@
tree = gtk.glade.XML(glade_filename)
tree.signal_autoconnect(self)
- # windows and dialogs
+ # main window
self.window = tree.get_widget('main-window')
+
+ # font list widgets
self.fonts_treeview = tree.get_widget('fonts-treeview')
self.fonts_treeview_window = tree.get_widget('fonts-treeview-window')
+
+ # preview widgets
self.preview_treeview = tree.get_widget('preview-treeview')
+ self.preview_size_spinbutton = tree.get_widget('preview-size-spinbutton')
+ self.preview_text_entry = tree.get_widget('preview-text-entry')
+ self.preview_label = tree.get_widget('preview-label')
+
+ # update
+ self.on_preview_size_changed(self.preview_size_spinbutton)
+ self.on_preview_text_changed(self.preview_text_entry)
# populate the UI
self.load_fonts()
+ self.schedule_update_previews()
# show the window
self.window.show_all()
def on_destroy_event(self, widget, data=None):
- "Callback for the window destroy event"
+ 'Callback for the window destroy event'
gtk.main_quit()
def load_fonts(self):
- "Loads all fonts and updates the fonts treeview"
+ 'Loads all fonts and updates the fonts treeview'
# prepare the tree model
self.fonts_treestore = gtk.TreeStore(str, pango.FontFamily, pango.FontFace)
@@ -65,11 +80,10 @@
# populate the treemodel with all available fonts
context = self.window.get_pango_context()
self.families = list(context.list_families())
- self.families = list(self.families)
gobject.idle_add(self.load_fonts_cb)
def load_fonts_cb(self, user_data=None):
- "Idle callback that adds font families to the tree model"
+ 'Idle callback that adds font families to the tree model'
howmany_at_once = 25
@@ -92,9 +106,7 @@
# loading is done; the list of remaining families is empty
return False
-
def on_row_activated(self, treeview, path, viewcolumn, *user_data):
-
if len(path) == 1:
# this is a parent row, expand/collapse
is_expanded = treeview.row_expanded(path)
@@ -107,10 +119,68 @@
# this is a child row
(model, iter) = self.fonts_treeview_selection.get_selected()
(family, face) = model.get(iter, 1, 2)
- print family.get_name(), face.get_face_name()
- # about dialog
+ font_description = face.describe()
+ self.update_preview_label(font_description)
+
+ def on_preview_size_changed(self, widget, user_data=None):
+ 'Callback for changed preview point size'
+ try:
+ self.preview_size = 1000 * int(widget.get_text()) # TODO get_int?
+ except ValueError:
+ self.preview_size = 160000
+ self.schedule_update_previews()
+
+ def on_preview_text_changed(self, widget, user_data=None):
+ 'Callback for changed preview text'
+ self.preview_text = widget.get_text()
+ self.schedule_update_previews()
+
+ def schedule_update_previews(self):
+ 'Schedules an update of the previews'
+
+ if not self.update_timeout:
+ self.update_timeout = gobject.timeout_add(500, self.update_previews)
+
+ def update_previews(self):
+ 'Updates the previews'
+
+ self.update_timeout = 0
+
+ # TODO: update the previews
+ self.update_preview_label()
+
+ # Allow this method to be used as a single-run idle timeout
+ return False
+
+ def update_preview_label(self, fontdesc=None):
+ 'Updates the preview label (temporary hack)'
+ # TODO: remove this method if the list is in place
+
+ # set the text
+ self.preview_label.set_text(self.preview_text)
+
+ # set the font and size
+ try:
+ self.fontdesc
+ except (AttributeError):
+ self.fontdesc = None
+
+ if fontdesc is not None:
+ self.fontdesc = fontdesc
+
+ attrlist = pango.AttrList()
+
+ try:
+ attrlist.insert(pango.AttrFontDesc(self.fontdesc, 0, -1))
+ except (TypeError):
+ pass
+
+ attrlist.insert(pango.AttrSize(self.preview_size, 0, -1))
+ self.preview_label.set_attributes(attrlist)
+
def on_about_clicked(self, widget, data=None):
+ 'Callback for the Help->About menu item'
name = 'GNOME Specimen'
comments = 'A font preview application for GNOME'
copyright = u'Copyright \u00A9 2006 Wouter Bolsterlee'
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]