~ubuntu-branches/ubuntu/trusty/python-enable/trusty

« back to all changes in this revision

Viewing changes to enthought/enable/qt4/gl.py

  • Committer: Bazaar Package Importer
  • Author(s): Varun Hiremath
  • Date: 2011-04-05 21:54:28 UTC
  • mfrom: (1.1.5 upstream)
  • mto: (8.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20110405215428-1x2wtubz3ok2kxaq
Tags: upstream-3.4.1
ImportĀ upstreamĀ versionĀ 3.4.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#------------------------------------------------------------------------------
 
2
# Copyright (c) 2011, Enthought, Inc.
 
3
# All rights reserved.
 
4
#
 
5
# This software is provided without warranty under the terms of the BSD
 
6
# license included in enthought/LICENSE.txt and may be redistributed only
 
7
# under the conditions described in the aforementioned license.  The license
 
8
# is also available online at http://www.enthought.com/licenses/BSD.txt
 
9
# Thanks for using Enthought open source!
 
10
#------------------------------------------------------------------------------
 
11
 
 
12
import pyglet
 
13
pyglet.options['shadow_window'] = False
 
14
 
 
15
from enthought.traits.api import Bool, Instance
 
16
from enthought.kiva.gl import CompiledPath, GraphicsContext
 
17
 
 
18
from base_window import BaseGLWindow
 
19
from scrollbar import NativeScrollBar
 
20
 
 
21
class Window(BaseGLWindow):
 
22
    def _create_gc(self, size, pix_format=None):
 
23
        """ Create a GraphicsContext instance.
 
24
        """
 
25
        from pyglet.gl import Context
 
26
 
 
27
        gc = GraphicsContext((size[0]+1, size[1]+1))
 
28
        self._pyglet_gl_context = Context()
 
29
        gc.gl_init()
 
30
        gc.translate_ctm(0.5, 0.5)
 
31
        return gc
 
32
 
 
33
    def _init_gc(self):
 
34
        """ Gives the GC a chance to initialize itself before components perform layout
 
35
        and draw.  This is called every time through the paint loop.
 
36
        """
 
37
        self._pyglet_gl_context.set_current()
 
38
        self.control.makeCurrent()
 
39
        super(Window, self)._init_gc()
 
40
 
 
41
    def _paint(self, event=None):
 
42
        """ Paint the contents of the window.
 
43
        """
 
44
        if self.control is None:
 
45
            return
 
46
 
 
47
        size = self._get_control_size()
 
48
        self._size = tuple(size)
 
49
        self._gc = self._create_gc(size)
 
50
        self._init_gc()
 
51
        if hasattr(self.component, "do_layout"):
 
52
            self.component.do_layout()
 
53
        self._gc.clear(self.bgcolor_)
 
54
        self.component.draw(self._gc, view_bounds=(0, 0, size[0], size[1]))
 
55
        self._update_region = []
 
56
 
 
57
def font_metrics_provider():
 
58
    from enthought.kiva.fonttools import Font
 
59
    gc = GraphicsContext((1, 1))
 
60
    gc.set_font(Font())
 
61
    return gc
 
62
 
 
63
# EOF