Tue, Oct 22, 12:28 AM CDT

Renderosity Forums / Poser Python Scripting



Welcome to the Poser Python Scripting Forum

Forum Moderators: Staff

Poser Python Scripting F.A.Q (Last Updated: 2024 Sep 18 2:50 am)

We now have a ProPack Section in the Poser FreeStuff.
Check out the new Poser Python Wish List thread. If you have an idea for a script, jot it down and maybe someone can write it. If you're looking to write a script, check out this thread for useful suggestions.

Also, check out the official Python site for interpreters, sample code, applications, cool links and debuggers. This is THE central site for Python.

You can now attach text files to your posts to pass around scripts. Just attach the script as a txt file like you would a jpg or gif. Since the forum will use a random name for the file in the link, you should give instructions on what the file name should be and where to install it. Its a good idea to usually put that info right in the script file as well.

Checkout the Renderosity MarketPlace - Your source for digital art content!



Subject: Defining wxPython button font size on a Mac


PhilC ( ) posted Wed, 18 July 2012 at 1:53 PM · edited Mon, 21 October 2024 at 10:23 PM

Here's the thing, I wrote PZ3editor in Python and used py2exe to make it into an executable for the PC. Works great :)

Now I'm asked to try and get it working on a Mac and yes running the raw PY files does work but Macs apparently totally ignore the font size commands resulting in every button label being too big for the button.

Test script:-

test button

fontSize = 8

import wx

class MyApp(wx.Frame):
    def init(self,parent,title):
        wx.Frame.init(self,parent,title=title,size=(300,200))

        self.SetFont(wx.Font(fontSize, wx.SWISS, wx.NORMAL, wx.NORMAL))

        # add panel
        self.p = wx.Panel(self,-1, size=(300,200))
        # add button
        b = wx.Button(self.p, 10, "Press This Button", (20, 20))
        self.Bind(wx.EVT_BUTTON, self.OnClick, b)
        b.SetSize(b.GetBestSize())

    def OnClick(self, event):
        print "Font size = %i" % fontSize

app = wx.App(False)
frame = MyApp(None, "Button Test")
frame.Show(True)
app.MainLoop()

##############################

I know some folks swear by their Macs, me I just stand by mine and swear!

Anyone have any idea how to define button font sizes on a Mac. To reformat my GUI and the multitude of associated pop up dialogs is frankly just not worth the effort.


Pret-a-3D ( ) posted Wed, 18 July 2012 at 2:32 PM

Have you triied using:

style=wx.BU_EXACTFIT

in the wx.Button constructor?

Paolo

https://www.preta3d.com
FB: https://www.facebook.com/RealityPlugIn
Tw: @preta3d
G+: https://plus.google.com/106625816153304163119
The Reality Gallery: https://reality-plug-in.deviantart.com


PhilC ( ) posted Wed, 18 July 2012 at 3:25 PM

Thanks but I need to keep the buttons the same size or else I'll have to reformat/resize everything.


bagginsbill ( ) posted Wed, 18 July 2012 at 4:35 PM

If you set the font on the button itself, instead of the parent frame, it respects it. However, it does not grow or shrink its height for bigger fonts, like Windows does. It would appear that the User Interface Enforcement Bureau at Apple think buttons must only come in one height.

But you seem to be trying to get them narrower? That works to a degree.

I found it possible to rename the wx.Button and then add my own definition. Then all existing code uses mine.

 


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


bagginsbill ( ) posted Wed, 18 July 2012 at 4:36 PM

fontSize = 8 buttonFont = wx.Font(fontSize, wx.FONTFAMILY_DEFAULT, wx.NORMAL, wx.NORMAL)

if not hasattr(wx, 'RealButton'):
        wx.RealButton = wx.Button

class MyButton(wx.RealButton):
        def __init__(self, *a, **k):
                RealButton.__init__(self, *a, **k)
                self.Font = buttonFont

wx.Button = MyButton


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


bagginsbill ( ) posted Wed, 18 July 2012 at 4:39 PM · edited Wed, 18 July 2012 at 4:41 PM

file_483990.png

Looks like this.

Note: Swiss works at 8 but is hard to read.


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


Pret-a-3D ( ) posted Wed, 18 July 2012 at 4:46 PM

The whole re-aliasing of wx.Button is brilliant! Being able to do that kind of stuff can open a lot of possiblities. Thanks for the tip!

Paolo

https://www.preta3d.com
FB: https://www.facebook.com/RealityPlugIn
Tw: @preta3d
G+: https://plus.google.com/106625816153304163119
The Reality Gallery: https://reality-plug-in.deviantart.com


bagginsbill ( ) posted Wed, 18 July 2012 at 4:52 PM · edited Wed, 18 July 2012 at 4:54 PM

Paolo,

Glad you like it. You know what is even more interesting? You can inject methods into those existing classes without subclassing them!!!

It's a little harder than subclassing, but very convenient for cases where you can't get in there fast enough to swap your class before some other bit of code is already remembering pointers to the original.

For example, as soon as you import wx, you're getting all of it. There may be library subclasses of wx.Button already set up. They will not derive from MyButton.

So in such cases, replacing a method of wx.Button (the original class) works.


Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)


Pret-a-3D ( ) posted Wed, 18 July 2012 at 5:29 PM

Yeah, that part I was aware of it. It's similar to what you can do with JavaScript (shudder), I extended the String class in JS to provide missing services. But, the fact that you could alias/redirect a class is defintely handy. A good way to shoot yourself in the foot or play practical jokes too! ;-)

Paolo

https://www.preta3d.com
FB: https://www.facebook.com/RealityPlugIn
Tw: @preta3d
G+: https://plus.google.com/106625816153304163119
The Reality Gallery: https://reality-plug-in.deviantart.com


Privacy Notice

This site uses cookies to deliver the best experience. Our own cookies make user accounts and other features possible. Third-party cookies are used to display relevant ads and to analyze how Renderosity is used. By using our site, you acknowledge that you have read and understood our Terms of Service, including our Cookie Policy and our Privacy Policy.