Ejemplo n.º 1
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory

        # Initialize factory provided level of detail settings:
        self.lod         = factory.facet_value( 'lod' )
        self.maximum_lod = factory.facet_value( 'maximum_lod' )
        self.is_vertical = (factory.orientation == 'vertical')
        self.theme       = factory.theme

        # Initialize and create the underlying stacker control:
        self.adapter = control = toolkit().create_scrolled_panel( parent )
        stacker      = toolkit().create_control( control, handle_keys = True )
        control.content = self.stacker = stacker

        # Initialize the StackContext object provided to each stack item:
        self.context.facet_set(
            graphics = stacker.temp_graphics,
            control  = stacker,
            owner    = self
        )

        # Initialize the various control event handlers:
        control.set_event_handler(
            size = self._size
        )

        stacker.set_event_handler(
            paint     = self._paint,
            mouse     = self._mouse,
            key_press = self._key,
            key       = self._key
        )

        # Allow the editor to expand both horizontally and vertically:
        control.size_policy = ( 'expanding', 'expanding' )
        control.min_size    = ( 40, 40 )

        # Set up the additional 'list items changed' event handler needed for
        # a list based facet:
        self.context_object.on_facet_set(
            self.update_editor_item, self.extended_name + '_items?',
            dispatch = 'ui'
        )

        # Set up the item filter:
        self.sync_value( factory.filter, 'filter', 'from' )

        # Set up selection synchronization:
        self.sync_value( factory.selected, 'selected', 'both' )
        if factory.selected != '':
            self.on_facet_set( self._selected_modified, 'items:selected' )

        # Set up external change synchronization:
        self.sync_value( factory.changed, 'changed', 'from' )

        # Add the developer specified tooltip information:
        self.set_tooltip()
Ejemplo n.º 2
0
    def exception ( self, type, value, traceback,
                    msg = '', offset = 0, debug_frame = None ):
        """ Handles a program exception or break point.
        """
        # Get the correct status message and execution frames:
        if value is None:
            msg    = msg or 'Called the FBI'
            frames = [ StackFrame( frame )
                       for frame in stack( 15 )[ offset + 2: ] ]
        else:
            msg    = 'Exception: %s' % str( value )
            frames = [ StackFrame( frame )
                       for frame in getinnerframes( traceback, 15 ) ]
            frames.reverse()
            frames.extend( [ StackFrame( frame )
                             for frame in stack( 15 )[3:] ] )

        # Make sure we don't handle and more exceptions for the moment:
        self.enabled = False

        # Set the new debugging context data:
        self.msg         = msg
        self.frames      = frames
        self.debug_frame = debug_frame

        # Activate the user interface containing all of the debugger tools:
        self.tools.activate()

        # Stop execution here until the developer resumes execution:
        self.active = True
        toolkit().event_loop()
        self.active = False

        # Resume execution and re-enable the debugger:
        self.enabled = (not self.has_quit)
Ejemplo n.º 3
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        super( SimpleEditor, self ).init( parent )

        factory = self.factory
        if factory.evaluate is None:
            self.adapter = control = toolkit().create_combobox( parent )
            control.add_items( self.names )
            control.set_event_handler( choose = self.update_object )
        else:
            self.adapter = control = toolkit().create_combobox( parent, True )
            control.add_items( self.names )
            control.set_event_handler(
                choose     = self.update_object,
                text_enter = self.update_text_object,
                lose_focus = self.on_kill_focus
            )

            if (not factory.is_grid_cell) and factory.auto_set:
                control.set_event_handler(
                    text_change = self.update_text_object
                )

        self._no_enum_update = 0

        self.set_tooltip()
