From: Schollnick, B. <Ben...@xe...> - 2005-06-06 12:06:11
|
Alex, Not exactly what you are asking for....but it might be a feeble starting point.... def wxPython_YesNo_Cancel_Dialog ( wxapp =3D None, title=3D"Alert!", msg_text=3D"Nothing to say" ): """Display a QUESTION string which can be answered with Yes or No. =09 Return 1 when the user clicks the Yes button. Return 0 when the user clicks the No button. Return -1 when the user clicks the Cancel button. =09 When the user presses Return, the DEFAULT value is returned. If omitted, this is 0 (No). =09 The QUESTION string can be at most 255 characters. """ =09 dlg =3D wxPython.wx.wxMessageDialog(wxapp, msg_text, title,=20 wxPython.wx.wxYES_NO | wxPython.wx.wxCANCEL | wxPython.wx.wxICON_INFORMATION) results =3D dlg.ShowModal() if results =3D=3D wxPython.wx.wxID_YES: results =3D True elif results =3D=3D wxPython.wx.wxID_NO: results =3D False elif results =3D=3D wxPython.wx.wxID_CANCEL: results =3D -1 dlg.Destroy() return results I have not had a need since using Pythoncard to create the exact wrapper you are discussing... I think that WXPython has a MessageDialog that allows you to configure the 3 buttons, but I have not looked that up yet... I just glanced, but did not see any obvious way to modify the messagedialog in wxpython... Without possibly customizing a subclass or creating a dialog from scratch in wxpython.... But I am *NOT* a wxpython guru.... I was good at Tkinter, but got tired of using Tkinter, started to use wxPython, and held a "pity" party of myself regarding wxPython documentation, and migrated to PythonCard... So I classify myself as "good enough to be dangerous" in regards to straight wxPython... - Benjamin=20 - Benjamin > -----Original Message----- > From: pyt...@li...=20 > [mailto:pyt...@li...] On=20 > Behalf Of Alex Tweedly > Sent: Saturday, June 04, 2005 4:38 PM > To: PythonCard > Subject: [Pythoncard-users] Easy way to get a multi-button dialg box >=20 >=20 >=20 > I was looking for an easy way to get a dialog box which=20 > presented some=20 > info, and then let the user choose one from a set of options, by=20 > clicking on one of a set of buttons. I was sure there was a=20 > way provided=20 > in Pythoncard (or at least in wxPython) to do this - but=20 > can't find it. >=20 > All I want is to get a dialog like >=20 > Can I go to the movies tonight ? >=20 > +-------+ +-------+ +-------+ > | Yes | | No | | Maybe | > +-------+ +-------+ +-------+ >=20 > without needing to build a new custom dialog each time. >=20 > So, I've built a couple of functions to do that for me - see=20 > code below=20 > to see the kind of thing I want. They could be improved and=20 > generalized=20 > a bit - but there's still this nagging feeling I'm missing=20 > some easy way=20 > .... anyone ? If no one tells me about an easy way that=20 > already exists,=20 > I'll improve these a bit and post them somewhere ... >=20 > testdialogs.py (needs a resource file, which only needs=20 > one button,=20 > so I didn't include it !!) > =3D=3D=3D=3D=3D=3D=3D=3D=3D > #!/usr/bin/python >=20 > """ > __version__ =3D "$Revision: 1.5 $" > __date__ =3D "$Date: 2004/04/30 16:26:12 $" > """ >=20 > from PythonCard import model > import multiButtonDialog >=20 > class MyBackground(model.Background): >=20 > def on_initialize(self, event): > # if you have any initialization > # including sizer setup, do it here > pass >=20 > def on_Button1_mouseClick(self, event): > result =3D multiButtonDialog.multiButtonDialog(self, 'some=20 > question', ['OK', 'Not OK', "Cancel"], "Test Dialog Title") > print "Dialog result:\naccepted: %s\ntext: %s" %=20 > (result.accepted, result.text) >=20 > result =3D multiButtonDialog.multiButtonDialog(self,=20 > 'Dad, can I=20 > go to the movies tonight', \ > ['Yes', 'No', 'Maybe', 'Ask me later', 'Ask=20 > your mum'],=20 > "Movies Dialog Title") > print "Dialog result:\naccepted: %s\ntext: %s" %=20 > (result.accepted, result.text) >=20 >=20 > if __name__ =3D=3D '__main__': > app =3D model.Application(MyBackground) > app.MainLoop() >=20 > multiButtonDialog.py > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > """ > __version__ =3D "$Revision: 1.3 $" > __date__ =3D "$Date: 2004/08/12 19:14:23 $" > """ >=20 > # dialog to present a block of text and a number of=20 > alternative buttons >=20 >=20 > from PythonCard import model > import controls >=20 > rsrc =3D {'type':'CustomDialog', > 'name':'Template', > 'title':'Template', > 'position':(176, 176), > 'size':(367, 230), > 'components': [ >=20 > ## {'type':'TextArea', > {'type':'StaticText', > 'name':'Text', > 'position':(10, 10), > 'size':(341, 123), > 'actionBindings':{}, > }, >=20 > {'type':'Button', > 'id':5101, > 'name':'Button', > 'position':(269, 145), > 'actionBindings':{}, > 'label':'template', > }, >=20 > ] # end components > } # end CustomDialog >=20 >=20 > class MyDialog(model.CustomDialog): > def __init__(self, parent, txt, buttons): > model.CustomDialog.__init__(self, parent, rsrc) > self.components.Text.text =3D txt > self.components.Button.visible =3D False > self.components.Button.enabled =3D False > if len(buttons) =3D=3D 0: buttons =3D ["OK"] > bx, by =3D self.components.Button.size > dx =3D bx + 20 > # check if all buttons will fit in window > owx, owy =3D self.size > startx, starty =3D self.components.Button.position > if len(buttons)*dx + bx + 40 > owx: > wx =3D len(buttons)*dx + bx + 40 > self.size =3D (wx, owy) > startx, starty =3D (wx-bx-20, owy-by-30) # AGT - why 30 = ?? > tsx, tsy =3D self.components.Text.size > self.components.Text.size =3D (wx-20, tsy) > =20 > localbuttons =3D buttons > localbuttons.reverse() > count =3D 0 > for b in localbuttons: > n =3D controls.copyButton(self, "Button",=20 > "Button"+str(count), b) > self.components[n.name].position =3D startx-count*dx, = starty > self.components[n.name].visible =3D True > self.components[n.name].enabled =3D True > count +=3D 1 > self.accepted =3D False > self.text =3D "" > =20 > def on_mouseClick(self, event): > self.text =3D event.target.userdata > if self.text =3D=3D "Cancel": > self.accepted =3D False > else: > self.accepted =3D True > self.Close() >=20 > def multiButtonDialog(parent, txt, buttons, title=3D""): > rsrc["title"] =3D title > dlg =3D MyDialog(parent, txt, buttons) > result =3D dlg.showModal() > result.accepted =3D dlg.accepted > result.text =3D dlg.text > dlg.destroy() > return result >=20 > controls.py > =3D=3D=3D=3D=3D=3D=3D >=20 > #!/usr/bin/python >=20 > # controls.py - a set of funcitonsd to manipulate contorls at run time >=20 > from PythonCard import model > from wxPython import wx > import string, copy > from types import * >=20 >=20 > class copyButton: > def __init__(self, Background, ButtonName, newname,=20 > Text=3D"new button"): > Flds =3D ['position', 'size', 'backgroundColor',=20 > 'foregroundColor', 'command', 'font'] > aWidget =3D Background.components[ButtonName] > d =3D {} > d['type'] =3D aWidget.__class__.__name__ > for key in Flds: # attributes > # I'm not exactly sure why I have to special-case=20 > these tuples > if key =3D=3D 'bitmap': > # this should get recreated from the file attribute > pass > elif key in ['position', 'size']: > d[key] =3D getattr(aWidget, key) > elif getattr(aWidget, key) is not None: > d[key] =3D getattr(aWidget, key) > d['userdata'] =3D Text > d['label'] =3D Text > d['name'] =3D newname > Background.components[newname] =3D d > self.name =3D newname >=20 > --=20 > Alex Tweedly http://www.tweedly.net >=20 >=20 >=20 > --=20 > No virus found in this outgoing message. > Checked by AVG Anti-Virus. > Version: 7.0.322 / Virus Database: 267.5.2 - Release Date: 03/06/2005 >=20 >=20 >=20 > ------------------------------------------------------- > This SF.Net email is sponsored by: NEC IT Guy Games. How far=20 > can you shotput a projector? How fast can you ride your desk=20 > chair down the office luge track? If you want to score the=20 > big prize, get to know the little guy. =20 > Play to win an NEC 61" plasma display:=20 > http://www.necitguy.com/?r=3D20=20 > _______________________________________________ > Pythoncard-users mailing list Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users >=20 |