Package gui :: Module wizard_elements
[hide private]
[frames] | no frames]

Source Code for Module gui.wizard_elements

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2012 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """Module containing a set of special GUI elements to be used in the relax wizards.""" 
 25   
 26  # Python module imports. 
 27  from string import upper 
 28  import sys 
 29  import wx 
 30  import wx.lib.mixins.listctrl 
 31   
 32  # relax module imports. 
 33  from relax_errors import RelaxError 
 34  from status import Status; status = Status() 
 35   
 36  # relax GUI module imports. 
 37  from gui.components.combo_list import Combo_list 
 38  from gui.fonts import font 
 39  from gui.misc import add_border, gui_to_int, gui_to_list, gui_to_str, int_to_gui, list_to_gui, str_to_gui 
 40  from gui import paths 
 41   
 42   
43 -class Base_value:
44 """Base wizard GUI element for the input of all types of lists.""" 45
46 - def __init__(self, name=None, parent=None, element_type='text', sizer=None, desc=None, combo_choices=None, combo_data=None, combo_default=None, tooltip=None, divider=None, padding=0, spacer=None, read_only=False):
47 """Set up the base value element. 48 49 50 @keyword name: The name of the element to use in titles, etc. 51 @type name: str 52 @keyword parent: The wizard GUI element. 53 @type parent: wx.Panel instance 54 @keyword element_type: The type of GUI element to create. If set to 'text', a wx.TextCtrl element will be used. If set to 'combo', a wx.ComboBox element will be used. 55 @type element_type: str 56 @param sizer: The sizer to put the input field widget into. 57 @type sizer: wx.Sizer instance 58 @param desc: The text description. 59 @type desc: str 60 @keyword combo_choices: The list of choices to present to the user. This is only used if the element_type is set to 'combo'. 61 @type combo_choices: list of str 62 @keyword combo_data: The data returned by a call to GetValue(). This is only used if the element_type is set to 'combo'. If supplied, it should be the same length at the combo_choices list. If not supplied, the combo_choices list will be used for the returned data. 63 @type combo_data: list 64 @keyword combo_default: The default value of the ComboBox. This is only used if the element_type is set to 'combo'. 65 @type combo_default: str or None 66 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 67 @type tooltip: str 68 @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. 69 @type divider: None or int 70 @keyword padding: Spacing to the left and right of the widgets. 71 @type padding: int 72 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. 73 @type spacer: None or int 74 @keyword read_only: A flag which if True means that the text of the element cannot be edited. 75 @type read_only: bool 76 """ 77 78 # Store the args. 79 self.name = name 80 self.element_type = element_type 81 82 # Init. 83 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 84 85 # Left padding. 86 sub_sizer.AddSpacer(padding) 87 88 # The description. 89 text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) 90 text.SetFont(font.normal) 91 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 92 93 # The divider. 94 if not divider: 95 divider = parent._div_left 96 97 # Spacing. 98 x, y = text.GetSize() 99 sub_sizer.AddSpacer((divider - x, 0)) 100 101 # Initialise the text input field. 102 if element_type == 'text': 103 # Set up the text control. 104 self._field = wx.TextCtrl(parent, -1, '') 105 106 # Read only field. 107 if read_only: 108 # Cannot edit. 109 self._field.SetEditable(False) 110 111 # Change the colour to the background. 112 colour = parent.GetBackgroundColour() 113 self._field.SetOwnBackgroundColour(colour) 114 115 # Initialise the combo box input field. 116 elif element_type == 'combo': 117 # The style. 118 style = wx.CB_DROPDOWN 119 if read_only: 120 style = style | wx.CB_READONLY 121 122 # Set up the combo box. 123 self._field = wx.ComboBox(parent, -1, '', style=style) 124 125 # Update the choices. 126 self.ResetChoices(combo_choices=combo_choices, combo_data=combo_data, combo_default=combo_default) 127 128 # Unknown field. 129 else: 130 raise RelaxError("Unknown element type '%s'." % element_type) 131 132 # Set up the input field. 133 self._field.SetMinSize((50, parent.height_element)) 134 self._field.SetFont(font.normal) 135 sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 136 137 # Right padding. 138 sub_sizer.AddSpacer(padding) 139 140 # Add to the main sizer. 141 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 142 143 # Spacing below the widget. 144 if spacer == None: 145 sizer.AddStretchSpacer() 146 else: 147 sizer.AddSpacer(spacer) 148 149 # Tooltip. 150 if tooltip: 151 text.SetToolTipString(tooltip) 152 self._field.SetToolTipString(tooltip) 153 154 # Set up the specific conversion functions. 155 self.conversion_fns()
156 157
158 - def Clear(self):
159 """Special method for clearing or resetting the GUI element.""" 160 161 # Clear the value from a TextCtrl or ComboBox. 162 if self.element_type in ['text', 'combo']: 163 self._field.Clear()
164 165
166 - def GetValue(self):
167 """Special method for returning the value of the GUI element. 168 169 @return: The string list value. 170 @rtype: list of str 171 """ 172 173 # Convert and return the value from a TextCtrl. 174 if self.element_type == 'text': 175 return self.convert_from_gui(self._field.GetValue()) 176 177 # Convert and return the value from a ComboBox. 178 if self.element_type == 'combo': 179 return self.convert_from_gui(self._field.GetClientData(self._field.GetSelection()))
180 181
182 - def ResetChoices(self, combo_choices=None, combo_data=None, combo_default=None):
183 """Special wizard method for resetting the list of choices in a ComboBox type element. 184 185 @param key: The key corresponding to the desired GUI element. 186 @type key: str 187 @keyword combo_choices: The list of choices to present to the user. This is only used if the element_type is set to 'combo'. 188 @type combo_choices: list of str 189 @keyword combo_data: The data returned by a call to GetValue(). This is only used if the element_type is set to 'combo'. If supplied, it should be the same length at the combo_choices list. If not supplied, the combo_choices list will be used for the returned data. 190 @type combo_data: list 191 @keyword combo_default: The default value of the ComboBox. This is only used if the element_type is set to 'combo'. 192 @type combo_default: str or None 193 """ 194 195 # A TextCtrl?! 196 if self.element_type == 'text': 197 raise RelaxError("Cannot reset the list of ComboBox choices as this is a TextCtrl!") 198 199 # Reset the choices for a ComboBox. 200 if self.element_type == 'combo': 201 # First clear all data. 202 self.Clear() 203 204 # The data. 205 if combo_data == None: 206 combo_data = combo_choices 207 208 # Loop over the choices and data, adding both to the end. 209 for i in range(len(combo_choices)): 210 self._field.Insert(str_to_gui(combo_choices[i]), i, combo_data[i]) 211 212 # Set the default selection. 213 if combo_default: 214 self._field.SetStringSelection(combo_default)
215 216
217 - def SetValue(self, value):
218 """Special method for setting the value of the GUI element. 219 220 @param value: The value to set. 221 @type value: list of str 222 """ 223 224 # Convert and set the value for a TextCtrl. 225 if self.element_type == 'text': 226 self._field.SetValue(self.convert_to_gui(value)) 227 228 # Convert and set the value for a ComboBox. 229 if self.element_type == 'combo': 230 # Loop until the proper client data is found. 231 for i in range(self._field.GetCount()): 232 if self._field.GetClientData(i) == value: 233 self._field.SetSelection(i) 234 break
235 236
237 - def conversion_fns(self):
238 """Dummy method for setting up the conversion functions. 239 240 This should define the self.convert_to_gui() and self.convert_from_gui() function aliases. 241 """
242 243 244
245 -class Integer(Base_value):
246 """Wizard GUI element for the input of integers.""" 247
248 - def conversion_fns(self):
249 """Set up the conversion functions.""" 250 251 self.convert_from_gui = gui_to_int 252 self.convert_to_gui = int_to_gui
253 254
255 -class List:
256 """Base wizard GUI element for the input of all types of lists.""" 257
258 - def __init__(self, name=None, parent=None, element_type='default', sizer=None, desc=None, combo_choices=None, combo_data=None, combo_default=None, combo_list_size=None, tooltip=None, divider=None, padding=0, spacer=None):
259 """Set up the element. 260 261 @keyword name: The name of the element to use in titles, etc. 262 @type name: str 263 @keyword parent: The wizard GUI element. 264 @type parent: wx.Panel instance 265 @keyword element_type: The type of GUI element to create. If set to 'default', the wx.TextCtrl element with a button to bring up a dialog with ListCtrl will be used. If set to 'combo_list', the special gui.components.combo_list.Combo_list element will be used. 266 @type element_type: str 267 @keyword sizer: The sizer to put the input field widget into. 268 @type sizer: wx.Sizer instance 269 @keyword desc: The text description. 270 @type desc: str 271 @keyword combo_choices: The list of choices to present to the user. This is only used if the element_type is set to 'combo'. 272 @type combo_choices: list of str 273 @keyword combo_data: The data returned by a call to GetValue(). This is only used if the element_type is set to 'combo'. If supplied, it should be the same length at the combo_choices list. If not supplied, the combo_choices list will be used for the returned data. 274 @type combo_data: list 275 @keyword combo_default: The default value of the ComboBox. This is only used if the element_type is set to 'combo'. 276 @type combo_default: str or None 277 @keyword combo_list_size: The number of initial entries in a Combo_list object. 278 @type combo_list_size: int or None 279 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 280 @type tooltip: str 281 @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. 282 @type divider: None or int 283 @keyword padding: Spacing to the left and right of the widgets. 284 @type padding: int 285 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. 286 @type spacer: None or int 287 """ 288 289 # Store the args. 290 self.name = name 291 292 # Initialise the default element. 293 if element_type == 'default': 294 # Init. 295 sub_sizer = wx.BoxSizer(wx.HORIZONTAL) 296 297 # Left padding. 298 sub_sizer.AddSpacer(padding) 299 300 # The description. 301 text = wx.StaticText(parent, -1, desc, style=wx.ALIGN_LEFT) 302 text.SetFont(font.normal) 303 sub_sizer.Add(text, 0, wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 0) 304 305 # The divider. 306 if not divider: 307 divider = parent._div_left 308 309 # Spacing. 310 x, y = text.GetSize() 311 sub_sizer.AddSpacer((divider - x, 0)) 312 313 # The input field. 314 self._field = wx.TextCtrl(parent, -1, '') 315 self._field.SetMinSize((50, parent.height_element)) 316 self._field.SetFont(font.normal) 317 self._field.SetEditable(False) 318 colour = parent.GetBackgroundColour() 319 self._field.SetOwnBackgroundColour(colour) 320 sub_sizer.Add(self._field, 1, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 321 322 # A little spacing. 323 sub_sizer.AddSpacer(5) 324 325 # The file selection button. 326 button = wx.BitmapButton(parent, -1, wx.Bitmap(paths.icon_16x16.edit_rename, wx.BITMAP_TYPE_ANY)) 327 button.SetMinSize((parent.height_element, parent.height_element)) 328 sub_sizer.Add(button, 0, wx.ADJUST_MINSIZE|wx.ALIGN_CENTER_VERTICAL, 0) 329 parent.Bind(wx.EVT_BUTTON, self.open_dialog, button) 330 331 # Right padding. 332 sub_sizer.AddSpacer(padding) 333 334 # Add to the main sizer. 335 sizer.Add(sub_sizer, 1, wx.EXPAND|wx.ALL, 0) 336 337 # Spacing below the widget. 338 if spacer == None: 339 sizer.AddStretchSpacer() 340 else: 341 sizer.AddSpacer(spacer) 342 343 # Tooltip. 344 if tooltip: 345 text.SetToolTipString(tooltip) 346 self._field.SetToolTipString(tooltip) 347 348 # Initialise the combo list input field. 349 elif element_type == 'combo_list': 350 self._field = Combo_list(parent, sizer, desc, n=combo_list_size, choices=combo_choices, tooltip=tooltip) 351 352 # Unknown field. 353 else: 354 raise RelaxError("Unknown element type '%s'." % element_type)
355 356
357 - def GetValue(self):
358 """Special method for returning the value of the GUI element. 359 360 @return: The string list value. 361 @rtype: list of str 362 """ 363 364 # Convert and return the value. 365 return gui_to_list(self._field.GetValue())
366 367
368 - def SetValue(self, value):
369 """Special method for setting the value of the GUI element. 370 371 @param value: The value to set. 372 @type value: list of str 373 """ 374 375 # Convert and set the value. 376 self._field.SetValue(list_to_gui(value))
377 378
379 - def init_window(self):
380 """Dummy method which must be overridden."""
381 382
383 - def open_dialog(self, event):
384 """Open a special dialog for inputting a list of text values. 385 386 @param event: The wx event. 387 @type event: wx event 388 """ 389 390 # Initialise the model selection window. 391 win = self.init_window() 392 393 # Set the model selector window selections. 394 win.SetValue(self.GetValue()) 395 396 # Show the model selector window. 397 if status.show_gui: 398 win.ShowModal() 399 win.Close() 400 401 # Set the values. 402 self.SetValue(win.GetValue()) 403 404 # Destroy the window. 405 del win
406 407 408
409 -class String(Base_value):
410 """Wizard GUI element for the input of strings.""" 411
412 - def conversion_fns(self):
413 """Set up the conversion functions.""" 414 415 self.convert_from_gui = gui_to_str 416 self.convert_to_gui = str_to_gui
417 418 419
420 -class String_list(List):
421 """Wizard GUI element for the input of lists of strings.""" 422
423 - def init_window(self):
424 """Set up the specific window type.""" 425 426 # Specify the window type to open. 427 return String_list_window(name=self.name)
428 429 430
431 -class String_list_of_lists(List):
432 """Wizard GUI element for the input of a list of lists of strings.""" 433
434 - def __init__(self, name=None, titles=None, parent=None, sizer=None, desc=None, tooltip=None, divider=None, padding=0, spacer=None):
435 """Set up the element. 436 437 @keyword name: The name of the element to use in titles, etc. 438 @type name: str 439 @keyword titles: The titles of each of the elements of the fixed width second dimension. 440 @type titles: list of str 441 @keyword parent: The wizard GUI element. 442 @type parent: wx.Panel instance 443 @keyword sizer: The sizer to put the input field widget into. 444 @type sizer: wx.Sizer instance 445 @keyword desc: The text description. 446 @type desc: str 447 @keyword tooltip: The tooltip which appears on hovering over the text or input field. 448 @type tooltip: str 449 @keyword divider: The optional position of the divider. If None, the class variable _div_left will be used. 450 @type divider: None or int 451 @keyword padding: Spacing to the left and right of the widgets. 452 @type padding: int 453 @keyword spacer: The amount of spacing to add below the field in pixels. If None, a stretchable spacer will be used. 454 @type spacer: None or int 455 """ 456 457 # Store some of the args. 458 self.titles = titles 459 460 # Initialise the base class. 461 List.__init__(self, name=name, parent=parent, sizer=sizer, desc=desc, tooltip=tooltip, divider=divider, padding=padding, spacer=spacer)
462 463
464 - def init_window(self):
465 """Set up the specific window type.""" 466 467 # Specify the window type to open. 468 return String_list_of_lists_window(name=self.name, titles=self.titles)
469 470 471
472 -class String_list_ctrl(wx.ListCtrl, wx.lib.mixins.listctrl.TextEditMixin, wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin):
473 """The string list ListCtrl object.""" 474
475 - def __init__(self, parent):
476 """Initialise the control. 477 478 @param parent: The parent window. 479 @type parent: wx.Frame instance 480 """ 481 482 # Execute the parent __init__() methods. 483 wx.ListCtrl.__init__(self, parent, -1, style=wx.BORDER_SUNKEN|wx.LC_REPORT|wx.LC_HRULES|wx.LC_VRULES) 484 wx.lib.mixins.listctrl.TextEditMixin.__init__(self) 485 wx.lib.mixins.listctrl.ListCtrlAutoWidthMixin.__init__(self)
486 487 488
489 -class String_list_window(wx.Dialog):
490 """The string list editor window.""" 491 492 # The window size. 493 SIZE = (600, 600) 494 495 # A border. 496 BORDER = 10 497 498 # Sizes. 499 SIZE_BUTTON = (150, 33) 500
501 - def __init__(self, name=''):
502 """Set up the string list editor window. 503 504 @keyword name: The name of the window. 505 @type name: str 506 """ 507 508 # Store the args. 509 self.name = name 510 511 # The title of the dialog. 512 title = "The list of %s" % name 513 514 # Set up the dialog. 515 wx.Dialog.__init__(self, None, id=-1, title=title) 516 517 # Initialise some values 518 width = self.SIZE[0] - 2*self.BORDER 519 520 # Set the frame properties. 521 self.SetSize(self.SIZE) 522 self.Centre() 523 self.SetFont(font.normal) 524 525 # The main box sizer. 526 main_sizer = wx.BoxSizer(wx.VERTICAL) 527 528 # Pack the sizer into the frame. 529 self.SetSizer(main_sizer) 530 531 # Build the central sizer, with borders. 532 sizer = add_border(main_sizer, border=self.BORDER, packing=wx.VERTICAL) 533 534 # Add the list control. 535 self.add_list(sizer) 536 537 # Some spacing. 538 sizer.AddSpacer(self.BORDER) 539 540 # Add the bottom buttons. 541 self.add_buttons(sizer)
542 543
544 - def GetValue(self):
545 """Return the values as a list of strings. 546 547 @return: The list of values. 548 @rtype: list of str 549 """ 550 551 # Init. 552 values = [] 553 554 # Loop over the entries. 555 for i in range(self.list.GetItemCount()): 556 values.append(gui_to_str(self.list.GetItemText(i))) 557 558 # Return the list. 559 return values
560 561
562 - def SetValue(self, values):
563 """Set up the list values. 564 565 @param values: The list of values to add to the list. 566 @type values: list of str 567 """ 568 569 # Loop over the entries. 570 for i in range(len(values)): 571 self.list.InsertStringItem(i, str_to_gui(values[i]))
572 573
574 - def add_buttons(self, sizer):
575 """Add the buttons to the sizer. 576 577 @param sizer: A sizer object. 578 @type sizer: wx.Sizer instance 579 """ 580 581 # Create a horizontal layout for the buttons. 582 button_sizer = wx.BoxSizer(wx.HORIZONTAL) 583 sizer.Add(button_sizer, 0, wx.ALIGN_CENTER|wx.ALL, 0) 584 585 # The add button. 586 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Add") 587 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.add, wx.BITMAP_TYPE_ANY)) 588 button.SetFont(font.normal) 589 button.SetToolTipString("Add a row to the list.") 590 button.SetMinSize(self.SIZE_BUTTON) 591 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 592 self.Bind(wx.EVT_BUTTON, self.append_row, button) 593 594 # Spacer. 595 button_sizer.AddSpacer(20) 596 597 # The delete all button. 598 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Delete all") 599 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.edit_delete, wx.BITMAP_TYPE_ANY)) 600 button.SetFont(font.normal) 601 button.SetToolTipString("Delete all items.") 602 button.SetMinSize(self.SIZE_BUTTON) 603 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 604 self.Bind(wx.EVT_BUTTON, self.delete_all, button) 605 606 # Spacer. 607 button_sizer.AddSpacer(20) 608 609 # The Ok button. 610 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Ok") 611 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.dialog_ok, wx.BITMAP_TYPE_ANY)) 612 button.SetFont(font.normal) 613 button.SetMinSize(self.SIZE_BUTTON) 614 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 615 self.Bind(wx.EVT_BUTTON, self.close, button)
616 617
618 - def add_list(self, sizer):
619 """Set up the list control. 620 621 @param sizer: A sizer object. 622 @type sizer: wx.Sizer instance 623 """ 624 625 # The control. 626 self.list = String_list_ctrl(self) 627 628 # Set the column title. 629 title = "%s%s" % (upper(self.name[0]), self.name[1:]) 630 631 # Add a single column, full width. 632 self.list.InsertColumn(0, title) 633 self.list.SetColumnWidth(0, wx.LIST_AUTOSIZE) 634 635 # Add the table to the sizer. 636 sizer.Add(self.list, 1, wx.ALL|wx.EXPAND, 0)
637 638
639 - def append_row(self, event):
640 """Append a new row to the list. 641 642 @param event: The wx event. 643 @type event: wx event 644 """ 645 646 # The next index. 647 next = self.list.GetItemCount() 648 649 # Add a new empty row. 650 self.list.InsertStringItem(next, '')
651 652
653 - def close(self, event):
654 """Close the window. 655 656 @param event: The wx event. 657 @type event: wx event 658 """ 659 660 # Destroy the window. 661 self.Destroy()
662 663
664 - def delete_all(self, event):
665 """Remove all items from the list. 666 667 @param event: The wx event. 668 @type event: wx event 669 """ 670 671 # Delete. 672 self.list.DeleteAllItems()
673 674 675
676 -class String_list_of_lists_window(wx.Dialog):
677 """The string list of lists editor window.""" 678 679 # The window size. 680 SIZE = (600, 600) 681 682 # A border. 683 BORDER = 10 684 685 # Sizes. 686 SIZE_BUTTON = (150, 33) 687
688 - def __init__(self, name='', titles=None):
689 """Set up the string list editor window. 690 691 @keyword name: The name of the window. 692 @type name: str 693 @keyword titles: The titles of each of the elements of the fixed width second dimension. 694 @type titles: list of str 695 """ 696 697 # Store the args. 698 self.name = name 699 self.titles = titles 700 701 # The number of elements. 702 self.num = len(self.titles) 703 704 # The title of the dialog. 705 title = "The list of %s" % name 706 707 # Set up the dialog. 708 wx.Dialog.__init__(self, None, id=-1, title=title) 709 710 # Initialise some values 711 self.width = self.SIZE[0] - 2*self.BORDER 712 713 # Set the frame properties. 714 self.SetSize(self.SIZE) 715 self.Centre() 716 self.SetFont(font.normal) 717 718 # The main box sizer. 719 main_sizer = wx.BoxSizer(wx.VERTICAL) 720 721 # Pack the sizer into the frame. 722 self.SetSizer(main_sizer) 723 724 # Build the central sizer, with borders. 725 sizer = add_border(main_sizer, border=self.BORDER, packing=wx.VERTICAL) 726 727 # Add the list control. 728 self.add_list(sizer) 729 730 # Some spacing. 731 sizer.AddSpacer(self.BORDER) 732 733 # Add the bottom buttons. 734 self.add_buttons(sizer)
735 736
737 - def GetValue(self):
738 """Return the values as a list of lists of strings. 739 740 @return: The list of lists of values. 741 @rtype: list of lists of str 742 """ 743 744 # Init. 745 values = [] 746 747 # Loop over the entries. 748 for i in range(self.list.GetItemCount()): 749 # Append a new list. 750 values.append([]) 751 752 # Loop over the items. 753 for j in range(self.num): 754 # The item. 755 item = self.list.GetItem(i, j) 756 757 # Append the value. 758 values[-1].append(gui_to_str(item.GetText())) 759 760 # Return the list. 761 return values
762 763
764 - def SetValue(self, values):
765 """Set up the list of lists values. 766 767 @param values: The list of lists of values to add to the list. 768 @type values: list of lists of str 769 """ 770 771 # Loop over the entries. 772 for i in range(len(values)): 773 # The first value. 774 self.list.InsertStringItem(sys.maxint, str_to_gui(values[i][0])) 775 776 # Loop over the values. 777 for j in range(1, self.num): 778 # Set the value. 779 self.list.SetStringItem(i, j, str_to_gui(values[i][j])) 780 781 # Refresh. 782 self.Refresh()
783 784
785 - def add_buttons(self, sizer):
786 """Add the buttons to the sizer. 787 788 @param sizer: A sizer object. 789 @type sizer: wx.Sizer instance 790 """ 791 792 # Create a horizontal layout for the buttons. 793 button_sizer = wx.BoxSizer(wx.HORIZONTAL) 794 sizer.Add(button_sizer, 0, wx.ALIGN_CENTER|wx.ALL, 0) 795 796 # The add button. 797 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Add") 798 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.add, wx.BITMAP_TYPE_ANY)) 799 button.SetFont(font.normal) 800 button.SetToolTipString("Add a row to the list.") 801 button.SetMinSize(self.SIZE_BUTTON) 802 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 803 self.Bind(wx.EVT_BUTTON, self.append_row, button) 804 805 # Spacer. 806 button_sizer.AddSpacer(20) 807 808 # The delete all button. 809 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Delete all") 810 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.edit_delete, wx.BITMAP_TYPE_ANY)) 811 button.SetFont(font.normal) 812 button.SetToolTipString("Delete all items.") 813 button.SetMinSize(self.SIZE_BUTTON) 814 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 815 self.Bind(wx.EVT_BUTTON, self.delete_all, button) 816 817 # Spacer. 818 button_sizer.AddSpacer(20) 819 820 # The Ok button. 821 button = wx.lib.buttons.ThemedGenBitmapTextButton(self, -1, None, " Ok") 822 button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.dialog_ok, wx.BITMAP_TYPE_ANY)) 823 button.SetFont(font.normal) 824 button.SetMinSize(self.SIZE_BUTTON) 825 button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) 826 self.Bind(wx.EVT_BUTTON, self.close, button)
827 828
829 - def add_list(self, sizer):
830 """Set up the list control. 831 832 @param sizer: A sizer object. 833 @type sizer: wx.Sizer instance 834 """ 835 836 # The control. 837 self.list = String_list_ctrl(self) 838 839 # Set the column title. 840 title = "%s%s" % (upper(self.name[0]), self.name[1:]) 841 842 # Add the columns. 843 for i in range(self.num): 844 self.list.InsertColumn(i, self.titles[i]) 845 self.list.SetColumnWidth(i, self.width/self.num) 846 847 # Add the table to the sizer. 848 sizer.Add(self.list, 1, wx.ALL|wx.EXPAND, 0)
849 850
851 - def append_row(self, event):
852 """Append a new row to the list. 853 854 @param event: The wx event. 855 @type event: wx event 856 """ 857 858 # The next index. 859 next = self.list.GetItemCount() 860 861 # Add a new empty row. 862 self.list.InsertStringItem(next, '')
863 864
865 - def close(self, event):
866 """Close the window. 867 868 @param event: The wx event. 869 @type event: wx event 870 """ 871 872 # Destroy the window. 873 self.Destroy()
874 875
876 - def delete_all(self, event):
877 """Remove all items from the list. 878 879 @param event: The wx event. 880 @type event: wx event 881 """ 882 883 # Delete. 884 self.list.DeleteAllItems()
885