ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/learning/Downloaded/filemaker.py
Revision: 8
Committed: Sat May 5 04:21:19 2012 UTC (13 years, 10 months ago) by ninoborges
Content type: text/x-python
File size: 3742 byte(s)
Log Message:
Initial Import

File Contents

# User Rev Content
1 ninoborges 8 from Tkinter import *
2     from string import *
3     from fileselector import *
4     from sys import exit
5    
6     class FileMaker(Frame):
7     def __init__(self, objecttype, objectname, labelformula, master = None):
8     Frame.__init__(self,master)
9     self.objecttype = objecttype
10     self.objectname = objectname
11     self.labelformula = labelformula
12     self.objects = []
13     self.createmenus()
14     self.createwidgets()
15    
16     def addobject(self, s):
17     s.index = len(self.objects)
18     self.objects.append(s)
19    
20     def update(self):
21     self.objectlist.delete(0, 'end')
22     for i in range(len(self.objects)):
23     s = self.objects[i]
24     name = self.labelformula(s)
25     self.objectlist.insert('end',name)
26    
27     def newset(self):
28     fname = newfileselector(self, "New Set")
29    
30     def saveset(self):
31     pass
32    
33     def loadset(self):
34     fname = oldfileselector(self, "Existing Set")
35    
36     def new_object(self):
37     object = self.objecttype(self,None)
38    
39     def choose_object(self, e):
40     selection = self.objectlist.curselection()
41     if selection and len(selection) == 1:
42     index = atoi(e.widget.curselection()[0])
43     object = self.objecttype(self, self.objects[index])
44    
45     def exit(self):
46     sys.exit
47    
48     def makeFileMenu(self):
49     File_button = Menubutton(self.mBar, text = 'File', borderwidth = 1, underline = 0)
50     File_button.pack( side = LEFT, padx = '1m')
51     File_button.menu = Menu(File_button, borderwidth = 1, tearoff = 0, activeborderwidth = 0)
52     File_button.menu.add('command', label = 'New '+self.objectname+' Set...', underline = 0,
53     command = self.newset)
54     File_button.menu.add('command', label = 'Load '+self.objectname+' Set...',
55     underline = 0, command = self.loadset)
56     File_button.menu.add('command', label = 'Save '+self.objectname+' Set...',
57     underline = 0, command = self.saveset)
58     File_button.menu.add('command', label = 'Quit',
59     underline = 0, command = self.exit)
60     # set up a pointer from the file menubutton back to the file menu
61     File_button['menu'] = File_button.menu
62     return File_button
63    
64     def makeEditMenu(self):
65     Edit_button = Menubutton(self.mBar, text = 'Edit', borderwidth = 1, underline = 0)
66     Edit_button.pack( side = LEFT, padx = '1m')
67     Edit_button.menu = Menu(Edit_button, borderwidth =1, tearoff = 0, activeborderwidth = 0)
68     # just to be cute, let's disable the undo option:
69     Edit_button.menu.add('command', label = "Undo" )
70     # undo is the 0th entry...
71     Edit_button.menu.entryconfig(1, state = DISABLED )
72     # and these are just for show. No "command" callbacks attached.
73     Edit_button.menu.add('command', label = "Cut" )
74     Edit_button.menu.add('command', label = "Copy" )
75     Edit_button.menu.add('command', label = "Paste" )
76    
77     # set up a pointer from the file menubutton back to the file menu
78     Edit_button['menu'] = Edit_button.menu
79    
80     return Edit_button
81    
82     def createmenus(self):
83     self.mBar = Frame(self, relief = RAISED, bd = 1)
84     self.mBar.pack( side = TOP, fill = X)
85     self.fileButton = self.makeFileMenu()
86     self.editButton = self.makeEditMenu()
87     self.mBar.tk_menuBar(self.fileButton, self.editButton)
88    
89     def createwidgets(self):
90     self.new = Button(self, borderwidth =1)
91     self.new['text'] = "Create New " + self.objectname
92     self.new['command'] = self.new_object
93     self.new.pack( expand =1, fill = BOTH )
94     self.objectlist = Listbox(self, width =300, height =300, highlightcolor = 'grey',selectmode = BROWSE, selectborderwidth = 0, relief = SUNKEN, borderwidth = 1)
95     self.objectlist.bind('<Double-1>', self.choose_object)
96     self.objectscroll = Scrollbar(self, orient = VERTICAL, width = 12, borderwidth = 1)
97     self.objectlist['yscrollcommand'] = self.objectscroll.set
98     self.objectscroll['command'] = self.objectlist.yview
99     self.objectscroll.pack( side = RIGHT, fill = BOTH, expand = 1)
100     self.objectlist.pack( side = LEFT , fill = BOTH )
101     self.pack()
102