python真是太强大了,越用越喜欢,都担心能否够毕业设计要求的代码量了,嘻嘻。
这个模块的功能就是选取选取自己喜欢的分类然后保存选取的结果
1,主程序文件,resume
#!/usr/bin/python
import resume_imp
import resume_view
if __name__== "__main__":
resume_view.CResumeView(resume_imp.CResumeImp())
resume_view.main()
2,界面文件resume_view.py
#!/usr/bin/python
import pygtk
pygtk.require('2.0')
import gtk
class CResumeView:
def __init__(self,resume_imp):
self.resume_imp = resume_imp
self.init_gui()
def check_callback(self, widget,data=None):
i = data
state = widget.get_active()
res=self.resume_imp.select_do(i,state)
if(res < 0):
widget.set_active(False)
max= self.resume_imp.get_max_active_class()
self.msgbox('warnning','you must choice at most %d classes'%max)
def msgbox(self,title_str,msg_str):
def done(widget,data):
data.destroy()
dialog = gtk.Dialog(title_str, self.window, gtk.DIALOG_MODAL)
button = gtk.Button("ok")
button.connect('clicked',done,dialog)
dialog.action_area.pack_start(button, True, True, 0)
button.show()
label = gtk.Label(msg_str)
dialog.vbox.pack_start(label, True, True,0)
label.show()
dialog.show()
def button_callback(self, widget, data=None):
self.resume_imp.finish_resume()
def delete_event(self, widget, event, data=None):
gtk.main_quit()
return False
def init_gui(self):
#windows init
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("delete_event", self.delete_event)
self.window.set_border_width(20)
n = self.resume_imp.get_list_len()
table = gtk.Table(n+1,4,True)
self.window.add(table)
#check button init
i = 0
while i top = i
bottom = i+1
left = self.resume_imp.get_class_level(i)
right = left + 1
button = gtk.CheckButton(self.resume_imp.get_show_name(i))
if self.resume_imp.get_class_state(i) == 'active':
button.set_active(True)
else :
button.set_active(False)
button.connect("toggled",self.check_callback,i)
j = 0
while j label = gtk.Label('--------')
table.attach(label,j,j+1,top,bottom)
label.show()
j = j + 1
table.attach(button, left,right,top,bottom)
button.show()
i=i+1
#button init
button = gtk.Button("OK")
table.attach(button, 0,1,n,n+1)
button.connect("clicked",self.button_callback,"ok")
button.show()
table.show()
self.window.show()
def main():
gtk.main()
return 0
3,实现文件resume_imp.py
#!/usr/bin/python
import resume_node
class CResumeImp:
def __init__(self):
self.init_resume()
def init_resume(self):
self.class_list = []
self.max_active_class = 5
self.list_len = self.init_raw_resume()
self.num_active_class = self.init_last_resume()
def init_raw_resume(self):
n=0
f=file('class.db')
while True:
line = f.readline()
if len(line) == 0:
break
n = n+1
self.class_list.append(self.split_entry(self.get_string(line)))
f.close()
return n
def init_last_resume(self):
f=file('resume.db')
n = 0
while True:
line = f.readline()
if len(line) == 0:
break
n = n + 1
i = self.find_entry(self.get_string(line))
# not find out
if (i < 0):
continue
self.class_list[i].state='active'
return n
f.close()
def find_entry(self, elem):
i = 0
while i < self.list_len:
if self.class_list[i].id == elem:
return i
i = i+1
return -1
def finish_resume(self):
self.write_resume_file()
def write_resume_file(self):
if self.num_active_class == 0:
print "please choice at least one class"
return
f=file('resume.db','w')
n = len(self.class_list)
i=0
while i < n:
state = self.class_list[i].state
if state == 'active':
line = self.class_list[i].id
f.write(line)
f.write('\n')
i=i+1
f.close()
# replace the \n
def get_string(self,str):
return str.replace('\n','')
def get_list_len(self):
return self.list_len
def get_show_name(self,i):
# all is not used
#id = self.class_list[i].id
#name = self.class_list[i].name
#n = self.get_class_level(id)
#result = ""
#i=0
#while i # result = result + '----'
# i=i+1
#result = result + name
#end
return self.class_list[i].name
def get_class_level(self, index):
id = self.class_list[index].id
n = 0
while True:
i = id.find('.')
if i < 0:
return n
n = n + 1
id = id[i+1:len(id)]
def split_entry(self,entry):
i=entry.find(':')
if i == -1:
return {}
id=entry[0:i]
name=entry[i+1:len(entry)]
return resume_node.CResumeNode(id,name,'inactive')
def select_do(self,i,state):
if state == True :
self.num_active_class = self.num_active_class + 1
if(self.num_active_class > self.max_active_class):
return -1
self.set_active(i)
else:
self.num_active_class = self.num_active_class - 1
self.set_inactive(i)
return 0
def get_class_state(self, i):
return self.class_list[i].state
def get_max_active_class(self):
return self.max_active_class
def set_active(self,i):
self.class_list[i].state = 'active'
def set_inactive(self,i):
self.class_list[i].state = 'inactive'
4,列表节点类文件
#/usr/bin/python
class CResumeNode:
def __init__(self,id,name,state='inactive'):
self.id=id
self.name=name
self.state=state