2003-11-12 16:34:20 -05:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
# Name: wxPython.lib.rightalign
|
|
|
|
# Purpose: A class derived from wxTextCtrl that aligns the text
|
|
|
|
# on the right side of the control, (except when editing.)
|
|
|
|
#
|
|
|
|
# Author: Josu Oyanguren
|
|
|
|
#
|
|
|
|
# Created: 19-October-2001
|
|
|
|
# RCS-ID: $Id$
|
|
|
|
# Copyright: (c) 2001 by Total Control Software
|
|
|
|
# Licence: wxWindows license
|
|
|
|
#----------------------------------------------------------------------
|
2003-12-16 19:34:40 -05:00
|
|
|
# 12/11/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o 2.5 compatability update.
|
|
|
|
# o Added deprecation warning.
|
|
|
|
#
|
2003-12-22 14:09:54 -05:00
|
|
|
# 12/20/2003 - Jeff Grimmett (grimmtooth@softhome.net)
|
|
|
|
#
|
|
|
|
# o wxRightTextCtrl -> RightTextCtrl
|
|
|
|
#
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
"""
|
|
|
|
Some time ago, I asked about how to right-align
|
|
|
|
wxTextCtrls. Answer was that it is not supported. I forgot it.
|
|
|
|
|
|
|
|
Just a week ago, one of my clients asked me to have numbers right
|
|
|
|
aligned. (Indeed it was that numbers MUST be right aligned).
|
|
|
|
|
|
|
|
So the game begun. Hacking, hacking, ...
|
|
|
|
|
|
|
|
At last, i succeed. Here is some code that someone may find
|
|
|
|
useful. ubRightTextCtrl is right-aligned when you are not editing, but
|
|
|
|
left-aligned if it has focus.
|
|
|
|
|
|
|
|
Hope this can help someone, as much as this list helps me.
|
|
|
|
|
|
|
|
Josu Oyanguren
|
2004-04-30 02:14:22 -04:00
|
|
|
Ubera Servicios Informaticos.
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
P.S. This only works well on wxMSW.
|
|
|
|
"""
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
import warnings
|
|
|
|
import wx
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-16 19:34:40 -05:00
|
|
|
warningmsg = r"""\
|
|
|
|
|
|
|
|
##############################################################\
|
|
|
|
# THIS MODULE IS DEPRECATED |
|
|
|
|
# |
|
|
|
|
# This control still functions, but it is deprecated because |
|
|
|
|
# wx.TextCtrl now supports the wx.TE_RIGHT style flag |
|
|
|
|
##############################################################/
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
warnings.warn(warningmsg, DeprecationWarning, stacklevel=2)
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------
|
|
|
|
|
2003-12-22 14:09:54 -05:00
|
|
|
class RightTextCtrl(wx.TextCtrl):
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self, parent, id, *args, **kwargs):
|
2003-12-16 19:34:40 -05:00
|
|
|
wx.TextCtrl.__init__(self, parent, id, *args, **kwargs)
|
|
|
|
self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
|
|
|
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnPaint(self, event):
|
2003-12-16 19:34:40 -05:00
|
|
|
dc = wx.PaintDC(self)
|
2003-11-12 16:34:20 -05:00
|
|
|
dc.SetFont(self.GetFont())
|
|
|
|
dc.Clear()
|
|
|
|
text = self.GetValue()
|
|
|
|
textwidth, textheight = dc.GetTextExtent(text)
|
2003-12-16 19:34:40 -05:00
|
|
|
dcwidth, dcheight = self.GetClientSize()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
y = (dcheight - textheight) / 2
|
|
|
|
x = dcwidth - textwidth - 2
|
|
|
|
|
|
|
|
if self.IsEnabled():
|
|
|
|
fclr = self.GetForegroundColour()
|
|
|
|
else:
|
2003-12-16 19:34:40 -05:00
|
|
|
fclr = wx.SystemSettings_GetColour(wx.SYS_COLOUR_GRAYTEXT)
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
dc.SetTextForeground(fclr)
|
|
|
|
|
2004-01-12 22:25:58 -05:00
|
|
|
dc.SetClippingRegion((0, 0), (dcwidth, dcheight))
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawText(text, x, y)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
if x < 0:
|
|
|
|
toofat = '...'
|
|
|
|
markwidth = dc.GetTextExtent(toofat)[0]
|
2003-12-16 19:34:40 -05:00
|
|
|
dc.SetPen(wx.Pen(dc.GetBackground().GetColour(), 1, wx.SOLID ))
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawRectangle(0,0, markwidth, dcheight)
|
2003-12-16 19:34:40 -05:00
|
|
|
dc.SetPen(wx.Pen(wx.RED, 1, wx.SOLID ))
|
|
|
|
dc.SetBrush(wx.TRANSPARENT_BRUSH)
|
2004-05-01 22:41:33 -04:00
|
|
|
dc.DrawRectangle(1, 1, dcwidth-2, dcheight-2)
|
|
|
|
dc.DrawText(toofat, 1, y)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
def OnKillFocus(self, event):
|
|
|
|
if not self.GetParent(): return
|
|
|
|
self.Refresh()
|
|
|
|
event.Skip()
|
2003-07-02 19:13:10 -04:00
|
|
|
|