ZZucker 342 Practically a Master Poster

Read my lips, it's the ecnomics!

"I mean, these good folks are revolutionizing how businesses conduct their business. And, like them, I am very optimistic about our position in the world and about its influence on the United States. We're concerned about the short-term economic news, but long-term I'm optimistic. And so, I hope investors, you know -secondly, I hope investors hold investments for periods of time -that I've always found the best investments are those that you salt away based on economics."
Words of wisdom from George W. Bush (Austin, TX 01/04/2001)

ZZucker 342 Practically a Master Poster

I'm completely in favor of the separation of Church and State. My idea is that these two institutions screw us up enough on their own, so both of them together is certain death.
-- George Carlin

ZZucker 342 Practically a Master Poster

An interesting way to check if a letter is between A and Z:

def has_cap(text):
    """return True if text contains a capital letter"""
    for ch in text:
        # character ch is between A and Z inclusive
        if 'A' <= ch <= 'Z':
            return True
    return False

text1 = 'the Good die young, Pricks live forever!'
text2 = 'the good die young, pricks live forever!'
print 'text1 =', text1 
print 'text2 =', text2

# test the function has_cap()
if has_cap(text1):
    print "text1 has a capital letter"
else:
    print "text1 has no capital letter"

if has_cap(text2):
    print "text2 has a capital letter"
else:
    print "text2 has no capital letter"
ZZucker 342 Practically a Master Poster

The polls so far indicate a rather close race. Many folks I know are scared of the faltering US economy, and a war to be paid for by inflation. Reagan ran the Russians down by lavishly outspending them on the military. Now it looks like we are doing the same thing to ourselves!

ZZucker 342 Practically a Master Poster

anakastakis: Thank you for giving the rest of us the solution of your problem.

ZZucker 342 Practically a Master Poster

I took the above wxPython templet and added a background or splash image. So now you have a templet that shows you how to create a frame, a panel, a label, an entry (input), a button, sizers, a multiline display and show an image. Could be the backbone of many wxPython GUI applications:

# basic wx.Frame with splash image panel (panel needed for sizers)
# label, edit, button, display, sizer, and border sizer

import wx

class MyFrame(wx.Frame):
    """
    frame and panel
    panel is neded for any sizer widgets
    """
    def __init__(self, parent, id, title):
        # this will be self
        wx.Frame.__init__(self, parent, id, title)
        # add panel
        panel = wx.Panel(self, -1)
        
        # pick a splash image file you have in the working folder
        image_file = 'HIVirus1.jpg'
        bmp = wx.Bitmap(image_file)
        # allow for alternative if splash image file not found
        if bmp:
            splash = wx.StaticBitmap(panel, -1, bmp)
        else:
            panel.SetBackgroundColour('green')
            splash = panel

        # now add the needed widgets
        self.label1 = wx.StaticText(splash, -1, 'Enter ... :')
        self.entry1 = wx.TextCtrl(splash, -1, '...')
        self.button1 = wx.Button(splash, -1, 'Do ... ')
        self.button1.SetBackgroundColour('yellow')
        self.button1.Bind(wx.EVT_BUTTON, self.onCmd)
        info = "Optional instructive message!"
        self.display = wx.TextCtrl(splash, -1, info, size=(250, 100), 
            style=wx.TE_MULTILINE)
        
        # use gridbagsizer for layout of widgets
        # set optional vertical and horizontal gaps
        sizer = wx.GridBagSizer(vgap=5, hgap=10)
        sizer.Add(self.label1, pos=(0, 0))       # pos(row,column)
        sizer.Add(self.entry1, pos=(0, 1))  # row 0, column 1

        # span=(1, 2) --> allow to span over 2 columns 
        sizer.Add(self.button1, pos=(1, 0), span=(1, 2))
        sizer.Add(self.display, pos=(2, 0), span=(1, 2))
        
        # use boxsizer to add border around …
sneekula commented: nicely orchestrated +4
ZZucker 342 Practically a Master Poster

The internal run (ctrl/F9) is pretty klutzy when you have even the slightest error in your code, it simply shuts down!!!!

The external run (alt/F9) behaves more normal, showing you the error message in the output window. So, I would say use alt/F9. The little green run symbol should have been that command!

Otherwise PyScripter is a great Python IDE for the Windows environment. On top of that it is a standalone executable file. I think it is written and compiled in Delphi/Pascal or something like Python4Delphi. Code completion works great.

ZZucker 342 Practically a Master Poster

Where's Pat Paulsen when we need him?

