Merged the wxPy_newswig branch into the HEAD branch (main trunk)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2003-11-12 21:34:20 +00:00
parent eb6a4098a0
commit d14a1e2856
987 changed files with 671143 additions and 783083 deletions

View File

@@ -1,8 +1,82 @@
# -*- 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
#----------------------------------------------------------------------
"""Renamer stub: provides a way to drop the wx prefix from wxPython objects."""
"""
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
Ubera Servicios Inform<72>ticos.
P.S. This only works well on wxMSW.
"""
from wxPython.wx import *
#----------------------------------------------------------------------
class wxRightTextCtrl(wxTextCtrl):
def __init__(self, parent, id, *args, **kwargs):
wxTextCtrl.__init__(self, parent, id, *args, **kwargs)
EVT_KILL_FOCUS(self, self.OnKillFocus)
EVT_PAINT(self, self.OnPaint)
def OnPaint(self, event):
dc = wxPaintDC(self)
dc.SetFont(self.GetFont())
dc.Clear()
text = self.GetValue()
textwidth, textheight = dc.GetTextExtent(text)
dcwidth, dcheight = self.GetClientSizeTuple()
y = (dcheight - textheight) / 2
x = dcwidth - textwidth - 2
if self.IsEnabled():
fclr = self.GetForegroundColour()
else:
fclr = wxSystemSettings_GetColour(wxSYS_COLOUR_GRAYTEXT)
dc.SetTextForeground(fclr)
dc.SetClippingRegion(0, 0, dcwidth, dcheight)
dc.DrawText(text, x, y)
if x < 0:
toofat = '...'
markwidth = dc.GetTextExtent(toofat)[0]
dc.SetPen(wxPen(dc.GetBackground().GetColour(), 1, wxSOLID ))
dc.DrawRectangle(0,0, markwidth, dcheight)
dc.SetPen(wxPen(wxRED, 1, wxSOLID ))
dc.SetBrush(wxTRANSPARENT_BRUSH)
dc.DrawRectangle(1, 1, dcwidth-2, dcheight-2)
dc.DrawText(toofat, 1, y)
def OnKillFocus(self, event):
if not self.GetParent(): return
self.Refresh()
event.Skip()
from wx import _rename
from wxPython.lib import rightalign
_rename(globals(), rightalign.__dict__, modulename='lib.rightalign')
del rightalign
del _rename