Ejemplo n.º 4
0
    def _create_image_grid ( self, parent ):
        """ Populates a specified window with a grid of image buttons.
        """
        # Create the panel to hold the ImageControl buttons:
        self.adapter = adapter = toolkit().create_panel( parent )

        # Create the layout manager:
        layout = toolkit().create_grid_layout( -1, self.factory.cols )

        # Add the set of all possible choices:
        factory   = self.factory
        mapping   = factory._mapping
        cur_value = self.value
        ics       = []
        for name in self.factory._names:
            value   = mapping[ name ]
            ic      = ImageControl(
                          image      = '%s%s%s' % ( factory.prefix,
                                                    name, factory.suffix ),
                          selectable = True,
                          selected   = (value == cur_value),
                          _value     = value,
                          parent     = adapter
                      )
            ics.append( ic )
            layout.add( ic(), left = 2, right = 2, top = 2, bottom = 2 )

            self.set_tooltip( ic() )

        self.image_controls = ics

        # Finish setting up the layout manager:
        adapter.layout = layout
        adapter.shrink_wrap()
Ejemplo n.º 5
0
    def rebuild_editor ( self ):
        """ Rebuilds the contents of the editor whenever the original factory
            object's **values** facet changes.
        """
        # Clear any existing content:
        panel  = self.adapter
        layout = panel.layout
        if layout is not None:
            layout.clear()

        # Get the current facet value:
        cur_name = self.str_value

        # Create a sizer to manage the radio buttons:
        names   = self.names
        mapping = self.mapping
        n       = len( names )
        cols    = self.factory.cols
        rows    = ( n + cols - 1 ) / cols
        incr    = [ n / cols ] * cols
        rem     = n % cols
        for i in range( cols ):
            incr[i] += (rem > i)

        incr[-1] = -(reduce( lambda x, y: x + y, incr[:-1], 0 ) - 1)
        if cols > 1:
            layout = toolkit().create_grid_layout( 0, cols, 2, 4 )
        else:
            layout = toolkit().create_box_layout()

        # Add the set of all possible choices:
        ### style = wx.RB_GROUP
        index = 0
        for i in range( rows ):
            for j in range( cols ):
                if n > 0:
                    name    = label = names[ index ]
                    label   = self.string_value( label, capitalize )
                    control = toolkit().create_radio_button( panel, label )
                    ### control = wx.RadioButton( panel, -1, label, style = style )
                    control._value = mapping[ name ]
                    ### style         = 0
                    control.checked = (name == cur_name)
                    control.set_event_handler( dialed = self.update_object )
                    self.set_tooltip( control )
                    index += incr[j]
                    n     -= 1
                else:
                    control         = toolkit().create_radio_button( panel )
                    control._value  = ''
                    control.visible = False

                layout.add( control, top = 5, fill = False )

        # Set-up the layout:
        panel.layout = layout
        panel.shrink_wrap()
Ejemplo n.º 6
0
    def error ( self, excp ):
        """ Handles an error that occurs while setting the object's facet value.
        """
        self._text.background_color = ErrorColor
        self._text.refresh()
        toolkit().beep()

        if self._error is None:
            self._error     = True
            self.ui.errors += 1
Ejemplo n.º 7
0
    def exit_ui ( self ):
        """ Exits the user interface.
        """
        # Release no longer needed data being held by the debugger:
        self.debug_frame     = None
        self.frames          = []
        self.local_variables = []
        self.frame_locals    = {}

        # Terminate the debugger's event loop and allow the program to resume
        # execution:
        toolkit().event_loop( 0 )
