From 2d45e5e6e39ea040f89020adbbfd1bd0163865cc Mon Sep 17 00:00:00 2001 From: David Van Assche Date: Thu, 10 Sep 2009 11:56:57 +0000 Subject: added new pyclicuser.png and pyclicuser now draws results to main window --- diff --git a/pyclicuser.png b/pyclicuser.png new file mode 100644 index 0000000..b469b93 --- /dev/null +++ b/pyclicuser.png Binary files differ diff --git a/pyclicuser.py b/pyclicuser.py index d2ac301..572ebed 100644 --- a/pyclicuser.py +++ b/pyclicuser.py @@ -90,53 +90,27 @@ class PyClicAdmin: #Make sure it's not a blank string if (item_node.firstChild): - self.title_entry.set_text(item_node.firstChild.nodeValue) + self.title_label.set_text(item_node.firstChild.nodeValue) else: - print "Tag not loaded, probably empty" + print "Tag wasnt loaded, probably empy" title_loaded = True - # Title Tag loaded at this point and placed by self.title_entry.set_text elif (item_node.nodeName == PyClicCommon._xml_tags[CATEGORY_TAG]): """Set the category, the firstChild in this case is the actual category that we saved.""" #Make sure it's not a blank string if (item_node.firstChild): - #we make quite a hacky loop through the listbox, since gtk - #doesnt have very nice manipulation of listboxes, and uses - #just number indexing. - if item_node.firstChild.nodeValue=="Geography": - catindex=0 - elif item_node.firstChild.nodeValue=="Science": - catindex=1 - elif item_node.firstChild.nodeValue=="ICT": - catindex=2 - elif item_node.firstChild.nodeValue=="Languages": - catindex=3 - elif item_node.firstChild.nodeValue=="Maths": - catindex=4 - elif item_node.firstChild.nodeValue=="Music": - catindex=5 - elif item_node.firstChild.nodeValue=="History": - catindex=6 - elif item_node.firstChild.nodeValue=="Business": - catindex=7 - elif item_node.firstChild.nodeValue=="Art": - catindex=8 - #we set the active listbox element to category it found - self.cb_category.set_active(catindex) + self.title_category.set_text("Subject: " + item_node.firstChild.nodeValue) else: - print "Tag not loaded, probably empty" + print "Tag wasnt loaded, probably empy" category_loaded = True - #At this point we have found category and title and have placed them in their - #their corresponding positions elif (item_node.nodeName == PyClicCommon._xml_tags[AUTHOR_TAG]): """Set the author, the firstChild in this case is - the actual author that we saved. This tag is not really that important - and in fact was put in as an after though just in case its wanted""" + the actual author that we saved.""" #Make sure it's not a blank string if (item_node.firstChild): - self.author_entry.set_text(item_node.firstChild.nodeValue) + self.author_label.set_text("Author: " + item_node.firstChild.nodeValue) else: - print "Tag not loaded, probably empty" + print "Tag wasnt loaded, probably empy" author_loaded = True #At this point category, title and author have been loaded and placed in the document elif (item_node.nodeName == PyClicCommon._xml_tags[IMAGE_TAG]): @@ -197,6 +171,7 @@ class PyClicAdmin: for entry in self.entradas: self.answers_list.append(item_node.firstChild.nodeValue) self.label=gtk.Label("("+str(len(item_node.firstChild.nodeValue))+" letras)") + self.label_list.append(self.label) self.entry=gtk.Entry(max=30) self.entry_list.append(self.entry) # the below adds the text to the entry boxes @@ -418,7 +393,29 @@ class PyClicAdmin: self.cr.set_source_rgb(1, 1, 1) #show the pango object self.cr.show_text(self.string) - + + height=50 + while self.iterate < len(self.Entries): + if self.iterate==0: + #Draw the results page + self.cr.set_source_rgb(0.7, 0.2, 0.0) + #draw outer rectangle + self.cr.rectangle(10,40,270,320) + self.cr.fill() + self.cr.set_source_rgb(0.25,0.5,0.5) + #draw rectangle in which to draw results + self.cr.rectangle(20, 50, 250, 300) + self.cr.fill() + if self.Entries[self.iterate]==self.answers_list[self.iterate]: + self.answer_string="%s is the right answer" %(self.Entries[self.iterate]) + self.cr.move_to(30,30+height) + self.cr.set_source_rgb(0,0,0) + self.cr.show_text(self.answer_string) + else: + print "wrong!" + self.iterate=self.iterate+1 + height=height+30 + #needed function to get the active text from the combo box, as gtk doesnt have that built in. found on the web #some place def get_active_text(combobox): @@ -513,17 +510,10 @@ class PyClicAdmin: #function to check answers against entry list. def on_check_answers(self,widget): - iterate=1 + self.iterate=0 for entry in self.entry_list: self.Entries.append(entry.get_text()) - while iterate < len(self.Entries): - if self.Entries[iterate]==self.answers_list[iterate]: - print self.Entries[iterate]+" is the right answer" - else: - print "wrong!" - iterate=iterate+1 -# self.label.set_text(answers) -# self.window.queue_draw() + self.window.queue_draw() def on_set_label(self,answer): on_check_answers(self,widget) @@ -538,8 +528,7 @@ class PyClicAdmin: self.entry_list=[] self.Entries=[] self.coordinates=[] - self.author_entry.set_text("") - self.title_entry.set_text("") + self.answers_list=[] self.question_list=[] self.xml_file = None self.entry="" @@ -635,19 +624,6 @@ class PyClicAdmin: options = gtk.MenuItem("Options") #set optionsmenu as a submenu options.set_submenu(optionsmenu) - #create open image option -# openimage = gtk.MenuItem("Open Image") - #add activate handler to open_image function -# openimage.connect("activate",self.open_image) - #add open to the optionsmenu -# optionsmenu.append(openimage) - #create change color option -# colormenu = gtk.MenuItem("Change Color") - #add activate handler to on_clicked function -# colormenu.connect("activate", self.on_clicked) - #add color option to optionsmenu -# optionsmenu.append(colormenu) - #add filemenu and options to menubar mb.append(filem) mb.append(options) @@ -682,7 +658,7 @@ class PyClicAdmin: #create a drawing area where we will place the image self.darea=gtk.DrawingArea() #introduce a startup image called pyclic.png which gives usage instructions - self.image = cairo.ImageSurface.create_from_png("pyclic.png") + self.image = cairo.ImageSurface.create_from_png("pyclicuser.png") #make initial image filename pyclic.png self.image_filename="pyclic.png" #connect the drawing area to the expose_event handler via the expose function. @@ -692,9 +668,7 @@ class PyClicAdmin: self.darea.connect("expose_event", self.expose) #create the events mask, in this case a button click self.darea.set_events(gtk.gdk.BUTTON_PRESS_MASK) - #add another handler on button_press_event to the grab_click function which takes - #care of grabbing x,y coordinates -# self.darea.connect("button_press_event",self.grab_click) + #set the drawing area size self.darea.set_size_request(606,540) #define empty coordinates list @@ -737,34 +711,15 @@ class PyClicAdmin: # Add a title label - title_label=gtk.Label("Title") - self.vbox2.pack_start(title_label,False,False,0) - #Add a Title entry box - self.title_entry=gtk.Entry(max=50) - self.vbox2.pack_start(self.title_entry,False,False,0) + self.title_label=gtk.Label("Title") + self.vbox2.pack_start(self.title_label,False,False,0) + #Add an author label - author_label=gtk.Label("Author") - self.vbox2.pack_start(author_label,False,False,0) - #Add an author entry box - self.author_entry=gtk.Entry(max=50) - self.vbox2.pack_start(self.author_entry,False,False,0) + self.author_label=gtk.Label("Author") + self.vbox2.pack_start(self.author_label,False,False,0) #Add a Category label - title_category=gtk.Label("Category") - self.vbox2.pack_start(title_category,False,False,0) - #Add a combobox called category to the right hand side and connect changed - #handler to on_changed, which captures the category selected - self.cb_category=gtk.combo_box_new_text() - self.cb_category.connect("changed", self.on_changed) - self.cb_category.append_text("Geography") - self.cb_category.append_text("Science") - self.cb_category.append_text("ICT") - self.cb_category.append_text("Languages") - self.cb_category.append_text("Maths") - self.cb_category.append_text("Music") - self.cb_category.append_text("History") - self.cb_category.append_text("Business") - self.cb_category.append_text("Art") - self.vbox2.pack_start(self.cb_category,False,False,0) + self.title_category=gtk.Label("Category") + self.vbox2.pack_start(self.title_category,False,False,0) #submit button for entries submit_button=gtk.Button("Submit") -- cgit v0.9.1