Patrick Layton Paulsen (July 6, 1927 – April 24, 1997) was an American comedian notable for his campaigns for President of the United States in 1968, 1972, 1980, 1988, 1992, and 1996.

Presidential Campaign Slogan: "If elected, I will win."

Well, Pat is gone, but there are others like Comedy Central's Dr. Stephen T. Colbert, or Bill O'Reilly from Fox News' The O'Reilly Factor. They could be good replacements for John McCain if his senior moments get too numerous.

ZZucker 342 Practically a Master Poster

Believe that everything is beautiful, including what is ugly, everything good, especially the bad, and everything right that is wrong.

ZZucker 342 Practically a Master Poster

A new teacher was trying to make use of her psychology courses. She started her class by saying, "Everyone who thinks they are stupid, stand up!"

After a few seconds, Little Johnny stood up.

"Do you think you're stupid, Little Johnny?"

"No, ma'am, but I hate to see you standing there all by yourself!"

ZZucker 342 Practically a Master Poster

"None are more hopelessly enslaved than those who falsely believe they are free."
Johann Wolfgang von Goethe

ZZucker 342 Practically a Master Poster

"Natural Gas" that is delivered to homes and businesses has 27 different additives that do not occur naturally.

ZZucker 342 Practically a Master Poster

I took Lardmeister's code and made a generic wxPython templet that you can then flesh out for cases when you need the user to enter data, press a button to process the data, and then show the result in an output area:

# basic wx.Frame with panel (needed for sizers), label, 
# edit, button, display, sizer, and border sizer

import wx

class MyFrame(wx.Frame):
    """
    frame and panel
    panel is neded for any sizer widgets
    """
    def __init__(self, parent, id, title):
        # this will be self
        wx.Frame.__init__(self, parent, id, title)
        # add panel
        panel = wx.Panel(self, -1)
        panel.SetBackgroundColour('green')

        # now add the needed widgets
        self.label1 = wx.StaticText(panel, -1, 'Enter ... :')
        self.entry1 = wx.TextCtrl(panel, -1, '...')
        self.button1 = wx.Button(panel, -1, 'Do ... ')
        self.button1.SetBackgroundColour('yellow')
        self.button1.Bind(wx.EVT_BUTTON, self.onCmd)
        info = "Optional instructive message!"
        self.display = wx.TextCtrl(panel, -1, info, size=(250, 100), 
            style=wx.TE_MULTILINE)
        
        # use gridbagsizer for layout of widgets
        # set optional vertical and horizontal gaps
        sizer = wx.GridBagSizer(vgap=5, hgap=10)
        sizer.Add(self.label1, pos=(0, 0))       # pos(row,column)
        sizer.Add(self.entry1, pos=(0, 1))  # row 0, column 1

        # span=(1, 2) --> allow to span over 2 columns 
        sizer.Add(self.button1, pos=(1, 0), span=(1, 2))
        sizer.Add(self.display, pos=(2, 0), span=(1, 2))
        
        # use boxsizer to add border around sizer
        border = wx.BoxSizer()
        border.Add(sizer, 0, wx.ALL, 20)
        panel.SetSizerAndFit(border)
        self.Fit()
        
    def onCmd(self, event):
        """process data and show result"""
        # get the data from the input widget
        string1 = self.entry1.GetValue()
        # do the processing ...
        proc_data = string1 * 3   
        # show the result ...
        self.display.SetValue(proc_data) 
        

