This is a simple one guys... I just want the last field of a status bar to adjust based on the length of the text contained within. I was using the example from the wxPython status bar demo where there is a timer in the last field, however on some systems with higher resolution the timer's minutes and seconds are cut-off. I tried adjusting the statusbarwidths to the length of the string, but this obviously won't work because that length is not in pixels. Here's my update function: -
# This is the timer's update function
-
def Notify(self):
-
t = time.localtime(time.time())
-
st = time.strftime(" %b %d, %Y %I:%M:%S", t)
-
self.SetStatusWidths([-4, -2, 17, len(st)])
-
self.SetStatusText(st, 3)
-
And then this next part can be put into any wx.Frame -
self.sb = self.CreateStatusBar(4)
-
self.sb.SetStatusWidths([-4, -2, 17, 150])
-
So my question is basically is there a way to convert from len(str) into the pixels required to display len(str) ?
Thanks in advance
2 8079 bartonc 6,596
Recognized Expert Expert
So my question is basically is there a way to convert from len(str) into the pixels required to display len(str) ?
I've seen this once, but can't find it at the moment. It goes something like the: -
f = window.GetFont()
-
dc = wx.WindowDC(window)
-
dc.SetFont(f)
-
width, height = dc.GetTextExtent("Text to measure")
By "window", I mean the widget that will get the text.
I've seen this once, but can't find it at the moment. It goes something like the: -
f = window.GetFont()
-
dc = wx.WindowDC(window)
-
dc.SetFont(f)
-
width, height = dc.GetTextExtent("Text to measure")
By "window", I mean the widget that will get the text.
Once again BartonC saves the day! Thanks a bunch, that code worked flawlessly with only one minor thing.
Since this is in a status bar and the text is at the end of the status bar, it gets cut off by the window resize 'grabber area' (if that makes any sense). See I have a date/time display in the last field of my status bar... so as I update the text I adjust the size of that last field with the following code: -
# This is the timer's update function
-
def Notify(self):
-
t = time.localtime(time.time())
-
st = time.strftime(" %b %d, %Y %I:%M:%S", t)
-
self.SetStatusText(st, 3)
-
f = self.sb.GetFont()
-
dc = wx.WindowDC(self.sb)
-
dc.SetFont(f)
-
width, height = dc.GetTextExtent(st)
-
self.sb.SetStatusWidths([-4, -2, 17, width + 30])
-
I know it's not a very good idea to just use an assumed size of 30 for that little box in the corner, but it works on the systems that used to get cut off and looks the same on the systems that never had the problem in the first place so; success!!
Thanks again to BartonC, the Forum Rock Star.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Steve Lamb |
last post by:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ok, this one I did try before coming here... :)
I am trying to report the status of what is going on to the status
bar of the main window of my wxPython app. I know I'm on the right
track with SetStatusText() but it doesn't always alter the text. What
the program is doing is taking a...
|
by: flupke |
last post by:
Hi,
i'm trying to convert my java console app to a python gui.
Now, the only problem i seem to have at the moment are the resizers
for the layout. It seems that for the purpose of what i'm trying to do,
specifying the coordinates is easier that fighting with the layout resizers.
1) I have a screen split in 2. Left side is a textcontrol...
|
by: Tom |
last post by:
1) Portable to Windows, Unix-like platforms, and the Macintosh;
2) Powerful, GUI is very beautiful ;
3) Efficiency of development is high;
What's the best, Tkinter, wxPython, QT, GTK or other?
Thanks!
|
by: Petr Prikryl |
last post by:
Hi,
I am experimenting with wxPython on Windows box.
What I need to implement is a check tree control
with 3 states for each checkbox: unchecked, checked,
gray checked. The status of the checkbox should reflect
the status of the children. When ALL children are checked,
then the status should be checked. When NO children
are checked, the...
|
by: Sean Tynan |
last post by:
I want to find out the best way for a method to notify calling code of
situations such as validation errors, etc. that may occur during method
execution.
e.g. say I have a method (business logic layer) that inserts a user into a
database, and returns the newly created UserID:
public function CreateUser(userName as string, userEmail as...
| |
by: zxo102 |
last post by:
Hi everyone,
I am using a python socket server to collect data from a socket
client and then control a image location ( wxpython) with the data,
i.e. moving the image around in the wxpython frame.
But the "app.MainLoop()" in wxpython looks like conflicting with
the "while 1:" in socket server. After I commented the
"app.MainLoop()",...
|
by: WuJianWei |
last post by:
If you type a string:
"It's good."
there's one space between the two words.
but how can i adjust the string to two spaces or more.
"it's good."
|
by: Jia Lu |
last post by:
HI all
I am making an application with wxpython.
But I got a problem when I want to change the display string
according to process status.
I passed the frame to the processing function and use the
frame.txtobj to change displaying strings.
I found it is a bad method to do that.
|
by: Yasir Zaheer |
last post by:
Hi,
We are using Bloomberg API for .Net to connect to Bloomberg and get
the field information for specific securities. The application is
running on a Bloomberg terminal. While requesting, we first start the
'MarketDataAdapter' and then send the request.
Whenever we send the request to the Bloomberg agent, the application
gets a series...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |