7
from libtovid.gui.configs import TovidConfig
8
from libtovid.gui.constants import *
9
from libtovid.gui.util import _
15
class FontChooserDialog(wx.Dialog):
16
"""A simple font chooser"""
18
def __init__(self, parent, id, curFacename = "Default"):
19
wx.Dialog.__init__(self, parent, id, _("Font chooser"), wx.DefaultPosition,
25
# Get global configuration
26
self.curConfig = TovidConfig()
28
# Construct a list of fonts. Always list "Default" first.
30
strFontChoices.extend(self.curConfig.wx_IM_FontMap.keys())
32
strFontChoices.insert(0, "Default")
34
# List of fonts, label and sample of selected font
35
self.listFonts = wx.ListBox(self, wx.ID_ANY, wx.DefaultPosition,
36
wx.DefaultSize, strFontChoices, wx.LB_SINGLE)
37
self.lblFont = wx.StaticText(self, wx.ID_ANY, _("Sample of the selected font:"))
38
self.lblFontSample = wx.StaticText(self, wx.ID_ANY, "The quick brown fox\n "
39
"jumps over the lazy dog.")
40
wx.EVT_LISTBOX(self, self.listFonts.GetId(), self.OnSelectFont)
42
# Set listbox selection to given facename
43
curFontIdx = self.listFonts.FindString(curFacename)
44
self.listFonts.SetSelection(curFontIdx)
45
# Remember given facename
46
self.font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
47
wx.FONTWEIGHT_NORMAL, False, "Default")
48
# Show sample in current font
49
self.lblFontSample.SetFont(self.font)
52
self.btnOK = wx.Button(self, wx.ID_OK, "OK")
53
self.btnCancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
54
sizButtons = wx.BoxSizer(wx.HORIZONTAL)
55
sizButtons.Add(self.btnOK, 1, wx.EXPAND | wx.ALL, 16)
56
sizButtons.Add(self.btnCancel, 1, wx.EXPAND | wx.ALL, 16)
57
# Sizer to hold controls
58
sizMain = wx.BoxSizer(wx.VERTICAL)
59
sizMain.Add(self.listFonts, 1, wx.EXPAND | wx.ALL, 8)
60
sizMain.Add(self.lblFont, 0, wx.EXPAND | wx.ALL, 8)
61
sizMain.Add(self.lblFontSample, 0, wx.EXPAND | wx.ALL, 16)
62
sizMain.Add(sizButtons, 0, wx.EXPAND)
63
self.SetSizer(sizMain)
66
# If there are very few (<6) fonts available,
67
# show a message telling how to get more
68
if len(self.curConfig.wx_IM_FontMap.keys()) < 6:
69
dlgGetMoreFonts = wx.MessageDialog(self,
70
"You have less than six fonts to choose from. See the\n"
71
"tovid documentation (http://tovid.org/)\n"
72
"for instructions on how to get more.",
73
"How to get more fonts", wx.OK | wx.ICON_INFORMATION)
74
dlgGetMoreFonts.ShowModal()
76
def OnSelectFont(self, evt):
77
"""Change the sample font to reflect the selected font"""
78
face = self.listFonts.GetStringSelection()
79
self.font = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
80
wx.FONTWEIGHT_NORMAL, False, face)
81
self.lblFontSample.SetFont(self.font)
83
def GetSelectedFont(self):
84
"""Return the font that was selected"""
87
class PreferencesDialog(wx.Dialog):
88
"""Preferences/configuration settings dialog. Not yet used."""
90
def __init__(self, parent, id):
91
wx.Dialog.__init__(self, parent, id, "tovid GUI Preferences", \
92
wx.DefaultPosition, (400, 200))
95
# Get global configuration
96
self.curConfig = TovidConfig()
98
self.txtHeading = HeadingText(self, wx.ID_ANY, "Preferences")
100
self.btnOK = wx.Button(self, wx.ID_OK, "OK")
101
self.btnCancel = wx.Button(self, wx.ID_CANCEL, "Cancel")
102
self.sizButtons = wx.BoxSizer(wx.HORIZONTAL)
103
self.sizButtons.Add(self.btnOK, 1, wx.EXPAND | wx.ALL, 16)
104
self.sizButtons.Add(self.btnCancel, 1, wx.EXPAND | wx.ALL, 16)
105
wx.EVT_BUTTON(self, wx.ID_OK, self.OnOK)
106
# Main sizer to hold all controls
107
self.sizMain = wx.BoxSizer(wx.VERTICAL)
108
self.sizMain.Add(self.txtHeading, 0, wx.EXPAND | wx.ALL, 8)
109
# Controls will go here
110
self.sizMain.Add(self.sizButtons, 0, wx.EXPAND | wx.ALL, 8)
111
self.SetSizer(self.sizMain)
114
"""Assign configuration to underlying Config class"""
115
# Config assignment goes here
116
self.EndModal(wx.ID_OK)