My son wants me to teach him Python

Rick Johnson rantingrickjohnson at gmail.com
Sun Jun 16 15:04:07 EDT 2013


On Thursday, June 13, 2013 11:05:00 PM UTC-5, Chris Angelico wrote:

Chris, a GUI interface can be created for *ANY* command line
functionality. By utilizing the GUI you can be more
productive because a "point" and a "click" are always faster
than "peck-peck-peck" * INFINITY. 

For instance, if i want to start a certain program (or func)
on the commandline, first i will need to know what commands
are available. To see these commands i must *FIRST* type a
command. On the windows box that command would be "help".
Now hopefully the command list will fit within the console's
buffer capacity, or else i need to enter a page buffer mode
(SOMEBODY KILL ME NOW!!!).

This is where the GUI shines!

When i choose to open my "system tools gui" (instead of the
antiquated text only console), a list of commands will be
displayed in a nice list box with scroll-bars that have near
unlimited capacity to scroll. All i need to do is "point"
and "click" and this "magical" piece of software runs
another GUI program for that specific task or tool.

> Also - Show me an efficient way, with a GUI, to invoke any
> file with any program with any parameters, without
> cheating and using something like Alt-F2 to enter a
> command line. Your solution must be utterly generic. I
> need to be able to tail -F and tail -f a file.

Just because you lack the graphical tools on your machine,
or the skill to create those graphical tools on your
machine, does not mean the rest of us are as incapable. 

Note: The following solution requires you to have a windows
OS, if you are using anything else, then you should be geeky
enough to roll your own solution!

## BEGIN SCRIPT ##
# Python Version < 3.0 only!
import sys, os
import Tkinter as tk
import tkSimpleDialog, tkMessageBox

msg1 = 'Greetings master, by what method shall i execute "{0}"?'
msg2 = """\
And the master sayeth:

"{0}"

So it is written, so shall it be done"""
ivalue = "some/path/to/nowhere.txt -opt1=foo -opt2=bar"

def prompt_master():
    argv = sys.argv
    path = argv[1]
    fname = os.path.basename(path)
    msg = msg1.format(fname)
    argstr = tkSimpleDialog.askstring('',
                                      msg,
                                      initialvalue=ivalue,
                                      parent=root
                                      )
    if argstr:
        tkMessageBox.showinfo('', msg2.format(argstr),parent=root)
        os.system('{0} {1}'.format(path, argstr))
    root.destroy()

if __name__ == '__main__':
    root = tk.Tk()
    root.withdraw()
    prompt_master()
    root.mainloop()
## END SCRIPT ##

Save that code in a file named "PepsiChallenge.py", then
throw that script in your "Send To" folder and it
"magically" becomes accessible from the "SendTo" command of
the windows context menu. If you don't know where to find
your windows "send to" folder then ask my good friend
Google.

To use, simply open your windows file browser, navigate to a
file icon, right click the file, and send it to the
PepsiChallenge script. 

By doing this we've harnessed the power of an existing GUI
without actually writing all the GUI code. But more
importantly we've won the challenge :-P"

*school-bell*



More information about the Python-list mailing list