GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Dec-2006, 21:32
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,671
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice
Post

Re: Simple Python Inventory Program


I just posted a GID Community blog entitled: Simple Python Inventory Program.

Quote:
Well, it's been a while since I posted anything about Python. I completed my BS in Computer Engineering and I'm working on my MS in IT Management, so not a lot of spare time lately.

The main thing I've been working on the last few weeks has been making an inventory system for my wife's business. She currently uses a spreadsheet to create her price lists and inventory, but she has to manually create an order form in email every time she buys new things (she's a consultant for a friend's home business, so no one has spent money on a real ordering system yet). read more...

Please let me know what you think.

This is an auto-generated message posted by GIDNetwork™ on behalf of the author.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.

Interested in pen & paper role playing games from the "golden age" of gaming? Visit Old School Role-Playing Games
  #2  
Old 26-Dec-2006, 10:49
Ene Uran Ene Uran is offline
New Member
 
Join Date: Oct 2006
Location: USA West
Posts: 8
Ene Uran is on a distinguished road

Re: Simple Python Inventory Program


What is module quitter and which book did it come from?
  #3  
Old 26-Dec-2006, 11:00
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,671
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Simple Python Inventory Program


Quote:
Originally Posted by Ene Uran
What is module quitter and which book did it come from?
It came from "Programming Python, 3rd Edition". I forgot to include my import files. Here's the quitter source code:
Python Code:
############################################################################
# a Quit button that verifies exit requests;
# to reuse, attach an instance to other GUIs
############################################################################

from Tkinter import *   #get widget classes
from tkMessageBox import askokcancel    #get canned std dialog

class Quitter(Frame):   #subclass our GUI
    def __init__(self, parent = None):   #constructor method
        Frame.__init__(self, parent)
        self.pack()
        widget = Button(self, text = "Quit", command = self.quit)
        widget.pack(side = LEFT)

    def quit(self):
        ans = askokcancel("Verify exit", "Really quit?")
        if ans: Frame.quit(self)

if __name__ == "__main__":
    Quitter().mainloop()

Here's the code for MultiListbox (found at the Activestate Python Cookbook):
Python Code:
from Tkinter import *

class MultiListbox(Frame):
    def __init__(self, master, lists):
	Frame.__init__(self, master)
	self.lists = []
	for l,w in lists:
	    frame = Frame(self); frame.pack(side=LEFT, expand=YES, fill=BOTH)
	    Label(frame, text=l, borderwidth=1, relief=RAISED).pack(fill=X)
	    lb = Listbox(frame, width=w, borderwidth=0, selectborderwidth=0,
			 relief=FLAT, exportselection=FALSE)
	    lb.pack(expand=YES, fill=BOTH)
	    self.lists.append(lb)
	    lb.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
	    lb.bind('<Button-1>', lambda e, s=self: s._select(e.y))
	    lb.bind('<Leave>', lambda e: 'break')
	    lb.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
	    lb.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
	frame = Frame(self); frame.pack(side=LEFT, fill=Y)
	Label(frame, borderwidth=1, relief=RAISED).pack(fill=X)
	sb = Scrollbar(frame, orient=VERTICAL, command=self._scroll)
	sb.pack(expand=YES, fill=Y)
	self.lists[0]['yscrollcommand']=sb.set

    def _select(self, y):
	row = self.lists[0].nearest(y)
	self.selection_clear(0, END)
	self.selection_set(row)
	return 'break'

    def _button2(self, x, y):
	for l in self.lists: l.scan_mark(x, y)
	return 'break'

    def _b2motion(self, x, y):
	for l in self.lists: l.scan_dragto(x, y)
	return 'break'

    def _scroll(self, *args):
	for l in self.lists:
	    apply(l.yview, args)

    def curselection(self):
	return self.lists[0].curselection()

    def delete(self, first, last=None):
	for l in self.lists:
	    l.delete(first, last)

    def get(self, first, last=None):
	result = []
	for l in self.lists:
	    result.append(l.get(first,last))
	if last: return apply(map, [None] + result)
	return result
	    
    def index(self, index):
	self.lists[0].index(index)

    def insert(self, index, *elements):
	for e in elements:
	    i = 0
	    for l in self.lists:
		l.insert(index, e[i])
		i = i + 1

    def size(self):
	return self.lists[0].size()

    def see(self, index):
	for l in self.lists:
	    l.see(index)

    def selection_anchor(self, index):
	for l in self.lists:
	    l.selection_anchor(index)

    def selection_clear(self, first, last=None):
	for l in self.lists:
	    l.selection_clear(first, last)

    def selection_includes(self, index):
	return self.lists[0].selection_includes(index)

    def selection_set(self, first, last=None):
	for l in self.lists:
	    l.selection_set(first, last)

if __name__ == '__main__':
    tk = Tk()
    Label(tk, text='MultiListbox').pack()
    mlb = MultiListbox(tk, (('Subject', 40), ('Sender', 20), ('Date', 10)))
    for i in range(1000):
	mlb.insert(END, ('Important Message: %d' % i, 'John Doe', '10/10/%04d' % (1900+i)))
    mlb.pack(expand=YES,fill=BOTH)
    tk.mainloop()
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.

