Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Newbie wxPython questions.

Reply
Thread Tools

Newbie wxPython questions.

 
 
nuffnough@gmail.com
Guest
Posts: n/a
 
      04-07-2006
I am running through the wxPython guide and docs and extrapolating
enough to get confused.

BAsed on the tute in the getting started wiki I created a panel that
has most of the elements I want; some check boxes and a couple of
buttons. The button I have is a simple thing that is supposed to just
close (destroy) the app. Only thing is, it destroys the panel and
leaves the app behind. I have attempted to place this on teh frame by
defining a frame; the button works great and closes the app, but
because it isn't part of the panel, the panel is all squished up into
the very top left corner and all you can see is the first checkbox,
which you can't even check. Can I make a button on the panel destroy
the frame?

The next question I have is about adding a second button to the panel
(or frame, I guess) that will then execute a bunch of things depending
on which checkboxes are ticked. My attempts to add the button have
been wrong so far, as you'll see with my code.

The first code block is my panel only app. The second is how it looks
after I defined the Frame first and then moved the Cancel button.

TIA

Nuffnough



--

import wx, sys, os
class Form1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.quote = wx.StaticText(self, -1, "Launching
:",wx.Point(20,30))

st = wx.StaticText(self, -1, "Select the applications you need
to launch:")#, (10, 10)

cb1 = wx.CheckBox(self, -1, "Read Calander, Check
Email")#,(65,40), (150, 20), wx.NO_BORDER)
cb2 = wx.CheckBox(self, -1, "Internet Browser")

self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddMany( [ cb1,
cb2,
])

border = wx.BoxSizer(wx.VERTICAL)
border.Add(st, 0, wx.ALL, 15)
border.Add(sizer, 0, wx.LEFT, 50)
self.SetSizer(border)

pos = cb2.GetPosition().x + cb2.GetSize().width + 25
btn0 = wx.Button(self, -1, "Cancel", (pos, 150))
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

''' Commented out btn1 cause I couldn't make it work
btn1 = wx.Button(self, -1, "Open Apps", (pos + 60, 150))
self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn1)
'''

def EvtCheckBox(self, event):
self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
cb = event.GetEventObject()
if cb.Is3State():
self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())


def OnTestButton(self, evt):
self.cb1.SetString(1, "FUBAR")

def OnCloseMe(self, event):
self.Close(True)

def OnCloseWindow(self, event):
self.Destroy()



app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "An application launcher")
Form1(frame, -1)
frame.Show(1)
app.MainLoop()





--




import wx, sys, os

ID_ABOUT = 101
ID_EXIT = 110

class Frame1(wx.Frame):
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,wx.ID_ANY, title, size =
(300, 400), style=wx.DEFAULT_FRAME_STYLE)
#self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
self.CreateStatusBar() # A Statusbar in the bottom of the
window
# Setting up the menu.
filemenu= wx.Menu()
filemenu.Append(ID_ABOUT, "&About"," Information about this
program")
filemenu.AppendSeparator()
filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu,"&File") # Adding the "filemenu" to
the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
content.

pos = 20
btn0 = wx.Button(self, -1, "Button Text", (pos, 220))
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)


# def OnTestButton(self, evt):
#Run some code that checks which boxes are ticked
#Then perform a function for each ticked box

def OnCloseMe(self, event):
self.Close(True)

def OnCloseWindow(self, event):
self.Destroy()

self.Show(True)


class Form1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.quote = wx.StaticText(self, -1, "Choose Applications
:",wx.Point(20,30))

st = wx.StaticText(self, -1, "Select the application(s) you
need to open:")#, (10, 10)

cb1 = wx.CheckBox(self, -1, "Email, Calender")#,(65,40), (150,
20), wx.NO_BORDER)
cb2 = wx.CheckBox(self, -1, "Browser")

self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.AddMany( [ cb1,
cb2,
])

border = wx.BoxSizer(wx.VERTICAL)
border.Add(st, 0, wx.ALL, 15)
border.Add(sizer, 0, wx.LEFT, 50)
self.SetSizer(border)


def EvtCheckBox(self, event):
self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
cb = event.GetEventObject()
if cb.Is3State():
self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())


app = wx.PySimpleApp()
frame = Frame1(None, -1, "Nuffy's wxPython explorer")
Form1(frame, -1)
frame.Show(1)
app.MainLoop()

 
Reply With Quote
 
 
 
 
diffuser78@gmail.com
Guest
Posts: n/a
 
      04-07-2006
I am also a newbie and learning like you are. I was wondering if do you
know any wxPython forum just for GUIs ?
Good luck with your project and hope that some guru helps us out.

 
Reply With Quote
 
 
 
 
callmebill@gmail.com
Guest
Posts: n/a
 
      04-07-2006
