]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/rightalign.py
1 # -*- coding: iso-8859-1 -*-
2 #----------------------------------------------------------------------
3 # Name: wxPython.lib.rightalign
4 # Purpose: A class derived from wxTextCtrl that aligns the text
5 # on the right side of the control, (except when editing.)
7 # Author: Josu Oyanguren
9 # Created: 19-October-2001
11 # Copyright: (c) 2001 by Total Control Software
12 # Licence: wxWindows license
13 #----------------------------------------------------------------------
14 # 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
16 # o 2.5 compatability update.
17 # o Added deprecation warning.
19 # 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
21 # o wxRightTextCtrl -> RightTextCtrl
25 Some time ago, I asked about how to right-align
26 wxTextCtrls. Answer was that it is not supported. I forgot it.
28 Just a week ago, one of my clients asked me to have numbers right
29 aligned. (Indeed it was that numbers MUST be right aligned).
31 So the game begun. Hacking, hacking, ...
33 At last, i succeed. Here is some code that someone may find
34 useful. ubRightTextCtrl is right-aligned when you are not editing, but
35 left-aligned if it has focus.
37 Hope this can help someone, as much as this list helps me.
40 Ubera Servicios Informaticos.
43 P.S. This only works well on wxMSW.
49 #----------------------------------------------------------------------
53 ##############################################################\
54 # THIS MODULE IS DEPRECATED |
56 # This control still functions, but it is deprecated because |
57 # wx.TextCtrl now supports the wx.TE_RIGHT style flag |
58 ##############################################################/
63 warnings
.warn(warningmsg
, DeprecationWarning, stacklevel
=2)
65 #----------------------------------------------------------------------
67 class RightTextCtrl(wx
.TextCtrl
):
68 def __init__(self
, parent
, id, *args
, **kwargs
):
69 wx
.TextCtrl
.__init
__(self
, parent
, id, *args
, **kwargs
)
70 self
.Bind(wx
.EVT_KILL_FOCUS
, self
.OnKillFocus
)
71 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
73 def OnPaint(self
, event
):
75 dc
.SetFont(self
.GetFont())
77 text
= self
.GetValue()
78 textwidth
, textheight
= dc
.GetTextExtent(text
)
79 dcwidth
, dcheight
= self
.GetClientSize()
81 y
= (dcheight
- textheight
) / 2
82 x
= dcwidth
- textwidth
- 2
85 fclr
= self
.GetForegroundColour()
87 fclr
= wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_GRAYTEXT
)
89 dc
.SetTextForeground(fclr
)
91 dc
.SetClippingRegion((0, 0), (dcwidth
, dcheight
))
92 dc
.DrawText(text
, (x
, y
))
96 markwidth
= dc
.GetTextExtent(toofat
)[0]
97 dc
.SetPen(wx
.Pen(dc
.GetBackground().GetColour(), 1, wx
.SOLID
))
98 dc
.DrawRectangle((0,0), (markwidth
, dcheight
))
99 dc
.SetPen(wx
.Pen(wx
.RED
, 1, wx
.SOLID
))
100 dc
.SetBrush(wx
.TRANSPARENT_BRUSH
)
101 dc
.DrawRectangle((1, 1), (dcwidth
-2, dcheight
-2))
102 dc
.DrawText(toofat
, (1, y
))
105 def OnKillFocus(self
, event
):
106 if not self
.GetParent(): return