예제 #1
0
    def __init__(self, parent, wid=-1, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, **traits):
        AbstractWindow.__init__(self, **traits)
        self._timer          = None
        self._mouse_captured = False

        # Due to wx wonkiness, we don't reliably get cursor position from
        # a wx KeyEvent.  Thus, we manually keep track of when we last saw
        # the mouse and use that information instead.  These coordinates are
        # in the wx coordinate space, i.e. pre-self._flip_y().
        self._last_mouse_pos = (0, 0)

        # Create the delegate:
        self.control = control = self._create_control(parent, wid, pos, size)

        # Set up the 'erase background' event handler:
        wx.EVT_ERASE_BACKGROUND( control, self._on_erase_background )

        # Set up the 'paint' event handler:
        wx.EVT_PAINT( control, self._paint )
        wx.EVT_SIZE(  control, self._on_size )

        # Set up mouse event handlers:
        wx.EVT_LEFT_DOWN(     control, self._on_left_down )
        wx.EVT_LEFT_UP(       control, self._on_left_up )
        wx.EVT_LEFT_DCLICK(   control, self._on_left_dclick )
        wx.EVT_MIDDLE_DOWN(   control, self._on_middle_down )
        wx.EVT_MIDDLE_UP(     control, self._on_middle_up )
        wx.EVT_MIDDLE_DCLICK( control, self._on_middle_dclick )
        wx.EVT_RIGHT_DOWN(    control, self._on_right_down )
        wx.EVT_RIGHT_UP(      control, self._on_right_up )
        wx.EVT_RIGHT_DCLICK(  control, self._on_right_dclick )
        wx.EVT_MOTION(        control, self._on_mouse_move )
        wx.EVT_ENTER_WINDOW(  control, self._on_window_enter )
        wx.EVT_LEAVE_WINDOW(  control, self._on_window_leave )
        wx.EVT_MOUSEWHEEL(    control, self._on_mouse_wheel )

        # Handle key up/down events:
        wx.EVT_KEY_DOWN( control, self._on_key_pressed )
        wx.EVT_KEY_UP(   control, self._on_key_released )
        wx.EVT_CHAR(     control, self._on_character )

        # Attempt to allow wxPython drag and drop events to be mapped to
        # Enable drag events:

        # Handle window close and cleanup
        wx.EVT_WINDOW_DESTROY(control, self._on_close)

        if PythonDropTarget is not None:
            control.SetDropTarget( LessSuckyDropTarget( self ) )
            self._drag_over = []

        # In some cases, on the Mac at least, we never get an initial EVT_SIZE
        # since the initial size is correct. Because of this we call _on_size
        # here to initialize our bounds.
        self._on_size(None)

        return
예제 #2
0
    def __init__(self,
                 parent=None,
                 id=-1,
                 pos=None,
                 size=None,
                 config=None,
                 fullscreen=False,
                 resizable=True,
                 vsync=True,
                 **traits):
        """ **parent** is an unneeded argument with the pyglet backend, but
        we need to preserve compatibility with other AbstractWindow
        subclasses.
        """
        # TODO: Fix fact that other backends' Window classes use positional
        # arguments

        self.control = None
        AbstractWindow.__init__(self, **traits)
        self._mouse_captured = False

        # Due to wx wonkiness, we don't reliably get cursor position from
        # a wx KeyEvent.  Thus, we manually keep track of when we last saw
        # the mouse and use that information instead.  These coordinates are
        # in the wx coordinate space, i.e. pre-self._flip_y().
        self._last_mouse_pos = (0, 0)

        # Try to get antialiasing, both for quality rendering and for
        # reproducible results. For example, line widths are measured in the
        # X or Y directions rather than perpendicular to the line unless if
        # antialiasing is enabled.
        display = window.get_platform().get_default_display()
        screen = display.get_default_screen()
        if config is None:
            if self.enable_antialias:
                template_config = gl.Config(double_buffer=True,
                                            sample_buffers=True,
                                            samples=4)
            else:
                template_config = gl.Config(double_buffer=False)
            try:
                config = screen.get_best_config(template_config)
            except window.NoSuchConfigException:
                # Rats. No antialiasing.
                config = screen.get_best_config(gl.Config(double_buffer=True))
        # Create the underlying control.
        kwds = dict(config=config,
                    fullscreen=fullscreen,
                    resizable=resizable,
                    vsync=vsync)
        if size is not None and not fullscreen:
            kwds['width'], kwds['height'] = size
        self.control = PygletWindow(enable_window=self, **kwds)
        if pos is not None:
            self.control.set_location(*pos)

        return
예제 #3
0
파일: base_window.py 프로젝트: pib/enable
    def __init__(self, parent, wid=-1, pos=None, size=None, **traits):
        AbstractWindow.__init__(self, **traits)

        self._mouse_captured = False

        self.control = self._create_control(self)

        if pos is not None:
            self.control.move(*pos)

        if size is not None:
            self.control.resize(*size)
    def __init__(self, parent, wid=-1, pos=None, size=None, **traits):
        AbstractWindow.__init__(self, **traits)

        self._mouse_captured = False

        if isinstance(parent, QtWidgets.QLayout):
            parent = parent.parentWidget()
        self.control = self._create_control(parent, self)

        if pos is not None:
            self.control.move(*pos)

        if size is not None:
            self.control.resize(*size)
