1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module containing a set of special GUI elements to be used in the relax wizards."""
24
25
26 import wx
27
28
29 from graphics import fetch_icon
30 from gui.filedialog import RelaxDirDialog
31 from gui.fonts import font
32 from gui.string_conv import gui_to_str, str_to_gui
33 from lib.errors import RelaxError
34 from status import Status; status = Status()
35
36
38 """Wizard GUI element for selecting directories."""
39
40 - def __init__(self, name=None, default=None, parent=None, sizer=None, desc=None, message='File selection', style=wx.FD_DEFAULT_STYLE, tooltip=None, divider=None, padding=0, spacer=None, height_element=27, read_only=False):
41 """Build the file selection element.
42
43 @keyword name: The name of the element to use in titles, etc.
44 @type name: str
45 @keyword default: The default value of the element.
46 @type default: str
47 @keyword parent: The wizard GUI element.
48 @type parent: wx.Panel instance
49 @keyword sizer: The sizer to put the input field into.
50 @type sizer: wx.Sizer instance
51 @keyword desc: The text description.
52 @type desc: str
53 @keyword message: The file selector prompt string.
54 @type message: String
55 @keyword style: The dialog style. To open a single file, set to wx.FD_OPEN. To open multiple files, set to wx.FD_OPEN|wx.FD_MULTIPLE. To save a single file, set to wx.FD_SAVE. To save multiple files, set to wx.FD_SAVE|wx.FD_MULTIPLE.
56 @type style: long
57 @keyword tooltip: The tooltip which appears on hovering over all the GUI elements.
58 @type tooltip: str
59 @keyword divider: The position of the divider.
60 @type divider: int
61 @keyword padding: Spacing to the left and right of the widgets.
62 @type padding: int
63 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used.
64 @type spacer: None or int
65 @keyword height_element: The height in pixels of the GUI element.
66 @type height_element: int
67 @keyword read_only: A flag which if True means that the text of the element cannot be edited.
68 @type read_only: bool
69 """
70
71
72 self.name = name
73
74
75 if default == None:
76 default = wx.EmptyString
77
78
79 sub_sizer = wx.BoxSizer(wx.HORIZONTAL)
80
81
82 sub_sizer.AddSpacer(padding)
83
84
85 text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT)
86 text.SetFont(font.normal)
87 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0)
88
89
90 if not divider:
91 raise RelaxError("The divider position has not been supplied.")
92
93
94 x, y = text.GetSize()
95 sub_sizer.AddSpacer((divider - x, 0))
96
97
98 self._field = wx.TextCtrl(parent, -1, default)
99 self._field.SetMinSize((-1, height_element))
100 self._field.SetFont(font.normal)
101 sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
102
103
104 obj = RelaxDirDialog(parent, field=self._field, message=message, defaultPath=default, style=style)
105
106
107 sub_sizer.AddSpacer(5)
108
109
110 button = wx.BitmapButton(parent, -1, wx.Bitmap(fetch_icon('oxygen.actions.document-open-folder'), wx.BITMAP_TYPE_ANY))
111 button.SetMinSize((height_element, height_element))
112 button.SetToolTipString("Select the directory.")
113 sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0)
114 parent.Bind(wx.EVT_BUTTON, obj.select_event, button)
115
116
117 sub_sizer.AddSpacer(padding)
118
119
120 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0)
121
122
123 if spacer == None:
124 sizer.AddStretchSpacer()
125 else:
126 sizer.AddSpacer(spacer)
127
128
129 if tooltip:
130 text.SetToolTipString(tooltip)
131 self._field.SetToolTipString(tooltip)
132
133
135 """Special method for clearing or resetting the GUI element."""
136
137
138 self._field.Clear()
139
140
142 """Special method for returning the value of the GUI element.
143
144 @return: The string value.
145 @rtype: list of str
146 """
147
148
149 return gui_to_str(self._field.GetValue())
150
151
153 """Special method for setting the value of the GUI element.
154
155 @param value: The value to set.
156 @type value: str
157 """
158
159
160 self._field.SetValue(str_to_gui(value))
161