Ejemplo n.º 8
0
    def __init__ ( self, dock_control, use_mouse = False, **facets ):
        """ Initializes the object.
        """
        super( DockWindowShell, self ).__init__( **facets )

        control      = dock_control.control
        self.control = shell = toolkit().create_frame( control.root_parent(),
                                   shell_style, dock_control.name )
        shell.icon             = FrameIcon
        shell.background_color = WindowColor

        shell.set_event_handler( close = self._on_close )

        theme = dock_control.theme
        self.dock_window = dw = DockWindow(
            shell,
            auto_close = True,
            theme      = theme ).set(
            style      = 'tab'
        )

        shell.layout = layout = toolkit().create_box_layout()
        layout.add( dw.control, stretch = 1, fill = True )

        if use_mouse:
            x, y = shell.mouse_position
        else:
            x, y = dock_control.control.screen_position

        dx, dy = control.size
        tis    = theme.tab.image_slice
        tc     = theme.tab.content
        tdy    = theme.tab_active.image_slice.dy
        dx    += (tis.xleft + tc.left + tis.xright  + tc.right)
        dy    += (tis.xtop  + tc.top  + tis.xbottom + tc.bottom + tdy)

        self.add_control( dock_control )

        # Set the correct window size and position, accounting for the tab size
        # and window borders:
        shell.bounds  = ( x, y, dx, dy )
        cdx, cdy      = shell.client_size
        ex_dx         = dx - cdx
        ex_dy         = dy - cdy
        shell.bounds  = ( x - (ex_dx / 2) - tis.xleft - tc.left,
                          y - ex_dy + (ex_dx / 2) - tdy - tis.xtop - tc.top,
                          dx + ex_dx, dy + ex_dy )
        shell.visible = True
Ejemplo n.º 9
0
    def _pop_up_text ( self ):
        """ Pop-up a text control to allow the user to enter a value using
            the keyboard.
        """
        control     = self.adapter
        factory     = self.factory
        self._text  = text = toolkit().create_text_input( control(),
                                 password     = factory.password,
                                 handle_enter = True,
                                 align        = self.alignment )
        text.value  = self.str_value
        slice       = self.image_slice
        wdx, wdy    = control.client_size
        tdx, tdy    = text.size
        text.bounds = ( slice.xleft,
                        ((wdy + slice.xtop - slice.xbottom - tdy) / 2) + 1,
                        wdx - slice.xleft - slice.xright,
                        tdy )
        text.selection = ( -1, -1 )
        text.set_focus()

        text.set_event_handler(
            lose_focus = self._text_completed,
            key        = self._key_entered,
            text_enter = self.update_object
        )

        if factory.auto_set and (not factory.is_grid_cell):
            text.set_event_handler( text_change = self.update_object )
Ejemplo n.º 10
0
    def create_editor ( self, parent ):
        """ Creates the editor control (a button).
        """
        self._button = button = toolkit().create_button( parent )
        button.set_event_handler( clicked = self.edit_instance )

        return button
Ejemplo n.º 11
0
 def _layout_set ( self, layout ):
     """ Handles the 'layout' facet being changed.
     """
     if layout is None:
         self.control.layout = None
     else:
         self.control.layout = toolkit().layout_adapter_for( layout )
Ejemplo n.º 12
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        if WebView is not None:
            from PyQt4.QtWebKit import QWebPage

            self.control = control = WebView( parent, self )

            factory = self.factory
            self.sync_value( factory.title, 'title', 'to' )
            control.connect( control, SIGNAL( 'titleChanged(QString)' ),
                             self._on_title_modified )

            url     = factory.url
            alt_url = factory.alt_url
            if (url != '') or (alt_url != ''):
                self.sync_value( url,     'url',     'to' )
                self.sync_value( alt_url, 'alt_url', 'to' )
                control.page().setLinkDelegationPolicy(
                    QWebPage.DelegateAllLinks )
                control.connect( control, SIGNAL( 'linkClicked(QUrl)' ),
                                 self._on_link_clicked )
        else:
            self.renders_html = False
            self.adapter      = toolkit().create_text_input( parent,
                                           read_only = True, multi_line = True )

        self.set_tooltip()
Ejemplo n.º 13
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        # Create the control:
        self.adapter = control = toolkit().create_control( parent )
        control.min_size = ( 150, 150 )

        # Set up the event handlers:
        control.set_event_handler(
            paint       = self._paint,
            left_down   = self._left_down,
            left_dclick = self._left_dclick,
            left_up     = self._left_up,
            middle_down = self._middle_down,
            middle_up   = self._middle_up,
            right_down  = self._right_down,
            right_up    = self._right_up,
            motion      = self._motion,
            wheel       = self._mouse_wheel,
            size        = self._size
        )
        if self.factory.allow_drop:
            control.drop_target = self

        self.sync_value( self.factory.selected, 'selected', 'both' )

        # Set the tooltip:
        self.set_tooltip()
