Beispiel #1
0
    def create_combobox ( self, parent, editable = False ):
        """ Returns an adapted wx.Choice or wx.ComboBox control.
        """
        if editable:
            return control_adapter(
                wx.ComboBox( as_toolkit_control( parent ), -1, '',
                             wx.Point( 0, 0 ), wx.Size( -1, -1 ), [],
                             style = wx.CB_DROPDOWN )
            )

        return control_adapter(
            wx.Choice( as_toolkit_control( parent ), -1,
                       wx.Point( 0, 0 ), wx.Size( -1, -1 ), [] )
        )
Beispiel #2
0
 def create_separator ( self, parent, is_vertical = True ):
     """ Returns an adapted separator line control.
     """
     return control_adapter(
         wx.StaticLine( as_toolkit_control( parent ), -1,
                        style = separator_map[ is_vertical ] )
     )
Beispiel #3
0
 def create_label ( self, parent, label = '', align = 'left' ):
     """ Returns an adapted label control.
     """
     return control_adapter(
         wx.StaticText( as_toolkit_control( parent ), -1, label,
                        style = horizontal_alignment_styles[ align ] )
     )
Beispiel #4
0
    def create_text_input ( self, parent, read_only = False, password = False,
                                  handle_enter = False, multi_line = False,
                                  align = 'left' ):
        """ Returns an adapted single or mutli line text input control.
        """
        style = input_horizontal_alignment_styles[ align ]

        if read_only:
            style |= wx.TE_READONLY

        if password:
            style |= wx.TE_PASSWORD

        if handle_enter:
            style |= wx.TE_PROCESS_ENTER

        if multi_line:
            style |= wx.TE_MULTILINE

        if read_only and multi_line:
            style |= wx.NO_BORDER

        return control_adapter(
            wx.TextCtrl( as_toolkit_control( parent ), -1, '', style = style )
        )
Beispiel #5
0
 def create_panel ( self, parent ):
     """ Returns an adapted panel control.
     """
     return control_adapter(
         FacetsUIPanel( as_toolkit_control( parent ), -1,
                        style = wx.CLIP_CHILDREN )
     )
Beispiel #6
0
    def create_scrolled_panel ( self, parent ):
        """ Returns a panel that can scroll its contents.
        """
        tuisp = FacetsUIScrolledPanel( as_toolkit_control( parent ) )
        tuisp.SetScrollRate( 1, 1 )

        return control_adapter( tuisp )
Beispiel #7
0
    def hook_events ( self, ui, control, events = None, handler = None,
                      drop_target = None ):
        """ Hooks all specified events for all controls in a UI so that they
            can be routed to the correct event handler.
        """
        wx_control = as_toolkit_control( control )
        if isinstance( wx_control, wx.Window ):
            if events is None:
                events = (
                   wx.wxEVT_LEFT_DOWN, wx.wxEVT_LEFT_DCLICK, wx.wxEVT_LEFT_UP,
                   wx.wxEVT_MIDDLE_DOWN, wx.wxEVT_MIDDLE_DCLICK,
                   wx.wxEVT_MIDDLE_UP, wx.wxEVT_RIGHT_DOWN,
                   wx.wxEVT_RIGHT_DCLICK, wx.wxEVT_RIGHT_UP, wx.wxEVT_MOTION,
                   wx.wxEVT_ENTER_WINDOW, wx.wxEVT_LEAVE_WINDOW,
                   wx.wxEVT_MOUSEWHEEL, wx.wxEVT_PAINT
                )
                wx_control.SetDropTarget( PythonDropTarget(
                                    DragHandler( ui = ui, control = wx_control ) ) )
            elif events == 'keys':
                events = ( wx.wxEVT_CHAR, )

            if handler is None:
                handler = ui.route_event

            id            = wx_control.GetId()
            event_handler = wx.EvtHandler()
            connect       = event_handler.Connect

            for event in events:
                connect( id, id, event, handler )

            wx_control.PushEventHandler( event_handler )

        for child in control.children:
            self.hook_events( ui, child, events, handler, drop_target )
Beispiel #8
0
def check_parent ( parent ):
    """ Verifies that the parent object is a QWidget; otherwise it returns None
        to prevent constructor errors from Qt.
    """
    parent = as_toolkit_control( parent )

    if isinstance( parent, QWidget ):
        return parent

    return None
