Removed gettext marking from a multilingual string.
[jben2_gui.git] / python / jben / interface / gtk / dialog / preferences / tab_prefsfonts.py
blob0175b7b9b86157060a2cebe3961f01b7aeb32cc7
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Project: J-Ben, Python front-end
5 # File: tab_prefsfonts.py
6 # Author: Paul Goins
7 # Created on: 28 Nov 2008
9 from __future__ import absolute_import
11 import gtk
12 import os
13 from jben import global_refs
16 class TabPrefsFonts(gtk.VBox):
18 def __init__(self):
20 gtk.VBox.__init__(self, spacing = 5)
22 # We're loading 4 rows of GUI controls, all following the same
23 # order: 0 = Japanese Normal, 1 = Japanese Large,
24 # 2 = English Normal, 3 = English Small.
26 params = [("font.ja", _("Japanese Font, Normal")),
27 ("font.ja.large", _("Japanese Font, Large")),
28 ("font.native", _("English Font, Normal")),
29 ("font.native.small", _("English Font, Small"))]
31 self.controls = []
32 table = gtk.Table(4, 3)
33 for k, s in params:
34 self.controls.append(
35 (k, gtk.Label(s), gtk.TextView(), gtk.Button(_("Change..."))))
37 for i, (key, label, textview, button) in enumerate(self.controls):
39 label.set_alignment(1.0, 0.5)
41 textview.set_accepts_tab(False)
42 textview.set_editable(False)
44 # Tacking the font_name onto the textview for convenience
45 textview.font_name = self.get_font_name(key)
47 self.update_font_control(self.controls[i], textview.font_name)
49 button.connect("clicked", self.on_font_change, self.controls[i])
51 frame = gtk.Frame()
52 frame.add(textview)
53 frame.set_shadow_type(gtk.SHADOW_IN)
54 bbox = gtk.HButtonBox()
55 bbox.pack_start(button)
57 table.attach(label, 0, 1, i, i + 1,
58 gtk.FILL, gtk.SHRINK, 5, 5)
59 table.attach(frame, 1, 2, i, i + 1,
60 gtk.FILL | gtk.EXPAND, gtk.SHRINK, 5, 5)
61 table.attach(bbox, 2, 3, i, i + 1,
62 gtk.SHRINK, gtk.SHRINK, 5, 5)
64 self.pack_start(table, expand = False);
66 def get_font_name(self, key):
67 prefs = global_refs.app.prefs
68 font_name = prefs.get(key)
69 if not font_name:
70 if os.name == "nt":
71 if key == "font.native": return "Tahoma 12"
72 elif key == "font.native.small": return "Tahoma 8"
73 elif key == "font.ja": return "MS Mincho 16"
74 elif key == "font.ja.large": return "MS Mincho 32"
75 else:
76 if key == "font.native": return "sans 12"
77 elif key == "font.native.small": return "sans 8"
78 elif key == "font.ja": return "serif 16"
79 elif key == "font.ja.large": return "serif 32"
80 return font_name
82 def update_font_control(self, ctrls, font_name):
83 key, label, textview, button = ctrls
84 print u"update_font_control: set %08X to font %s" \
85 % (id(textview), font_name)
86 buf = textview.get_buffer()
87 buf.set_text("")
89 table = buf.get_tag_table()
90 tag = table.lookup("font")
91 if tag:
92 table.remove(tag)
94 tag = gtk.TextTag("font")
95 tag.set_property("font", font_name)
96 table.add(tag)
97 start = buf.get_start_iter()
98 buf.insert_with_tags(start, font_name, tag)
100 def on_font_change(self, widget, ctrls):
101 print("TabPrefsFonts.on_font_change for key %s" % ctrls[0])
102 key, label, textview, button = ctrls
103 fd = gtk.FontSelectionDialog(_("Choose Font"))
104 if "font.ja" in key:
105 fd.set_preview_text("ROMAJI romaji 日本語 にほんご ニホンゴ")
106 fd.set_font_name(textview.font_name)
107 result = fd.run()
108 fd.hide()
109 if result == gtk.RESPONSE_OK:
110 textview.font_name = fd.get_font_name();
111 self.update_font_control(ctrls, textview.font_name)
113 def update_prefs(self):
114 prefs = global_refs.app.prefs
115 for key, label, textview, button in self.controls:
116 buf = textview.get_buffer()
117 s = buf.get_start_iter()
118 e = buf.get_end_iter()
119 text = textview.get_buffer().get_text(s, e, False)
120 prefs[key] = text
121 print "Setting '%s' to '%s'" % (key, text)