Ejemplo n.º 14
0
    def create_control ( self ):
        """ Creates and returns the underlying toolkit neutral control used to
            implement the window.
        """
        control = toolkit().create_control( self.parent,
            tab_stop    = self.tab_stop,
            handle_keys = self.handle_keys
        )
        control.set_event_handler(
            paint         = self._paint,
            size          = self.resize,
            left_down     = self._left_down,
            left_up       = self._left_up,
            left_dclick   = self._left_dclick,
            middle_down   = self._middle_down,
            middle_up     = self._middle_up,
            middle_dclick = self._middle_dclick,
            right_down    = self._right_down,
            right_up      = self._right_up,
            right_dclick  = self._right_dclick,
            motion        = self._motion,
            enter         = self._enter,
            leave         = self._leave,
            wheel         = self._wheel
        )
        control.drop_target = self

        return control
Ejemplo n.º 15
0
    def __getstate__ ( self ):
        ftc = toolkit().from_toolkit_color

        return {
            'image':      None if self.image is None else str( self.image ),
            'bg_color':   ftc( self.bg_color ),
            'text_color': ftc( self.text_color ),
            'lfdx':       self.lfdx,
            'mfdx':       self.mfdx,
            'rfdx':       self.rfdx,
            'sdx':        self.sdx,
            'tfdy':       self.tfdy,
            'mfdy':       self.mfdy,
            'bfdy':       self.bfdy,
            'sdy':        self.sdy,
            'lfx':        self.lfx,
            'mfx':        self.mfx,
            'rfx':        self.rfx,
            'tfy':        self.tfy,
            'mfy':        self.mfy,
            'bfy':        self.bfy,
            'hsx':        self.hsx,
            'vsy':        self.vsy,
            'lcdx':       self.lcdx,
            'rcdx':       self.rcdx,
            'tcdy':       self.tcdy,
            'bcdy':       self.bcdy
        }
Ejemplo n.º 16
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory       = self.factory
        self.evaluate = factory.evaluate
        self.sync_value( factory.evaluate_name, 'evaluate', 'from' )

        multi_line = self.multi_line
        if (not factory.multi_line) or factory.password:
            multi_line = False

        self.scrollable    = multi_line
        self._handle_enter = (factory.enter_set and (not multi_line))
        self.adapter       = adapter = toolkit().create_text_input( parent,
                                           password     = factory.password,
                                           handle_enter = self._handle_enter,
                                           multi_line   = multi_line )
        adapter.value = self.str_value
        adapter.set_event_handler( lose_focus = self.update_object )

        if self._handle_enter:
            adapter.set_event_handler( text_enter = self.update_object )
            if not factory.auto_set:
                adapter.set_event_handler( text_change = self.check_update )

        if factory.auto_set:
            adapter.set_event_handler( text_change = self.update_object )

        self.set_tooltip()
Ejemplo n.º 17
0
    def __init__ ( self, name = '', search_path = None, bitmap = None,
                   width = None, height = None, **facets ):
        """ Initializes the object.
        """
        self.name = name

        if (width is not None) and (height is not None) and (bitmap is None):
            from facets.api import toolkit

            bits         = '\x00' * (width * height * 4)
            bitmap       = toolkit().create_bitmap( bits, width, height )
            bitmap._bits = bits

        if bitmap is not None:
            self.bitmap = bitmap

        if search_path is not None:
            self.search_path = search_path
        else:
            search_path, name = split( name )
            if search_path != '':
                self.name        = name
                self.search_path = [ search_path ]
            else:
                self.search_path = [ resource_path() ]

        super( MImageResource, self ).__init__( **facets )
