def reset(self, *largs): self.boat_speed.value = 5.0 self.river_speed.value = 5.0 self.boat_angle.value = 0.0 self.boat.x, self.boat.y = sp(100), sp(RIVERSIDE_SIZE + BOAT_HEIGHT / 2) self.boat.init() self.update()
def build(self): self.root = NavigationDrawer() self.root.side_panel_opacity = 0 self.root.separator_image_width = sp(0) menu = BoxLayout(orientation='vertical') resetButton = Factory.GreenButton(text='New Game') settingsButton = Factory.OrangeButton(text='Settings') helpButton = Factory.PurpleButton(text='Help') menu.add_widget(resetButton) menu.add_widget(settingsButton) menu.add_widget(helpButton) resetButton.bind(on_press=self.reset) self.root.add_widget(menu) content = AnchorLayout(anchor_x='right', anchor_y='bottom', paddind=sp(5)) toggleButton = IconButton (icon="atlas://img/icon/iconatlas/icon-menu", size_hint=(.15, .1), background_normal='atlas://img/button/buttonatlas/red', background_down='atlas://img/button/buttonatlas/orange') toggleButton.bind(on_press=lambda j: self.root.toggle_state()) content.add_widget(sm) content.add_widget(toggleButton) self.root.add_widget(content) sm.current = 'titleScreen' return self.root
def reload(self, *args): provider = self.provider if not provider: return text = provider.get() wordtype = provider.itype antonym = provider.antonym zoom = provider.zoom key = provider.dump_settings() if self._last_reload_key == key: return self._last_reload_key = key self.text = text self.wordtype = wordtype self.antonym = antonym self.zoom = zoom if self._do_animation: Animation( fontzoom=self.zoom * sp(5), padding=max(dp(20), dp(20) - self.zoom * dp(10)), direction=(provider.tense - 1) * dp(5), d=0.3, t='out_quart').start(self) else: self.fontzoom = self.zoom * sp(5) self.padding = max(dp(20), dp(20) - self.zoom * dp(10)) self.direction = (provider.tense - 1) * dp(5)
def add_widget(self, widget, **kwargs): """ Add tabs to the screen or the layout. :param widget: The widget to add. """ if isinstance(widget, MDBottomNavigationItem): self.widget_index += 1 widget.index = self.widget_index widget.parent_widget = self tab_header = MDBottomNavigationHeader(tab=widget, panel=self, height=widget.height) self.ids.tab_bar.add_widget(tab_header) widget.header = tab_header self.ids.tab_manager.add_widget(widget) if self.widget_index == 1: self.previous_tab = widget tab_header._current_color = self.theme_cls.primary_color tab_header._label_font_size = sp(14) tab_header.active = True self.first_widget = widget else: tab_header._label_font_size = sp(12) self._refresh_tabs() else: super(MDBottomNavigation, self).add_widget(widget)
def update_file_layout(self): auth_token='S2_xUq0_iNAAAAAAAAAACYNG1zf1GAzKpVWVfmLcZLA-FIiSlGxMvmxBkAtspuWQ' client = dropbox.client.DropboxClient(auth_token) self.clear_widgets() b=BoxLayout(orientation='vertical') file_system = FileSystemLocal() root_dir= App.get_running_app().user_data_dir+'/';result_dir=root_dir+'results' file_list=file_system.listdir(root_dir) # this returns a list of files in dir if os.path.exists(result_dir):file_list.extend(file_system.listdir(App.get_running_app().user_data_dir+'/'+'results'+'/')) file_list=[x for x in file_list if x[-4:]=='.csv'] b.add_widget(Label(text='Select Files to Upload',bold=True,font_size=sp(25),size_hint_y= 0.1)) file_system = FileSystemLocal() file_list=file_system.listdir(App.get_running_app().user_data_dir+'/') # this returns a list of files in dir file_list=[x for x in file_list if x[-4:]=='.csv'] s=ScrollView(size_hint_y=0.75) g=GridLayout(cols=2,size_hint_y=None) for file_1 in file_list: c=CheckBox(active=False) l=Label(bold= True,font_size=sp(20),text=file_1,size_hint_y= None,height=70) self.check_boxes[c]=file_1 g.add_widget(l);g.add_widget(c) g.bind(minimum_height=g.setter('height')) s.add_widget(g) b.add_widget(s) g_options=GridLayout(cols=2,size_hint_y= 0.1,orientation='horizontal') g_options.add_widget(Button(text="Send",on_press=self.upload,font_size=sp(25))) g_options.add_widget(Button(text="Back",on_press=self.return_back,font_size=sp(25))) b.add_widget(g_options) self.add_widget(b)
def _draw_field_node(self, db_node, node_depth): # First, calculate and store the X / Y coordinates of the Node if not db_node.parent: db_node.value = (self.get_center_x(), self.get_center_y() + \ k_met.sp((self.rbt_draw_depth - 1) * 2 * Node.radius)) else: if db_node is db_node.parent.child[rbt_ns.LEFT]: DIRECTION_INDICATOR = -1 else: DIRECTION_INDICATOR = 1 x_offset = 2 ** (self.rbt_draw_depth - node_depth - 1) x_position = db_node.parent.value[POS_X] + \ k_met.sp((2 * Node.radius * x_offset * DIRECTION_INDICATOR)) y_position = db_node.parent.value[POS_Y] - \ k_met.sp((2 * 2 * Node.radius)) db_node.value = (x_position, y_position) # Next, draw the graphical node onto the canvas using previous coordinates new_node = Node(db_node.key, db_node.color) new_node.set_center_x(db_node.value[POS_X]) new_node.set_center_y(db_node.value[POS_Y]) self.add_widget(new_node) if db_node.parent: with self.canvas: Color(0, 0, 1, 1) Line(points = [db_node.value[POS_X], db_node.value[POS_Y] + k_met.sp(Node.radius), db_node.parent.value[POS_X], db_node.parent.value[POS_Y] - k_met.sp(Node.radius)])
def _calculate_optimum_font_size(self): #cw = self._calculate_widths() words = list(self._iterate_words()) text = ' '.join([x.text for x in words]) font_size = WORD_FONTSIZE corelabel = CoreLabel(text=text, font_name=words[0].font_name) padding = words[0].padding * len(words) # too many words ? if padding > self.width / 2: padding = int(self.width / 2 / len(words)) for word in words: word.padding = padding else: for word in words: word.padding = Word.padding.defaultvalue while True: corelabel.options['font_size'] = sp(font_size) w, h = corelabel.render() if w < self.width - padding: break font_size -= 1 font_size = sp(font_size) if font_size != words[0].font_size: for word in words: word.font_size = font_size word.texture_update()
def addImage(self, filename): image = Image(source=filename) image.size_hint = None, None image.width = metrics.sp(120) image.height = metrics.sp(120) self.add_widget(image) return
def on_pos(self, *args): self.hint_anim_in = Animation(_hint_y=dp(34), _hint_lbl_font_size=sp(12), duration=.2, t='out_quad') self.hint_anim_out = Animation(_hint_y=dp(10), _hint_lbl_font_size=sp(16), duration=.2, t='out_quad')
def on_font_style(self, instance, style): info = self._font_styles[style] self.font_name = info[0] self.bold = info[1] if DEVICE_TYPE == 'desktop' and info[3] is not None: self.font_size = sp(info[3]) else: self.font_size = sp(info[2])
def _draw_current_map(self): left = self.pos[0] bottom = self.pos[1] self.canvas.clear() heat_width_step = sp(self.HEAT_MAP_WIDTH_STEP) path_count = len(self._scaled_paths.keys()) heat_width = sp(self.heat_width_scale * self.height) + ((path_count - 1) * heat_width_step) with self.canvas: Color(*self.track_color) Line(points=self._scaled_map_points, width=sp(self.track_width_scale * self.height), closed=True, cap='round', joint='round') color_gradient = HeatColorGradient() # draw all of the traces for key, path_points in self._scaled_paths.iteritems(): heat_path = self._heat_map_values.get(key) if heat_path: # draw heat map point_count = len(path_points) heat_min = self.heat_min heat_range = self.heat_max - heat_min value_index = 0 current_heat_pct = 0 i = 0 line_points = [] try: line_points.extend([path_points[i], path_points[i + 1]]) current_heat_pct = int(((heat_path[value_index] - heat_min) / heat_range) * 100.0) while i < point_count - 2: heat_value = heat_path[value_index] heat_pct = int(((heat_value - heat_min) / heat_range) * 100.0) if heat_pct != current_heat_pct: heat_color = color_gradient.get_color_value(heat_pct / 100.0) Color(*heat_color) Line(points=line_points, width=heat_width, closed=False, joint='miter', cap='round') line_points = [path_points[i - 2], path_points[i - 1]] current_heat_pct = heat_pct line_points.extend([path_points[i], path_points[i + 1]]) value_index += 1 i += 2 heat_width -= heat_width_step except IndexError: # if the number of heat values mismatch the heat map points, terminate early pass else: # draw regular map trace Color(*self._paths[key].color) Line(points=path_points, width=sp(self.path_width_scale * self.height), closed=True, cap='square', joint='miter') # draw the markers marker_size = (self.marker_width_scale * self.height) * self.marker_scale for key, marker_point in self._marker_points.iteritems(): scaled_point = self._scale_point(marker_point, self.height, left, bottom) Color(*marker_point.color) self._marker_locations[key] = Line(circle=(scaled_point.x, scaled_point.y, marker_size), width=marker_size, closed=True)
def move(self): new_x = self.x + self.offset is_beyond_rim = ( new_x < self.parent.right + sp(50) or new_x > self.parent.left - sp(50)) if is_beyond_rim: self.y -= self.offset else: self.x = new_x
def __init__(self, **kwargs): super(MyGrid2, self).__init__(**kwargs) self.cols = 10 self.fields = [] self.button1 = Button(text="Save", size_hint=(None, None), width=metrics.sp(120), height=metrics.sp(120)) self.button2 = Button(text="Next", size_hint=(None, None), width=metrics.sp(120), height=metrics.sp(120)) self.add_widget(self.button1) self.add_widget(self.button2) self.button1.bind(on_press=self.savePressed) self.loadImages()
def reset(self, *largs): super(CannonExperimentWindow, self).reset(*largs) self.ball.x, self.ball.y = sp(100), GROUND_SIZE + sp(16) self.ball.init_pos_x, self.ball.init_pos_y = self.ball.x, self.ball.y self.ball.init() self.ball.time_in_air = 0.0 self.ball.max_height = 0.0 self.ball.max_length = 0.0 self.update_ball_params() self.update()
def __init__(self,**kwargs): super(LSystemsEdit, self).__init__(**kwargs) self.name="edit" self.main_layout=BoxLayout(orientation='horizontal') self.edit_layout=BoxLayout(orientation='vertical',size_hint_x=.4) #Text boxes self.name_input = TextInput(multiline=False,size_hint_y=None,height=sp(30)) self.name_input.bind(text=self.on_text) self.angle = TextInput(multiline=False,size_hint_y=None,height=sp(30)) self.angle.bind(text=self.on_text) self.axiom = TextInput(multiline=False,size_hint_y=None,height=sp(30)) self.axiom.bind(text=self.on_text) self.rules = TextInput(multiline=True,size_hint=(1,.4)) self.rules.bind(text=self.on_text) self.rule_chooser = GridLayout(cols=6,size_hint=(1,.2)) #buttons for changing number of iterations self.iterations_buttons = BoxLayout(orientation = 'horizontal',size_hint_y=None,height=sp(30)) self.minus = Button(text="-") self.iter_label = Label(text = "1") self.plus = Button(text = "+") self.minus.bind(on_press = self.iter_press) self.plus.bind(on_press = self.iter_press) self.iterations_buttons.add_widget(self.minus) self.iterations_buttons.add_widget(self.iter_label) self.iterations_buttons.add_widget(self.plus) self.image = LSystemImage() self.edit_layout.add_widget(Label(text="[b]Name[/b]",markup=True,size_hint_y=None,height=sp(30))) self.edit_layout.add_widget(self.name_input) self.edit_layout.add_widget(Label(text="[b]Angle[/b]",markup=True,size_hint_y=None,height=sp(30))) self.edit_layout.add_widget(self.angle) self.edit_layout.add_widget(Label(text="[b]Axiom[/b]",markup=True,size_hint_y=None,height=sp(30))) self.edit_layout.add_widget(self.axiom) self.edit_layout.add_widget(Label(text="[b]Rules[/b]",markup=True,size_hint_y=None,height=sp(30))) self.edit_layout.add_widget(self.rules) self.edit_layout.add_widget((Label(text="[b]Choose rule to visualise[/b]",markup=True,size_hint_y=None,height=sp(30)))) self.edit_layout.add_widget(self.rule_chooser) self.edit_layout.add_widget((Label(text="[b]Change number of iterations[/b]",markup=True,size_hint_y=None,height=sp(30)))) self.edit_layout.add_widget(self.iterations_buttons) self.edit_layout.add_widget((Label(text="[b]L-systems syntax[/b]",markup=True,size_hint_y=None,height=sp(30)))) syntax_label=ScrollableLabel() syntax_label.text = syntax # def f(*args,**kwargs): syntax_label.text_size = syntax_label.size # syntax_label.bind(size = f) self.edit_layout.add_widget(syntax_label) self.main_layout.add_widget(self.edit_layout) self.main_layout.add_widget(self.image) #self.load_lsystem(('quartet', ('fb', {'a': 'fbfa+hfa+fb-fa', 'h': '-', 'b': 'fb+fa-fb-jfbfa', 'j': '+', 'f': ''}, 90.0))) self.add_widget(self.main_layout)
def init_aggressors(self): for col in range(params.aggressors_col_num): for row in range(params.aggressors_row_num): relative_x = float(col) relative_y = float(row) aggressor = Aggressor() aggressor.x = sp(50) + sp(50) * relative_x aggressor.y = sp(150) + sp(50) * relative_y self.ids.aggressors.add_widget(aggressor) Logger.debug("{}", self.ids.aggressors.children[:])
def _toggle_dropdown(self, *largs): ddn = self._dropdown ddn.size_hint_x = None # if container was set incorrectly and/or is missing if not ddn.container: return children = ddn.container.children # set DropDown width manually or if not set, then widen # the ActionGroup + DropDown until the widest child fits if children: ddn.width = self.dropdown_width or max( self.width, max(c.pack_width for c in children) ) else: ddn.width = self.width # set the DropDown children's height for item in children: item.size_hint_y = None item.height = max([self.height, sp(48)]) # dismiss DropDown manually # auto_dismiss applies to touching outside of the DropDown item.bind(on_release=ddn.dismiss)
def updateDisplay(self): self.list_items.clear_widgets() total_height = 0 for (index, locality) in self.allItems.items(): itemButton = ListIconItemButton() itemButton.set_left_icon(None) itemButton.set_text(locality.loclbnom) itemButton.set_font_size(sp(22)) itemButton.set_index(index) itemButton.height = sp(80) itemButton.left_icon_width = sp(80) itemButton.right_icon_width = sp(40) itemButton.bind(on_press=self.select_item) self.list_items.add_widget(itemButton) total_height += itemButton.height self.list_items.height = total_height
def on_text(self, instance, text): if len(text) > 0: self.has_had_text = True if self.max_text_length is not None: self._right_msg_lbl.text = "{}/{}".format(len(text), self.max_text_length) max_text_length = self.max_text_length else: max_text_length = sys.maxsize if len(text) > max_text_length or all([self.required, len(self.text) == 0, self.has_had_text]): self._text_len_error = True else: self._text_len_error = False if self.error or self._text_len_error: if self.focus: Animation(duration=.2, _current_hint_text_color=self.error_color, _current_line_color=self.error_color).start(self) if self.helper_text_mode == "on_error" and (self.error or self._text_len_error): Animation(duration=.2, _current_error_color=self.error_color).start(self) if self._text_len_error: Animation(duration=.2, _current_right_lbl_color=self.error_color).start(self) else: if self.focus: Animation(duration=.2, _current_right_lbl_color=self.theme_cls.disabled_hint_text_color).start(self) Animation(duration=.2, _current_hint_text_color=self.line_color_focus, _current_line_color=self.line_color_focus).start(self) if self.helper_text_mode == "on_error": Animation(duration=.2, _current_error_color=(0, 0, 0, 0)).start(self) if len(self.text) != 0 and not self.focus: self._hint_y = dp(14) self._hint_lbl_font_size = sp(12)
def generate_new_data(self): # Create a data set contacts = [] names = ["Robert", "George", "Joseph", "Donald", "Mark", "Anthony", "Gary"] medias = [ "http://pbs.twimg.com/profile_images/3312895495/8e39061bdad2b5d18dc8a9be63a2f50a_normal.png", "http://www.geglobalresearch.com/media/Alhart-Todd-45x45.jpg", ] for x in range(1000): if x % 100 == 0: contacts.append({ "viewclass": "ContactSeparator", "height": sp(20) }) contacts.append({ "index": x, "viewclass": "ContactItem", "contact_media": random.choice(medias), "contact_name": "{} {}".format( random.choice(names), random.choice(names) ) }) self.root.ids.rv.data = contacts
def _set_ellipse(self, instance, value): ellipse = self.ellipse ripple_rad = self.ripple_rad if ripple_rad > self._finnish_rad * .6: self.fade_out() ellipse.size = (ripple_rad, ripple_rad) ellipse.pos = (int(self.center_x - self.height + self.active_norm_pos * sp(41)), int(self.center_y - self.height/2))
def _get_form(self): layout = BoxLayout(orientation='vertical', spacing=5) layout.add_widget(Widget()) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Factory.XLabel(text=_('Login:'******'right', size_hint_x=None, width=metrics.dp(80))) pnl.add_widget(TextInput(id='login', multiline=False, font_size=metrics.sp(14), text=self.login)) layout.add_widget(pnl) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Factory.XLabel(text=_('Password:'******'right', size_hint_x=None, width=metrics.dp(80))) pnl.add_widget(TextInput(id='password', multiline=False, font_size=14, password=True, text=self.password)) layout.add_widget(pnl) if self.autologin is not None: pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget(CheckBox( id='autologin', size_hint_x=None, width=metrics.dp(80), active=self.autologin)) pnl.add_widget( Factory.XLabel(text=_('Login automatically'), halign='left')) layout.add_widget(pnl) layout.add_widget(Widget()) return layout
def on_touch_down(self, touch): if (not any([marker.collide_point(*touch.pos) for marker in self.markers]) and self.collide_point(*touch.pos)): marker = WvMarker(pos=(touch.pos[0]-sp(20), touch.pos[1]-sp(20)), touch=touch) self.add_widget(marker) marker.recalculate_k() self.markers.append(marker) length = min(self.width, self.height) dx = touch.x - self.center_x dy = touch.y - self.center_y self.shader_widget.wavevectors.append(marker) else: super(WavevectorMaker, self).on_touch_down(touch)
def load(self, *largs): self.boat = Boat(scale=self.scale, source=self.get_file('data/boat.png'), size=(BOAT_WIDTH, BOAT_HEIGHT), show_trajectory=True, pos=(100, 100)) self.boat.init() self.boat.add_vector('boat_speed', 'Vb', self.boat_speed.value, self.boat_angle.value, (1, 0.4, 1, 1)) self.boat.add_vector('river_speed', 'Vr', self.river_speed.value, 90.0, (0.4, 1, 1, 1)) self.boat.add_vector('speed', 'V', self.boat_speed.value, self.boat_angle.value) self.boat.show_trajectory = self.show_trajectory.value self.river = TexturedWidget(source=self.get_file('data/river.png')) self.riverside_bottom = TexturedWidget(source=self.get_file('data/riverside.png')) self.riverside_top = TexturedWidget(source=self.get_file('data/riverside.png')) self.speed_label = Label(text='0.0 m/s', font_size=sp(16), bold=True, halign='center', valign='middle') self.add_widget(self.river) self.add_widget(self.riverside_bottom) self.add_widget(self.riverside_top) self.add_widget(self.boat) self.add_widget(self.speed_label) self.bind(on_drag=self.update_angle)
def update_layout(self,btn): data_dir= App.get_running_app().user_data_dir+'/' self.store = JsonStore(join(data_dir, 'storage.json')) try: self.username=self.store.get('credentials')['username'] exp_data.set_username(self.username) self.parent.current = 'ExperimentSelectScreen' except KeyError: box=BoxLayout(orientation= 'vertical',padding=(100,100,100,100)) #l=Label(size_hint_y=0.25) #box.add_widget(l) box.add_widget(Label(text="Enter email",font_size= sp(30),size_hint_y=.5)) self.t=TextInput(font_size= sp(30),size_hint_y=0.5) box.add_widget(self.t) box.add_widget(Button(text="Okay",on_press=self.change_screen,font_size=sp(25),size_hint_y=.25)) #box.add_widget(l) self.add_widget(box)
def __init__(self, **kwargs): super(MaterialCheckBox, self).__init__(**kwargs) self.register_event_type('on_active') self.color = self._theme_cls.secondary_text_color() self.check_anim_out = Animation(font_size=0, duration=.1, t='out_quad') self.check_anim_in = Animation(font_size=sp(24), duration=.1, t='out_quad') self.check_anim_in.bind(on_complete=self._set_state) self.check_anim_out.bind(on_complete=lambda *x: self.check_anim_in.start(self))
def __init__(self, **kwargs): super(FieldLabel, self).__init__(**kwargs) self.bind(width=self.width_changed) self.spacing = (20,3) self.font_name = "resource/fonts/ASL_light.ttf" self.font_size = sp(20) self.shorten = True self.shorten_from = 'right'
def __init__(self, **kwargs): super(MyScroll, self).__init__(**kwargs) self.grid1 = GridLayout(cols=10) self.add_widget(self.grid1) self.grid1.size_hint = None, None self.grid1.bind(minimum_height=self.grid1.setter("height")) self.grid1.bind(minimum_width=self.grid1.setter("width")) for i in range(20): for j in range(10): ti = TextInput(size_hint=(None, None)) ti.width = metrics.sp(160) ti.height = metrics.sp(40) ti.row = i ti.col = j self.grid1.add_widget(ti) ti.bind(text=self.textChanged) return
def __init__(self, **kwargs): super(MDCheckbox, self).__init__(**kwargs) self.register_event_type('on_active') self.check_anim_out = Animation(font_size=0, duration=.1, t='out_quad') self.check_anim_in = Animation(font_size=sp(24), duration=.1, t='out_quad') self.check_anim_out.bind( on_complete=lambda *x: self.check_anim_in.start(self))
def call_popup(self): box = BoxLayout(orientation= 'vertical') self.filename=TextInput(text='',font_size= sp(25)) box.add_widget(self.filename) close_button=Button(text='Ok',size_hint=(.5,.5),pos_hint={'right': 0.75}) box.add_widget(close_button) self.popup = Popup(title='Enter Experiment Name',content=box,size_hint=(1,.35),auto_dismiss=True) close_button.bind(on_release=self.exp_button_clicked) self.popup.open()
def on_text(self, instance, text): if len(text) > 0: self.has_had_text = True if self.max_text_length is not None: self._right_msg_lbl.text = f"{len(text)}/{self.max_text_length}" max_text_length = self.max_text_length else: max_text_length = sys.maxsize if len(text) > max_text_length or all( [self.required, len(self.text) == 0, self.has_had_text]): self._text_len_error = True else: self._text_len_error = False if self.error or self._text_len_error: if self.focus: Animation( duration=0.2, _current_hint_text_color=self.error_color, _current_line_color=self.error_color, ).start(self) if self.helper_text_mode == "on_error" and ( self.error or self._text_len_error): Animation( duration=0.2, _current_error_color=self.error_color).start(self) if self._text_len_error: Animation( duration=0.2, _current_right_lbl_color=self.error_color).start(self) else: if self.focus: disabled_hint_text_color = ( self.theme_cls.disabled_hint_text_color) Animation( duration=0.2, _current_right_lbl_color=disabled_hint_text_color, ).start(self) Animation( duration=0.2, _current_hint_text_color=self.line_color_focus, _current_line_color=self.line_color_focus, ).start(self) if self.helper_text_mode == "on_error": Animation(duration=0.2, _current_error_color=(0, 0, 0, 0)).start(self) if len(self.text) != 0 and not self.focus: self._hint_y = dp(14) self._hint_lbl_font_size = sp(12)
def on_tab_press(self, *args): par = self.parent_widget par.ids.tab_manager.current = self.name if par.previous_tab is not self: Animation(_label_font_size=sp(12), d=0.1).start(par.previous_tab.header) Animation( _text_color_normal=par.previous_tab.header.text_color_normal if par.previous_tab.header.text_color_normal != [1, 1, 1, 1] else self.theme_cls.disabled_hint_text_color, d=0.1, ).start(par.previous_tab.header) par.previous_tab.header.active = False self.header.active = True par.previous_tab = self
def create(self): anchor_layout = AnchorLayout(size_hint=(1, 0.1), anchor_x='left', anchor_y='top', padding=(dp(20), dp(20), dp(0), dp(0))) header = Label(halign='left', valign='top', font_size=sp(20), color=get_color_from_hex('#023b80'), text='[font=assets/Inter-SemiBold.ttf]Profile Page', markup=True) header.bind(size=header.setter('text_size')) anchor_layout.add_widget(header) return anchor_layout
def scan_button_pressed(self): print("Starting scan prep") import netifaces as ni print("IMported") netconns = [ i for i in ni.interfaces() if i.startswith("e") or i.startswith("w") ] print("netConns: %s" % netconns) connected = False for netcon in netconns: print("ifaddresses: %s" % ni.ifaddresses(netcon)) if ni.AF_INET in ni.ifaddresses(netcon).keys(): connected = True print("Interfaces: %s" % netconns) if connected: self.parent.current = "scanning" else: self.box_popup = BoxLayout(orientation='vertical') self.box_popup.add_widget( Label(text="Connect to Wifi first!", font_size=sp(20))) self.popup_exit = Popup(title='Hey now!', content=self.box_popup, size_hint=(0.8, 0.3), auto_dismiss=True) self.box_popup.add_widget( Button(text="Okay", font_size=sp(20), on_press=lambda _: self.popup_exit.dismiss(), size_hint=(0.8, 0.2), pos_hint={'center_x': .5})) self.popup_exit.open()
def refresh_tabs(self, *args) -> None: """Refresh all tabs.""" if self.ids: tab_bar = self.ids.tab_bar tab_bar.clear_widgets() tab_manager = self.ids.tab_manager self._active_color = self.theme_cls.primary_color if self.text_color_active != [1, 1, 1, 1]: self._active_color = self.text_color_active for tab in tab_manager.screens: self.tab_header = MDBottomNavigationHeader(tab=tab, panel=self) tab.header = self.tab_header tab_bar.add_widget(self.tab_header) if tab is self.first_widget: self.tab_header._text_color_normal = self._active_color self.tab_header._label_font_size = sp(14) self.tab_header.active = True else: self.tab_header.ids._label.font_size = sp(12) self.tab_header._label_font_size = sp(12)
def animation_to_top(self): user_name_y = Window.height - self._obj_toolbar.height + ( self.theme_cls.standard_increment // 2 - dp(12)) user_name_x = self.theme_cls.horizontal_margins + dp(12) * 5 Animation(y=-self._obj_toolbar.height, d=.4, t='in_out_cubic').start(self.user_animation_card.ids.scroll) Animation(y=user_name_y, d=.3, x=user_name_x, t='in_out_cubic').start(self._obj_user_name) Animation(font_size=sp(20), d=.3, t='in_out_cubic').start(self._obj_user_name) Animation(y=self._obj_avatar.y + 30, d=.4, t='in_out_cubic').start(self._obj_avatar) Animation(a=1, d=.4, t='in_out_cubic').start(self._obj_avatar.canvas.children[3])
class MDBottomNavigationHeader(BaseFlatButton, BasePressedButton): panel_color = ListProperty([1, 1, 1, 0]) width = BoundedNumericProperty( dp(0), min=dp(80), max=dp(168), errorhandler=lambda x: small_error_warn(x), ) tab = ObjectProperty() panel = ObjectProperty() active = BooleanProperty(False) text = StringProperty() _label = ObjectProperty() _label_font_size = NumericProperty(sp(12)) _current_color = ListProperty([0.0, 0.0, 0.0, 0.0]) _capitalized_text = StringProperty() def on_text(self, instance, value): self._capitalized_text = value.upper() def __init__(self, panel, height, tab): self.panel = panel self.height = height self.tab = tab super().__init__() self._current_color = self.theme_cls.disabled_hint_text_color self._label = self.ids._label self._label_font_size = sp(12) self.theme_cls.bind( primary_color=self._update_theme_color, disabled_hint_text_color=self._update_theme_style, ) self.active = False def on_press(self): Animation(_label_font_size=sp(14), d=0.1).start(self) Animation(_current_color=self.theme_cls.primary_color, d=0.1).start(self) def _update_theme_color(self, instance, color): if self.active: self._current_color = self.theme_cls.primary_color def _update_theme_style(self, instance, color): if not self.active: self._current_color = self.theme_cls.disabled_hint_text_color
class FlexSpinner(RectangularRippleBehavior, Spinner, HoverBehavior): background_color = [0, 0, 0, 0] background_normal = '' background_down = '' ripple_duration_in_fast = 0.2 color = ListProperty([0.0, 0.4471, 0.8235, 1]) fg_color = ListProperty([.3, .3, .3, 1]) ripple_color = ListProperty([0.0, 0.6784, 0.9569, 1]) border_color = ListProperty([0.0, 0.4471, 0.8235, 1]) primary_color = [0.12, 0.58, 0.95, 1] hover_color = ListProperty([.6, .8, 1, 1]) unhover_color = ListProperty([1, 1, 1, 1]) bg_color = ListProperty([1, 1, 1, 1]) bg_color_normal = ListProperty([1, 1, 1, 1]) bg_color_press = ListProperty([.9, .9, .9, 1]) font_size = sp(20) radius = ListProperty([ 10, ]) border_weigth = NumericProperty(dp(1)) font_size = NumericProperty(20) border_width = 2 dropdown_max_height = NumericProperty(50) def __init__(self, **kwargs): super(FlexSpinner, self).__init__(**kwargs) self.halign = 'center' self.valign = 'middle' self.ripple_color = kwargs.get("ripple_color", self.ripple_color) self.fg_color = kwargs.get("fg_color", self.fg_color) self.bg_color = kwargs.get("bg_color", self.bg_color) def on_dropdown_font_size(self, obj, number): self.option_cls.font_size = number def on_dropdown_max_height(self, obj, number): self.dropdown_cls.max_height = number def on_fg_color(self, obj, val): self.color = val def on_press(self, *args): self.bg_color = self.bg_color_press def on_release(self, *args): self.bg_color = self.bg_color_normal
class RecycleLabel(Widget): text = StringProperty() font_size = NumericProperty(sp(14)) font_name = StringProperty("Roboto") halign = OptionProperty("center", options=("left", "center", "right")) line_height = NumericProperty() markup = BooleanProperty(False) color = ListProperty([1, 1, 1, 1]) def __init__(self, **kwargs): super(RecycleLabel, self).__init__(**kwargs) self._trigger_refresh_label = Clock.create_trigger(self.refresh_label) self.bind(text=self._trigger_refresh_label, font_size=self._trigger_refresh_label, font_name=self._trigger_refresh_label, halign=self._trigger_refresh_label, width=self._trigger_refresh_label, markup=self._trigger_refresh_label) self._trigger_refresh_label() def refresh_label(self, *args): lcls = CoreLabel label = lcls(text=self.text, text_size=(self.width, None), halign=self.halign, font_size=self.font_size, font_name=self.font_name, markup=self.markup) label.resolve_font_name() label.render() # get lines font_name = self.font_name font_size = self.font_size halign = self.halign markup = self.markup color = self.color data = ({ "text": " ".join([word.text for word in line.words]), "font_name": font_name, "font_size": font_size, "height": line.h, "size_hint_y": None, "halign": halign, "markup": markup, "color": color } for index, line in enumerate(label._cached_lines)) self.ids.rv.data = data
class KivyPresApp(App): font_size_regular = sp(25) font_size_large = font_size_regular * 2 font_size_xlarge = font_size_regular * 3 def build(self): return KivyPres() def on_pause(self): return True def on_resume(self): pass def open_browser(self, url): browser.open_url(url)
def __init__(self, size=Window.size, nome_tela="sobre", titulo="Titulo Padrão", dados: List = [], **kwargs): super(TelaSobreWidget, self).__init__(**kwargs) self.size = size self.titulo = titulo self.nome_tela = nome_tela self.fonte_padrao = sp(20) self.dados = dados self.constroi_titulo() self.constroi_tela() self.add_widget(Label(size_hint_y=None, height=self.height * .05))
def animation_to_top(self): user_name_y = (Window.height - self._obj_toolbar.height + (self.theme_cls.standard_increment // 2 - dp(12))) user_name_x = self.theme_cls.horizontal_margins + dp(12) * 5 Animation(y=-self._obj_toolbar.height, d=0.4, t="in_out_cubic").start(self._obj_scroll) Animation(y=user_name_y, d=0.3, x=user_name_x, t="in_out_cubic").start(self._obj_user_name) Animation(font_size=sp(20), d=0.3, t="in_out_cubic").start(self._obj_user_name) Animation(_primary_color=self.theme_cls.primary_color, d=0.3, t="in_out_cubic").start(self.user_animation_card) Animation(y=self._obj_avatar.y + 30, d=0.4, t="in_out_cubic").start(self._obj_avatar)
def create(self): box_layout = BoxLayout(orientation='vertical', spacing=dp(30), padding=(dp(35), dp(35), dp(35), dp(35))) box_layout.add_widget(self.Header().create()) box_layout.add_widget( Label(font_size=sp(40), color=get_color_from_hex('#150470'), text='[font=assets/Inter-SemiBold.ttf]', markup=True)) report_screen = Screen(name='Report') report_screen.add_widget(box_layout) return report_screen
def animation_to_bottom(self): Animation(y=self._scroll_y, d=0.4, t="in_out_cubic").start( self._obj_scroll ) Animation(y=self._user_name_y, d=0.5, x=dp(15), t="in_out_cubic").start( self._obj_user_name ) Animation(font_size=sp(36), d=0.3, t="in_out_cubic").start( self._obj_user_name ) Animation(y=self._avatar_y, d=0.4, t="in_out_cubic").start( self._obj_avatar ) Animation(a=0, d=0.4, t="in_out_cubic").start( self._obj_avatar.canvas.children[3] )
def _toggle_dropdown(self, *largs): self.is_open = not self.is_open ddn = self._dropdown ddn.size_hint_x = None if not ddn.container: return children = ddn.container.children if children: ddn.width = max(self.width, max(c.pack_width for c in children)) else: ddn.width = self.width for item in children: item.size_hint_y = None item.height = max([self.height, sp(48)])
def on_press(self) -> None: """Called when clicking on a panel item.""" if self.theme_cls.material_style == "M2": Animation(_label_font_size=sp(14), d=0.1).start(self) elif self.theme_cls.material_style == "M3": Animation( _selected_region_width=dp(64), t="in_out_sine", d=0, ).start(self) Animation( _text_color_normal=self.theme_cls.primary_color if self.text_color_active == [1, 1, 1, 1] else self.text_color_active, d=0.1, ).start(self)
def _create_popup(self, instance): # Create Popup layout content = BoxLayout(orientation='vertical', spacing=dp(5)) self.popup = Popup(content=content, title=self.title, size_hint=(0.25, None), auto_dismiss=False, separator_color=[1, 1, 1, 0], height=dp(234)) content.add_widget(SettingSpacer()) # Create the label to show the numeric value self._set_unit() self.Label = Label(text=self.value + self.units, markup=True, font_size=sp(24), size_hint_y=None, height=dp(50), halign='left') content.add_widget(self.Label) # Add a plus and minus increment button to change the value by +/- one btnlayout = BoxLayout(size_hint_y=None, height=dp(50), spacing=dp(50)) btn = Button(text='-') btn.bind(on_press=self._minus_value) btnlayout.add_widget(btn) btn = Button(text='+') btn.bind(on_press=self._plus_value) btnlayout.add_widget(btn) content.add_widget(btnlayout) content.add_widget(SettingSpacer()) # Add an OK button to set the value, and a cancel button to return to # the previous panel btnlayout = BoxLayout(size_hint_y=None, height=dp(50), spacing=dp(5)) btn = Button(text='Ok') btn.bind(on_release=self._set_value) btnlayout.add_widget(btn) btn = Button(text='Cancel') btn.bind(on_release=self.popup.dismiss) btnlayout.add_widget(btn) content.add_widget(btnlayout) # Open the popup self.popup.open()
def OrderStatus(self, btn, disable, *args): def SelectAll(checkbox, value): for b in statuspanel.children: if type(b).__name__=='BoxLayout': b.children[0].state = value def ApplyChange(btn): for b in statuspanel.children: if type(b).__name__=='BoxLayout': check = b.children[0] proc = b.children[1].text.lower() if proc=='': continue if check.state=='down': o.ES[proc] = 0.0 o.EE[proc] = 0.0 o.CopytoSuborders(proc) else: o.ES[proc] = -1.0 o.EE[proc] = -1.0 o.CopytoSuborders(proc) self.UpdateResult(self.orders) statuspopup.dismiss() jo = btn.parent.parent.children[-1].text o = [o for o in self.orders if o.jo==jo][0] statuspanel = BoxLayout(orientation='vertical') b = BoxLayout() b.add_widget(Label(text='')) selectall = MDCheckbox(state='down' if not [proc for proc in machines if o.EE[proc]<0] else 'normal', disabled=disable) selectall.bind(state=SelectAll) b.add_widget(selectall) statuspanel.add_widget(b) for key in machines: b = BoxLayout() b.add_widget(Label(text=key.upper())) b.add_widget(MDCheckbox(state='down' if o.EE[key]>=0 else 'normal', disabled=disable)) statuspanel.add_widget(b) statuspopup = Popup(title='JO#'+jo+' Status', title_size=sp(20), content=statuspanel, size_hint=(.3,.8)) if not disable: statuspanel.add_widget(MDRaisedButton(text='Apply', on_release=ApplyChange, size_hint=(1,1))) statuspopup.background = 'atlas://data/images/defaulttheme/button' statuspopup.open()
def gera_ler_dados(self): box_geral = BoxLayout(orientation="vertical") spacing = "20sp" padding = [f"{i}sp" for i in [10, 50, 10, 50]] grid = GridLayout(cols=2, size_hint_y=None, spacing=spacing, padding=padding) grid.bind(minimum_height=grid.setter("height")) nomes = "Peso_em_Arrobas Preco_em_Arrobas Peso_em_KG Preco_em_Reais" nomes = nomes.split() altura = sp(30) for nome in nomes: txt = " ".join(nome.split("_")) lb = Label(text=txt, size_hint_y=None, height=altura) inp = TextInput(write_tab=False, input_filter="float", multiline=False) grid.add_widget(lb) grid.add_widget(inp) self.ids["calculos_input_" + nome.lower()] = inp scroll = ScrollView(size_hint=(1, 1)) #scroll.width = self.width * .9 #scroll.height = self.height * .85 #scroll.add_widget(grid) #box_geral.add_widget(scroll) bnt = Button(text="Relizar os Calculos", size_hint_y=None, height="30sp") bnt.on_release = self.faz_calculos self.ids["calculos_botao_calculos"] = bnt p = [f"{i}sp" for i in [40, 0, 40, 40]] box = BoxLayout(orientation="vertical", padding=p) box.add_widget(bnt) box_geral.add_widget(grid) box_geral.add_widget(box) scroll.add_widget(box_geral) self.add_widget(scroll)
class FlexSelectableLabel(RecycleDataViewBehavior, RectangularRippleBehavior, HoverBehavior, Label): ''' Add selection support to the Label ''' index = None selected = BooleanProperty(False) selectable = BooleanProperty(True) color = ListProperty([.2,.2,.2,1]) fg_color = ListProperty([.2,.2,.2,1]) selected_bg_color = ListProperty([.2,.2,.6,1]) unselected_bg_color = ListProperty([.2,.2,.8,1]) hover_color = ListProperty([.2,.2,.7,1]) unhover_color = ListProperty([.2,.2,.8,1]) border_color = ListProperty([0.0, 0.4471, 0.8235, 1]) ripple_color = ListProperty([0.0, 0.6784, 0.9569, 1]) radius = ListProperty([5]) ripple_duration_in_fast = NumericProperty(0.2) font_size = NumericProperty(sp(12)) border_weigth = ListProperty([1,1,1,1]) def refresh_view_attrs(self, rv, index, data): ''' Catch and handle the view changes ''' self.index = index return super(FlexSelectableLabel, self).refresh_view_attrs( rv, index, data) def on_enter(self, *args): self.unselected_bg_color = self.hover_color def on_leave(self): self.unselected_bg_color = self.unhover_color def on_fg_color(self, inst, val): self.color = val def on_touch_down(self, touch): ''' Add selection on touch down ''' if super(FlexSelectableLabel, self).on_touch_down(touch): return True if self.collide_point(*touch.pos) and self.selectable: return self.parent.select_with_touch(self.index, touch) def apply_selection(self, tb, index, is_selected): ''' Respond to the selection of items in the view. ''' self.selected = is_selected
class MyApp(App): title = "Organizex" switch = BooleanProperty(False) color_background2 = ListProperty( [0.20392156862745098, 0.596078431372549, 0.8588235294117647, 1]) color_font2 = 0.9254901960784314, 0.9411764705882353, 0.9450980392156862, 1 color_font1 = 0.9254901960784314, 0.9411764705882353, 0.9450980392156862, 1 color_background1 = ListProperty( [0.20392156862745098, 0.28627450980392155, 0.3686274509803922, 1]) color_button = 0.08627450980392157, 0.6274509803921569, 0.5215686274509804, 1 color_button_pressed = 0.10196078431372549, 0.7372549019607844, 0.611764705882353, 1 color_menubar = 0.10196078431372549, 0.7372549019607844, 0.611764705882353, 1 tam_font = sp('30') def build(self): self.icon = './img/logo.png' return Display()
class FlexText(TextInput): font_size = NumericProperty(sp(15)) radius = ListProperty([ 10, ]) border_weigth = NumericProperty(1) bg_normal_color = ListProperty([1, 1, 1, 1]) bg_active_color = ListProperty([.98, .98, 1, 1]) border_normal_color = ListProperty([.1, .1, .1, 1]) border_active_color = ListProperty([0.0, 0.4471, 0.8235, 1]) hint_text_color = ListProperty([.3, .3, .3, 1]) cursor_color = ListProperty([0.0, 0.4471, 0.8235, 1]) fg_color = ListProperty([.1, .1, .1, 1]) disabled_fg_color = ListProperty([1, .5, 0, 1]) def __init__(self, **kwargs): super().__init__(**kwargs)
class FlexLabel(Label): font_size = NumericProperty(sp(15)) bold = BooleanProperty(False) radius = ListProperty([0]) halign = StringProperty('center') valign = StringProperty('middle') color = ListProperty([.2, .2, .2, 1]) fg_color = ListProperty([.2, .2, .2, 1]) bg_color = ListProperty([1, 1, 1, 1]) def __init__(self, **kwargs): super().__init__(**kwargs) self.fg_color = kwargs.get("fg_color", self.color) self.bg_color = kwargs.get("bg_color", self.bg_color) def on_fg_color(self, obj, val): self.color = val
def __init__(self, title, choices): layout = BoxLayout(orientation="vertical", spacing=dp(34), padding=(dp(20), dp(15))) for key, string in choices.items(): btn = Button(string, font_size=sp(16)) def _make_select_function(key): def _select(btn): self.dismiss() self.choice = key return _select btn.bind(on_release=_make_select_function(key)) layout.add_widget(btn) super().__init__(title, layout, size_hint=(0.5, 0.8))
def on_text(self, instance, text): if len(text) > 0: self.has_had_text = True if self.max_text_length is not None: self._right_msg_lbl.text = "{}/{}".format(len(text), self.max_text_length) max_text_length = self.max_text_length else: max_text_length = 9999999999999 if len(text) > max_text_length or (True if self.required and len(text) == 0 and self.has_had_text else False): self.text_len_error = True else: self.text_len_error = False if self.error or self.text_len_error: if self.focus: Animation(duration=.2, _current_hint_text_color=self.error_color, _current_line_color=self.error_color).start(self) if self.message_mode == "on_error" and (self.error or self.text_len_error): Animation( duration=.2, _current_error_color=self.error_color).start(self) if self.text_len_error: Animation( duration=.2, _current_right_lbl_color=self.error_color).start(self) else: if self.focus: Animation(duration=.2, _current_right_lbl_color=self.theme_cls. disabled_hint_text_color).start(self) Animation( duration=.2, _current_hint_text_color=self.base_line_color_focus, _current_line_color=self.base_line_color_focus).start(self) if self.message_mode == "on_error": Animation(duration=.2, _current_error_color=(0, 0, 0, 0)).start(self) if len(self.text) != 0 and not self.focus: self._hint_y = dp(14) self._hint_lbl_font_size = sp(12)
def _get_form(self): layout = BoxLayout(orientation='vertical', spacing=5) layout.add_widget(Widget()) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Factory.XLabel(text=_('Login:'******'right', size_hint_x=None, width=metrics.dp(80))) pnl.add_widget( TextInput(id='login', multiline=False, font_size=metrics.sp(14), text=self.login)) layout.add_widget(pnl) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Factory.XLabel(text=_('Password:'******'right', size_hint_x=None, width=metrics.dp(80))) pnl.add_widget( TextInput(id='password', multiline=False, font_size=14, password=True, text=self.password)) layout.add_widget(pnl) if self.autologin is not None: pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( CheckBox(id='autologin', size_hint_x=None, width=metrics.dp(80), active=self.autologin)) pnl.add_widget( Factory.XLabel(text=_('Login automatically'), halign='left')) layout.add_widget(pnl) layout.add_widget(Widget()) return layout
def open_load_popup(self): effects_to_load = get_all_files( join(dirname(__file__), 'effects'), '.kep') content = ScrolledPopupContent() content_layout = content.ids.content_layout popup = CustomPopup(content=content, title='Load Effect', title_size=sp(16)) emitter_system = self.ids.emitter loaded_effects = emitter_system.loaded_effects for effect in effects_to_load: real_effect_name = splitext(split(effect)[1])[0] if real_effect_name not in loaded_effects: emitter_system.load_effect(effect) wid = EffectChoiceButton(choice_name=real_effect_name, font_group_id='effect_choice', on_release=self.load_effect) wid.popup = popup content_layout.add_widget(wid) popup.open()
def on_touch_move(self, touch): if self._get_uid('svavoid') in touch.ud or\ self._swipe_touch is not touch: return super(SwipeBehavior, self).on_touch_move(touch) or\ self._get_uid() in touch.ud if touch.grab_current is not self: return True uid = self._get_uid() ud = touch.ud[uid] mode = ud['mode'] if mode == 'unknown': ud['dx'] += abs(touch.dx) if ud['dx'] > sp(self.swipe_distance): mode = 'drag' ud['mode'] = mode if mode == 'drag': self.x += touch.dx return True
def _get_form(self): layout = BoxLayout(orientation='vertical', spacing=5) layout.add_widget(Widget()) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Label(text='Login:'******'right', size_hint_x=None, width=metrics.dp(80))) text_input = TextInput(multiline=False, font_size=metrics.sp(14), text=self.login) setattr(text_input, 'id', 'login') pnl.add_widget(text_input) layout.add_widget(pnl) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Label(text='Password:'******'right', size_hint_x=None, width=metrics.dp(80))) text_password = TextInput(multiline=False, font_size=14, password=True, text=self.password) setattr(text_password, 'id', 'password') pnl.add_widget(text_password) layout.add_widget(pnl) if self.autologin is not None: pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) checkbox = CheckBox(size_hint_x=None, width=metrics.dp(80), active=self.autologin) setattr(checkbox, 'id', 'autologin') pnl.add_widget(checkbox) pnl.add_widget(Label(text='Login automatically', halign='left')) layout.add_widget(pnl) layout.add_widget(Widget()) return layout
def on_commands(self, *args): self.container.clear_widgets() self.log += 'got a list of commands!\n' for command, arguments in self.commands: box = BoxLayout(height=sp(30)) button = Button(text=command) args_inputs = [] for arg in arguments.split(','): if arg == 'str': txtinput = TextInput() args_inputs.append(txtinput) box.add_widget(txtinput) button.bind(on_press=partial(self.execute, command, arguments.split(','), args_inputs)) box.add_widget(button) self.container.add_widget(box)