def on_enter(self): # Будет вызвана в момент открытия экрана self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) back_button = Button(text='< Назад в главное меню', on_press=lambda x: set_screen('menu'), size_hint_y=None, height=dp(40)) self.layout.add_widget(back_button) root = RecycleView(size_hint=(1, None), size=(Window.width, Window.height)) root.add_widget(self.layout) self.add_widget(root) dic_foods = ast.literal_eval( App.get_running_app().config.get('General', 'user_data')) i = 0 rand = random.randint(10,20) for f, d in sorted(dic_foods.items(), key=lambda x: x[1]): i += 1 fd = f.decode('u8') btn = Button(text=fd, size_hint_y=None, height=dp(40)) if i == rand: btn = Button(text='Try catch token!', on_press=lambda x: set_screen('get_token'), size_hint_y=None, height=dp(40)) self.layout.add_widget(btn) else: self.layout.add_widget(btn)
def done_progress(self): self.pb.value = self.pb.max print("Completed. Qsize: ", self.outbox.qsize()) print(self.outbox.get_nowait()) similar_images = ImageHasher.group_by_similar_images(self.outbox) scrollView = RecycleView() rv = RecycleBoxLayout() for img_path in similar_images: print("Adding to rv: " + img_path) #button = Button() #button.text = "Image: " + img_path img = Image(source=img_path) #button.add_widget(img) rv.add_widget(img) scrollView.add_widget(rv) self.images_row.add_widget(scrollView) return image_per_row = 2 rows_count = math.floor(len(self._infiles) / image_per_row) for row in range(rows_count): for c in range(image_per_row): img_path = self._infiles[c * row] img = Image(source=img_path) print(self._infiles[c * row]) self.images_row.add_widget(img)
def on_enter(self): # Будет вызвана в момент открытия экрана self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) back_button = Button(text='< Назад к игре', on_press=lambda x: set_screen('add_food'), size_hint_y=None, height=dp(40)) self.layout.add_widget(back_button) root = RecycleView(size_hint=(1, None), size=(Window.width, Window.height)) root.add_widget(self.layout) self.add_widget(root) dic_foods = ast.literal_eval(App.get_running_app().config.get( 'General', 'user_data')) file = 'file_words.pk' with open(file, 'rb') as fi: time = pickle.load(fi) for f, d in sorted(dic_foods.items(), key=lambda x: x[1]): fd = f.decode('u8') if time > d: pass else: btn = Button(text=fd, size_hint_y=None, height=dp(40)) self.layout.add_widget(btn)
def __init__(self, **kwargs): # initialise super classes RecycleView.__init__(self, **kwargs) # initialise client super class Server.__init__(self, './scripts/transfer/log', 3600, settings.get_verbose()) # initialise server CommandLookup.__init__( self, './scripts/transfer/log') # initialise command lookup
def on_enter(self): # Будет вызвана в момент открытия экрана global bbb self.layout = GridLayout(cols=bbb) self.layout.bind(minimum_height=self.layout.setter('height')) root = RecycleView(size_hint=(1, None), size=(Window.width, Window.height)) root.add_widget(self.layout) self.add_widget(root) for i in range(aaaa): btn = Button(text="succ", on_press=lambda x: succc()) self.layout.add_widget(btn)
def on_enter(self): # Будет вызвана в момент открытия экрана self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) back_button = Button(text='< Назад к выбору коллекции', on_press=lambda x: set_screen('start_menu'), size_hint_y=None, height=dp(40)) self.layout.add_widget(back_button) root = RecycleView(size_hint=(1, None), size=(Window.width, Window.height)) root.add_widget(self.layout) self.add_widget(root)
def new(self): # self.size_hint_y = 0.95 self.buildings_upgrading = [None] * 2 self.building_labels = {} self.building_buttons = {} # scrool: self.recycleview = RecycleView() self.box_scroll =\ BoxLayout(orientation="vertical", size_hint_y=None) self.box_scroll.\ bind(minimum_height=self.box_scroll.setter('height')) self.create_time_menu() self.create_available_box() self.create_unavailable_box() self.recycleview.add_widget(self.box_scroll) self.add_widget(self.recycleview)
def populate_location_mapping(db, producer, base, view_cls): """Mapping for locations to items""" pairs = producer.refreshed_store_mappings(db) dict_ = {} values = [] for mapping, store in pairs: dict_[store.name] = mapping values.append(store.name) base = base() base.values = values rv = RecycleView(viewclass=view_cls) rv.data = mapping base.add_widget(rv) rv.refresh_from_data() base.options = values return base
def __init__(self, **kwargs): super(History, self).__init__(**kwargs) self.orientation = 'vertical' self.toolbar = MDToolbar(title='History', anchor_title='center', elevation=10) self.toolbar.md_bg_color = color( f"images/{theme_image[config_data['theme']][2]}.png") self.toolbar.specific_text_color = color( f"images/{theme_image[config_data['theme']][0]}.png") self.scroll = RecycleView() self.layout = MDList() self.do_scroll_x = False self.refresh() self.scroll.add_widget(self.layout) self.add_widget(self.toolbar) self.add_widget(self.scroll)
def on_enter(self): # Будет вызвана в момент открытия экрана self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) back_button = Button(text='< Go BAck', on_press=lambda x: set_screen('menu'), size_hint_y=None, height=dp(40)) self.layout.add_widget(back_button) root = RecycleView(size_hint=(1, None), size=(Window.width, Window.height)) root.add_widget(self.layout) self.add_widget(root) dic_foods = ast.literal_eval( App.get_running_app().config.get('General', 'user_data')) for f, d in sorted(dic_foods.items(), key=lambda x: x[1]): fd = f.decode('u8') + ' ' + (datetime.fromtimestamp(d).strftime('%Y-%m-%d')) btn = Button(text=fd, size_hint_y=None, height=dp(40)) self.layout.add_widget(btn)
def __init__(self, **kwargs): super(MenuScreen, self).__init__(**kwargs) self.name = 'screen_main' self.base_layout = FloatLayout() self.add_widget(self.base_layout) scroll = RecycleView(size=(400, 400), size_hint=(None, None), center=Window.center) scroll.background = (1, 1, 1) self.base_layout.add_widget(scroll) scroll_box = BoxLayout(orientation='vertical', spacing=2, padding=10, size_hint_y=None) scroll_box.bind(minimum_height=scroll_box.setter('height')) scroll.add_widget(scroll_box) self.load_data() for key, item in list(self.data.items()): l = Button(text=item['name'], size=(400, 30), size_hint=(1, None)) scroll_box.add_widget(l)
def build(self): self.layout = GridLayout(cols=1, spacing=10, size_hint_y=None) self.layout.bind(minimum_height=self.layout.setter('height')) back_button = Button(text='< Назад в главное меню', on_press=lambda x: set_screen('menu'), size_hint_y=None, height=dp(40)) self.layout.add_widget(back_button) self.TodayOrNot.bind(on_press=self.Today_func) self.layout.add_widget(self.TodayOrNot) root = RecycleView(size_hint=(1, None), size=(Window.width, Window.height)) root.add_widget(self.layout) self.add_widget(root) dic_foods = ast.literal_eval( App.get_running_app().config.get('General', 'user_data')) TodayCalories = 0.0 TodayProt = 0.0 TodayFat = 0.0 TodayCarboh = 0.0 arr = [] for f, d in sorted(dic_foods.items(), key=lambda x: x[1], reverse=True): if datetime.fromtimestamp(d).strftime('%Y-%m-%d') == datetime.today().strftime('%Y-%m-%d') or not self.Tod: product = f.decode('u8') fd = product + ' ' + (datetime.fromtimestamp(d).strftime('%Y-%m-%d')) TodayCalories += float(product[product.find("гр., ") + 5:product.find("ккал") - 1]) TodayProt += float(product[product.find("ккал, ") + 6:product.find("белк") - 1]) TodayFat += float(product[product.find("белк, ") + 6:product.find("жир") - 1]) TodayCarboh += float(product[product.find("жир, ") + 5:product.find("углв") - 1]) btn = Button(text=fd, size_hint_y=None, height=dp(40)) arr.append(btn) if self.Tod: btn1 = Button(text="За сегодня вы съели: %s ккал, %s белк, %s жир, %s углв" % (TodayCalories, TodayProt, TodayFat, TodayCarboh), size_hint_y=None, height=dp(40)) self.layout.add_widget(btn1) for i in arr: self.layout.add_widget(i)
def __init__(self, **kwargs): super().__init__(**kwargs) self.orientation = "vertical" config = utils.read_config() # Armor item button bar armor_button_bar = self._create_button_bar(config["armor"]) # Weapon button bar weapon_button_bar = self._create_button_bar(config["weapons"]) # Item header bar item_header = BoxLayout(size_hint=(1, None), size_hint_y=None, height=25) item_name = Label(text="Name", bold=True) item_reqs = Label(text="Requirements", bold=True) item_quality = Label(text="Quality", bold=True) item_location = Label(text="Location", bold=True) item_notes = Label(text="Notes", bold=True) item_header.add_widget(item_name) item_header.add_widget(item_reqs) item_header.add_widget(item_quality) item_header.add_widget(item_location) item_header.add_widget(item_notes) # Populate item table - default item view armor_button_bar.children[0].trigger_action() # Item list item_list = BoxLayout() recycle_view = RecycleView() recycle_view.add_widget(ui.SelectableRecycleGridLayout()) recycle_view.data = [{"text": str(x)} for x in self.items] recycle_view.orientation = "vertical" recycle_view.viewclass = "SelectableButton" item_list.add_widget(recycle_view) self.add_widget(armor_button_bar) self.add_widget(weapon_button_bar) self.add_widget(item_header) self.add_widget(item_list)
def page_up(self): '''Scrolls viewport up by it's height * 0.9''' scroll = RecycleView.convert_distance_to_scroll(self, 0, self.height)[1] * 0.9 self.scroll_y = min(self.scroll_y + scroll, 1.0) self._update_effect_bounds()
def page_down(self): '''Scrolls viewport down by it's height * 0.9''' scroll = RecycleView.convert_distance_to_scroll(self, 0, self.height)[1] * 0.9 self.scroll_y = max(self.scroll_y - scroll, 0.0) self._update_effect_bounds()
class AllBuildingsUpgrade(AvailableUnavailableMenu): def __init__(self, **kwargs): super().__init__(**kwargs) self.new() def new(self): # self.size_hint_y = 0.95 self.buildings_upgrading = [None] * 2 self.building_labels = {} self.building_buttons = {} # scrool: self.recycleview = RecycleView() self.box_scroll =\ BoxLayout(orientation="vertical", size_hint_y=None) self.box_scroll.\ bind(minimum_height=self.box_scroll.setter('height')) self.create_time_menu() self.create_available_box() self.create_unavailable_box() self.recycleview.add_widget(self.box_scroll) self.add_widget(self.recycleview) def update(self, *args): self.buildings_upgrading[0].text = str(self.app.current_upgrading) if self.app.time_left > 0: self.add_box_time() self.buildings_upgrading[1].text = "%s" % int(self.app.time_left) else: self.buildings_upgrading[1].text = "" self.remove_box_time() for building in self.all_available_rows: self.building_labels[building.name].text = "%s\n(Level %s)" % ( building.name, building.level) self.building_buttons[building.name].text = str( int(building.level + 1)) # update availables: for building_name in BUILDINGS: building = getattr(self.app, building_name.lower()) if not building.unlock: continue for building_to_check_name, building_to_check_level in building.unlock: building_to_check = getattr(self.app, building_to_check_name.lower()) if building_to_check.level < building_to_check_level: break else: # no breaks: if building in self.all_unavailable_rows: self.unavailable_box.remove_widget( self.all_unavailable_rows[building]) if building not in self.all_available_rows: self.add_1_available_row(building) def upgrade(self, *args): right_button = args[0] for building_name, button in self.building_buttons.items(): if button is right_button: building = getattr(self.app, building_name.lower()) self.app.upgrade_building(building) ############################################################## # time menu: def create_time_menu(self): self.box_time = BoxLayout(orientation="vertical", size_hint_y=None) self.box_time.bind(minimum_height=self.box_time.setter('height')) # header: size_hint_x = self.app.headquarters.menus.get("TIME") header = [["Construction", size_hint_x[0]], ["Duration", size_hint_x[1]], ["Completation", size_hint_x[2]], ["Cancellation", size_hint_x[3]]] self.header_time = self.create_header(header, "return", BLACK) # 1 row self.row_time = BoxLayout(orientation="horizontal", size_hint_y=None, height=100) # building name building_name = DarkLabel(text="%s" % self.app.current_upgrading, size_hint=(size_hint_x[0], None)) self.buildings_upgrading[0] = building_name self.app.bind(current_upgrading=self.update) self.app.bind(time_left=self.update) self.row_time.add_widget(building_name) # time left: time_label = DarkLabel(text="", size_hint=(size_hint_x[1], None)) self.buildings_upgrading[1] = time_label self.row_time.add_widget(time_label) # datetime when will be finish: label = DarkLabel(text=self.app.time_eta, size_hint=(size_hint_x[2], None)) self.app.bind(time_eta=label.setter("text")) self.row_time.add_widget(label) # cancel button: cancel_button = Button(text="Cancel", pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, size_hint=(size_hint_x[3], 0.5)) cancel_button.bind(on_press=self.app.cancel_upgrading) self.row_time.add_widget(cancel_button) # add to scroll: self.box_scroll.add_widget(self.box_time) def add_box_time(self): try: self.box_time.add_widget(self.header_time) self.box_time.add_widget(self.row_time) except: pass def remove_box_time(self): self.box_time.remove_widget(self.header_time) self.box_time.remove_widget(self.row_time) ############################################################## # AVAILABLE: def create_available_box(self): self.available_box = BoxLayout(orientation="vertical", size_hint_y=None) self.available_box.bind( minimum_height=self.available_box.setter('height')) size_hint_x = self.app.headquarters.menus.get("AVAILABLES") header = [["Buildings", size_hint_x[0]], ["Wood", size_hint_x[1]], ["Clay", size_hint_x[2]], ["Iron", size_hint_x[3]], ["Time", size_hint_x[4]], ["Pop", size_hint_x[5]], ["Construct", size_hint_x[6]]] self.create_header(header, self.available_box, BLACK) possibles = BUILDINGS self.create_all_availables(possibles) self.box_scroll.add_widget(self.available_box) def create_all_availables(self, possibles): for name in possibles: building = getattr(self.app, name.lower()) if self.check_if_is_available(building): self.add_1_available_row(building) def add_1_available_row(self, building): row = BoxLayout(orientation="horizontal", size_hint_y=None, height=100) self.all_available_rows[building] = row size_hint_x = self.app.headquarters.menus.get("AVAILABLES") # Building: img = Image(source=building.icon, size_hint_x=size_hint_x[0] / 4) building_label = DarkLabel(text="%s\n(Level %s)" % (building.name, building.level), size_hint_x=size_hint_x[0] * 3 / 4, font_size=24) self.building_labels[building.name] = building_label building.bind(level=self.update) row.add_widget(img) row.add_widget(building_label) # Requirements: img = Image(source=self.app.wood.icon, size_hint_x=size_hint_x[1] / 2) label = DarkLabel(text=str(int((building.wood))), size_hint_x=size_hint_x[1] / 2, font_size=24) building.bind(wood_str=label.setter("text")) row.add_widget(img) row.add_widget(label) img = Image(source=self.app.clay.icon, size_hint_x=size_hint_x[2] / 2) label = DarkLabel(text=str(int((building.clay))), size_hint_x=size_hint_x[2] / 2, font_size=24) building.bind(clay_str=label.setter("text")) row.add_widget(img) row.add_widget(label) img = Image(source=self.app.iron.icon, size_hint_x=size_hint_x[3] / 2) label = DarkLabel(text=str(int((building.clay))), size_hint_x=size_hint_x[3] / 2, font_size=24) building.bind(iron_str=label.setter("text")) row.add_widget(img) row.add_widget(label) img = Image(source=RESOURCES.get("ICON").get("TIME"), size_hint_x=size_hint_x[4] / 2) label = DarkLabel(text=str(int((building.time))), size_hint_x=size_hint_x[4] / 2, font_size=24) row.add_widget(img) row.add_widget(label) img = Image(source=RESOURCES.get("ICON").get("POPULATION"), size_hint_x=size_hint_x[5] / 2) label = DarkLabel(text=str(int((building.population_for_next_level))), size_hint_x=size_hint_x[5] / 2, font_size=24) row.add_widget(img) row.add_widget(label) # button: button = Button(text="lv %s" % (building.level + 1), size_hint=(size_hint_x[6], 0.6), pos_hint={ "center_x": 0.5, "center_y": 0.5 }) self.building_buttons[building.name] = button button.bind(on_press=self.upgrade) row.add_widget(button) self.available_box.add_widget(row) ############################################################## # UNAVAILABLE: def create_unavailable_box(self): self.unavailable_box = BoxLayout(orientation="vertical", size_hint_y=None) self.unavailable_box.bind( minimum_height=self.unavailable_box.setter('height')) size_hint_x = self.app.headquarters.menus.get("UNAVAILABLES") header = [["Not yet available", size_hint_x[0]], ["Requirements", size_hint_x[1]]] self.create_header(header, self.unavailable_box, BLACK) self.create_all_not_availables() # self.add_widget(self.unavailable_box) self.box_scroll.add_widget(self.unavailable_box) def create_all_not_availables(self): for building_name in BUILDINGS: building = getattr(self.app, building_name.lower()) if not self.check_if_is_available(building): self.add_1_not_available_row(building) def add_1_not_available_row(self, building): row = BoxLayout(orientation="horizontal", size_hint_y=None, height=100) if building in self.all_unavailable_rows: return self.all_unavailable_rows[building] = row size_hint_x = self.app.headquarters.menus.get("UNAVAILABLES") img = Image(source=building.icon, size_hint_x=None, width=Window.width * size_hint_x[0] / 4) row.add_widget(img) label = DarkLabel(text=building.name, size_hint_x=None, width=Window.width * size_hint_x[0] * 3 / 4, font_size=24) row.add_widget(label) for building_req, level_req in building.unlock: label = Label(text="%s (Level %s)" % (building_req, level_req), size_hint_x=None, width=Window.width * size_hint_x[1] / 3, font_size=24, color=(0.5, 0.5, 0.5, 1)) row.add_widget(label) self.unavailable_box.add_widget(row) ############################################################## def check_if_is_available(self, building): unlock = building.unlock if not unlock: return True for building_name, level_to_unlock in unlock: building = getattr(self.app, building_name.lower()) if building.level < level_to_unlock: return False return True
class History(MyBoxLayout): to_delete = False left_check_list = ListProperty() main = ObjectProperty() def item_check(self, *args): count = 0 def checkall(*args): count = 0 for item in self.left_check_list: item.state = 'down' count += 1 self.toolbar.left_action_items = [["select-all", uncheckall]] self.toolbar.right_action_items = [["delete-sweep", self.action]] def uncheckall(*args): for item in self.left_check_list: item.state = 'normal' self.toolbar.left_action_items = self.toolbar.right_action_items = [] for item in self.left_check_list: if item.state == 'down': count += 1 if count > 0 and args[0].text != 'yes': self.toolbar.left_action_items = [[ "select", checkall ]] if count == 1 else [["select-all", uncheckall]] self.toolbar.right_action_items = [[ "delete", self.action ]] if count == 1 else [["delete-sweep", self.action]] else: uncheckall() def refresh(self, *args): self.layout.clear_widgets() self.left_check_list = [] with open('history.json', 'r+') as data: data = json.load(data) for list_data in data: list_container = Container() list_item = ListItem(text=str( list(data[list_data][0].keys())[0] + ' = ' + list(data[list_data][0].values())[0]), secondary_text=data[list_data][1], time=list_data, container=list_container, width_mult=1.4) left_check = CheckboxLeftWidget() left_check.unselected_color = list_item.text_color left_check.update_color() left_check.update_primary_color(self, list_item.text_color) left_check.bind(on_release=self.item_check) list_item.add_widget(left_check) self.left_check_list.append(left_check) for list_container_item in ('content-copy', 'qrcode', 'history'): item = Icon(icon=list_container_item) item.bind(on_release=self.action) list_container.add_widget(item) list_item.bind(on_size=lambda arg: print(arg)) list_item.add_widget(list_container) self.layout.add_widget(list_item) self.layout.children.reverse() def action(self, button): item = [] if type(button.parent.parent.parent).__name__ == 'History': for data in self.left_check_list: if data.state == 'down': item.append(data.parent.parent) else: item.append(button.parent.parent.parent) item_data = str(item[0].text + ' ' + item[0].secondary_text) if button.icon == 'content-copy': Clipboard.copy(item_data) elif button.icon == 'history': self.main.pages.pages_list[ current_page[0]].entry.text = item_data.split()[0] self.parent.dismiss() elif button.icon == 'qrcode': image = Image(source="") imgIO = io.BytesIO() qrcode.make(item_data).save(imgIO, ext='png') imgIO.seek(0) imgData = io.BytesIO(imgIO.read()) image.texture = CoreImage(imgData, ext='png').texture image.reload() dialog = ModalView(size_hint=(None, None), size=image.texture.size) dialog.add_widget(image) dialog.open() elif button.icon in ['delete', 'delete-sweep']: dialog_yes = MDFlatButton(text="yes") dialog_no = MDRaisedButton(text="no") dialog = MDDialog(text="Delete {} item{}?".format( len(item), '' if len(item) == 1 else 's'), buttons=[dialog_no, dialog_yes]) with open('history.json', 'r') as file: data = json.load(file) for item_ in item: data.pop(item_.time) dialog_no.bind(on_release=dialog.dismiss) dialog_yes.bind(on_release=dialog.dismiss) dialog_yes.bind(on_release=lambda button: json.dump( data, open('history.json', 'w'), indent=4)) dialog_yes.bind(on_release=self.item_check) dialog.bind(on_dismiss=self.refresh) dialog.open() def __init__(self, **kwargs): super(History, self).__init__(**kwargs) self.orientation = 'vertical' self.toolbar = MDToolbar(title='History', anchor_title='center', elevation=10) self.toolbar.md_bg_color = color( f"images/{theme_image[config_data['theme']][2]}.png") self.toolbar.specific_text_color = color( f"images/{theme_image[config_data['theme']][0]}.png") self.scroll = RecycleView() self.layout = MDList() self.do_scroll_x = False self.refresh() self.scroll.add_widget(self.layout) self.add_widget(self.toolbar) self.add_widget(self.scroll)
class Table(ScrollView): '''A view handling the behavior of the inputs from :ref:`sqlite`. Separates the values from :ref:`sqlite` according to its :ref:`data`'s column types into three Python categories - `int`, `float` or `unicode` and assigns an alphabetic order for each column together with row number to each value. .. versionadded:: 0.1.0 ''' # use with ....add_widget(Table(max_cols=3, max_rows=3)) # Grid -> Scroll, grid as container - better for sizing and placing # set "address" for table pos in grid to item number_size = (30, 30) default_size = (100, 30) def __init__(self, **kw): app = App.get_running_app() self.rv = RecycleView(bar_width='10dp', scroll_type=['bars', 'content']) container = RecycleGridLayout(size_hint=(None, None)) container.viewclass = TableItem container.bind(minimum_size=container.setter('size')) self.max_rows = kw.get('max_rows', 1) self.rows = self.max_rows + 1 self.max_cols = kw.get('max_cols', 1) self.cols = self.max_cols + 1 self.values = kw.get('values', []) self.labels = kw.get('labels') self.types = kw.get('types') container.rows = self.rows container.cols = self.cols ltr = [' (' + letter + ')' for letter in self.get_letters()] self.rv.add_widget(container) if 'item_size' not in kw: item_size = self.default_size super(Table, self).__init__(**kw) for r in range(self.rows): for c in range(self.cols): if r == 0: if c == 0: self.rv.data.append({ 'text': u'', 'disabled': True, 'size': self.number_size, 'origin': self.rv }) else: self.rv.data.append({ 'text': self.labels[c - 1] + ltr[c - 1], '_text': self.labels[c - 1], 'disabled': True, 'cell': 'label' + str(c - 1), 'type': type(u''), 'size': self.default_size, 'origin': self.rv }) else: if c == 0: self.rv.data.append({ 'text': unicode(r), 'disabled': True, 'size': self.number_size, 'origin': self.rv }) else: filter = app.root.simple_chars try: val = self.values.pop(0) text_type = type(val) filter_val = repr(text_type)[7:-2] if filter_val in ['int', 'float']: filter = filter_val except IndexError: print 'values < space' val = '.' if 'e+' in str(val) or 'e-' in str(val): val = '{0:.10f}'.format(val) if self.types: if self.types[c - 1] == 'INTEGER': filter = 'int' text_type = type(1) elif self.types[c - 1] == 'REAL': filter = 'float' text_type = type(1.1) self.rv.data.append({ 'text': unicode(val), 'old_text': unicode(val), 'disabled': False, 'cell': self.labels[c - 1] + str(r), 'r': r, 'rows': self.rows, 'c': c, 'cols': self.cols, 'type': text_type, 'size': self.default_size, 'input_filter': filter, 'origin': self.rv }) if self.values: raise Exception('Not enough space for all values! \ Increase rows/cols!') self.add_widget(self.rv) def get_letters(self): '''Gets a list of letters the same length as :ref:`data`'s columns. .. versionadded:: 0.1.0 ''' letters = [chr(letter + 65) for letter in range(26)] result = [] label = [] cols = range(self.cols + 1) for i in cols: if i != 0: while i: i, rem = divmod(i - 1, 26) label[:0] = letters[rem] result.append(''.join(label)) label = [] return result def lock(self, disabled=True): '''docs .. versionadded:: 0.1.0 ''' for i in self.rv.data: if 'cell' in i and 'label' not in i['cell']: i['disabled'] = disabled self.rv.refresh_from_data() def clean(self, *args): '''Removes all data from :mod:`main.Table` .. versionadded:: 0.1.0 ''' self.rv.data = []
def __init__(self, **kw): app = App.get_running_app() self.rv = RecycleView(bar_width='10dp', scroll_type=['bars', 'content']) container = RecycleGridLayout(size_hint=(None, None)) container.viewclass = TableItem container.bind(minimum_size=container.setter('size')) self.max_rows = kw.get('max_rows', 1) self.rows = self.max_rows + 1 self.max_cols = kw.get('max_cols', 1) self.cols = self.max_cols + 1 self.values = kw.get('values', []) self.labels = kw.get('labels') self.types = kw.get('types') container.rows = self.rows container.cols = self.cols ltr = [' (' + letter + ')' for letter in self.get_letters()] self.rv.add_widget(container) if 'item_size' not in kw: item_size = self.default_size super(Table, self).__init__(**kw) for r in range(self.rows): for c in range(self.cols): if r == 0: if c == 0: self.rv.data.append({ 'text': u'', 'disabled': True, 'size': self.number_size, 'origin': self.rv }) else: self.rv.data.append({ 'text': self.labels[c - 1] + ltr[c - 1], '_text': self.labels[c - 1], 'disabled': True, 'cell': 'label' + str(c - 1), 'type': type(u''), 'size': self.default_size, 'origin': self.rv }) else: if c == 0: self.rv.data.append({ 'text': unicode(r), 'disabled': True, 'size': self.number_size, 'origin': self.rv }) else: filter = app.root.simple_chars try: val = self.values.pop(0) text_type = type(val) filter_val = repr(text_type)[7:-2] if filter_val in ['int', 'float']: filter = filter_val except IndexError: print 'values < space' val = '.' if 'e+' in str(val) or 'e-' in str(val): val = '{0:.10f}'.format(val) if self.types: if self.types[c - 1] == 'INTEGER': filter = 'int' text_type = type(1) elif self.types[c - 1] == 'REAL': filter = 'float' text_type = type(1.1) self.rv.data.append({ 'text': unicode(val), 'old_text': unicode(val), 'disabled': False, 'cell': self.labels[c - 1] + str(r), 'r': r, 'rows': self.rows, 'c': c, 'cols': self.cols, 'type': text_type, 'size': self.default_size, 'input_filter': filter, 'origin': self.rv }) if self.values: raise Exception('Not enough space for all values! \ Increase rows/cols!') self.add_widget(self.rv)