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 _slot_clicked ( self, handler, connect ): from facets.extra.helper.debug import log_if log_if( 2, 'clicked!' ) if connect: QObject.connect( self.control, SIGNAL( 'clicked()' ), handler ) else: QObject.disconnect( self.control, SIGNAL( 'clicked()' ), handler )
def hook_events ( self, ui, control, events = None, handler = None ): """ Hooks all specified events for all controls in a UI so that they can be routed to the correct event handler. """ # fixme: Implement this method. For now just log that is was called... from facets.extra.helper.debug import log_if log_if( 2, ('hook_events( ui = %s, control = %s, events = %s, ' 'handler = %s )' % ( ui, control, events, handler )) )
def shrink_wrap ( self ): """ Resizes the control so that it fits snugly around its child controls. """ # fixme: Not sure how to do this for Qt. Maybe we do not have to do # anything? For now we'll just print a message to log the call... from facets.extra.helper.debug import log_if log_if( 2, 'shrink_wrap called for: %s' % self.control )
def _slot_choose ( self, handler, connect ): from facets.extra.helper.debug import log_if log_if( 2, 'choose!' ) if connect: QObject.connect( self.control, SIGNAL( 'activated(QString)' ), handler ) else: QObject.disconnect( self.control, SIGNAL( 'activated(QString)' ), handler )
def processEvent ( self, object, event ): """ Handles a Qt event by mapping it to a corresponding controller method (if any). """ # Try to convert the Qt event type to a GUI toolkit neutral name: name = EventMap.get( event.type(), None ) if name is not None: handlers = [] # Check to see if this is a mouse related event, which requires some # additional processing: if name in MouseEvents: handlers.extend( self.event_map.get( 'mouse', NoHandlers ) ) # Now check to see if the name is also mouse button related, # which requires some additional qualification: if name in MouseButtons: # Try to get the appropriate mouse button name: prefix = MousePrefix.get( event.button(), None ) if prefix is None: return None # Create a composite name composed of the button name and # the event type: name = prefix + name # See if we have any methods to handle the event: handlers.extend( self.event_map.get( name, NoHandlers ) ) if len( handlers ) > 0: from facets.extra.helper.debug import log_if log_if( 2 , 'event: %s' % name ) # Create the right kind of adapted event: if name in DragDropEvents: adapter = QtDrag( event, name = name ) else: adapter = QtUIEvent( event, name = name, control_adapter = adapted_control( object ) ) # Invoke the handler with the adapted version of the event: for handler in handlers: handler( adapter ) # Return whether or not we completely handled the event or not: if name in NeverHandledEvents: adapter.handled = False return adapter return None
def _slot_text_enter ( self, handler, connect ): from facets.extra.helper.debug import log_if log_if( 2, 'text enter!' ) control = self.control if isinstance( control, QComboBox ): control = control.lineEdit() if connect: QObject.connect( control, SIGNAL( 'editingFinished()' ), handler ) else: QObject.disconnect( control, SIGNAL( 'editingFinished()' ), handler )
def _slot_text_change ( self, handler, connect ): from facets.extra.helper.debug import log_if log_if( 2, 'text change!' ) control = self.control if isinstance( control, QComboBox ): control = control.lineEdit() signal = 'textEdited(QString)' if isinstance( control, QTextEdit ): signal = 'textChanged()' if connect: QObject.connect( control, SIGNAL( signal ), handler ) else: QObject.disconnect( control, SIGNAL( signal ), handler )
def resynch_editor ( self ): """ Resynchronizes the contents of the editor when the object facet changes externally to the editor. """ # To try and reduce the number of double updates caused by a new object # and synchronized view name being changed in response to the same # event, we check that either the object or its displayed view has been # changed before preceding with the update: view = None value = self.value if isinstance( value, HasFacets ): view = self.view_for( value, self.item_for( value ) ) if (value is self._last_value) and (view is self._last_view): return self._last_value, self._last_view = value, view panel = self._panel if panel is not None: # Dispose of the previous contents of the panel: if self._ui is not None: self._ui.dispose() self._ui = None else: panel.destroy_children() panel.layout = None # Create the new content for the panel: stretch = 0 if not isinstance( value, HasFacets ): str_value = '' if value is not None: str_value = self.str_value control = toolkit().create_label( panel, str_value ) is_control = True else: context = value.facet_context() handler = None if isinstance( value, Handler ): handler = value context.setdefault( 'context', self.object ) context.setdefault( 'context_handler', self.ui.handler ) self._ui = ui = view.ui( context, panel, 'editor', value.facet_view_elements(), handler, self.factory.id ) control = ui.control is_control = ui.is_control self.scrollable = ui._scrollable ui.parent = self.ui if view.resizable or view.scrollable or ui._scrollable: stretch = 1 # Add the control to the layout: layout = panel.layout if is_control: if layout is None: layout = toolkit().create_box_layout() layout.add( control, stretch = stretch ) else: layout = control panel.layout = layout panel.update() # It is possible that this instance editor is embedded at some level # in a ScrolledWindow. If so, we need to inform the window that the # size of the editor's contents have (potentially) changed: # NB: There is a typo in the wxPython 2.6 code that prevents the # 'SendSizeEvent' from working correctly, so we just skip it. # fixme: Make this GUI toolkit neutral... if False: ###not is_wx26: while ((parent is not None) and (not isinstance( parent(), wx.ScrolledWindow ))): parent = parent.parent if parent is not None: parent().SendSizeEvent() from facets.extra.helper.debug import log_if log_if( 2, panel )
def _set_scroll_horizontal ( self, can_scroll ): from facets.extra.helper.debug import log_if log_if( 2, "control_adapter._set_scroll_horizontal called" )
def _get_is_panel ( self ): # fixme: I'm not sure what the Qt equivalent of a panel is... from facets.extra.helper.debug import log_if log_if( 2, 'is_panel query for: %s' % self.control ) return (self.control.__class__ is QWidget)