Interested in pen & paper role playing games from the "golden age" of gaming? Visit Old School Role-Playing Games
  #4  
Old 26-Dec-2006, 11:34
Ene Uran Ene Uran is offline
New Member
 
Join Date: Oct 2006
Location: USA West
Posts: 8
Ene Uran is on a distinguished road

Re: Simple Python Inventory Program


Thanks for clearing that up Crystal,

I thought I had seen that feeble-minded Quitter thing before. Another thing is that the MultiListbox code has the old Python NoNo of mixed space and tab indents and hangs up misserably on the DrPython IDE.

I guess there are many dangers of importing these kind of modules.
  #5  
Old 26-Dec-2006, 11:45
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,671
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Simple Python Inventory Program


I usually go through and clean up imported code when I use it in my programs, even if it's just to add comments so I know what it's doing. But usually I find a lot of small quirks that I can fix, like the tabs vs. spaces indenting.

The code I just posted are straight from the "source"; they aren't the modified ones I'm actually using, though I didn't modify the quitter program very much since it does what I need it to. However, they should work for someone who wants to use them as-is.

Out of curiosity, why do you consider the Quitter "feeble-minded"? (I just like to know how other programmers think so I can get better myself).
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.

Interested in pen & paper role playing games from the "golden age" of gaming? Visit Old School Role-Playing Games
  #6  
Old 09-Jan-2007, 09:17
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 1,015
admin will become famous soon enough

Re: Simple Python Inventory Program


Congratulations C, and thank you for sharing your work.

Recently, I was also interested in a simple "inventory program", and I was going to write to you about your program but problems with my Internet connection prevented me from starting a discussion with you.

Considering that I know nothing about Python, how difficult is it to 'install' this program on my (Windows XP) PC? That's considering that you are willing to share the files with me, of course.

On a related note, I have been using StarOffice / OpenOffice since 2000, and the only thing I missed is the fact that it didn't include a database program.

Today, I see that this is no longer true. Version 2+ (I was using ver.1+) comes with a database program (Base), and the best part, is that I can use it to connect to my existing MySQL server.

I have just downloaded the file (took a while!) and I will experiment to see if I can create a simple form to help me manage my inventory.

I am still struggling with the JDBC driver...
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
  #7  
Old 09-Jan-2007, 10:57
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,671
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Simple Python Inventory Program


As long as you have Python installed on your computer, it should work just fine. The easiest way to run it is just type "python MPPInventory.py" at a DOS prompt; you just have to make sure that all the necessary files are put in the same directory. Because of the interest, I'll see about making a .exe file so everything will be in one package and easily runs on Windows.

Please be aware that it's a very simplistic program right now. I made it as a coding practice mostly so it doesn't have all the whiz-bang features a true DB should have; it's really just using hash tables to store everything. But if people are interested I can work on it some more; Python 2.5 has SQLite built in so I make a true DB out of it.

I wasn't aware that Base connected to MySQL. That's pretty cool. I thought it was just an Access clone; it sounds like it may be even better than Access in that sense.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.

Interested in pen & paper role playing games from the "golden age" of gaming? Visit Old School Role-Playing Games
  #8  
Old 09-Jan-2007, 11:41
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,671
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Simple Python Inventory Program


I've created a Windows .exe file but it weighs in at 4MB, so I can't upload it here. If you would like a copy, just PM me w/ your email address. Otherwise you can just use the Python scripts in the below ZIP file. If you need help, just ask.
Attached Files
File Type: zip MPPInventory_small.zip (5.9 KB, 134 views)
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.

Interested in pen & paper role playing games from the "golden age" of gaming? Visit Old School Role-Playing Games
  #9  
Old 16-Jan-2007, 21:07
Ene Uran Ene Uran is offline
New Member
 
Join Date: Oct 2006
Location: USA West
Posts: 8
Ene Uran is on a distinguished road

Re: Simple Python Inventory Program


Is something like Quitter "feeble-minded"?
In my opinion yes! If I want to exit a program, I really don't want to be asked again! That is something you ask a five year old child.
  #10  
Old 17-Jan-2007, 12:18
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,671
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Simple Python Inventory Program


So what happens if you didn't want to quit but clicked the wrong button accidentally? I've had it happen several times so I personally like being asked if I really want to quit.

Now, if I close the window with the "X" corner button, then I don't want to be bothered because I'm voluntarily closing the whole thing. Of course, it still might be good to have an "are you sure?" dialog in case the user was trying to maximize/minimize the window.

Probably the best thing is to make it user selectable: have a check box where a person can specify "don't ask me again". That way everyone should be happy.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.

Interested in pen & paper role playing games from the "golden age" of gaming? Visit Old School Role-Playing Games
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
BOOKEEPING program, HELP!! yabud C Programming Language 10 17-Nov-2006 03:48
i need help with a simple program!! alfie27 C++ Forum 1 06-Oct-2006 21:29
Looking for opinions crystalattice Miscellaneous Programming Forum 6 27-Sep-2006 21:02
Help with simple math table program (was a SIMPLE program) Bubba C Programming Language 3 09-Mar-2005 12:40

Network Sites: GIDNetwork · GIDApp · GIDBlog · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:17.


vBulletin, Copyright © 2000 - 2014, Jelsoft Enterprises Ltd.