Author: bugman Date: Mon Jun 20 18:18:58 2011 New Revision: 13123 URL: http://svn.gna.org/viewcvs/relax?rev=13123&view=rev Log: The buttons are now added to the wizards. The add_button() method has been converted to build_buttons() and is executed at the start of the run() wizard method. Modified: branches/gui_testing/gui/wizard.py Modified: branches/gui_testing/gui/wizard.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/wizard.py?rev=13123&r1=13122&r2=13123&view=diff ============================================================================== --- branches/gui_testing/gui/wizard.py (original) +++ branches/gui_testing/gui/wizard.py Mon Jun 20 18:18:58 2011 @@ -89,9 +89,6 @@ # Some class variables. art_spacing = 20 - button_apply = True - button_cancel = True - button_ok = True divider = None image_path = None input_size = 27 @@ -653,7 +650,7 @@ @type sizer: wx.Sizer instance @param desc: The text description. @type desc: str - @keyword default: The default text. + @keyword default: The default text. @type default: str @return: The input field object. @rtype: wx.TextCtrl instance @@ -699,7 +696,7 @@ def __init__(self, size_x=None, size_y=None, title='', border=10, style=wx.DEFAULT_DIALOG_STYLE): """Set up the window. - + @keyword style: The dialog style. @type style: wx style """ @@ -730,74 +727,110 @@ self.page_sizers = [] self.button_sizers = [] self.button_flags = [] - - - def add_buttons(self, sizer): - """Add the buttons to the sizer. - - @param sizer: A sizer object. - @type sizer: wx.Sizer instance - """ - - # Create a horizontal layout for the buttons. - button_sizer = wx.BoxSizer(wx.HORIZONTAL) - sizer.Add(button_sizer, 0, wx.ALIGN_RIGHT|wx.ALL, 0) - - # The apply button. - if self.button_apply: - button = buttons.ThemedGenBitmapTextButton(self, -1, None, "Apply") - button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.apply, wx.BITMAP_TYPE_ANY)) - button.SetToolTipString("Apply the operation") - button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) - self.Bind(wx.EVT_BUTTON, self.apply, button) + self.button_apply = [] + + + def add_page(self, panel, apply_button=True): + """Add a new page to the wizard. + + @param panel: The page to add to the wizard. + @type panel: wx.Panel instance + @keyword apply_button: A flag which if true will show the apply button for that page. + @type apply_button: bool + """ + + # Store the page. + self.pages.append(panel) + + # Store a new sizer for the page and its buttons. + self.page_sizers.append(wx.BoxSizer(wx.VERTICAL)) + self.main_sizer.Add(self.page_sizers[-1], 1, wx.ALL|wx.EXPAND, 0) + + # Add the sizer for the top half. + top_sizer = wx.BoxSizer(wx.VERTICAL) + self.page_sizers[-1].Add(top_sizer, 1, wx.ALL|wx.EXPAND, 0) + + # Add the page to the top sizer. + top_sizer.Add(panel, 1, wx.ALL|wx.EXPAND, 0) + + # Add the sizer for the wizard buttons. + self.button_sizers.append(wx.BoxSizer(wx.HORIZONTAL)) + self.page_sizers[-1].Add(self.button_sizers[-1], 0, wx.ALIGN_RIGHT|wx.ALL, 0) + + # Store the apply button flag. + self.button_apply.append(apply_button) + + + def build_buttons(self): + """Construct the buttons for all pages of the wizard.""" + + # The number of pages. + num_pages = len(self.pages) + + # Loop over each page. + for i in range(num_pages): + # The back button (only for multi-pages, after the first). + if num_pages > 1 and i > 0: + # Create the button. + button = buttons.ThemedGenBitmapTextButton(self, -1, None, "Back") + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.back, wx.BITMAP_TYPE_ANY)) + button.SetToolTipString("Return to the previous page") + self.button_sizers[i].Add(button, 0, wx.ADJUST_MINSIZE, 0) + self.Bind(wx.EVT_BUTTON, self.go_back, button) + + # Spacer. + self.button_sizers[i].AddSpacer(5) + + # The apply button. + if self.button_apply[i]: + # Create the button. + button = buttons.ThemedGenBitmapTextButton(self, -1, None, "Apply") + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.apply, wx.BITMAP_TYPE_ANY)) + button.SetToolTipString("Apply the operation") + self.button_sizers[i].Add(button, 0, wx.ADJUST_MINSIZE, 0) + self.Bind(wx.EVT_BUTTON, self.pages[i].apply, button) + + # Spacer. + self.button_sizers[i].AddSpacer(5) + + # The next button (only for multi-pages, excluding the last). + if num_pages > 1 and i < num_pages - 1: + # Create the button. + button = buttons.ThemedGenBitmapTextButton(self, -1, None, "Next") + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.next, wx.BITMAP_TYPE_ANY)) + button.SetToolTipString("Move to the next page") + self.button_sizers[i].Add(button, 0, wx.ADJUST_MINSIZE, 0) + self.Bind(wx.EVT_BUTTON, self.go_forward, button) + + # Spacer. + self.button_sizers[i].AddSpacer(5) + + # The OK button (only for single pages). + if num_pages == 1: + button = buttons.ThemedGenBitmapTextButton(self, -1, None, "OK") + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.ok, wx.BITMAP_TYPE_ANY)) + button.SetToolTipString("Accept the operation") + self.button_sizers[i].Add(button, 0, wx.ADJUST_MINSIZE, 0) + self.Bind(wx.EVT_BUTTON, self.pages[i].ok, button) + + # The finish button (only for the last page with multi-pages). + if num_pages > 1 and i == num_pages - 1: + button = buttons.ThemedGenBitmapTextButton(self, -1, None, "Finish") + button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.ok, wx.BITMAP_TYPE_ANY)) + button.SetToolTipString("Accept the operation") + self.button_sizers[i].Add(button, 0, wx.ADJUST_MINSIZE, 0) + self.Bind(wx.EVT_BUTTON, self.pages[i].ok, button) # Spacer. - button_sizer.AddSpacer(5) - - # The OK button. - if self.button_ok: - button = buttons.ThemedGenBitmapTextButton(self, -1, None, "OK") - button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.ok, wx.BITMAP_TYPE_ANY)) - button.SetToolTipString("Accept the operation") - button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) - self.Bind(wx.EVT_BUTTON, self.ok, button) - - # Spacer. - button_sizer.AddSpacer(15) - - # The cancel button. - if self.button_cancel: + self.button_sizers[i].AddSpacer(15) + + # The cancel button. button = buttons.ThemedGenBitmapTextButton(self, -1, None, "Cancel") button.SetBitmapLabel(wx.Bitmap(paths.icon_22x22.cancel, wx.BITMAP_TYPE_ANY)) button.SetToolTipString("Abort the operation") - button_sizer.Add(button, 0, wx.ADJUST_MINSIZE, 0) - self.Bind(wx.EVT_BUTTON, self.cancel, button) - - - def add_page(self, panel): - """Add a new page to the wizard. - - @param panel: The page to add to the wizard. - @type panel: wx.Panel instance - """ - - # Store the page. - self.pages.append(panel) - - # Store a new sizer for the page and its buttons. - self.page_sizers.append(wx.BoxSizer(wx.VERTICAL)) - self.main_sizer.Add(self.page_sizers[-1], 1, wx.ALL|wx.EXPAND, 0) - - # Add the sizer for the top half. - top_sizer = wx.BoxSizer(wx.VERTICAL) - self.page_sizers[-1].Add(top_sizer, 1, wx.ALL|wx.EXPAND, 0) - - # Add the page to the top sizer. - top_sizer.Add(panel, 1, wx.ALL|wx.EXPAND, 0) - - # Add the sizer for the wizard buttons. - self.button_sizers.append(wx.BoxSizer(wx.HORIZONTAL)) - self.page_sizers[-1].Add(self.button_sizers[-1]) + self.button_sizers[i].Add(button, 0, wx.ADJUST_MINSIZE, 0) + self.Bind(wx.EVT_BUTTON, self.pages[i].cancel, button) + def display_page(self, i): @@ -821,6 +854,9 @@ def run(self): """Execute the wizard.""" + + # Build the buttons for the entire wizard. + self.build_buttons() # Show the wizard. self.ShowModal()