def ui_dialog(ui, parent, style): """ Creates a live GUI toolkit neutral user interface for a specified UI object. """ if ui.owner is None: ui.owner = LiveWindow() ui.owner.init(ui, parent, style) ui.control = control = ui.owner.control ui.control._parent = parent try: ui.prepare_ui() except: ui.control.destroy() # fixme: Who sets 'ui' and why?... ui.control().ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position(ui.info) restore_window(ui, is_popup=(style in Popups)) from facets.extra.helper.debug import log_if log_if(2, ui.control) control.update() control.modal = style == MODAL control.activate()
def display_ui(ui, parent, style): """Display the UI.""" ui.owner.init(ui, parent, style) ui.control = ui.owner.control ui.control._parent = parent try: ui.prepare_ui() except: ui.control.setParent(None) ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position(ui.info) restore_window(ui) if style == BaseDialog.NONMODAL: ui.control.show() else: ui.control.setWindowModality(QtCore.Qt.ApplicationModal) ui.control.exec_()
def ui_dialog(ui, parent, is_modal): """ Creates a wxPython dialog box for a specified UI object. Changes are not immediately applied to the underlying object. The user must click **Apply** or **OK** to apply changes. The user can revert changes by clicking **Revert** or **Cancel**. """ if ui.owner is None: ui.owner = ModalDialog() ui.owner.init(ui, parent, is_modal) ui.control = ui.owner.control ui.control._parent = parent try: ui.prepare_ui() except: ui.control.Destroy() ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position(ui.info) restore_window(ui) if is_modal: ui.control.ShowModal() else: ui.control.Show()
def ui_dialog(ui, parent, style): """ Creates a live wxPython user interface for a specified UI object. """ if ui.owner is None: ui.owner = LiveWindow() ui.owner.init(ui, parent, style) ui.control = ui.owner.control ui.control._parent = parent try: ui.prepare_ui() except: ui.control.Destroy() ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position(ui.info) restore_window(ui, is_popup=(style in Popups)) ui.control.Layout() # Check if the control is already being displayed modally. This would be # the case if after the window was displayed, some event caused the ui to # get rebuilt (typically when the user fires the 'updated' event on the ui # ). In this case, calling ShowModal again leads to the parent window # hanging even after the control has been closed by clicking OK or Cancel # (maybe the modal mode isn't ending?) if style == MODAL and not ui.control.IsModal(): ui.control.ShowModal() else: ui.control.Show()
def ui_dialog ( ui, parent, is_modal ): """ Creates a wxPython dialog box for a specified UI object. Changes are not immediately applied to the underlying object. The user must click **Apply** or **OK** to apply changes. The user can revert changes by clicking **Revert** or **Cancel**. """ if ui.owner is None: ui.owner = ModalDialog() ui.owner.init( ui, parent, is_modal ) ui.control = ui.owner.control ui.control._parent = parent try: ui.prepare_ui() except: ui.control.Destroy() ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position( ui.info ) restore_window( ui ) if is_modal: ui.control.ShowModal() else: ui.control.Show()
def display_ui(ui, parent, style): """Display the UI.""" ui.owner.init(ui, parent, style) ui.control = ui.owner.control ui.control._parent = parent try: ui.prepare_ui() except: ui.control.setParent(None) ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position(ui.info) restore_window(ui) if style == BaseDialog.NONMODAL: ui.control.show() else: ui.control.setWindowModality(QtCore.Qt.WindowModal) ui.control.exec_()
def ui_dialog ( ui, parent, is_modal ): """ Creates a GUI toolkit neutral dialog box for a specified UI object. Changes are not immediately applied to the underlying object. The user must click **Apply** or **OK** to apply changes. The user can revert changes by clicking **Revert** or **Cancel**. """ if ui.owner is None: ui.owner = ModalDialog() ui.owner.init( ui, parent, is_modal ) ui.control = ui.owner.control # fixme: Why do we need this?... ui.control._parent = parent try: ui.prepare_ui() except: ui.control.destroy() ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position( ui.info ) restore_window( ui ) ui.control.modal = is_modal ui.control.visible = True
def display_ui(ui, parent, style): """Display the UI.""" ui.owner.init(ui, parent, style) ui.control = ui.owner.control ui.control.parent = parent try: ui.prepare_ui() except: ui.control.setParent(None) ui.control.ui = None ui.control = None ui.owner = None ui.result = False raise ui.handler.position(ui.info) restore_window(ui) if style != BaseDialog.NONMODAL: ui.control.setModal(True) if parent is not None: parent.addWindow(ui.control) else: SimpleApplication.ui = ui.control muntjac(SimpleApplication, nogui=True, debug=True)
def ui_wizard ( ui, parent ): """ Creates a wizard-based wxPython user interface for a specified UI object. """ # Create the copy of the 'context' we will need while editing: context = ui.context ui._context = context new_context = {} for name, value in context.items(): if value is not None: new_context[ name ] = value.clone_traits() else: new_context[ name ] = None ui.context = new_context # Now bind the context values to the 'info' object: ui.info.bind_context() # Create the wxPython wizard window: title = ui.view.title if title == '': title = DefaultTitle ui.control = wizard = wz.Wizard( parent, -1, title ) # Create all of the wizard pages: pages = [] editor_pages = [] info = ui.info shadow_group = ui.view.content.get_shadow( ui ) min_dx = min_dy = 0 # Create a dictionary mapping each contained group in shadow_group to # its id and enabled_when fields. group_fields_mapping = {} for group in shadow_group.get_content(): # FIXME: When the group's id or enabled_when or visible_when is # set, the "fill_panel_for_group" will create a new Panel to hold the # contents of the group (instead of adding them to the page itself). # This leads to an incorrect sizing of the panel(not sure why # actually): example would be 'test_ui2.py' in # Traits/integrationtests/ui. In addition, # it leads to incorrect bindings (of the id) on the UIInfo object: # the id is bound to the GroupEditor created in "fill_panel.." # instead of the PageGroupEditor created here. # A simple solution is to clear out these fields before calling # "fill_panel_for_group", and then reset these traits. group_fields_mapping[group] = (group.id, group.enabled_when) (group.id, group.enabled_when) = ('', '') page = UIWizardPage( wizard, editor_pages ) pages.append( page ) fill_panel_for_group( page, group, ui ) # Size the page correctly, then calculate cumulative minimum size: sizer = page.GetSizer() sizer.Fit( page ) size = sizer.CalcMin() min_dx = max( min_dx, size.GetWidth() ) min_dy = max( min_dy, size.GetHeight() ) # If necessary, create a PageGroupEditor and attach it to the right # places: (group.id, group.enabled_when) = group_fields_mapping[group] if group.id or group.enabled_when: page.editor = editor = PageGroupEditor( control = page ) if group.id: page.id = group.id editor_pages.append( page ) info.bind( page.id, editor ) if group.enabled_when: ui.add_enabled( group.enabled_when, editor ) # Size the wizard correctly: wizard.SetPageSize( wx.Size( min_dx, min_dy ) ) # Set up the wizard 'page changing' event handler: wz.EVT_WIZARD_PAGE_CHANGING( wizard, wizard.GetId(), page_changing ) # Size the wizard and the individual pages appropriately: prev_page = pages[0] wizard.FitToPage( prev_page ) # Link the pages together: for page in pages[1:]: page.SetPrev( prev_page ) prev_page.SetNext( page ) prev_page = page # Finalize the display of the wizard: try: ui.prepare_ui() except: ui.control.Destroy() ui.control.ui = None ui.control = None ui.result = False raise # Position the wizard on the display: ui.handler.position( ui.info ) # Restore the user_preference items for the user interface: restore_window( ui ) # Run the wizard: if wizard.RunWizard( pages[0] ): # If successful, apply the modified context to the original context: original = ui._context for name, value in ui.context.items(): if value is not None: original[ name ].copy_traits( value ) else: original[ name ] = None ui.result = True else: ui.result = False # Clean up loose ends, like restoring the original context: save_window( ui ) ui.finish() ui.context = ui._context ui._context = {}
def ui_wizard(ui, parent): """ Creates a wizard-based wxPython user interface for a specified UI object. """ # Create the copy of the 'context' we will need while editing: context = ui.context ui._context = context new_context = {} for name, value in context.items(): if value is not None: new_context[name] = value.clone_traits() else: new_context[name] = None ui.context = new_context # Now bind the context values to the 'info' object: ui.info.bind_context() # Create the wxPython wizard window: title = ui.view.title if title == '': title = DefaultTitle ui.control = wizard = wz.Wizard(parent, -1, title) # Create all of the wizard pages: pages = [] editor_pages = [] info = ui.info shadow_group = ui.view.content.get_shadow(ui) min_dx = min_dy = 0 # Create a dictionary mapping each contained group in shadow_group to # its id and enabled_when fields. group_fields_mapping = {} for group in shadow_group.get_content(): # FIXME: When the group's id or enabled_when or visible_when is # set, the "fill_panel_for_group" will create a new Panel to hold the # contents of the group (instead of adding them to the page itself). # This leads to an incorrect sizing of the panel(not sure why # actually): example would be 'test_ui2.py' in # Traits/integrationtests/ui. In addition, # it leads to incorrect bindings (of the id) on the UIInfo object: # the id is bound to the GroupEditor created in "fill_panel.." # instead of the PageGroupEditor created here. # A simple solution is to clear out these fields before calling # "fill_panel_for_group", and then reset these traits. group_fields_mapping[group] = (group.id, group.enabled_when) (group.id, group.enabled_when) = ('', '') page = UIWizardPage(wizard, editor_pages) pages.append(page) fill_panel_for_group(page, group, ui) # Size the page correctly, then calculate cumulative minimum size: sizer = page.GetSizer() sizer.Fit(page) size = sizer.CalcMin() min_dx = max(min_dx, size.GetWidth()) min_dy = max(min_dy, size.GetHeight()) # If necessary, create a PageGroupEditor and attach it to the right # places: (group.id, group.enabled_when) = group_fields_mapping[group] if group.id or group.enabled_when: page.editor = editor = PageGroupEditor(control=page) if group.id: page.id = group.id editor_pages.append(page) info.bind(page.id, editor) if group.enabled_when: ui.add_enabled(group.enabled_when, editor) # Size the wizard correctly: wizard.SetPageSize(wx.Size(min_dx, min_dy)) # Set up the wizard 'page changing' event handler: wz.EVT_WIZARD_PAGE_CHANGING(wizard, wizard.GetId(), page_changing) # Size the wizard and the individual pages appropriately: prev_page = pages[0] wizard.FitToPage(prev_page) # Link the pages together: for page in pages[1:]: page.SetPrev(prev_page) prev_page.SetNext(page) prev_page = page # Finalize the display of the wizard: try: ui.prepare_ui() except: ui.control.Destroy() ui.control.ui = None ui.control = None ui.result = False raise # Position the wizard on the display: ui.handler.position(ui.info) # Restore the user_preference items for the user interface: restore_window(ui) # Run the wizard: if wizard.RunWizard(pages[0]): # If successful, apply the modified context to the original context: original = ui._context for name, value in ui.context.items(): if value is not None: original[name].copy_traits(value) else: original[name] = None ui.result = True else: ui.result = False # Clean up loose ends, like restoring the original context: save_window(ui) ui.finish() ui.context = ui._context ui._context = {}