app = wx.App(redirect=False)
frame = MyFrame(None, -1, "Title …
ZZucker 342 Practically a Master Poster

Use something like this:

self.button2 = Button(frameToolbar, text="PRINT", bg="light green", width=5, 
    relief=RAISED, font=("Verdana", "9", "bold"), command=self.print_)
self.button2.grid(row=0, column=0) 

self.button = Button(frameToolbar, text="CLOSE", bg="red", width=5, 
    relief=RAISED, font=("Verdana", "9", "bold"), command=self.destrparent)
self.button.grid(row=0, column=1) 

self.button1 = Button(frameToolbar, text="SUM", bg="light blue", width=5, 
    relief=RAISED, font=("Verdana", "9", "bold"), command=self.mult)
self.button1.grid(row=0, column=2)

Please use code tags -->
[code=python]
your Python code here

[/code]

ZZucker 342 Practically a Master Poster

Save your script as somefilename.py and double click on the name to run it from the Windows file manager. Or better, use the editor of an IDE like IDLE, DrPython or PyScripter to write your code and run it from there.

See:
http://www.daniweb.com/forums/thread20774.html

ZZucker 342 Practically a Master Poster

There are three reasons why lawyers are replacing rats as laboratory research animals. One is that they are plentiful, another is that lab assistants don't get so attached to them, and the third is that they will do things that you just can't get rats to do.

ZZucker 342 Practically a Master Poster

Looking for a male couch/mouse potato with a large beer belly and a minor amount of hair on top, should be ugly enough to scare any insects out of my place.

jephthah commented: snicker +3
ZZucker 342 Practically a Master Poster

Bacterial infections are becoming more and more difficult to treat. Strange varieties of normally mild acting bacteria appear on common food items. Makes you think.

Maybe we can blame the Iranians.

ZZucker 342 Practically a Master Poster

Where can I find a place that sells square pizza in a round box?

ZZucker 342 Practically a Master Poster

A cap of good acid costs twenty bucks and for that you can hear the Universal Symphony with God singing solo and the Holy Ghost on drums.

ZZucker 342 Practically a Master Poster

Smooth seas do not make for a skillful sailor.
African Proverb

ZZucker 342 Practically a Master Poster

Watching and listening to the surf come in, is very inspiring to my creativity. Not quite sure how my notebook handles sand and salt.

ZZucker 342 Practically a Master Poster

Hopefully it's 41 month at hard labor! Oh yes, no computer in the prison cell, and let his cellmates be 350 pound horny roughnecks.

ZZucker 342 Practically a Master Poster

Go Settings/Preferences/Calltips and mark enable.

It works, but is rather poorly implemented.

ZZucker 342 Practically a Master Poster

With so much hoopla about hydrogen as fuel of the future let's do this:
Write a Python program that calculates the energy obtained from burning one liter of hydrogen (H2) gas, as compared to one liter of methane gas or propane gas.

ZZucker 342 Practically a Master Poster

I just saw that in my LA neighborhood:
$4.99 for a gallon (3.8 liters) of regular gasoline.

I guess the fuel wars are on in the good old USA!

For our friends in Europe, that's 0.85 Euro per liter.

ZZucker 342 Practically a Master Poster

You have simple use the try/except error routine:

numblist = [1 , 2 , 3, 5, 6, 7, 8, 9, 11]

for i in numblist:
    try:
        if numblist[i] == numblist[i + 1] - 1:
            print 'yay'
        else:
            print 'gap'
    except:
        pass
ZZucker 342 Practically a Master Poster

BTW, I use the wxPython based SPE IDE and like it a lot. Its a free download from:
for any CPU
http://prdownload.berlios.de/python/SPE-0.8.4.c-wx2.6.1.0-no_setup.zip
for i386 CPU
http://prdownload.berlios.de/python/SPE-0.8.4.d-wx2.6.1.0-no_setup.zip.zip

Make sure you have wxPython installed, then simply extract the zip file into your Python Lib directory, open the _spe directory and run SPE.pyw, thats it.

ZZucker 342 Practically a Master Poster

To be able to run eric4 you should have the following installed first:

Python 2.4.0 or better
Qt 4.2.0 or better (from Trolltech)
PyQt 4.1.0 or better (from Riverbank)
QScintilla 2.1 or better (from Riverbank)

Do have all of these installed?

ZZucker 342 Practically a Master Poster

Welcome to the world of self! Just a side note, the Python style guide recommends to start class names with upper case and function/method names with lower case. If you write larger programs, this really helps.

The Python style guide by GVR himself:
http://www.python.org/peps/pep-0008.html

ZZucker 342 Practically a Master Poster

John McCain pulled a very slick trick to have George Bush appear at one of his fund risers, but to exclude the press from the event. I guess he doesn't want to be seen publicly next to GW. After all, GW might come through as the brighter of the two!

ZZucker 342 Practically a Master Poster

If all the world's oceans were divided amongst all the people on the planet, each person would get five cubic miles of water.

ZZucker 342 Practically a Master Poster

I suggest you study your class notes more carefully. Here is a short example that might help you:

class Die(object):

    def __init__(self, v):
        """
        the constructor of the class
        self 'carries' the instance
        dice initially has value v
        """
        self.value = v
        
    def __str__(self):
        """overload __str__ will be used in print statement"""
        s = "dice shows " + str(self.value)
        return s

    def throw(self):
        """throw one dice here to show 1 - 6"""
        import random
        self.value = random.randint(1, 6)


# create an instance of class Die and set initial value to 1
# uses Die.__init__(self, 1) where self would be the instance q
q = Die(1)

print q  # dice shows 1

q.throw()

print q  # eg. dice shows 3

q.throw()

print q  # eg. dice shows 6
ZZucker 342 Practically a Master Poster

The short Python program below shows you how to create a hot-spot on a frame/window surface using the Tkinter GUI toolkit:

# show mouse position as mouse is moved and create a hot-spot

import Tkinter as tk

root = tk.Tk()

def showxy(event):
    xm = event.x
    ym = event.y
    str1 = "mouse at x=%d  y=%d" % (xm, ym)
    root.title(str1)
    # switch color to red if mouse enters a set location range (hot-spot)
    x = 100
    y = 100
    delta = 10  # range around center x,y
    if abs(xm - x) < delta and abs(ym - y) < delta:
        frame.config(bg='red')
    else:
        frame.config(bg='yellow')
        

frame = tk.Frame(root, bg= 'yellow', width=300, height=200)
frame.bind("<Motion>", showxy)
frame.pack()

root.mainloop()

Your project will be to put a picture or map image on the surface, and then create a number of hot-spots. When the mouse pointer gets in range of these hot-spots a descriptive text message could appear. You could also make it different sounds or whatever, use your imagination.

ZZucker 342 Practically a Master Poster

You need to use one of the GUI toolkits for Python. The simplest one is Tkinter that normally comes with Python. You simply add an if statement that does something when your x,y matches the mouse's x,y coordinates (or range):

# show mouse position as mouse is moved and create a hot spot

import Tkinter as tk

root = tk.Tk()

def showxy(event):
    xm = event.x
    ym = event.y
    str1 = "mouse at x=%d  y=%d" % (xm, ym)
    root.title(str1)
    # switch color to red if mouse enters a set location range
    x = 100
    y = 100
    delta = 10  # range
    if abs(xm - x) < delta and abs(ym - y) < delta:
        frame.config(bg='red')
    else:
        frame.config(bg='yellow')
        

frame = tk.Frame(root, bg= 'yellow', width=300, height=200)
frame.bind("<Motion>", showxy)
frame.pack()

root.mainloop()

You can create several hot spots on top of a picture or map and have different text show up.

ZZucker 342 Practically a Master Poster

You could use module re and its sub() method.

ZZucker 342 Practically a Master Poster

Looks like x is a list of lists.

ZZucker 342 Practically a Master Poster

Vegaseat has given Tkinter a namspace tk. Good coding practice to avoid method collisions, and to tell folks that read your code where the method came from. Is that what's confusing to you?

ZZucker 342 Practically a Master Poster

The standard try/except way would be:

def choose(s):
    try:
        return "You entered " + {
        '1' : "one",
        '2' : "two",
        '3' : "three"
        }[s]
    except:
        return "Bad input"

var1 = raw_input("Input a number between one and three: ")
print choose(var1)

Or straight foreward with dictionary method get():

def choose2(s):
    return "You entered " + {
    '1' : "one",
    '2' : "two",
    '3' : "three"
    }.get(s, "a bad number")

var1 = raw_input("Input a number between one and three: ")
print choose2(var1)

This is closer to the switch/case default.

ZZucker 342 Practically a Master Poster

So, what is 'LOL' in Dutch?

ZZucker 342 Practically a Master Poster

The Iron Lady was a class act. Hillary would have to be reborn to follow in her shoes.

ZZucker 342 Practically a Master Poster

When you get to the end of your rope, tie a knot and hang on.
-- Franklin D. Roosevelt

ZZucker 342 Practically a Master Poster

The whole thing is a little bit like the painted flags on some military uniforms. Most folks don't know what they are for. I always thought that the stars where the LOL count.

ZZucker 342 Practically a Master Poster

I wonder if folks celebrate Mothers Day in every country on Earth?

ZZucker 342 Practically a Master Poster

Very interesting.

ZZucker 342 Practically a Master Poster

Eating a large amount of beans and then do one or more of the following:
Take a bubble bath.
Get my teeth checked at the dentist.
Go to an IRS audit.
Go to jury duty.

scru commented: LOL +3
majestic0110 commented: Hehe +2
ZZucker 342 Practically a Master Poster

Wonder why it's called "The Stupid Test" and not "The Smart Test"?

ZZucker 342 Practically a Master Poster

Never tell a story because it is true: tell it because it is a good story.

ZZucker 342 Practically a Master Poster

My grandfather once told me that there were two kinds of people: those who do the work and those who take the credit. He told me to try to be in the first group; there was much less competition.
-- Indira Gandhi

ZZucker 342 Practically a Master Poster

Winston Churchill's favorite food was mayonnaise and pickles.