def display_fields(self, do_display): from kivy.uix.label import Label for tmpl in self.ids.options.tmplDict: for ids in tmpl.ids: wid = getattr(tmpl.ids, ids) if do_display == 'down': L = Label(text=str(ids), color=(1, 0, 0), font_size=30) wid.add_widget(L) L.center = wid.center def update(*args): L.center = wid.center wid.bind(pos=update, size=update) L.z = 100 from kivy.graphics import InstructionGroup, Color, Line wid._df = InstructionGroup() wid._df.add(Color(rgb=(1, 0, 0))) wid._df.add( Line(rectangle=(wid.x, wid.y, wid.width, wid.height), width=4)) wid.canvas.after.add(wid._df) else: wid.remove_widget(wid.children[0]) wid.canvas.after.remove(wid._df)
def addButton(self,text='',btntxt = '',callback=None): entrysize = [0,0] horiz = RelativeLayout(size_hint= (1.0,None))#orientation = 'lr-tb',padding=(5,5,5,5)) newtext = Label(text=text,markup=True, size_hint= (1.0,None) ) newtext.texture_update() newtext.size = newtext.texture_size newtext.size_hint = (None,None) entrysize = [ entrysize[0] + newtext.width , max(entrysize[1],newtext.height) ] #horiz.center = (Window.width/2,-entrysize[1]/2) #(Window.width/2-entrysize[0]/2-5, -entrysize[1]/2) #- newtext.width btn = Button(text=btntxt) if callback is not None: btn.bind(on_press=callback) btn.size_hint = (None,None) btn.texture_update() btn.size = btn.texture_size print newtext.size, btn.size btn.width += 10 btn.height += 10 entrysize = [ entrysize[0] + btn.width , max(entrysize[1], btn.height) ] horiz.size=(entrysize[0],entrysize[1]+7) btn.center = (Window.width/2 + btn.width/2+5, btn.height/2+5) #- newtext.width newtext.center = (Window.width/2 - newtext.width/2-5,btn.height/2+5)#(Window.width/2-newtext.width/2-5,-entrysize[1]/2) #horiz.size = (entrysize[0], entrysize[1]) print entrysize #horiz.center = (Window.width/2,-entrysize[1]/2) horiz.add_widget(newtext) horiz.add_widget(btn) self.verticality += entrysize[1]+7 self.size = (Window.width,self.verticality) self.add_widget(horiz) print self.verticality
def display_fields(self,do_display): from kivy.uix.label import Label for tmpl in self.ids.options.tmplDict: for ids in tmpl.ids: wid = getattr(tmpl.ids,ids) if do_display == 'down': L = Label(text = str(ids), color = (1,0,0), font_size=30) wid.add_widget(L) L.center = wid.center def update(*args): L.center = wid.center wid.bind(pos=update, size=update) L.z = 100 from kivy.graphics import InstructionGroup, Color, Line wid._df = InstructionGroup() wid._df.add(Color(rgb=(1,0,0))) wid._df.add(Line(rectangle =(wid.x, wid.y, wid.width, wid.height), width=4)) wid.canvas.after.add(wid._df) else: wid.remove_widget(wid.children[0]) wid.canvas.after.remove(wid._df)
def game_over(self): label = Label(text="GAME OVER\n Score: ") label.center = self.center self.add_widget(label)
def screenupdate(self, word, *args, **kwargs): for wid in self.maintree: #moves all main images to the left wid.center = (wid.center_x - 700, wid.center_y) for wid in self.maintreelabel: #moves all main labels to the left wid.center = (wid.center_x - 700, wid.center_y) for k, v in self.leaftree.items(): #deletes all composition images for val in v: self.root.remove_widget(val) self.leaftree[k].clear() for k, v in self.leaftreelabel.items( ): #deletes all composition labels for val in v: self.root.remove_widget(val) self.leaftreelabel[k].clear() if word in svg_dict.keys(): #if word is in dict, adds image of word and label to screen filename = file_root + svg_dict[word] svg = SvgWidget(filename, size_hint=(None, None)) svg.scale = 1 svg.center = Window.center self.maintree.append(svg) self.root.add_widget(self.maintree[-1]) mname = Label(text=word, color=(0, 0, 0, 1), size_hint=(None, None)) mname.center = (svg.center_x, svg.center_y - (svg.scale * 328) / 2) self.maintreelabel.append(mname) self.root.add_widget(self.maintreelabel[-1]) #if word has defined composition, adds compositional elements to screen if word in comp_dict.keys(): self.leaftree[word] = [] self.leaftreelabel[word] = [] leftpos = (self.maintree[-1].center[0] - ((len(comp_dict[word]) - 1) / 2 * 400 * self.maintree[-1].scale), self.maintree[-1].center[1] - (328.00 * 1.75 * svg.scale) / 2) n = 0 for val in comp_dict[word]: if val in svg_dict.keys(): str = file_root + svg_dict[val] else: #if image can't be found- default to circle image. (Should be removed with better error handling) str = './svg/blank.svg' #adds image of word and label of compositions to screen lsvg = SvgWidget(str, size_hint=(None, None)) lsvg.scale = self.maintree[-1].scale * .75 lsvg.center = (leftpos[0] + n * 400, leftpos[1]) lname = Label(text=val, color=(0, 0, 0, 1), size_hint=(None, None)) lname.center = (lsvg.center_x, lsvg.center_y - (lsvg.scale * 328) / 2) self.leaftree[word].append(lsvg) self.leaftreelabel[word].append(lname) self.root.add_widget(self.leaftree[word][-1]) self.root.add_widget(self.leaftreelabel[word][-1]) n = n + 1 else: #if word does not have associated svg- just place word in canvas mname = Label(text=word, color=(0, 0, 0, 1), size_hint=(None, None)) mname.center = Window.center self.maintree.append(mname) self.root.add_widget(self.maintree[-1])