1#!/usr/bin/env python
2
3import wx
4import os
5
6#----------------------------------------------------------------------
7class TestPanel(wx.Panel):
8    def __init__(self, parent, log):
9        self.log = log
10        wx.Panel.__init__(self, parent)
11
12        # Event Handlers
13        self.Bind(wx.EVT_PAINT, self.OnPaint)
14
15
16    def OnPaint(self, event):
17        dc = wx.GCDC(wx.PaintDC(self))
18        #dc = wx.PaintDC(self)
19        render = wx.RendererNative.Get()
20
21        # Setup Brushes
22        dc.SetBrush(wx.BLACK_BRUSH)
23        dc.SetTextForeground(wx.BLACK)
24        dc.SetFont(wx.NORMAL_FONT)
25
26        # The below code will use RendererNative to draw controls in
27        # various states. The wx.CONTROL_* flags are used to tell the
28        # Renderer which state to draw the control in.
29
30        # Draw some checkboxes
31        cb_lbl = "DrawCheckBoxes:"
32        dc.DrawText(cb_lbl, 15, 15)
33        render.DrawCheckBox(self, dc, (25, 35, 16, 16), wx.CONTROL_CHECKED)
34        render.DrawCheckBox(self, dc, (45, 35, 16, 16), wx.CONTROL_CHECKABLE)
35        render.DrawCheckBox(self, dc, (65, 35, 16, 16))
36        render.DrawCheckBox(self, dc, (85, 35, 16, 16), wx.CONTROL_CHECKED | wx.CONTROL_DISABLED)
37
38        lbl = "DrawRadioBitmap:"
39        dc.DrawText(lbl, 375, 15)
40        render.DrawRadioBitmap(self, dc, (385, 35, 16, 16), wx.CONTROL_CHECKED)
41        render.DrawRadioBitmap(self, dc, (405, 35, 16, 16), wx.CONTROL_CHECKABLE)
42        render.DrawRadioBitmap(self, dc, (425, 35, 16, 16))
43        render.DrawRadioBitmap(self, dc, (445, 35, 16, 16), wx.CONTROL_CHECKED | wx.CONTROL_DISABLED)
44
45        # Draw ComboBoxDropButton
46        xpos = self.GetTextExtent(cb_lbl)[0] + 40
47        cb_lbl = "DrawComboBoxDropButton:"
48        dc.DrawText(cb_lbl, xpos, 15)
49        render.DrawComboBoxDropButton(self, dc, (xpos + 4, 35, 24, 24), wx.CONTROL_CURRENT)
50        render.DrawComboBoxDropButton(self, dc, (xpos + 44, 35, 24, 24), wx.CONTROL_PRESSED)
51        render.DrawComboBoxDropButton(self, dc, (xpos + 84, 35, 24, 24), wx.CONTROL_CURRENT | wx.CONTROL_DISABLED)
52        render.DrawComboBoxDropButton(self, dc, (xpos + 124, 35, 24, 24), wx.CONTROL_PRESSED | wx.CONTROL_DISABLED)
53
54        # Draw DropArrow
55        da_lbl = "DrawDropArrow:"
56        dc.DrawText(da_lbl, 15, 80)
57        render.DrawDropArrow(self, dc, (15, 100, 24, 24), wx.CONTROL_CURRENT)
58        render.DrawDropArrow(self, dc, (35, 100, 24, 24), wx.CONTROL_PRESSED)
59        render.DrawDropArrow(self, dc, (55, 100, 24, 24), wx.CONTROL_CURRENT | wx.CONTROL_DISABLED)
60
61        # Draw HeaderButton
62        dc.DrawText("DrawHeaderButton:", xpos, 80)
63        # Set some extra options for drawing
64        opts = wx.HeaderButtonParams()
65        hb_lbl = "HeaderButton Selected"
66        opts.m_labelText = hb_lbl
67        render.DrawHeaderButton(self, dc, (xpos, 100, self.GetTextExtent(hb_lbl)[0] + 30, 16),
68                                wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_DOWN, opts)
69        hb_lbl = "HeaderButton Normal"
70        opts.m_labelText = hb_lbl
71        render.DrawHeaderButton(self, dc, (xpos, 125, self.GetTextExtent(hb_lbl)[0] + 30, 16),
72                                sortArrow=wx.HDR_SORT_ICON_UP, params=opts)
73
74        hb_lbl = "HeaderButton Current"
75        opts.m_labelText = hb_lbl
76        render.DrawHeaderButton(self, dc, (xpos, 150, self.GetTextExtent(hb_lbl)[0] + 30, 16),
77                                wx.CONTROL_CURRENT, params=opts)
78
79        # Draw ItemSelectionRect
80        isr_lbl = "DrawItemSelectionRect:"
81        dc.DrawText(isr_lbl, 15, 185)
82        render.DrawItemSelectionRect(self, dc, (15, 205, 40, 24), wx.CONTROL_SELECTED)
83        render.DrawItemSelectionRect(self, dc, (65, 205, 40, 24), wx.CONTROL_CURRENT)
84        render.DrawItemSelectionRect(self, dc, (115, 205, 40, 24), wx.CONTROL_FOCUSED)
85
86        # DrawPushButton
87        pb_lbl = "DrawPushButton:"
88        dc.DrawText(pb_lbl, 15, 255)
89        render.DrawPushButton(self, dc, (15, 275, 45, 24), wx.CONTROL_CURRENT)
90        render.DrawPushButton(self, dc, (70, 275, 45, 24), wx.CONTROL_PRESSED | wx.CONTROL_SELECTED)
91        render.DrawPushButton(self, dc, (125, 275, 45, 24), wx.CONTROL_ISDEFAULT)
92        render.DrawPushButton(self, dc, (180, 275, 45, 24), wx.CONTROL_CURRENT | wx.CONTROL_DISABLED)
93
94        # DrawTreeItemButton
95        ti_lbl = "DrawTreeItemButton:"
96        dc.DrawText(ti_lbl, 15, 330)
97        render.DrawTreeItemButton(self, dc, (15, 350, 16, 16))
98        render.DrawTreeItemButton(self, dc, (45, 350, 16, 16), wx.CONTROL_EXPANDED)
99
100        # DrawComboBox
101        dc.DrawText("DrawComboBox:", 270, 185)
102        render.DrawComboBox(self, dc, (270, 205, 100, 21))
103        render.DrawComboBox(self, dc, (270, 230, 100, 21), wx.CONTROL_DISABLED)
104        render.DrawComboBox(self, dc, (270, 255, 100, 21), wx.CONTROL_CURRENT)
105        render.DrawComboBox(self, dc, (270, 280, 100, 21), wx.CONTROL_PRESSED | wx.CONTROL_SELECTED)
106        render.DrawComboBox(self, dc, (270, 305, 100, 21), wx.CONTROL_FOCUSED)
107
108        # DrawChoice
109        dc.DrawText("DrawChoice:", 400, 185)
110        render.DrawChoice(self, dc, (400, 205, 100, 21))
111        render.DrawChoice(self, dc, (400, 230, 100, 21), wx.CONTROL_DISABLED)
112        render.DrawChoice(self, dc, (400, 255, 100, 21), wx.CONTROL_CURRENT)
113        render.DrawChoice(self, dc, (400, 280, 100, 21), wx.CONTROL_PRESSED | wx.CONTROL_SELECTED)
114        render.DrawChoice(self, dc, (400, 305, 100, 21), wx.CONTROL_FOCUSED)
115
116        # DrawTextCtrl
117        dc.DrawText("DrawTextCtrl:", 270, 350)
118        render.DrawTextCtrl(self, dc, (270, 375, 100, 21))
119        render.DrawTextCtrl(self, dc, (380, 375, 100, 21), wx.CONTROL_FOCUSED)
120
121#----------------------------------------------------------------------
122
123def runTest(frame, nb, log):
124    win = TestPanel(nb, log)
125    return win
126
127#----------------------------------------------------------------------
128
129overview = """<html><body>
130<h2><center>wx.RendererNative</center></h2>
131<p>wx.RendererNative is a class which virtualizes drawing. It abstracts the
132operations of drawing controls and allows you to draw say, a button, without
133caring about exactly how it is done, in a native and platform independant way.
134</p>
135
136<p>All drawing functions take some standard parameters:<p>
137<ul>
138<li><b>win</b>: is the window being drawn.</li>
139<li><b>dc</b>: is the wxDC to draw on. Only this device context should be used
140               for drawing.</li>
141<li><b>rect</b>: The bounding rectangle for the element to be drawn.</li>
142<li><b>flags</b>: The optional flags (none by default) which can be a
143                  combination of the wx.CONTROL_XXX constants.</li>
144</ul>
145
146<p><b>Note</b>: Each drawing function restores the wxDC attributes if it
147changes them, so it is safe to assume that the same pen, brush and colours
148that were active before the call to this function are still in effect
149after it.</p>
150</body></html>
151"""
152
153#----------------------------------------------------------------------
154
155if __name__ == '__main__':
156    import sys
157    import run
158    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
159