Cross-platform issue with wxRadioBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gokhvat@gmail.com

    #1

    Cross-platform issue with wxRadioBox

    I am experiencing a strange cross-platform issue with my python
    program.

    I am using wxRadioBox to create radio buttons. When I run the python
    code on a mac, everything works perfectly, but not on a pc. On the pc,
    no matter what selection I made, the form would think that I was
    choosing the 1st (top) option.

    I am astounded that everything else could work and something this
    simple could have cross-platform issues.

    I looked into wxRadioBox online and no one seems to have any similar
    errors. I was thinking it might be the installation of the wx module on
    the pc, but I somehow doubt it.

    Does anyone have any insight as to what is going on here?



    # BEGIN CODE

    import wx;

    SUBMIT_BUTTON = wx.ID_HIGHEST + 10;

    class regFrame(wx.Fra me):
    def __init__(self, parent, title):
    wx.Frame.__init __(self, parent, -1, title,
    pos=(100, 100), size=(800, 600));

    fileDialog = wx.FileDialog(s elf, "Select a file to which to write",
    style = wx.SAVE | wx.OVERWRITE_PR OMPT,
    wildcard="*.txt |Text");
    if(fileDialog.S howModal() != wx.ID_OK):
    print "No file specified - closing";
    self.Close();
    return;
    write_file = fileDialog.GetP ath();

    self.write_file = open(write_file , "a");

    # init main frame with menu and status bars
    menuBar = wx.MenuBar();
    fileMenu = wx.Menu();

    fileMenu.Append (wx.ID_ABOUT, "&About\tAl t-A", "About this program");
    fileMenu.Append Separator();
    fileMenu.Append (wx.ID_EXIT, "&Quit\tAlt-Q", "Quit this program");
    menuBar.Append( fileMenu, "&File");
    self.SetMenuBar (menuBar);

    self.CreateStat usBar();

    self.ctrl_sizer = wx.GridBagSizer (5, 15);

    # build the controls
    # TO MODIFY THE LIST OF SIZES, CHANGE THIS:
    self.valid_size s = ['4XLT', '3XLT', '2XLT', '2XL', 'XLT', 'LT', 'XL',
    'L', 'M', 'S', 'XS', 'XXS'];


    instructions = "Enter your netid, full name, and size in the " + \
    "boxes below and press the 'Submit Order' button to place " + \
    "your order.";
    self.instructio n_text = wx.StaticText(s elf, -1, instructions);
    self.id_text = wx.StaticText(s elf, -1, "netid");
    self.id_input = wx.TextCtrl(sel f, -1, "", size=(100, -1));
    self.name_text = wx.StaticText(s elf, -1, "name");
    self.name_input = wx.TextCtrl(sel f, -1, "", size=(100, -1));
    self.size_text = wx.StaticText(s elf, -1, "size selection");
    self.size_selec tion = wx.RadioBox(sel f, -1,
    choices = self.valid_size s,
    style = wx.RA_SPECIFY_R OWS
    );
    self.submit_but ton = wx.Button(self, SUBMIT_BUTTON, "Submit Order");

    # put the controls into a grid
    self.ctrl_sizer .Add(self.instr uction_text, (0, 0),
    span=(1, 4), flag=wx.EXPAND) ;

    self.ctrl_sizer .Add(self.id_te xt, (1, 0), flag=wx.EXPAND) ;
    self.ctrl_sizer .Add(self.name_ text, (1, 1), flag=wx.EXPAND) ;
    self.ctrl_sizer .Add(self.size_ text, (1, 2), flag=wx.EXPAND) ;

    self.ctrl_sizer .Add(self.id_in put, (2, 0), flag=wx.HORIZON TAL);
    self.ctrl_sizer .Add(self.name_ input, (2, 1), flag=wx.HORIZON TAL);
    self.ctrl_sizer .Add(self.size_ selection, (2, 2), flag=wx.EXPAND) ;
    self.ctrl_sizer .Add(self.submi t_button, (2, 3), flag=wx.HORIZON TAL);

    self.SetSizer(s elf.ctrl_sizer) ;
    self.ctrl_sizer .Fit(self);

    # register event handling functions
    wx.EVT_MENU(sel f, wx.ID_ABOUT, self.OnAbout);
    wx.EVT_MENU(sel f, wx.ID_EXIT, self.OnExit);
    wx.EVT_BUTTON(s elf, SUBMIT_BUTTON, self.OnSubmit);

    def OnAbout(self, evt):
    return;

    def OnExit(self, evt):
    if(self.write_f ile):
    self.write_file .close();
    self.Close();

    def OnSubmit(self, evt):
    # build a tab-delimited-text line of the data and write it
    save_fields = [self.id_input.G etValue(),
    self.name_input .GetValue(),
    self.size_selec tion.GetStringS election()];
    save_str = "\t".join(save_ fields);

    # ask for validation before we save
    dialog_str = "Are you sure this is correct?" + \
    "\n Netid: " + save_fields[0] + \
    "\n Name: " + save_fields[1] + \
    "\n Size: " + save_fields[2];
    if(wx.MessageBo x(dialog_str, "Confirm Order",
    wx.YES_NO | wx.ICON_EXCLAMA TION)
    == wx.YES):
    # write it out and flush the buffer to make sure it's on disk
    self.write_file .write(save_str + "\n");
    self.write_file .flush();
    wx.MessageBox(" Your order has been saved. Thanks!");
    # reset the controls for the next user
    self.id_input.S etValue('');
    self.name_input .SetValue('');
    self.size_selec tion.SetSelecti on(0);


    class pyReg2App(wx.Ap p):
    def OnInit(self):
    main_frame = regFrame(None, "Senior Jacket Registration");
    self.SetTopWind ow(main_frame);
    main_frame.Show (True);
    return True;

    reg_app = pyReg2App(redir ect=False);
    reg_app.MainLoo p();
    # END CODE

  • eugene.gokhvat@gmail.com

    #2
    Re: Cross-platform issue with wxRadioBox

    I have updated my script to use wx.RadioButton instead, which works
    perfectly on my mac again, but now the submit button doesn't show up on
    the pc and I can't click in the netid field on the pc either. any
    ideas?

    # BEGIN CODE

    import wx;

    SUBMIT_BUTTON = wx.ID_HIGHEST + 10;

    class regFrame(wx.Fra me):
    def __init__(self, parent, title):
    wx.Frame.__init __(self, parent, -1, title,
    pos=(100, 100), size=(800, 600));

    fileDialog = wx.FileDialog(s elf, "Select a file to which to write",
    style = wx.SAVE | wx.OVERWRITE_PR OMPT,
    wildcard="*.txt |Text");
    if(fileDialog.S howModal() != wx.ID_OK):
    print "No file specified - closing";
    self.Close();
    return;
    write_file = fileDialog.GetP ath();

    self.write_file = open(write_file , "a");

    # init main frame with menu and status bars

    self.panel = wx.Panel ( self, -1 )

    menuBar = wx.MenuBar();
    fileMenu = wx.Menu();

    fileMenu.Append (wx.ID_ABOUT, "&About\tAl t-A", "About this program");
    fileMenu.Append Separator();
    fileMenu.Append (wx.ID_EXIT, "&Quit\tAlt-Q", "Quit this program");
    menuBar.Append( fileMenu, "&File");
    self.SetMenuBar (menuBar);

    self.CreateStat usBar();

    self.ctrl_sizer = wx.GridBagSizer (5, 15);

    # build the controls

    instructions = " Enter your netid and size in the " + \
    "boxes below and press the 'Submit Order' button to place " + \
    "your order.";

    self.instructio n_text = wx.StaticText(s elf, -1, instructions);
    self.id_text = wx.StaticText(s elf, -1, " netid");
    self.id_input = wx.TextCtrl(sel f, -1, "", size=(160, -1));
    self.size_text = wx.StaticText(s elf, -1, "size");
    self.submit_but ton = wx.Button(self, SUBMIT_BUTTON, "Submit Order");

    # put the controls into a grid

    self.ctrl_sizer .Add(self.instr uction_text, (0, 0),
    span=(1, 3), flag=wx.EXPAND) ;

    self.ctrl_sizer .Add(self.id_te xt, (1, 0), flag=wx.EXPAND) ;
    self.ctrl_sizer .Add(self.size_ text, (1, 1), flag=wx.EXPAND) ;
    self.ctrl_sizer .Add(self.id_in put, (2, 0), flag=wx.HORIZON TAL);

    # TO MODIFY THE LIST OF SIZES, CHANGE THIS:
    self.valid_size s = ['4XLT', '3XLT', '2XLT', '2XL', 'XLT',
    'XL', 'LT', 'L', 'M', 'S', 'XS', 'XXS'];
    first_size = 1;
    size_count = 0;
    self.button_arr ay = [];
    for this_size in self.valid_size s:
    this_button = '';
    if first_size:
    this_button = wx.RadioButton( self.panel, -1, this_size,
    style=wx.RB_GRO UP);
    first_size = 0;
    else:
    this_button = wx.RadioButton( self.panel, -1, this_size);
    self.button_arr ay.append(this_ button);
    self.ctrl_sizer .Add(this_butto n, (size_count+2, 1));
    size_count += 1;

    self.ctrl_sizer .Add(self.submi t_button, (2, 2), flag=wx.HORIZON TAL);

    self.SetSizer(s elf.ctrl_sizer) ;
    self.ctrl_sizer .Fit(self);
    # register event handling functions
    wx.EVT_MENU(sel f, wx.ID_ABOUT, self.OnAbout);
    wx.EVT_MENU(sel f, wx.ID_EXIT, self.OnExit);
    wx.EVT_BUTTON(s elf, SUBMIT_BUTTON, self.OnSubmit);

    def OnAbout(self, evt):
    return;

    def OnExit(self, evt):
    if(self.write_f ile):
    self.write_file .close();
    self.Close();

    def OnSubmit(self, evt):
    selected_index = -1;
    this_index = 0;
    for this_button in self.button_arr ay:
    if this_button.Get Value():
    selected_index = this_index;
    this_index += 1;

    # make sure the user selected something
    if selected_index == -1:
    wx.MessageBox(" You must select a size to place your order",
    "Please select a size",
    wx.ICON_EXCLAMA TION);
    return;

    # build a tab-delimited-text line of the data and write it
    save_fields = [self.id_input.G etValue(),
    self.valid_size s[selected_index]];
    save_str = "\t".join(save_ fields);

    # ask for validation before we save
    dialog_str = "Are you sure this is correct?" + \
    "\n Netid: " + save_fields[0] + \
    "\n Size: " + save_fields[1];
    if(wx.MessageBo x(dialog_str, "Confirm Order",
    wx.YES_NO | wx.ICON_EXCLAMA TION)
    == wx.YES):
    # write it out and flush the buffer to make sure it's on disk
    self.write_file .write(save_str + "\n");
    self.write_file .flush();
    wx.MessageBox(" Your order has been saved. Thanks!");
    # reset the controls for the next user
    self.id_input.S etValue('');
    self.button_arr ay[selected_index].SetValue(0);



    class pyReg2App(wx.Ap p):
    def OnInit(self):
    main_frame = regFrame(None, "Senior Jacket Registration");
    self.SetTopWind ow(main_frame);
    main_frame.Show (True);
    return True;

    reg_app = pyReg2App(redir ect=False);
    reg_app.MainLoo p();
    # END CODE

    Comment

    • cmcp

      #3
      Re: Cross-platform issue with wxRadioBox


      eugene.gokhvat@ gmail.com wrote:
      I have updated my script to use wx.RadioButton instead, which works
      perfectly on my mac again, but now the submit button doesn't show up on
      the pc and I can't click in the netid field on the pc either. any
      ideas?
      >
      I modified the __init__() method of class regFrame from your original
      posting to create a wx.Panel as a child of self and then made all the
      controls be children of this panel. Your app then seemed to work OK on
      Windows XP. Using a wx.Panel to hold the content of a frame is a
      standard wxPython idiom. I find reading the wxPython demo source is a
      very useful way to learn this sort of thing.

      HTH,
      -- CMcP

      Comment

      Working...