frame sizing and focus

Hi!

I’m writing an application with a small popup window. This window contains more or less a number of panels placed in a vertical BoxSizer, each of them containing one ore more labels aligned horizontally. Now my problem is that I want the frame to always be the same width (350px). This makes some of the labels wrap and I can’t find any way to calculate a new frame size which takes this wrapping into account to increase the height. In my one test case so far, I always seem to get a width of 950 (which won’t apply since I’ve set both min and max width to 350. Is there any way to do this?

I also want this window to appear sort of like a menu, in the way that it disappears as soon as the user clicks somewhere else. Is there any way to detect when a frame loses focus. I tried the focus killed event but couldn’t get it to work. Is that the way to go or is there another?

Thanks a lot!
//T

Hi!

I'm writing an application with a small popup window. This window contains
more or less a number of panels placed in a vertical BoxSizer, each of them
containing one ore more labels aligned horizontally. Now my problem is that
I want the frame to always be the same width (350px). This makes some of the
labels wrap and I can't find any way to calculate a new frame size which
takes this wrapping into account to increase the height. In my one test case
so far, I always seem to get a width of 950 (which won't apply since I've
set both min and max width to 350. Is there any way to do this?

If you have a small test case, as you said, you should post it to the list
so people can help you more easily.

Offhand, I can think of the harder way to do this. Loop through the
labels (using
GetLabel() or maybe you have that list already), count the letters in
the strings
that are the labels, and make if statements that set the height values based on
those label lengths. Something like:

labeled_widgets_list = [widget1, widget2, etc...] #however this got made
for widget in labeled_widgets_list:
    max_label_length = 10 #change to appropriate value for your needs
    height = 35 #change to appropriate value for
your needs
    label = widget.GetLabel()
    if len(label) > max_label_length:
       widget.SetSize(wx.Size(-1, height)
    else:
       pass

I suspect there is a built-in way to do this, but I can't think of it right now.

disappears as soon as the user clicks somewhere else. Is there any way to
detect when a frame loses focus. I tried the focus killed event but couldn't
get it to work. Is that the way to go or is there another?

Did you have a look at the Transient PopupWindow in the Demo? That's
what you need, I think.

Che

···

On Wed, Nov 12, 2008 at 1:54 PM, Thomas Järvstrand <ojve82@gmail.com> wrote:

Hey Che!

Thanks for your reply. The transient popupwindow is perfect!

I don’t know if my testcase is that small but here goes:

import wx

class AccountSummary(wx.Frame):

def __init__(self, parent_gui):
    account_msg_data = {2: {'status': (0, 1),
                            'unread_msgs': [('<9093C25DA17C4BAA94E25B292384F31C@doublep>', 'atencion@atumesa.com', 'Encuesta de Calidad en el Servicio #571752'),
                                            ('<16416556e463ee5e0d983d75d5382e52@localhost.localdomain>', 'Facebook', u'Anakaren Berenice Chac\xf3n Espinosa invited you to the event "- My 20 winters -"...'),
                                            ('<6e9381670811111143r3e624200o70e7d4078fd57624@mail.gmail.com>', 'Elena Jimenez', u'conversaci\xf3n coloquial'),
                                            ('<48D3DD280068138B@mailserver2.itesm.mx> (added by\r\n postmaster@itesm.mx)', 'Lic. Marcelo Bravo', 'IMPORTANTE: Jueves - Thursday  GENERATION PHOTO')],
                            'account_name': u'xxxxx@gmail.com',
                            'check_time': (2008, 11, 12, 3, 46, 50, 2, 317, 0)}}

    wx.Frame.__init__(self, None, -1, "Account summary", style = wx.FRAME_NO_TASKBAR | wx.CAPTION | wx.STAY_ON_TOP | wx.CLOSE_BOX )
    panel_back = wx.Panel(self)
   
    vbox_back = wx.BoxSizer(wx.VERTICAL)
   
    self.account_name_font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT )   
    self.account_name_font.SetPointSize(self.account_name_font.GetPointSize() + 2)
    self.account_name_font.SetWeight(wx.BOLD)
   
    self.account_bg_color = wx.Color(240, 240, 170)
    self.msg_bg_color = wx.Color(240, 240, 120)
   
    self.sender_name_font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT )   
    self.sender_name_font.SetWeight(wx.BOLD)
   
    self.account_controls = {}
   
    for account in account_msg_data.values():
        vbox = wx.BoxSizer(wx.VERTICAL)
        account_name_panel = wx.Panel(panel_back)
        account_name_panel.SetBackgroundColour(self.account_bg_color)
         
        account_name =  len(account["account_name"]) > 45 and account["account_name"][:42] + "...:" or account["account_name"] + ":"
        account_name_label = wx.StaticText(account_name_panel, -1,  account_name)
        account_name_label.SetFont(self.account_name_font)
                   
        vbox.Add(account_name_panel, 0, wx.EXPAND)
        for msg in account["unread_msgs"]:
            hbox = wx.BoxSizer(wx.HORIZONTAL)
            msg_panel = wx.Panel(panel_back)
            msg_panel.SetBackgroundColour(self.msg_bg_color)
           
            sender_name = len(msg[0]) > 24 and msg[1][:21] + "..." or msg[1] 
           
            sender_name_label = wx.StaticText(msg_panel, -1, sender_name)
            sender_name_label.SetFont(self.sender_name_font)
            label = wx.StaticText(msg_panel, -1, ":")
            label.SetFont(self.sender_name_font)
            subject_label = wx.StaticText(msg_panel, -1, msg[2])
           
            hbox.Add(sender_name_label, 1, wx.TOP | wx.LEFT, 3)
            hbox.Add(label, 0, wx.TOP | wx.RIGHT, 3)
            hbox.Add(subject_label, 1, wx.LEFT | wx.TOP, 3)
       
            msg_panel.SetSizer(hbox)
            vbox.Add(msg_panel, 0, wx.EXPAND)      
   
        vbox_back.Add(vbox, 1, wx.EXPAND)
       
   
    panel_back.SetSizer(vbox_back)
    self.SetMaxSize((350, -1))
    self.SetMinSize((350, -1))
   
    panel_back.SetMaxSize((350, -1))
    vbox_back.Layout()
    size = vbox_back.GetMinSize()
    self.SetClientSize(size)

if name == “main”:
app = wx.PySimpleApp()
frame = AccountSummary(None)
frame.Show()
app.MainLoop()

thanks!
//T

Thomas Järvstrand wrote:

Hi!

I'm writing an application with a small popup window. This window contains more or less a number of panels placed in a vertical BoxSizer, each of them containing one ore more labels aligned horizontally. Now my problem is that I want the frame to always be the same width (350px). This makes some of the labels wrap and I can't find any way to calculate a new frame size which takes this wrapping into account to increase the height. In my one test case so far, I always seem to get a width of 950 (which won't apply since I've set both min and max width to 350. Is there any way to do this?

The sizer's CalcMin method will help out.

I also want this window to appear sort of like a menu, in the way that it disappears as soon as the user clicks somewhere else. Is there any way to detect when a frame loses focus. I tried the focus killed event but couldn't get it to work. Is that the way to go or is there another?

EVT_ACTIVATE

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!