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