Пример #1
0
    def __init__(
            self,
            width=None,
            height=None,
            caption=None,
            resizable=False,
            fullscreen=False,
            display=None,
            screen=None):

        '''Create a window.

        All parameters are optional, and reasonable defaults are assumed
        where they are not specified.

        The `display`, `screen`, `config` and `context` parameters form
        a hierarchy of control: there is no need to specify more than
        one of these.  For example, if you specify `screen` the `display`
        will be inferred, and a default `config` and `context` will be
        created.

        `config` is a special case; it can be a template created by the
        user specifying the attributes desired, or it can be a complete
        `config` as returned from `Screen.get_matching_configs` or similar.

        The context will be active as soon as the window is created, as if
        `switch_to` was just called.

        :Parameters:
            `width` : int
                Width of the window, in pixels.  Not valid if `fullscreen`
                is True.  Defaults to 640.
            `height` : int
                Height of the window, in pixels.  Not valid if `fullscreen`
                is True.  Defaults to 480.
            `caption` : str or unicode
                Initial caption (title) of the window.  Defaults to
                ``sys.argv[0]``.
            `resizable` : bool
                If True, the window will be resizable.  Defaults to False.
            `fullscreen` : bool
                If True, the window will cover the entire screen rather
                than floating.  Defaults to False.
            `display` : `Display`
                The display device to use.  Useful only under X11.
            `screen` : `Screen`
                The screen to use, if in fullscreen.

        '''
        EventDispatcher.__init__(self)
        self._event_queue = deque()

        if not display:
            display = get_platform().get_default_display()

        if not screen:
            screen = display.get_default_screen()

        # Set these in reverse order to above, to ensure we get user
        # preference
        self._screen = screen
        self._display = display

        if fullscreen:
            if width is not None or height is not None:
                raise WindowException(
                    'Width and height cannot be specified with fullscreen.')
            self._windowed_size = self._default_width, self._default_height
            width = self._screen.width
            height = self._screen.height
        else:
            if width is None:
                width = self._default_width
            if height is None:
                height = self._default_height

        self._width = width
        self._height = height
        self._resizable = resizable
        self._fullscreen = fullscreen

        if caption is None:
            caption = sys.argv[0]
        self._caption = caption

        from pyglame import app
        app.windows.add(self)

        self._create()

        self.switch_to()
        self.activate()
Пример #2
0
 def dispatch_event(self, *args):
     if not self._enable_event_queue or self._allow_dispatch_event:
         EventDispatcher.dispatch_event(self, *args)
     else:
         self._event_queue.append(args)
Пример #3
0
 def dispatch_pending_events(self):
     while self._event_queue:
         event = self._event_queue.popleft()
         # pyglame event
         EventDispatcher.dispatch_event(self, *event)
Пример #4
0
    def __init__(self,
                 width=None,
                 height=None,
                 caption=None,
                 resizable=False,
                 fullscreen=False,
                 display=None,
                 screen=None):
        '''Create a window.

        All parameters are optional, and reasonable defaults are assumed
        where they are not specified.

        The `display`, `screen`, `config` and `context` parameters form
        a hierarchy of control: there is no need to specify more than
        one of these.  For example, if you specify `screen` the `display`
        will be inferred, and a default `config` and `context` will be
        created.

        `config` is a special case; it can be a template created by the
        user specifying the attributes desired, or it can be a complete
        `config` as returned from `Screen.get_matching_configs` or similar.

        The context will be active as soon as the window is created, as if
        `switch_to` was just called.

        :Parameters:
            `width` : int
                Width of the window, in pixels.  Not valid if `fullscreen`
                is True.  Defaults to 640.
            `height` : int
                Height of the window, in pixels.  Not valid if `fullscreen`
                is True.  Defaults to 480.
            `caption` : str or unicode
                Initial caption (title) of the window.  Defaults to
                ``sys.argv[0]``.
            `resizable` : bool
                If True, the window will be resizable.  Defaults to False.
            `fullscreen` : bool
                If True, the window will cover the entire screen rather
                than floating.  Defaults to False.
            `display` : `Display`
                The display device to use.  Useful only under X11.
            `screen` : `Screen`
                The screen to use, if in fullscreen.

        '''
        EventDispatcher.__init__(self)
        self._event_queue = deque()

        if not display:
            display = get_platform().get_default_display()

        if not screen:
            screen = display.get_default_screen()

        # Set these in reverse order to above, to ensure we get user
        # preference
        self._screen = screen
        self._display = display

        if fullscreen:
            if width is not None or height is not None:
                raise WindowException(
                    'Width and height cannot be specified with fullscreen.')
            self._windowed_size = self._default_width, self._default_height
            width = self._screen.width
            height = self._screen.height
        else:
            if width is None:
                width = self._default_width
            if height is None:
                height = self._default_height

        self._width = width
        self._height = height
        self._resizable = resizable
        self._fullscreen = fullscreen

        if caption is None:
            caption = sys.argv[0]
        self._caption = caption

        from pyglame import app
        app.windows.add(self)

        self._create()

        self.switch_to()
        self.activate()
Пример #5
0
 def dispatch_event(self, *args):
     if not self._enable_event_queue or self._allow_dispatch_event:
         EventDispatcher.dispatch_event(self, *args)
     else:
         self._event_queue.append(args)
Пример #6
0
 def dispatch_pending_events(self):
     while self._event_queue:
         event = self._event_queue.popleft()
         # pyglame event
         EventDispatcher.dispatch_event(self, *event)