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