File: kiva_render_panel.py

package info (click to toggle)
python-enable 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,280 kB
  • ctags: 13,899
  • sloc: cpp: 48,447; python: 28,502; ansic: 9,004; makefile: 315; sh: 44
file content (54 lines) | stat: -rw-r--r-- 1,607 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import wx

from enable.savage.svg.backends.kiva import renderer
from enable.savage.svg.document import SVGDocument
from enable.api import Container, Window
from traits.api import Instance, Float

class KivaContainer(Container):

    document = Instance(SVGDocument)
    zoom = Float(100.0)

    def draw(self, gc, view_bounds=None, mode="default"):
        gc.clear()
        if not self.document:
            gc.show_text_at_point("No Document", 20, 20)
            return

        with gc:
            # SVG origin is upper right with y positive is down. argh.
            # Set up the transforms to fix this up.
            gc.translate_ctm(0, gc.height())
            # zoom percentage
            scale = float(self.zoom) / 100.0
            gc.scale_ctm(scale, -scale)
            self.document.render(gc)



class RenderPanel(wx.Window):
    def __init__(self, parent, document=None):
        super(RenderPanel, self).__init__(parent)

        self.document = document
        if self.document is not None:
            self.document.renderer = renderer

        self.container = KivaContainer(document=self.document)

        size = wx.Size(200,200)
        if document is not None:
            size = document.getSize()

        self._window = Window( parent=self, size=size, component=self.container )
        self.control = self._window.control
        self._parent = parent
        
        self.SetBackgroundColour([int(255*c) for c in self.container.bgcolor_])        

    def GetBestSize(self):
        if not self.document:
            return (-1,-1)

        return self.document.getSize()