Ejemplo n.º 18
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        # Make sure the slider and track image slices have been initialized:
        self._factory_tip_style_modified()
        self._factory_body_style_modified()
        self._factory_track_style_modified()

        # Create the control:
        self.adapter = control = toolkit().create_control(
            parent, tab_stop = self.factory.tab_stop
        )
        control.min_size = ( 100, 19 )

        # Set up the event handlers:
        control.set_event_handler(
            paint     = self._paint,
            get_focus = self._set_focus,
            left_down = self._left_down,
            left_up   = self._left_up,
            motion    = self._motion,
            wheel     = self._mouse_wheel,
            enter     = self._enter_window,
            leave     = self._leave_window,
            size      = self._resize
        )

        # Initialize widest tip size seen so far:
        self._tsz = 0

        # Set the tooltip:
        self.has_tooltip = self.set_tooltip()
Ejemplo n.º 19
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        super( RadioEditor, self ).init( parent )

        # Create a panel to hold all of the radio buttons:
        self.adapter = toolkit().create_panel( parent )
        self.rebuild_editor()
Ejemplo n.º 20
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory

        # Establish the range of the slider:
        low, high, increment = factory.low, factory.high, factory.increment
        if high <= low:
            low = high = None
            range      = self.object.facet( self.name ).handler
            if isinstance( range, Range ):
                low, high = range._low, range._high

            if low is None:
                if high is None:
                    high = 1.0
                low = high - 1.0
            elif high is None:
                high = low + 1.0

        # Establish the slider increment:
        if increment <= 0.0:
            if isinstance( low, int ):
                increment = 1.0
            else:
                increment = pow( 10, int( log10( ( high - low ) / 1000.0 ) ) )

        # Save the values we calculated:
        self.set( low = low, high = high, increment = increment )

        # Synchronize with any dynamically specified range values:
        self.sync_value( factory.low_name,       'low',       'from' )
        self.sync_value( factory.high_name,      'high',      'from' )
        self.sync_value( factory.increment_name, 'increment', 'from' )

        # Create the control:
        self.adapter = control = toolkit().create_control( parent,
                                                           tab_stop = True )
        control.min_size = ( 30, 20 )

        # Set up the event handlers:
        control.set_event_handler(
            paint     = self._on_paint,
            get_focus = self._set_focus,
            left_down = self._left_down,
            left_up   = self._left_up,
            motion    = self._motion,
            wheel     = self._mouse_wheel,
            enter     = self._enter_window,
            leave     = self._leave_window,
            size      = self._resize
        )

        # Set the tooltip:
        if not self.set_tooltip():
            self._set_tooltip()
Ejemplo n.º 21
0
    def _rgba_color ( self, color ):
        """ Returns a standard (r,g,b,a) tuple representation of the specified
            GUI toolkit specific color.
        """
        result = toolkit().from_toolkit_color( color )
        if len( result ) == 4:
            return result

        return (result + ( 255, ))
Ejemplo n.º 22
0
    def __init__ ( self, parent, **facets ):
        """ Creates a new image control.
        """
        super( ImageButton, self ).__init__( **facets )

        # Calculate the size of the button:
        idx   = idy = tdx = tdy = 0
        image = self.image
        if image is not None:
            idx, idy, size = image.width, image.height, self.image_size
            if size > 0:
                idx_dy = max( idx, idy )
                if size != idx_dy:
                    self.image = image = image.scale( size / float( idx_dy ) )
                    idx, idy   = image.width, image.height

        self.control = control = toolkit().create_control( parent )

        if self.label != '':
            tdx, tdy = control.text_size( self.label )

        wp2 = self.width_padding  + 2
        hp2 = self.height_padding + 2

        if self.orientation == 'horizontal':
            self._ix = wp2
            spacing  = (idx > 0) * (tdx > 0) * 4
            self._tx = self._ix + idx + spacing
            dx       = idx + tdx + spacing
            dy       = max( idy, tdy )
            self._iy = hp2 + ((dy - idy) / 2)
            self._ty = hp2 + ((dy - tdy) / 2)
        else:
            self._iy = hp2
            spacing  = (idy > 0) * (tdy > 0) * 2
            self._ty = self._iy + idy + spacing
            dx       = max( idx, tdx )
            dy       = idy + tdy + spacing
            self._ix = wp2 + ((dx - idx) / 2)
            self._tx = wp2 + ((dx - tdx) / 2)

        # Finish initializing the control:
        self._dx            = dx + wp2 + wp2
        self._dy            = dy + hp2 + hp2
        control.size        = control.min_size = ( self._dx, self._dy )
        self.control._owner = self
        self._mouse_over    = self._button_down = False

        # Set up mouse event handlers:
        control.set_event_handler(
            enter     = self._on_enter_window,
            leave     = self._on_leave_window,
            left_down = self._on_left_down,
            left_up   = self._on_left_up,
            paint     = self._on_paint
        )