예제 #5
0
    def __init__(self, parent, wid=-1, pos=None, size=None, **traits):
        AbstractWindow.__init__(self, **traits)

        self._mouse_captured = False

        if isinstance(parent, QtGui.QLayout):
            parent = parent.parentWidget()
        self.control = self._create_control(parent, self)

        if pos is not None:
            self.control.move(*pos)

        if size is not None:
            self.control.resize(*size)
예제 #6
0
파일: window.py 프로젝트: GaZ3ll3/enable
    def __init__(self, parent=None, id=-1, pos=None, size=None, config=None,
        fullscreen=False, resizable=True, vsync=True, **traits):
        """ **parent** is an unneeded argument with the pyglet backend, but
        we need to preserve compatibility with other AbstractWindow
        subclasses.
        """
        # TODO: Fix fact that other backends' Window classes use positional
        # arguments

        self.control = None
        AbstractWindow.__init__(self, **traits)
        self._mouse_captured = False

        # Due to wx wonkiness, we don't reliably get cursor position from
        # a wx KeyEvent.  Thus, we manually keep track of when we last saw
        # the mouse and use that information instead.  These coordinates are
        # in the wx coordinate space, i.e. pre-self._flip_y().
        self._last_mouse_pos = (0, 0)

        # Try to get antialiasing, both for quality rendering and for
        # reproducible results. For example, line widths are measured in the
        # X or Y directions rather than perpendicular to the line unless if
        # antialiasing is enabled.
        display = window.get_platform().get_default_display()
        screen = display.get_default_screen()
        if config is None:
            if self.enable_antialias:
                template_config = gl.Config(double_buffer=True, sample_buffers=True,
                    samples=4)
            else:
                template_config = gl.Config(double_buffer=False)
            try:
                config = screen.get_best_config(template_config)
            except window.NoSuchConfigException:
                # Rats. No antialiasing.
                config = screen.get_best_config(gl.Config(double_buffer=True))
        # Create the underlying control.
        kwds = dict(config=config, fullscreen=fullscreen,
            resizable=resizable, vsync=vsync)
        if size is not None and not fullscreen:
            kwds['width'], kwds['height'] = size
        self.control = PygletWindow(enable_window=self, **kwds)
        if pos is not None:
            self.control.set_location(*pos)

        return
예제 #7
0
    def __init__(self,
                 parent,
                 wid=-1,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 **traits):
        AbstractWindow.__init__(self, **traits)
        self._timer = None
        self._mouse_captured = False

        # Due to wx wonkiness, we don't reliably get cursor position from
        # a wx KeyEvent.  Thus, we manually keep track of when we last saw
        # the mouse and use that information instead.  These coordinates are
        # in the wx coordinate space, i.e. pre-self._flip_y().
        self._last_mouse_pos = (0, 0)

        # Create the delegate:
        self.control = control = self._create_control(parent, wid, pos, size)

        # Figure out the pixel scale factor
        if self.high_resolution:
            self.base_pixel_scale = self.control.GetContentScaleFactor()

        # Set up the 'erase background' event handler:
        control.Bind(wx.EVT_ERASE_BACKGROUND, self._on_erase_background)

        # Set up the 'paint' event handler:
        control.Bind(wx.EVT_PAINT, self._paint)
        control.Bind(wx.EVT_SIZE, self._on_size)

        # Set up mouse event handlers:
        control.Bind(wx.EVT_LEFT_DOWN, self._on_left_down)
        control.Bind(wx.EVT_LEFT_UP, self._on_left_up)
        control.Bind(wx.EVT_LEFT_DCLICK, self._on_left_dclick)
        control.Bind(wx.EVT_MIDDLE_DOWN, self._on_middle_down)
        control.Bind(wx.EVT_MIDDLE_UP, self._on_middle_up)
        control.Bind(wx.EVT_MIDDLE_DCLICK, self._on_middle_dclick)
        control.Bind(wx.EVT_RIGHT_DOWN, self._on_right_down)
        control.Bind(wx.EVT_RIGHT_UP, self._on_right_up)
        control.Bind(wx.EVT_RIGHT_DCLICK, self._on_right_dclick)
        control.Bind(wx.EVT_MOTION, self._on_mouse_move)
        control.Bind(wx.EVT_ENTER_WINDOW, self._on_window_enter)
        control.Bind(wx.EVT_LEAVE_WINDOW, self._on_window_leave)
        control.Bind(wx.EVT_MOUSEWHEEL, self._on_mouse_wheel)

        # Handle key up/down events:
        control.Bind(wx.EVT_KEY_DOWN, self._on_key_pressed)
        control.Bind(wx.EVT_KEY_UP, self._on_key_released)
        control.Bind(wx.EVT_CHAR, self._on_character)

        # Attempt to allow wxPython drag and drop events to be mapped to
        # Enable drag events:

        # Handle window close and cleanup
        control.Bind(wx.EVT_WINDOW_DESTROY, self._on_close)

        if PythonDropTarget is not None:
            control.SetDropTarget(LessSuckyDropTarget(self))
            self._drag_over = []

        # In some cases, on the Mac at least, we never get an initial EVT_SIZE
        # since the initial size is correct. Because of this we call _on_size
        # here to initialize our bounds.
        self._on_size(None)