Example #1
0
 def _screen_graphics_paint ( self, event ):
     """ Handles an overlap screen graphics widget getting a paint event.
     """
     sg = self._sg_control
     if sg is not None:
         painter = painter_for( sg.control )
         painter.drawPixmap( 0, 0, sg._pixmap )
Example #2
0
    def _get_temp_graphics ( self ):
        global TempGraphics

        if TempGraphics is None:
            pixmap       = QPixmap( 1, 1 )
            TempGraphics = QtGraphics(
                painter_for( pixmap ), _temp_graphics = True, _pixmap = pixmap
            )

        return TempGraphics
Example #3
0
    def _get_screen_graphics ( self ):
        from facets.ui.toolkit import toolkit

        if self._screen_graphics is None:
            control = self.control
            pixmap  = QPixmap.grabWindow( control.winId() )
            self._sg_control = sg = toolkit().create_control( self )
            sg._pixmap = pixmap
            dx, dy     = self.size
            sg.bounds  = ( 0, 0, dx, dy )
            sg.set_event_handler( paint = self._screen_graphics_paint )
            painter = painter_for( pixmap )
            painter._control = sg.control
            self._screen_graphics = (
                QtGraphics( painter, bitmap = pixmap ), 0, 0
            )

        return self._screen_graphics
Example #4
0
    def drag ( self, data, type = None, request = 'copy', image = None ):
        """ Initiates a drag operation with the specified *data*. If *type* is
            **None**, the control will try to determine the kind of data being
            dragged from the data itself. Other than **None**, the legal values
            for *type* are: 'color', 'image', 'text', 'html', 'files', 'urls'
            and 'object'.

            *Request* specifies whether the data is to be copied ('copy'),
            moved ('move') or linked ('link'), with the default request being to
            copy the data.

            *Image* specifies an ImageResource image to be used while dragging
            to provide the user with some indication of what is being dragged.
            This may not be supported with all UI back-ends. If not supported,
            the *image* value is treated as *None*. A value of *None* indicates
            that the default drag image should be used.

            The result is a string indicating the action taken by the receiver
            (if any) of the data at the completion of the drag and drop
            operation. The possible values are: 'copy', 'move', 'link' and
            'ignore'.
        """
        if type is None:
            if isinstance( data, basestring ):
                type = 'text'
            elif isinstance( data, QColor ):
                type = 'color'
            elif isinstance( data, AnImageResource ):
                type = 'image'
                data = data.image
            elif isinstance( data, SequenceTypes ):
                type = 'urls'
                data = [ QUrl( item ) for item in data ]
            else:
                type = 'object'

        mime_data = getattr( self, '_drag_%s' % type,
                             self._drag_object )( data )
        drag      = QDrag( self.control )
        drag.setMimeData( mime_data )

        # Set up the drag image (if one was specified):
        if isinstance( image, AnImageResource ):
            bitmap   = image.bitmap
            idx, idy = image.width, image.height
            ratio    = max( idx, idy ) / 128.0
            if ratio > 1.0:
                # Create a scaled version of the image if it is larger than the
                # maximum nominal size:
                sdx = int( round( idx / ratio ) )
                sdy = int( round( idy / ratio ) )
                pm  = QPixmap( sdx, sdy )
                pm.fill( QColor( 0, 0, 0, 0 ) )
                painter = painter_for( pm )
                painter.drawPixmap( 0, 0, sdx, sdy, bitmap, 0, 0, idx, idy )
                painter.end()
                bitmap, idx, idy = pm, sdx, sdy

            drag.setPixmap( bitmap )
            drag.setHotSpot( QPoint( idx / 2, idy / 2 ) )

        return RequestAction[ drag.exec_() ]
Example #5
0
 def _get_temp_graphics ( self ):
     return QtGraphics( painter_for( QPixmap( 1, 1 ) ),
                        _temp_graphics = True )
Example #6
0
 def _get_graphics ( self ):
     return QtGraphics( painter_for( self.control ) )