Ejemplo n.º 23
0
    def key_ctrl_c ( self, event ):
        """ Copy this item to the clipboard.

            The [[Ctrl-c]] command copies the item, including all textual
            annotations such as item ids and line numbers, to the clipboard.

            You can use the [[c]] command to copy the item without any
            annotations to the clipboard.
        """
        toolkit().clipboard().text = remove_color( self.text )
Ejemplo n.º 24
0
    def copy_clipboard ( self ):
        """ Copy the item to the clipboard.

            The [[c]] command copies the item, without any textual annotations
            such as item ids and line numbers, to the clipboard.

            You can use the [[Ctrl-c]] command to copy the item including all
            textual annotations to the clipboard.
        """
        toolkit().clipboard().text = remove_color( self.str( self.item ) )
Ejemplo n.º 25
0
    def str_color(self, color):
        """ Returns the text representation of a specified color value.
        """
        if isinstance(color, basestring):
            return color

        color = toolkit().from_toolkit_color(color)
        if (len(color) < 4) or (color[3] == 255):
            return "(%d,%d,%d)" % color[:3]

        return "(%d,%d,%d,%d)" % color
Ejemplo n.º 26
0
    def add ( self, item ):
        """ Adds an adapted item to the layout.
        """
        # We only need to do something here if the item being added is another
        # layout, since we only expect to have concrete controls as children.
        # So we create a panel and set its layout to the one we were given, and
        # so we will have the new panel as our child to layout:
        if isinstance( item, Layout ):
            toolkit().create_panel( self.image_panel.control ).layout = item

#-- EOF ------------------------------------------------------------------------
Ejemplo n.º 27
0
    def __str__ ( self ):
        """ Returns the string respresentation of the image slice.
        """
        ftc = toolkit().from_toolkit_color

        return ImageSliceTemplate % (
            self.image, ftc( self.bg_color ), ftc( self.text_color ), self.lfdx,
            self.mfdx, self.rfdx, self.sdx, self.tfdy, self.mfdy, self.bfdy,
            self.sdy, self.lfx, self.mfx, self.rfx, self.tfy, self.mfy,
            self.bfy, self.hsx, self.vsy, self.lcdx, self.rcdx, self.tcdy,
            self.bcdy
        )
Ejemplo n.º 28
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        self.adapter = control = toolkit().create_control( parent )
        control.set(
            size             = ( 1, 1 ),
            background_color = control.parent.background_color,
            size_policy      = ( 'expanding', 'expanding' )
        )

        control.set_event_handler( paint = self._on_paint )
Ejemplo n.º 29
0
    def init ( self, parent ):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        super( ListEditor, self ).init( parent )

        # Create a panel to hold all of the radio buttons:
        self.adapter = control = toolkit().create_listbox( parent )
        control.add_items( self.names )
        control.set_event_handler( selected = self.update_object )

        self.set_tooltip()
Ejemplo n.º 30
0
def set_color(editor):
    """  Sets the color of the specified color control.
    """
    color = editor.factory.to_toolkit_color(editor)
    control = editor.adapter
    control.background_color = color
    color = toolkit().from_toolkit_color(color)
    if (color[0] > 192) or (color[1] > 192) or (color[2] > 192):
        control.foreground_color = Black
    else:
        control.foreground_color = White

    control.refresh()