~ubuntu-branches/ubuntu/karmic/tovid/karmic

« back to all changes in this revision

Viewing changes to libtovid/gui/dialogs.py

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2008-01-24 22:04:40 UTC
  • Revision ID: james.westby@ubuntu.com-20080124220440-x7cheljduf1rdgnq
Tags: upstream-0.31
ImportĀ upstreamĀ versionĀ 0.31

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/env python
 
2
# dialogs.py
 
3
 
 
4
import wx
 
5
 
 
6
import libtovid
 
7
from libtovid.gui.configs import TovidConfig
 
8
from libtovid.gui.constants import *
 
9
from libtovid.gui.util import _
 
10
 
 
11
__all__ = [\
 
12
    "FontChooserDialog",
 
13
    "PreferencesDialog"]
 
14
 
 
15
class FontChooserDialog(wx.Dialog):
 
16
    """A simple font chooser"""
 
17
 
 
18
    def __init__(self, parent, id, curFacename = "Default"):
 
19
        wx.Dialog.__init__(self, parent, id, _("Font chooser"), wx.DefaultPosition,
 
20
                (400, 400))
 
21
 
 
22
        # Center dialog
 
23
        self.Centre()
 
24
 
 
25
        # Get global configuration
 
26
        self.curConfig = TovidConfig()
 
27
 
 
28
        # Construct a list of fonts. Always list "Default" first.
 
29
        strFontChoices = []
 
30
        strFontChoices.extend(self.curConfig.wx_IM_FontMap.keys())
 
31
        strFontChoices.sort()
 
32
        strFontChoices.insert(0, "Default")
 
33
 
 
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)
 
41
 
 
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)
 
50
 
 
51
        # OK/Cancel buttons
 
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)
 
64
        self.Show()
 
65
 
 
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()
 
75
 
 
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)
 
82
 
 
83
    def GetSelectedFont(self):
 
84
        """Return the font that was selected"""
 
85
        return self.font
 
86
 
 
87
class PreferencesDialog(wx.Dialog):
 
88
    """Preferences/configuration settings dialog. Not yet used."""
 
89
 
 
90
    def __init__(self, parent, id):
 
91
        wx.Dialog.__init__(self, parent, id, "tovid GUI Preferences", \
 
92
                wx.DefaultPosition, (400, 200))
 
93
        # Center dialog
 
94
        self.Centre()
 
95
        # Get global configuration
 
96
        self.curConfig = TovidConfig()
 
97
        # Heading
 
98
        self.txtHeading = HeadingText(self, wx.ID_ANY, "Preferences")
 
99
        # OK/Cancel buttons
 
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)
 
112
 
 
113
    def OnOK(self, evt):
 
114
        """Assign configuration to underlying Config class"""
 
115
        # Config assignment goes here
 
116
        self.EndModal(wx.ID_OK)
 
117