def create_property(self, name): '''Create a new property at runtime. .. warning:: This function is designed for the Kivy language, don't use it in your code. You should declare the property in your class instead of using this method. :Parameters: `name`: string Name of the property The class of the property cannot be specified, it will be always an :class:`~kivy.properties.ObjectProperty` class. The default value of the property will be None, until you set a new value. >>> mywidget = Widget() >>> mywidget.create_property('custom') >>> mywidget.custom = True >>> print mywidget.custom True ''' prop = ObjectProperty(None) prop.link(self, name) prop.link_deps(self, name) self.__properties[name] = prop setattr(self, name, prop)
def test_objectcheck(self): from kivy.properties import ObjectProperty a = ObjectProperty(False) a.link(wid, 'a') a.link_deps(wid, 'a') self.assertEqual(a.get(wid), False) a.set(wid, True) self.assertEqual(a.get(wid), True)
def add_jug_b(self,butt,loaded,menu,drop): btn1=ObjectProperty() self.ids.drop2.open(butt) if loaded!="done": for i in range(1,11): btn1=Factory.Nums_jugb() btn1.text=str(i) btn1.drop=str(menu) btn1.background_color=[25,1,100,.2] btn1.color=0,0,0,1 self.ids.drop2.add_widget(btn1) butt.loaded="done"
def add_to_presentation(self): """Download high-res image and add slide to presentation. """ app = ObjectProperty(None) slide = Slide(img_src=self.photo['thumb'], thumb_src=self.photo['thumb'], artist=self.photo['artist'], title=self.photo['title'], year=self.photo['year']) if self.provider == 'MET': # Check if high-res is available. url = self.photo['thumb'].replace('mobile-large', 'original') req = urllib.request.urlopen(url) if req.getcode() == 404: Logger.debug('Search: High-res image not available.') self.app.show_popup(_('Error'), _('High-res image not available, downloading inferior quality.')) self.app.download_img(self.thumbnail, slide) self.app.add_slide(slide) else: self.app.download_img(url, slide) self.app.add_slide(slide) elif self.provider == 'Getty': req = urllib.request.urlopen(self.photo['obj_link']) tree = html.parse(req) img_link = tree.xpath('//a[@id="download-open-content"]/@href') if img_link: link = urllib.parse.urlparse(img_link[0]) url = urllib.parse.parse_qs(link.query)['dlimgurl'][0] else: url = self.photo['thumb'] slide.img_src = url self.app.download_img(url, slide) self.app.add_slide(slide) elif self.provider == 'Flickr': # thumb_filename = basename(self.photo['thumb']) # thumb = splitext(thumb_filename) # url = ''.join((thumb[0][:-1], 'o', thumb[1])) url = app.get_flickr_url(self.photo, 'o') self.app.download_img(url, slide) self.app.add_slide(slide)
class loadwindow(FloatLayout): load = ObjectProperty(None) cancel = ObjectProperty(None)
class savewindow(FloatLayout): save = ObjectProperty(None) text_input = ObjectProperty(None) cancel = ObjectProperty(None)
class EffectWidget(RelativeLayout): ''' Widget with the ability to apply a series of graphical effects to its children. See the module documentation for more information on setting effects and creating your own. ''' background_color = ListProperty((0, 0, 0, 0)) '''This defines the background color to be used for the fbo in the EffectWidget. :attr:`background_color` is a :class:`ListProperty` defaults to (0, 0, 0, 0) ''' texture = ObjectProperty(None) '''The output texture of the final :class:`~kivy.graphics.Fbo` after all effects have been applied. texture is an :class:`~kivy.properties.ObjectProperty` and defaults to None. ''' effects = ListProperty([]) '''List of all the effects to be applied. These should all be instances or subclasses of :class:`EffectBase`. effects is a :class:`ListProperty` and defaults to []. ''' fbo_list = ListProperty([]) '''(internal) List of all the fbos that are being used to apply the effects. fbo_list is a :class:`ListProperty` and defaults to []. ''' _bound_effects = ListProperty([]) '''(internal) List of effect classes that have been given an fbo to manage. This is necessary so that the fbo can be removed if the effect is no longer in use. _bound_effects is a :class:`ListProperty` and defaults to []. ''' def __init__(self, **kwargs): # Make sure opengl context exists EventLoop.ensure_window() self.canvas = RenderContext(use_parent_projection=True, use_parent_modelview=True) with self.canvas: self.fbo = Fbo(size=self.size) with self.fbo.before: PushMatrix() with self.fbo: ClearColor(0, 0, 0, 0) ClearBuffers() self._background_color = Color(*self.background_color) self.fbo_rectangle = Rectangle(size=self.size) with self.fbo.after: PopMatrix() super(EffectWidget, self).__init__(**kwargs) Clock.schedule_interval(self._update_glsl, 0) fbind = self.fbind fbo_setup = self.refresh_fbo_setup fbind('size', fbo_setup) fbind('effects', fbo_setup) fbind('background_color', self._refresh_background_color) self.refresh_fbo_setup() self._refresh_background_color() # In case thi was changed in kwargs def _refresh_background_color(self, *args): self._background_color.rgba = self.background_color def _update_glsl(self, *largs): '''(internal) Passes new time and resolution uniform variables to the shader. ''' time = Clock.get_boottime() resolution = [float(size) for size in self.size] self.canvas['time'] = time self.canvas['resolution'] = resolution for fbo in self.fbo_list: fbo['time'] = time fbo['resolution'] = resolution def refresh_fbo_setup(self, *args): '''(internal) Creates and assigns one :class:`~kivy.graphics.Fbo` per effect, and makes sure all sizes etc. are correct and consistent. ''' # Add/remove fbos until there is one per effect while len(self.fbo_list) < len(self.effects): with self.canvas: new_fbo = EffectFbo(size=self.size) with new_fbo: ClearColor(0, 0, 0, 0) ClearBuffers() Color(1, 1, 1, 1) new_fbo.texture_rectangle = Rectangle(size=self.size) new_fbo.texture_rectangle.size = self.size self.fbo_list.append(new_fbo) while len(self.fbo_list) > len(self.effects): old_fbo = self.fbo_list.pop() self.canvas.remove(old_fbo) # Remove fbos from unused effects for effect in self._bound_effects: if effect not in self.effects: effect.fbo = None self._bound_effects = self.effects # Do resizing etc. self.fbo.size = self.size self.fbo_rectangle.size = self.size for i in range(len(self.fbo_list)): self.fbo_list[i].size = self.size self.fbo_list[i].texture_rectangle.size = self.size # If there are no effects, just draw our main fbo if len(self.fbo_list) == 0: self.texture = self.fbo.texture return for i in range(1, len(self.fbo_list)): fbo = self.fbo_list[i] fbo.texture_rectangle.texture = self.fbo_list[i - 1].texture # Build effect shaders for effect, fbo in zip(self.effects, self.fbo_list): effect.fbo = fbo self.fbo_list[0].texture_rectangle.texture = self.fbo.texture self.texture = self.fbo_list[-1].texture for fbo in self.fbo_list: fbo.draw() self.fbo.draw() def add_widget(self, widget): # Add the widget to our Fbo instead of the normal canvas c = self.canvas self.canvas = self.fbo super(EffectWidget, self).add_widget(widget) self.canvas = c def remove_widget(self, widget): # Remove the widget from our Fbo instead of the normal canvas c = self.canvas self.canvas = self.fbo super(EffectWidget, self).remove_widget(widget) self.canvas = c def clear_widgets(self, children=None): # Clear widgets from our Fbo instead of the normal canvas c = self.canvas self.canvas = self.fbo super(EffectWidget, self).clear_widgets(children) self.canvas = c
def add_goal(self,butt,loaded,jug_a,jug_b): btn1=ObjectProperty() self.ids.drop3.clear_widgets() self.ids.drop3.open(butt) for i in valid_goals(int(jug_a),int(jug_b)): btn1=Factory.Nums_goal() btn1.text=str(i) btn1.background_color=[25,1,100,.2] btn1.color=0,0,0,1 self.ids.drop3.add_widget(btn1) butt.loaded="done"