views:

341

answers:

1

Im looking for a way to present a flexible font, that will increase and decrease in size according to to the size of the screen resolution. I want to be able to do this without the HTML window class. Is there a way? I thought I've done quite a bit of googling without success.

EDIT This seems a good question, I changed the title to reflect closer what I was looking for.

EDIT

So now I've realized that the regular pixel sizes will scale in the way I mentioned already - but I saw this the other day and realized it might be helpful if someone wanted to use CSS with their wxPython Apps - its a library that allows you to 'skin' your application and I can think of a dozen neat ways to use it already - here is a link in lieu of a more well thought out question :)

link text

+1  A: 

Maybe something like this? You can scale any wx.Window in this way. Not sure if this is exactly what you mean though.

import wx

def scale(widget, percentage):
    font = widget.GetFont()
    font.SetPointSize(int(font.GetPointSize() * percentage / 100.0))
    widget.SetFont(font)

class Frame(wx.Frame):
    def __init__(self):
        super(Frame, self).__init__(None, -1, 'Scaling Fonts')
        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        for i in range(50, 201, 25):
            widget = wx.StaticText(panel, -1, 'Scale Factor = %d' % i)
            scale(widget, i)
            sizer.Add(widget, 0, wx.ALL, 5)
        panel.SetSizer(sizer)

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = Frame()
    frame.Show()
    app.MainLoop()
FogleBird
I suppose I meant to resize the fonts based on the size of the frame area .. so on an SIZE event the fonts would shrink in a flexible layout. But not so that you couldnt read them .. Im having trouble suddenly now that you pointed out the ambiguity of my question :) I actually attempted to modify the code as I meant it then realized I did not know what I meant. Give me a bit, I will edit the question a bit more.
Matt1776
Now that I look at this question again I realize that it no longer makes sense to me and I'm not sure what I was thinking. The font size on the wx widget sets are in pixels which are designed to scale in proportion to the viewing device resolution. So the default is already doing what I was talking about. -- I think I might have meant I wanted to have the fonts 'grow' like the sizers wxGROW and flex to their containing area - but again I'm not sure why I wanted to do that.
Matt1776
Thank you for taking a shot at what I was trying to do though! Maybe if someone used the wxGROW tag on a sizer containing a text widget, it would display the behavior I mentioned.
Matt1776
Perhaps it would be nice to use CSS style sheets on the widgets
Matt1776