File: Chart.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (126 lines) | stat: -rw-r--r-- 3,734 bytes parent folder | download | duplicates (4)
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python

import wx

## import the installed version
from wx.lib.floatcanvas import NavCanvas, FloatCanvas

## import a local version
#import sys
#sys.path.append("../")
#from floatcanvas import NavCanvas, FloatCanvas


class DrawFrame(wx.Frame):

    """
    A frame used for the FloatCanvas Demo

    """

    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        self.CreateStatusBar()

        # Add the Canvas
        Canvas = NavCanvas.NavCanvas(self,-1,
                                     size = (500,500),
                                     ProjectionFun = None,
                                     Debug = 0,
                                     BackgroundColor = "White",
                                     ).Canvas
#        Canvas = FloatCanvas.FloatCanvas(self,-1,
#                                     size = (500,500),
#                                     ProjectionFun = None,
#                                     Debug = 0,
#                                     BackgroundColor = "White",
#                                     )

        self.Canvas = Canvas

        self.Canvas.Bind(FloatCanvas.EVT_MOTION, self.OnMove )
        self.Canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnLeft)


        # Some default sizes:
        self.LineHeight = 1
        self.TextWidth = 8
        self.SpaceWidth = 1
        self.Labels = ["SW Tasks", "Set RX Rf"] + ["A Row Label"]*16
        self.NumRows = len(self.Labels)

        self.BuildChartBackground()
        self.AddLabels()
        self.Show()
        Canvas.MinScale=28
        Canvas.MaxScale=28
        Canvas.ZoomToBB()

    def BuildChartBackground(self):
        Canvas = self.Canvas
        top = 0
        bottom = -(self.LineHeight * self.NumRows)
        width = self.SpaceWidth * 16 + self.TextWidth
        # put in the rows:
        for i in range(1, self.NumRows+1, 2):
            Canvas.AddRectangle((0-self.TextWidth, -i*self.LineHeight),
                                (width, self.LineHeight),
                                LineColor = None,
                                FillColor = "LightGrey",
                                FillStyle = "Solid",)

        # put a dashed line in every 1 unit:
        for i in range(16):
            Canvas.AddLine(((i*self.SpaceWidth,bottom),(i*self.SpaceWidth,top)),
                           LineColor = "Black",
                           LineStyle = "Dot",
                           # or "Dot", "ShortDash", "LongDash","ShortDash", "DotDash"
                           LineWidth    = 1,)
    def AddLabels(self):
        Canvas = self.Canvas

        for i, label in enumerate(self.Labels):
            Canvas.AddScaledText(label,
                                 ( -self.TextWidth, -(i+0.2)*self.LineHeight ),
                                 Size = 0.6 * self.LineHeight,
                                 Color = "Black",
                                 BackgroundColor = None,
                                 Family = wx.MODERN,
                                 Style = wx.NORMAL,
                                 Weight = wx.NORMAL,
                                 Underlined = False,
                                 Position = 'tl',
                                 )

    def OnMove(self, event):
        """
        Updates the status bar with the world coordinates

        """
        self.SetStatusText("%.2f, %.2f"%tuple(event.Coords))

    def OnLeft(self, event):
        """
        Prints various info about the state of the canvas to stdout

        """
        print("Scale is:", self.Canvas.Scale)


app = wx.App(False)
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
app.MainLoop()