]>
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.
21 Some time ago, I asked about how to right-align
22 wxTextCtrls. Answer was that it is not supported. I forgot it.
24 Just a week ago, one of my clients asked me to have numbers right
25 aligned. (Indeed it was that numbers MUST be right aligned).
27 So the game begun. Hacking, hacking, ...
29 At last, i succeed. Here is some code that someone may find
30 useful. ubRightTextCtrl is right-aligned when you are not editing, but
31 left-aligned if it has focus.
33 Hope this can help someone, as much as this list helps me.
36 Ubera Servicios Informáticos.
39 P.S. This only works well on wxMSW.
45 #----------------------------------------------------------------------
49 ##############################################################\
50 # THIS MODULE IS DEPRECATED |
52 # This control still functions, but it is deprecated because |
53 # wx.TextCtrl now supports the wx.TE_RIGHT style flag |
54 ##############################################################/
59 warnings
.warn(warningmsg
, DeprecationWarning, stacklevel
=2)
61 #----------------------------------------------------------------------
63 class wxRightTextCtrl(wx
.TextCtrl
):
64 def __init__(self
, parent
, id, *args
, **kwargs
):
65 wx
.TextCtrl
.__init
__(self
, parent
, id, *args
, **kwargs
)
66 self
.Bind(wx
.EVT_KILL_FOCUS
, self
.OnKillFocus
)
67 self
.Bind(wx
.EVT_PAINT
, self
.OnPaint
)
69 def OnPaint(self
, event
):
71 dc
.SetFont(self
.GetFont())
73 text
= self
.GetValue()
74 textwidth
, textheight
= dc
.GetTextExtent(text
)
75 dcwidth
, dcheight
= self
.GetClientSize()
77 y
= (dcheight
- textheight
) / 2
78 x
= dcwidth
- textwidth
- 2
81 fclr
= self
.GetForegroundColour()
83 fclr
= wx
.SystemSettings_GetColour(wx
.SYS_COLOUR_GRAYTEXT
)
85 dc
.SetTextForeground(fclr
)
87 dc
.SetClippingRegion(0, 0, dcwidth
, dcheight
)
88 dc
.DrawText(text
, (x
, y
))
92 markwidth
= dc
.GetTextExtent(toofat
)[0]
93 dc
.SetPen(wx
.Pen(dc
.GetBackground().GetColour(), 1, wx
.SOLID
))
94 dc
.DrawRectangle((0,0), (markwidth
, dcheight
))
95 dc
.SetPen(wx
.Pen(wx
.RED
, 1, wx
.SOLID
))
96 dc
.SetBrush(wx
.TRANSPARENT_BRUSH
)
97 dc
.DrawRectangle((1, 1), (dcwidth
-2, dcheight
-2))
98 dc
.DrawText(toofat
, (1, y
))
101 def OnKillFocus(self
, event
):
102 if not self
.GetParent(): return