Instead of self.Close(), try parent.Close()

The self.Close() is closing self, which is a panel. The panel's parent
is the frame. This will let you keep the button on the frame, which
eliminates the spacing problem.

I'm not gonna test it, cuz the darn lines wrap and make it difficult to
copy your code, but it should go


http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I am running through the wxPython guide and docs and extrapolating
> enough to get confused.
>
> BAsed on the tute in the getting started wiki I created a panel that
> has most of the elements I want; some check boxes and a couple of
> buttons. The button I have is a simple thing that is supposed to just
> close (destroy) the app. Only thing is, it destroys the panel and
> leaves the app behind. I have attempted to place this on teh frame by
> defining a frame; the button works great and closes the app, but
> because it isn't part of the panel, the panel is all squished up into
> the very top left corner and all you can see is the first checkbox,
> which you can't even check. Can I make a button on the panel destroy
> the frame?
>
> The next question I have is about adding a second button to the panel
> (or frame, I guess) that will then execute a bunch of things depending
> on which checkboxes are ticked. My attempts to add the button have
> been wrong so far, as you'll see with my code.
>
> The first code block is my panel only app. The second is how it looks
> after I defined the Frame first and then moved the Cancel button.
>
> TIA
>
> Nuffnough
>
>
>
> --
>
> import wx, sys, os
> class Form1(wx.Panel):
> def __init__(self, parent, id):
> wx.Panel.__init__(self, parent, id)
> self.quote = wx.StaticText(self, -1, "Launching
> :",wx.Point(20,30))
>
> st = wx.StaticText(self, -1, "Select the applications you need
> to launch:")#, (10, 10)
>
> cb1 = wx.CheckBox(self, -1, "Read Calander, Check
> Email")#,(65,40), (150, 20), wx.NO_BORDER)
> cb2 = wx.CheckBox(self, -1, "Internet Browser")
>
> self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
> self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.AddMany( [ cb1,
> cb2,
> ])
>
> border = wx.BoxSizer(wx.VERTICAL)
> border.Add(st, 0, wx.ALL, 15)
> border.Add(sizer, 0, wx.LEFT, 50)
> self.SetSizer(border)
>
> pos = cb2.GetPosition().x + cb2.GetSize().width + 25
> btn0 = wx.Button(self, -1, "Cancel", (pos, 150))
> self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
> self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
>
> ''' Commented out btn1 cause I couldn't make it work
> btn1 = wx.Button(self, -1, "Open Apps", (pos + 60, 150))
> self.Bind(wx.EVT_BUTTON, self.OnTestButton, btn1)
> '''
>
> def EvtCheckBox(self, event):
> self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
> cb = event.GetEventObject()
> if cb.Is3State():
> self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())
>
>
> def OnTestButton(self, evt):
> self.cb1.SetString(1, "FUBAR")
>
> def OnCloseMe(self, event):
> self.Close(True)
>
> def OnCloseWindow(self, event):
> self.Destroy()
>
>
>
> app = wx.PySimpleApp()
> frame = wx.Frame(None, -1, "An application launcher")
> Form1(frame, -1)
> frame.Show(1)
> app.MainLoop()
>
>
>
>
>
> --
>
>
>
>
> import wx, sys, os
>
> ID_ABOUT = 101
> ID_EXIT = 110
>
> class Frame1(wx.Frame):
> def __init__(self,parent,id,title):
> wx.Frame.__init__(self,parent,wx.ID_ANY, title, size =
> (300, 400), style=wx.DEFAULT_FRAME_STYLE)
> #self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE)
> self.CreateStatusBar() # A Statusbar in the bottom of the
> window
> # Setting up the menu.
> filemenu= wx.Menu()
> filemenu.Append(ID_ABOUT, "&About"," Information about this
> program")
> filemenu.AppendSeparator()
> filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")
> # Creating the menubar.
> menuBar = wx.MenuBar()
> menuBar.Append(filemenu,"&File") # Adding the "filemenu" to
> the MenuBar
> self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame
> content.
>
> pos = 20
> btn0 = wx.Button(self, -1, "Button Text", (pos, 220))
> self.Bind(wx.EVT_BUTTON, self.OnCloseMe, btn0)
> self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
>
>
> # def OnTestButton(self, evt):
> #Run some code that checks which boxes are ticked
> #Then perform a function for each ticked box
>
> def OnCloseMe(self, event):
> self.Close(True)
>
> def OnCloseWindow(self, event):
> self.Destroy()
>
> self.Show(True)
>
>
> class Form1(wx.Panel):
> def __init__(self, parent, id):
> wx.Panel.__init__(self, parent, id)
> self.quote = wx.StaticText(self, -1, "Choose Applications
> :",wx.Point(20,30))
>
> st = wx.StaticText(self, -1, "Select the application(s) you
> need to open:")#, (10, 10)
>
> cb1 = wx.CheckBox(self, -1, "Email, Calender")#,(65,40), (150,
> 20), wx.NO_BORDER)
> cb2 = wx.CheckBox(self, -1, "Browser")
>
> self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb1)
> self.Bind(wx.EVT_CHECKBOX, self.EvtCheckBox, cb2)
> sizer = wx.BoxSizer(wx.VERTICAL)
> sizer.AddMany( [ cb1,
> cb2,
> ])
>
> border = wx.BoxSizer(wx.VERTICAL)
> border.Add(st, 0, wx.ALL, 15)
> border.Add(sizer, 0, wx.LEFT, 50)
> self.SetSizer(border)
>
>
> def EvtCheckBox(self, event):
> self.log.write('EvtCheckBox: %d\n' % event.IsChecked())
> cb = event.GetEventObject()
> if cb.Is3State():
> self.log.write("\t3StateValue: %s\n" % cb.Get3StateValue())
>
>
> app = wx.PySimpleApp()
> frame = Frame1(None, -1, "Nuffy's wxPython explorer")
> Form1(frame, -1)
> frame.Show(1)
> app.MainLoop()


 
Reply With Quote
 
chris
Guest
Posts: n/a
 
      04-07-2006
Oh, by the way... in your frame's constructor (the Frame1.__init__),
you'll have to make "parent" a member variable of the class so that
OnCloseMe has access to it.

I.e., in the __init__ add
self.FrameParent = parent

Then in OnCloseMe do:
self.FrameParent.Close()

 
Reply With Quote
 
John Ladasky
Guest
Posts: n/a
 
      04-07-2006

(E-Mail Removed) wrote:
> I am also a newbie and learning like you are. I was wondering if do you
> know any wxPython forum just for GUIs ?
> Good luck with your project and hope that some guru helps us out.


If you are reading this via Usenet, you can subscribe to the newsgroup
comp.soft-sys.wxwindows. You will find people there who use the
wxWidgets port in many different forms, including wxPython.

You can also visit wxpython.org and subscribe to the mailing list. The
mailing list is mirrored to the Usenet group. Good luck!

+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Ladasky Home Solar, Inc.: blowing sunshine up your |
| power grid since March 24, 2005. Fiat lux! |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Uptime Downtime kWh generated kWh consumed |
| 374 days none 6608 7143 |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

 
Reply With Quote
 
Butternut squash
Guest
Posts: n/a
 
      04-12-2006
John Ladasky wrote:

>
> (E-Mail Removed) wrote:
>> I am also a newbie and learning like you are. I was wondering if do you
>> know any wxPython forum just for GUIs ?
>> Good luck with your project and hope that some guru helps us out.

>
> If you are reading this via Usenet, you can subscribe to the newsgroup
> comp.soft-sys.wxwindows. You will find people there who use the
> wxWidgets port in many different forms, including wxPython.
>
> You can also visit wxpython.org and subscribe to the mailing list. The
> mailing list is mirrored to the Usenet group. Good luck!
>
> +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
> | Ladasky Home Solar, Inc.: blowing sunshine up your |
> | power grid since March 24, 2005. Fiat lux! |
> +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
> | Uptime Downtime kWh generated kWh consumed |
> | 374 days none 6608 7143 |
> +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+



The is alao a book on wxPython at Amazon and others.
wxPython in action.

 
Reply With Quote
 
bieliza@hotmail.com
Guest
Posts: n/a
 
      04-12-2006
And why donīt you use Pythoncard, it takes the headache out of messing
with wxPyhthon

 
Reply With Quote
 
dfh@forestfield.co.uk
Guest
Posts: n/a
 
      04-12-2006
(E-Mail Removed) wrote:
> I am running through the wxPython guide and docs and extrapolating
> enough to get confused.


There is mailing list for wxPython users -
(E-Mail Removed). It is pretty active and its
members, including Robin Dunn the main wxPython developer, are always
very helpful.

If you post code there, I suggest you include it as an attachment to
avoid line wrapping in the message body - the one thing Python doesn't
like!

Regards,
David Hughes

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[wxPython-users] ANNOUNCE: wxPython 2.6.3.0 Robin Dunn Python 0 03-28-2006 06:03 PM
[wxPython-users] Web based applications are possible with wxPython? Ruben Charles Python 6 10-25-2005 09:41 PM
wxPython - wx package (new style wxPython?) Logan Python 5 12-11-2003 04:12 PM
[PY GUI] interest function in python GUI(wxpython,pyqt) program.wxpython,pyqt ulysses Python 4 10-22-2003 03:28 PM
wxPython looses function "wxPython.wx.miscc" Anand Python 1 07-23-2003 01:59 AM



Advertisments