Beispiel #9
0
 def create_groupbox_layout ( self, is_vertical, parent, label, owner ):
     """ Returns a new GUI toolkit neutral vertical layout manager for a
         groupbox.
     """
     gbox       = wx.StaticBox( as_toolkit_control( parent ), -1, label )
     gbox.owner = owner
     return (
         None,
         layout_adapter(
             wx.StaticBoxSizer( gbox, orientation_map[ is_vertical ] ),
             is_vertical
         )
     )
Beispiel #10
0
    def create_control(self, parent):
        """ Creates the control.
        """
        parent = as_toolkit_control(parent)
        self.control = control = wx.ComboBox(
            parent, -1, self.value, wx.Point(0, 0), wx.Size(-1, -1), self.history, style=wx.CB_DROPDOWN
        )
        wx.EVT_COMBOBOX(parent, control.GetId(), self._update_value)
        wx.EVT_KILL_FOCUS(control, self._kill_focus)
        wx.EVT_TEXT_ENTER(parent, control.GetId(), self._update_text_value)
        if self.auto_set:
            wx.EVT_TEXT(parent, control.GetId(), self._update_value_only)

        return control
Beispiel #11
0
    def create_control ( self, parent, tab_stop = False, handle_keys = False ):
        """ Returns an adapted control suitable for use as a base for creating
            custom controls.
        """
        style = wx.FULL_REPAINT_ON_RESIZE

        if tab_stop:
            style |= wx.TAB_TRAVERSAL

        if handle_keys:
            style |= wx.WANTS_CHARS

        control = WxControl( as_toolkit_control( parent ), -1, style = style )
        control.accepts_focus = tab_stop or handle_keys

        return control_adapter( control )
Beispiel #12
0
    def prepare ( self, parent ):
        """ Finishes setting up the editor.
        """
        name = self.extended_name
        if name != 'None':
            if self.is_list:
                name += '[]'

            self.context_object.on_facet_set( self._update_editor,
                                              name, dispatch = 'ui' )

        if not self.is_toolkit_neutral:
            parent = as_toolkit_control( parent )

        self.init( parent )
        self._sync_values()
        self.update_editor()
        self._set_adapter( self )
Beispiel #13
0
    def add_separator(self, parent):
        """ Adds a separator to the layout.
        """
        cols = 1
        layout = self.layout
        if isinstance(layout, wx.GridSizer):
            cols = layout.GetCols()

        if self.is_vertical:
            style = wx.LI_HORIZONTAL
            flags = wx.EXPAND | wx.TOP | wx.BOTTOM
        else:
            style = wx.LI_VERTICAL
            flags = wx.EXPAND | wx.LEFT | wx.RIGHT

        parent = as_toolkit_control(parent)

        for i in xrange(cols):
            layout.Add(wx.StaticLine(parent, -1, style=style), 0, flags, 2)
Beispiel #14
0
    def create_frame ( self, parent, style, title = '' ):
        """ Returns an adapted top-level window frame/dialog control. The
            *style* parameter is a set containing values from the following
            list:
            - 'frame':      The result should be a normal top-level window.
            - 'dialog':     The result should be a dialog window.
            - 'resizable':  The window should have a resize border.
            - 'simple':     The window should have a simple border.
            - 'none':       The window should not have any border.
            - 'min_max':    The window should have minimize/maximize buttons.
            - 'float':      The window should float on top of its parent.
            - 'no_taskbar': The window should not appear on the system taskbar.
        """
        flags = (wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX)

        if 'frame' in style:
            flags |= (wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER)
        elif 'min_max' in style:
            flags |= (wx.MINIMIZE_BOX | wx.MAXIMIZE_BOX)

        if 'resizable' in style:
            flags |= wx.RESIZE_BORDER
        elif 'simple' in style:
            flags = wx.SIMPLE_BORDER
        elif 'none' in style:
            flags = wx.BORDER_NONE

        if 'float' in style:
            flags |= wx.FRAME_FLOAT_ON_PARENT

        if 'no_taskbar' in style:
            flags |= wx.FRAME_NO_TASKBAR

        klass = wx.Dialog
        if 'dialog' not in style:
            klass  = wx.Frame
            flags |= wx.CLIP_CHILDREN

        return control_adapter(
            klass( as_toolkit_control( parent ), -1, title, style = flags )
        )
Beispiel #15
0
 def create_checkbox ( self, parent, label = '' ):
     """ Returns an adapted checkbox control.
     """
     return control_adapter(
         wx.CheckBox( as_toolkit_control( parent ), -1, label )
     )
Beispiel #16
0
 def create_button ( self, parent, label = '' ):
     """ Returns an adapted button.
     """
     return control_adapter(
         wx.Button( as_toolkit_control( parent ), -1, label )
     )