LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 2009)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sun, 7 Jun 2009 02:24:43 -0700
Reply-To:     Albert-jan Roskam <fomcl@yahoo.com>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Albert-jan Roskam <fomcl@yahoo.com>
Subject:      Re: More Python
Comments: To: JonPeck <peck@spss.com>
Content-Type: text/plain; charset=utf-8

Hi Jon,

In his Python book, Mark Summerfield isn't very positive about WXPython for the reason you mentioned. He discusses Tkinter, because it's part of the Python basic library, but that module, too, has drawbacks. Isn't PyQt becoming the 'de facto' standard nowadays? (Summerfield barely mentions this package, perhaps out of modesty, because he's the main developer). Or how about PyGTK, or, for simpler projects, SimpleGUI?

Moreover, wouldn't it be easier to create a web survey (with e.g. Joomla or Limesurvey) to harvest the data, and approach the database using SPSS/PASW? That seems simpler to me than writing an entire gui. Then again, it might also be nice to just write a flashy GUI, for the heck of it.

Cheers, Albert-Jan

--- On Sat, 6/6/09, Peck, Jon <peck@spss.com> wrote:

> From: Peck, Jon <peck@spss.com> > Subject: Re: More Python > To: SPSSX-L@LISTSERV.UGA.EDU > Date: Saturday, June 6, 2009, 11:37 PM > > > > > > > > > > > > > > > > > The Python raw_input approach is not > going to work.  The > Python/SPSS interaction is not architected for this sort of > thing.  You > might be able to rig up something by spawning a Python > shell, but I wouldn't > recommend that approach. > >  > > I can think of three ways to go about > this sort of thing. Perhaps > one of these will meet your requirements.  I'll > list them from easiest to > hardest. > >  > > > If > the number of > questions is modest and static, you could create a > custom dialog box with > the Custom Dialog Builder in 17 and pose the questions > as controls in the > dialog. You could put the dialog on the Custom > menu or anywhere else > in the SPSS menu system. For example, a Combo > Box could have the > question as label and the possible answers as the > dropdown contents.  Text > controls, check boxes, or radio buttons could also > work here.  These dialogs > are very easy to create, and you can have subdialogs, > but this approach > probably would be awkward if there are a lot of > questions. > > >  > > > Use > Python in > external mode, where SPSS is running inside your > Python program.  In > this mode, the raw_input approach would work, but the > SPSS user interface > would never appear.  You could collect the > information and feed it to > SPSS in your program as appropriate, but the user > would not see SPSS or > SPSS output (unless you launched another visible SPSS > session). > > >  > > > Use > a third-party > library such as wxPython (http://www.wxpython.org/download.php > ) to create pop-up boxes posing the questions and > collecting the answers. > wxPython is a comprehensive GUI development > environment, so you can build > practically anything.  However, it's also > rather complex. > > >  > > The saving thing here is that > wxPython comes with some > very simple, prebuilt types of dialogs, so it is quite easy > to put up a series > of those, collect the responses, and get on with > life. These could be run > as a separate program or embedded within the SPSS session > or used in external > mode. > >  > > Here are some wxPython examples: > The first one just puts up an > alert with Yes/No responses possible. > > BEGIN PROGRAM. > > # wxPython Message Dialog > example > >  > > import wx > >  > > app = wx.PySimpleApp() > > > dlg = wx.MessageDialog(None, "Ok to > reformat hard disk?", > "Important Question", > >                       > wx.YES_NO | > wx.ICON_QUESTION) > > ret = dlg.ShowModal() > > if ret == wx.ID_YES: > >    # put Yes action code > here > >    print "You said > yes" > > else: > >    # put No action code > here > >    print "You said > No" > >  > > dlg.Destroy() > > app.Destroy() > > END PROGRAM. > >  > > Here is one that is more realistic. >  It opens a dataset and puts > up a choice list – in this case it is a list of the > scale variables in > the dataset. The user picks one items in the list, > presses OK, and the program > does something with it. > >  > > BEGIN PROGRAM. > > # wxPython variable > picker > >  > > import wx, spss, > spssaux > >  > > spssaux.OpenDataFile("c:/spss17/samples/english/cars.sav") > > > vardict = > spssaux.VariableDict(variableLevel=['scale']) > > > choicelist = > vardict.variables > >  > > app = wx.PySimpleApp() > > > dlg = wx.SingleChoiceDialog(None, > "Select a variable", "&Variables", > choicelist) > > if dlg.ShowModal() == > wx.ID_OK: > >    var = dlg.GetStringSelection() > > else: > >    var = > None > >    > > > dlg.Destroy() > > app.Destroy() > >  > > if var: > >    > spss.Submit("DESCRIPTIVES " + > str(var)) > > END PROGRAM. > >  > > There is also a simple input box that > just lets the user type some > text. > >  > > These examples all just put up one > dialog box and then close down the > gui, but you could equally put up a series of > these. > >  > > I have not tried wxPython with v17. >  With this approach, there are > two gui's active.  Since they would be in separate > processes, I expect > that they would get along well enough, but it would be a > good idea to > experiment a little to make sure. When Python was > running within the SPSS > process, this approach was a little fragile, but I expect > that that is no > longer the case with v17. > >  > > HTH, > > Jon Peck > >  > >  > > > > > > > > > > From: SPSSX(r) > Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On > Behalf Of Tim Hennigar > > Sent: Friday, > June 05, 2009 3:22 > PM > > To: > SPSSX-L@LISTSERV.UGA.EDU > > Subject: > [SPSSX-L] More Python > > > >  > > > > okay Python > gurus - > > > > > >  > > > > > > My next step is > to display a list of questions with default > answers displayed - then probe > > > > > > the user as to > whether they need to be changed and then if > so - ask each question in turn > > > > > > and get the > users input on new values - in real time, > pausing the python execution till > > > > > > I get the > correct answers > > > > > >  > > > > > > My initial > attempt to obtain user input > > > > > >  > > > > > > myorI = > raw_input('Portrait=1 : Landscape=2 <<< > ENTER CHOICE') > > > > > >  > > > > > > does not seem to > do anything - no prompt is 'raised' and so > the program just hangs there. > > > > > >  > > > > > > Hints? > > > > > > >  > > > > > >  > > > > > >  > > > > Thanks! > > Tim > > **************************** > > Notice: > This e-mail and any attachments may contain confidential > and privileged > information. If you are not the intended recipient, > please notify the > sender immediately by return e-mail, do not use the > information, delete this > e-mail and destroy any copies. Any dissemination or > use of this > information by a person other than the intended recipient > is unauthorized and > may be illegal. Email transmissions cannot be > guaranteed to be secure or > error free. The sender therefore does not accept any > liability for errors or > omissions in the contents of this message that arise as a > result of email > transmissions. > > > >  > > > > > > > > >

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD


Back to: Top of message | Previous page | Main SPSSX-L page