Translated using Weblate.
[wammu.git] / Wammu / Wizard.py
blobd59f2626ad003acbd931c9086f6089a0233c8b6c
1 # -*- coding: UTF-8 -*-
2 # vim: expandtab sw=4 ts=4 sts=4:
3 '''
4 Wammu - Phone manager
5 Wizard helper classes
6 '''
7 __author__ = 'Michal Čihař'
8 __email__ = 'michal@cihar.com'
9 __license__ = '''
10 Copyright © 2003 - 2010 Michal Čihař
12 This program is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License version 2 as published by
14 the Free Software Foundation.
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 more details.
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 '''
26 import wx
27 import wx.wizard
28 import Wammu.Paths
31 class SimplePage(wx.wizard.PyWizardPage):
32 """
33 Simple wizard page with unlimited rows of text.
34 """
35 def __init__(self, parent, titletext, bodytext = None, detailtexts = None):
36 wx.wizard.PyWizardPage.__init__(self, parent)
37 self.parent = parent
38 self.sizer = wx.BoxSizer(wx.VERTICAL)
39 self.SetSizer(self.sizer)
40 title = wx.StaticText(self, -1, titletext)
41 title.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
42 self.sizer.Add(title, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
43 self.sizer.Add(wx.StaticLine(self, -1), 0, wx.EXPAND|wx.ALL, 5)
44 self.prev = None
45 self.next = None
46 if bodytext is not None:
47 body = wx.StaticText(self, -1, bodytext)
48 body.Wrap(400)
49 self.sizer.Add(body, 0, wx.ALL, 5)
50 if detailtexts is not None:
51 for row in detailtexts:
52 detail = wx.StaticText(self, -1, row)
53 detail.Wrap(400)
54 self.sizer.Add(detail, 0, wx.ALL, 5)
56 def SetNext(self, next):
57 self.next = next
59 def SetPrev(self, prev):
60 self.prev = prev
62 def GetNext(self):
63 return self.next
65 def GetPrev(self):
66 return self.prev
68 def Activated(self, evt):
69 """
70 Executed when page is being activated.
71 """
72 return
74 def Blocked(self, evt):
75 """
76 Executed when page is about to be switched. Switching can be
77 blocked by returning True.
78 """
79 return False
81 def Cancel(self, evt):
82 """
83 Executed when wizard is about to be canceled. Canceling can be
84 blocked by returning False.
85 """
86 return True
88 class ChoicePage(SimplePage):
89 """
90 Page offering choice of several values and allowing to automatically
91 select next page according to choice.
92 """
93 def __init__(self, parent, title, text, choices, helps, nexts = None, nonetext ='', extratext = None):
94 Wammu.Wizard.SimplePage.__init__(self, parent, title, extratext)
95 self.type_rb = wx.RadioBox(self, -1, text,
96 size = (400, -1),
97 majorDimension = 1,
98 choices = choices)
99 self.texts = helps
100 self.nexts = nexts
101 self.Bind(wx.EVT_RADIOBOX, self.OnTypeChange, self.type_rb)
102 self.sizer.Add(self.type_rb, 0, wx.ALL, 5)
103 try:
104 self.body = wx.StaticText(self, -1, self.texts[0])
105 except:
106 self.body = wx.StaticText(self, -1, nonetext)
107 self.body.Wrap(400)
108 self.sizer.Add(self.body, 0, wx.ALL, 5)
110 def OnTypeChange(self, evt):
111 try:
112 self.body.SetLabel(self.texts[evt.GetSelection()])
113 self.body.Wrap(400)
114 except:
115 self.body.SetLabel('')
116 self.sizer.Fit(self)
118 def GetType(self):
119 return self.type_rb.GetSelection()
121 def GetNext(self):
122 if self.nexts is None or len(self.nexts) == 0:
123 return self.next
124 return self.nexts[self.type_rb.GetSelection()]
126 class InputPage(SimplePage):
128 Page offering text control input.
130 def __init__(self, parent, title, text, choices = None, help = ''):
131 Wammu.Wizard.SimplePage.__init__(self, parent, title, text)
132 if type(choices) == str:
133 self.edit = wx.TextCtrl(self, -1, choices, size = (300, -1))
134 else:
135 self.edit = wx.ComboBox(self, -1, '', choices = choices, size = (300, -1))
136 self.sizer.Add(self.edit, 0, wx.ALL, 5)
137 self.body = wx.StaticText(self, -1, help)
138 self.body.Wrap(400)
139 self.sizer.Add(self.body, 0, wx.ALL, 5)
141 class MultiInputPage(SimplePage):
143 Page offering several text control inputs.
145 def __init__(self, parent, title, texts, choices):
146 Wammu.Wizard.SimplePage.__init__(self, parent, title)
147 self.edits = {}
148 for i in range(len(texts)):
149 body = wx.StaticText(self, -1, texts[i])
150 body.Wrap(400)
151 self.sizer.Add(body, 0, wx.ALL, 5)
152 self.edits[i] = wx.ComboBox(self, -1, '', choices = choices[i], size = (300, -1))
153 self.sizer.Add(self.edits[i], 0, wx.ALL, 5)
155 class TextPage(SimplePage):
157 Page offering big text control.
159 def __init__(self, parent, title, text):
160 Wammu.Wizard.SimplePage.__init__(self, parent, title, text)
161 self.edit = wx.TextCtrl(self, -1, '', style = wx.TE_MULTILINE | wx.TE_READONLY)
162 self.sizer.Add(self.edit, 1, wx.ALL | wx.EXPAND, 5)