def add_var(self, var_name, eqn_text, do_save=True): """Add to the variables bubble list and dictionary. Arguments: - `self`: - `var_name`: - `eqn_text`: """ # This function was actually created and modeled after # self.add_to_history. Relevant comments can be found there. var_exists = var_name in self.var_dict self.var_dict[var_name] = eqn_text if do_save: with open(VARDB_FILE, "wb") as var_file: pickle.dump(self.var_dict, var_file) if not var_exists: new_btn = BubbleButton(text=var_name) last_pos = len(self.var_dict) new_btn.bind(on_press=lambda *args: self.set_eqn(self.var_dict[var_name], len(self.history_stack) + 1)) try: kivy.require("1.4.2") self.var_list_bubble.content.add_widget(new_btn, last_pos + 1) except Exception: self.var_list_bubble.content.clear_widgets() self.var_list_bubble.content.add_widget(new_btn) for dice_roll in reversed(self.var_list_stack): dice_bubble = BubbleButton(text=dice_roll) dice_bubble.bind(on_press=self.var_dict[dice_roll]) self.var_list_bubble.content.add_widget(dice_bubble) self.var_list_stack.append(var_name) if not hasattr(self, "bubble_height_var"): self.bubble_height_var = self.dice_eqn_input.height else: self.var_list_bubble.height += self.bubble_height_var self.var_list_bubble.parent.height += self.bubble_height_var
def _open(self, *args, **kwargs): try: self.remove_widget(self.bubble) self.percentage = self.slider.value del self.bubble, self.slider self.update_icons() except AttributeError: self.bubble = Bubble(orientation="vertical", size=(48, 200)) self.update_bubble_pos() self.bind(pos=self.update_bubble_pos) def on_perc(slider, value): slider.btn.percentage = value label = Label(text=self.label, size_hint_y=None, height=25) self.bubble.add_widget(label) self.slider = Slider(orientation="vertical", min=0, max=100, value=self.percentage) self.slider.btn = self self.slider.bind(value=on_perc) self.bubble.add_widget(self.slider) def on_reset(bbtn, *args, **kwargs): bbtn.slider.value = bbtn.reset_value bbtn = BubbleButton(text=self.reset_text, size_hint_y=None, height=40) bbtn.slider = self.slider bbtn.reset_value = self.reset_value bbtn.bind(on_release=on_reset) self.bubble.add_widget(bbtn) self.add_widget(self.bubble) self.icon = self.icons["close"]
class CalendarButton(FloatLayout): def __init__(self, activity, **kwargs): self.activity = activity super(CalendarButton, self).__init__() self.buttonInstance = Button(size_hint=(1, 1), pos_hint={'center_x':0.5, 'center_y':0.5}, **kwargs) self.buttonInstance.bind(on_release=self.onPressBubble) self.add_widget(self.buttonInstance) self.bubbleInstance = Bubble(size_hint=(None, None), size=(100, 40), pos_hint={'center_x':0.5, 'center_y':0.5}, arrow_pos='bottom_mid') self.bubbleChange = BubbleButton(text='Change', font_size=8) self.bubbleChange.bind(on_release=self.onPressChange) self.bubbleRemove = BubbleButton(text='Remove', font_size=8) self.bubbleRemove.bind(on_release=self.onPressRemove) self.bubbleInstance.add_widget(self.bubbleChange) self.bubbleInstance.add_widget(self.bubbleRemove) def onPressBubble(self, instance): if self.bubbleInstance.parent == None: self.add_widget(self.bubbleInstance) else: self.remove_widget(self.bubbleInstance) def onPressChange(self, instance): self.remove_widget(self.bubbleInstance) changeActivity(self.activity) def onPressRemove(self, instance): self.remove_widget(self.bubbleInstance) removeActivity(self.activity)
def show_bubble(self) -> None: self.bubb = Bubble(size_hint=(None, None), size=(160, 30), pos_hint={'center_x': .5, 'y': .6}) accuse = BubbleButton(text='Accuse') suspect = BubbleButton(text='Suspect') accuse.bind(on_press=partial(self.hide_bubble, accuse)) suspect.bind(on_press=partial(self.hide_bubble, suspect)) self.bubb.add_widget(accuse) self.bubb.add_widget(suspect) self.ids.empty.add_widget(self.bubb)
def signal(self): my_bubble= Bubble(orientation = 'vertical',size_hint=(None, None),size=(600, 100),pos=(200,0)) my_bubble.background_color =(20, 0, 0, .5) my_bubble.border = [50, 50, 50, 10] my_bubble.size = (150, 50) my_bubble.arrow_pos= 'top_mid' my_bub_btn1= BubbleButton(text='Remove signal') #my_bub_btn1.bind(on_release=lambda my_bub_btn1: self.Update(1, my_bubble, my_bub_btn1)) my_bub_btn1.bind(on_release=lambda my_bub_btn1: self.RemoveBub(my_bubble)) my_bubble.add_widget(my_bub_btn1) self.add_widget(my_bubble)
class ToolSelectFunction(Spinner): def __init__(self, **kwargs): self.map_pars = {} self.bubble = None self.bubb_layout = None self.button = None self.func_des = None self.background_color = (0.46, 0.46, 0.46, 0.6) super(ToolSelectFunction, self).__init__(**kwargs) def _on_dropdown_select(self, instance, data, *largs): self.text = data self.is_open = False #print('select function',self.text) self.func_des = '[color=#ffff00][i][b]' + self.parent.tool_library.read_obj.get_func_des( self.text) + '[/i][/b][/color]' self.set_select_parameter(self.text) if self.bubble is None: self.bubble = Bubble(size_hint=(.3, .2)) self.bubb_layout = AnchorLayout(anchor_x='right', anchor_y='top') def remove_bubble(instance): self.bubb_layout.remove_widget(self.bubble) self.parent.parent.remove_widget(self.bubb_layout) self.bubble = None self.bubb_layout = None self.button = BubbleButton(text=self.func_des, halign='left', valign='middle', text_size=(300, 300), background_color=(0, 0, 1, 1), markup=True) self.button.bind(on_press=remove_bubble) self.bubble.add_widget(self.button) self.bubble.arrow_pos = 'top_mid' self.bubb_layout.add_widget(self.bubble) self.parent.parent.parent.add_widget(self.bubb_layout) else: self.button.text = self.func_des def set_select_parameter(self, function): self.parent.tool_parameter.text = 'Select Parameter' self.map_pars = self.parent.tool_library.read_obj.get_pars_type( function) #print('map_pars',map_pars) self.parent.tool_parameter.values = self.map_pars.keys()
def add_to_history(self, eqn_text, do_save=True): """Add to equations history Arguments: """ # new button to be added to the history list new_btn = BubbleButton(text=eqn_text) last_pos = len(self.history_stack) eqn_fn = lambda *args: self.set_eqn(eqn_text, last_pos) if do_save: append_overwrite = "a" if last_pos < 40 else "w" with open(DICE_HISTORY_FILE, append_overwrite) as dh_file: # We only care about the last 40 if last_pos >= 40: for eqn in self.history_stack[last_pos - 40 : last_pos]: dh_file.write(eqn + "\n") dh_file.write(eqn_text + "\n") new_btn.bind(on_press=eqn_fn) try: # kivy 1.4.2 will respect the order bubble buttons are # added kivy.require("1.4.2") # this will throw an exception if # it's not 1.4.2 or later self.history_stack.append(eqn_fn) self.dice_history.content.add_widget(new_btn, last_pos + 1) except Exception: # nasty ugly work around for kivy issue #819 self.dice_history.content.clear_widgets() self.dice_history.content.add_widget(new_btn) for dice_roll in reversed(self.history_stack): dice_bubble = BubbleButton(text=dice_roll()) dice_bubble.bind(on_press=dice_roll) self.dice_history.content.add_widget(dice_bubble) self.history_stack.append(eqn_fn) self.dice_eqn_input.history_stack_pos = last_pos + 1 if not hasattr(self, "bubble_height"): self.bubble_height = self.dice_eqn_input.height else: self.dice_history.height += self.bubble_height # Why change the following? Because the parent is actually # an anchor layout. self.dice_history.parent.height += self.bubble_height
def add_to_history(self, eqn_text, do_save=True): """Add to equations history Arguments: """ #new button to be added to the history list new_btn = BubbleButton(text = eqn_text) last_pos = len(self.history_stack) eqn_fn = lambda *args: self.set_eqn(eqn_text, last_pos) if do_save: append_overwrite = 'a' if last_pos < 40 else 'w' with open(DICE_HISTORY_FILE, append_overwrite) as dh_file: # We only care about the last 40 if last_pos >= 40: for eqn in self.history_stack[last_pos-40:last_pos]: dh_file.write(eqn + '\n') dh_file.write(eqn_text + '\n') new_btn.bind(on_press = eqn_fn) try: #kivy 1.4.2 will respect the order bubble buttons are #added kivy.require('1.4.2') #this will throw an exception if #it's not 1.4.2 or later self.history_stack.append(eqn_fn) self.dice_history.content.add_widget(new_btn, last_pos+1) except Exception: #nasty ugly work around for kivy issue #819 self.dice_history.content.clear_widgets() self.dice_history.content.add_widget(new_btn) for dice_roll in reversed(self.history_stack): dice_bubble = BubbleButton(text = dice_roll()) dice_bubble.bind(on_press = dice_roll) self.dice_history.content.add_widget(dice_bubble) self.history_stack.append(eqn_fn) self.dice_eqn_input.history_stack_pos = last_pos+1 if not hasattr(self, 'bubble_height'): self.bubble_height = self.dice_eqn_input.height else: self.dice_history.height += self.bubble_height #Why change the following? Because the parent is actually #an anchor layout. self.dice_history.parent.height += self.bubble_height
def on_state(self, widget, state): # super(SettingView, self).on_state(**kwargs) if self.state == 'down': bubbleHeight = 50 self.bubble = Bubble(size_hint=(None,None), size=(self.width, bubbleHeight), center_x=self.center_x, y=self.height-bubbleHeight) b1 = BubbleButton(text="-", font_size=40) b1.bind(on_press = self.decr) b2 = BubbleButton(text="+", font_size=40) b2.bind(on_press = self.incr) self.text_size = self.size self.text_size[1] -= 10 self.valign='bottom' self.bubble.add_widget(b1) self.bubble.add_widget(b2) self.add_widget(self.bubble) else: self.remove_widget(self.bubble) self.valign='center' self.dispatch('on_change', self.value)
def add_var(self, var_name, eqn_text, do_save=True): """Add to the variables bubble list and dictionary. Arguments: - `self`: - `var_name`: - `eqn_text`: """ #This function was actually created and modeled after #self.add_to_history. Relevant comments can be found there. var_exists = var_name in self.var_dict self.var_dict[var_name] = eqn_text if do_save: with open(VARDB_FILE, 'wb') as var_file: pickle.dump( self.var_dict, var_file ) if not var_exists: new_btn = BubbleButton(text = var_name) last_pos = len(self.var_dict) new_btn.bind(on_press = lambda *args: self.set_eqn( \ self.var_dict[var_name], len(self.history_stack)+1)) try: kivy.require('1.4.2') self.var_list_bubble.content.add_widget(new_btn, last_pos+1) except Exception: self.var_list_bubble.content.clear_widgets() self.var_list_bubble.content.add_widget(new_btn) for dice_roll in reversed(self.var_list_stack): dice_bubble = BubbleButton(text = dice_roll) dice_bubble.bind(on_press = self.var_dict[dice_roll]) self.var_list_bubble.content.add_widget(dice_bubble) self.var_list_stack.append(var_name) if not hasattr(self, 'bubble_height_var'): self.bubble_height_var = self.dice_eqn_input.height else: self.var_list_bubble.height += self.bubble_height_var self.var_list_bubble.parent.height += self.bubble_height_var
def __init__(self, **kw): super(TransformBubble, self).__init__(**kw) self.size_hint = (0.5, None) self.size = (0, 200) self.pos_hint = {'right': 1, 'top': 1} self.arrow_pos = 'left_top' self.orientation = 'vertical' self.rows = 6 # Create and bind each button. button = BubbleButton(text='Identity') button.bind(on_press=self.select_option) self.add_widget(button) button = BubbleButton(text='Translate') button.bind(on_press=self.select_option) self.add_widget(button) button = BubbleButton(text='Scale') button.bind(on_press=self.select_option) self.add_widget(button) button = BubbleButton(text='Rotate') button.bind(on_press=self.select_option) self.add_widget(button) button = BubbleButton(text='Shear') button.bind(on_press=self.select_option) self.add_widget(button) button = BubbleButton(text='Reflect') button.bind(on_press=self.select_option) self.add_widget(button)
def show_objects(self): """ Create the entire layout for all profiles present in the database :return: None """ list_of_objects = self.interface_call.sql_to_object_screen() parent_widget = self.objects_holder parent_widget.clear_widgets() for item in list_of_objects: layout = GridLayout(cols=1, size_hint=(1, parent_widget.size_hint_y * 10), id=item['Title']) widg_1 = Label(text=item['Title'], size_hint=(1, .5)) widg_2 = BoxLayout() widg_2_1 = Label(text='Creator: ' + item['Creator']) widg_2_2 = GridLayout(cols=1) shp_2_2 = Label(text='Shp Name: ' + item['ShpName']) dbf_2_2 = Label(text='Dbf Name: ' + item['DbfName']) widg_2_2.add_widget(shp_2_2) widg_2_2.add_widget(dbf_2_2) widg_2_3 = Label(text='Date: ' + item['Date']) widg_2.add_widget(widg_2_1) widg_2.add_widget(widg_2_2) widg_2.add_widget(widg_2_3) widg_3 = BoxLayout() widg_3_1 = BubbleButton(id=item['Title'], text='2D', color=[0, 0, 0, 1], size_hint=(1.0, .5), background_normal='', background_color=[1, 1, 1, 1]) widg_3_1.bind(on_press=self.visual_screen_instance_2d) widg_3_2 = BubbleButton(id=item['Title'], text='3D', color=[0, 0, 0, 1], size_hint=(1.0, .5), background_normal='', background_color=[1, 1, 1, 1]) widg_3_2.bind(on_press=self.visual_screen_instance_3d) widg_3_3 = BubbleButton(text='VR', color=[0, 0, 0, 1], size_hint=(1.0, .5), background_normal='', background_color=[1, 1, 1, 1]) widg_3.add_widget(widg_3_1) widg_3.add_widget(widg_3_2) widg_3.add_widget(widg_3_3) layout.add_widget(widg_1) layout.add_widget(widg_2) layout.add_widget(widg_3) parent_widget.add_widget(layout)