def main_base_menu(build_place): scatter = ScatterLayout() menu = building.MenuLayout() inside_menu = building.InsideMenuLayout() main_box = BoxLayout(orientation='horizontal') left_box = BoxLayout(orientation='vertical', size_hint_x=.35) right_box = BoxLayout(size_hint_x=.65) icon_bottom_box = BoxLayout(size_hint=(.9, .8)) icon_layout = BoxLayout(size_hint_y=.4) # pos_hint=({'top': 1}) # Вывод производства ресурсов stat_res = res_generation('main_base') # Добавление вкладок Здания tb = TabbedPanel(do_default_tab=False, tab_width=130) base_e = TabbedPanelItem(text='Энергия') base_e.content = base_energy() base_f = TabbedPanelItem(text='Пища') base_f.content = base_food() tb.add_widget(base_e) tb.add_widget(base_f) icon_bottom_box.add_widget(stat_res) icon_layout.add_widget(Image(source='data/images/buildings/main-base.png')) left_box.add_widget(icon_layout) left_box.add_widget(icon_bottom_box) right_box.add_widget(tb) main_box.add_widget(left_box) main_box.add_widget(right_box) inside_menu.add_widget(main_box) close_b = building.CloseMenuButton(build_place, scatter) menu.add_widget(inside_menu) menu.add_widget(close_b) scatter.add_widget(menu) return scatter
def _manip_sort(task, sort_type, *args): sort_type = 'Asc' not in sort_type.text from_address = task.from_address(task.tablenum, ':all', extended=True) values, cols, rows, labels = from_address # get separated cols to sort chunks = [] for x in range(0, len(values), rows): chunks.append(values[x:x + rows]) values = [] for val in chunks: values.append(sorted(val, reverse=sort_type)) # add Table table = task.ids.tablesel.text table += ' (desc)' if sort_type else ' (asc)' tabletab = TabbedPanelItem(text=table) task.app.root.ids.tabpanel.add_widget(tabletab) values = list(zip(*values)) values = [v for vals in values for v in vals] task.app.root.tables.append((table, task.tablecls(max_cols=cols, max_rows=rows, pos=task.app.root.pos, size=task.app.root.size, values=values, labels=labels))) tabletab.content = task.app.root.tables[-1][1]
def _manip_sort(task, sort_type, *args): sort_type = 'Asc' not in sort_type.text from_address = task.from_address(task.tablenum, ':all', extended=True) values, cols, rows, labels = from_address # get separated cols to sort chunks = [] for x in range(0, len(values), rows): chunks.append(values[x:x + rows]) values = [] for val in chunks: values.append(sorted(val, reverse=sort_type)) # add Table table = task.ids.tablesel.text table += ' (desc)' if sort_type else ' (asc)' tabletab = TabbedPanelItem(text=table) task.app.root.ids.tabpanel.add_widget(tabletab) values = zip(*values) values = [v for vals in values for v in vals] task.app.root.tables.append(( table, task.tablecls(max_cols=cols, max_rows=rows, pos=task.app.root.pos, size=task.app.root.size, values=values, labels=labels) )) tabletab.content = task.app.root.tables[-1][1]
def populate(self): app = MDApp.get_running_app() sub_panel = self.children[0] for name, store in app.db.stores.items(): if name == 'default': # Duplicated store default_store = store.name continue store_panel = TabbedPanelItem(text=name.capitalize()) sub_panel.add_widget(store_panel) container = app.container_factory.get('map_locations', store) container.store = store items = set() for location in store.locations.values(): for item in location.items: if item: item = app.db.items[item] items.add((store, location, item)) # print(len(items)) container.generate_data(items) container.to_layout() store_panel.content = BoxLayout(orientation='vertical') store_panel.content.add_widget(LocationMapHeader(container=container)) store_panel.content.add_widget(container.container_display) for panel in sub_panel.tab_list: # noinspection PyUnboundLocalVariable if panel.text == default_store: sub_panel.default_tab = panel sub_panel.tab_width = MDApp.get_running_app().root.width / (len(app.db.stores) - 1)
def button_options(self): print("options pressed") app = App.get_running_app() cont = GridLayout(cols=1) # retrieve audio outputs / soundcards from audioengine class out_list = app.root.ae.get_outputs() print(out_list) # combine out_list, add to output selector for x, y in zip(*out_list): # intentional error to remember where left off b = Button(id="{}".format(y), text="{} {}".format(x, y)) b.bind(on_press=self.audio_opts_button_callback) cont.add_widget(b) for x in self.children: print(x) tp = TabbedPanel(do_default_tab=False) # audio tab th_audio = TabbedPanelItem(text="Audio") th_audio.content = GridLayout() th_audio.add_widget(cont) # files tab th_files = TabbedPanelItem(text="Files") th_files.add_widget(Button(text="files tab content")) tp.add_widget(th_audio) tp.add_widget(th_files) popup = Popup(title='Options', content=tp, size_hint=(None, None), size=(800, 800)) popup.open()
def _import_data(self, selection, *args): '''Imports :ref:`sqlite` from path selected in ``Dialog`` and puts it to :mod:`main.Table`. .. versionadded:: 0.1.0 ''' # limit table name and column name to [a-zA-Z] # CREATE TABLE test( # Column INTEGER NOT NULL CHECK( # typeof(Column) = 'integer')) if not selection: return else: selection = selection[0] if '.sqlite' not in selection: return conn = sqlite3.connect(op.join(selection)) c = conn.cursor() # get tables first! c.execute("SELECT name FROM sqlite_master WHERE type='table'") tables = [tab[0] for tab in c.fetchall()] for table in tables: c.execute("pragma table_info({0})".format(table)) table_info = c.fetchall() labels = [lbl[1] for lbl in table_info] # allow only: INTEGER, REAL, TEXT try: types = [type[2][0] for type in table_info] except IndexError: error = ErrorPop(msg='Bad file: No defined types in columns!') error.open() return tabletab = TabbedPanelItem(text=table) self.ids.tabpanel.add_widget(tabletab) c.execute('select * from {0}'.format(table)) values = [item for item in c.fetchone()] max_cols = len(values) values += [item for sublist in c.fetchall() for item in sublist] max_rows = int(math.ceil(len(values) / float(max_cols))) self.tables.append((table, Table(max_cols=max_cols, max_rows=max_rows, pos=self.pos, size=self.size, values=values, labels=labels))) tabletab.content = self.tables[-1][1] self.opendlg.dismiss() conn.close()
def __init__(self, screenmanager, **kwargs): super(GraphScreen, self).__init__(**kwargs) #Set screenmanager sm = screenmanager #Set master layout layout = BoxLayout(spacing=10) #Create tabpanel tabs = TabbedPanel() #Add tabs speedTab = TabbedPanelItem(text='Speed') speedTab.content = Label(text='Speed') backTab = TabbedPanelItem(text='Back') tabs.add_widget(speedTab) tabs.add_widget(backTab) layout.add_widget(tabs) self.add_widget(layout)
def buildTab(self): self.background_image = "images/gui_elements/tab_darkblue.png" with open("config/blocks.json") as json_data: blocks_config = json.load(json_data) for tab in blocks_config["tabs"]: #newTab = TabbedPanelItem(text = str(tab["id"])) block_type = str(tab["id"])[0] newTab = TabbedPanelItem() color_tab = [] for color in tab["rgba"]: color_tab.append(color) newTab.background_color = color_tab newLayout = StackLayout(spacing=10) for block in tab["blocks"]: newBlock = Block(block_type, str(block["id"]), str(block["source"])) newLayout.add_widget(newBlock) newTab.content = newLayout self.add_widget(newTab)
def prod_menu(build_place): scatter = ScatterLayout() menu = MenuLayout() inside_menu = InsideMenuLayout() main_box = BoxLayout(orientation='horizontal') left_box = BoxLayout(orientation='vertical', size_hint_x=.35) right_box = BoxLayout(size_hint_x=.65) icon_bottom_box = BoxLayout(size_hint=(.9, .8)) icon_layout = BoxLayout(size_hint_y=.4) # pos_hint=({'top': 1}) statistic_grid = GridLayout(cols=1, size_hint_y=None, pos_hint=({ 'top': .9 }), spacing=10, padding=5) for r in config.resources: res = config.resources[r] stat_box = BoxLayout(orientation='horizontal', height=40, size_hint_y=None) stat_box.add_widget(Image(source=res[2], size_hint_x=.2)) stat_box.add_widget(Label(text=f'{res[0]}', size_hint_x=.8)) statistic_grid.add_widget(stat_box) tb = TabbedPanel(do_default_tab=False, tab_width=130) ti = TabbedPanelItem(text='Улучшения') ti.content = prod_upgrade_content() tb.add_widget(ti) tb.add_widget(TabbedPanelItem(text='Автоматизация')) tb.add_widget(TabbedPanelItem(text='Статистика')) icon_bottom_box.add_widget(statistic_grid) icon_layout.add_widget(Image(source='data/images/buildings/buildings.zip')) left_box.add_widget(icon_layout) left_box.add_widget(icon_bottom_box) right_box.add_widget(tb) main_box.add_widget(left_box) main_box.add_widget(right_box) inside_menu.add_widget(main_box) close_b = CloseMenuButton(build_place, scatter) menu.add_widget(inside_menu) menu.add_widget(close_b) scatter.add_widget(menu) return scatter
def buildTab(self, size): self.background_image = "images/gui_elements/tab.png" with open("config/blocks.json") as json_data: blocks_config = json.load(json_data) for tab in blocks_config["tabs"]: block_id = tab["id"][0] newTab = TabbedPanelItem() newTab.background_normal = str(tab["tab_unpress"]) newTab.background_down = str(tab["tab_press"]) newLayout = BoxLayout(spacing=10) space = size * 0.80 / self.size[0] newLayout.size_hint = [len(tab["blocks"]) * space, 1] for block in tab["blocks"]: if '0' not in block["type"]: newBlock = Block(block_id, str(block["id"]), str(block["type"]), str(block["source"]), int(size * 0.80)) newLayout.add_widget(newBlock) newTab.content = newLayout self.add_widget(newTab)
def _manip_append(task, append_type, amount, container, overwrite, *args): append_type = append_type.text overwrite = overwrite.active amount = int(amount.text) if amount.text else 0 if append_type == 'Append type': raise Exception('No append type was chosen!') # Stop the task if no amount (or =0) is specified # or if no column is available if not amount and not container.children: raise Exception('No amount was specified!') from_address = task.from_address(task.tablenum, ':all', extended=True) values, cols, rows, labels = from_address rows = int(rows) # get columns chunks = [] for x in range(0, len(values), rows): chunks.append(values[x:x + rows]) if append_type == 'Columns': _cols = container.children[0].ids.columns.children for c in reversed(_cols): labels.append(c.ids.colname.text) _type = c.ids.coltype.text if _type == 'INTEGER': chunks.extend([[0 for _ in range(rows)]]) elif _type == 'REAL': chunks.extend([[0.0 for _ in range(rows)]]) else: chunks.extend([['' for _ in range(rows)]]) amount += 1 cols += 1 elif append_type == 'Rows': # append to columns a zero value according # to their type int(amount)-times for r in range(amount): for chunk in chunks: if isinstance(chunk[0], int): chunk.append(0) elif isinstance(chunk[0], float): chunk.append(0.0) else: chunk.append('') # increase row count by new rows rows += amount # zip chunks to values, flatten values values = list(zip(*chunks)) values = [v for vals in values for v in vals] # add Table tab_pos = 0 table = task.ids.tablesel.text tabpanel = task.app.root.ids.tabpanel tabpanel_len = len(tabpanel.tab_list) if overwrite: tab_pos = task.tablenum # list of available tabs in Task is 0 -> n (from tables), # but tab_list order is reversed in Kivy, therefore # reverse the index by going backwards with -1 # and increase tab_pos, which is only index of # value order in spinner old_tab = tabpanel.tab_list[-1 - (tab_pos + 1)] tabpanel.remove_widget(old_tab) tabletab = TabbedPanelItem(text=table) tabpanel.add_widget(tabletab, tabpanel_len - 1 - (tab_pos + 1)) else: # if space in name, sql save boom if append_type == 'Columns': table += '_append_{}_cols'.format(str(amount)) elif append_type == 'Rows': table += '_append_{}_rows'.format(str(amount)) tabletab = TabbedPanelItem(text=table) tabpanel.add_widget(tabletab, 0) # make new table new_table = (table, task.tablecls(max_cols=cols, max_rows=rows, pos=task.app.root.pos, size=task.app.root.size, values=values, labels=labels)) # place newly created table into tab's content if overwrite: task.app.root.tables[tab_pos] = new_table tabletab.content = task.app.root.tables[tab_pos][1] else: task.app.root.tables.append(new_table) tabletab.content = task.app.root.tables[-1][1]
def _manip_append(task, append_type, amount, container, overwrite, *args): append_type = append_type.text overwrite = overwrite.active amount = int(amount.text) if amount.text else 0 if append_type == 'Append type': raise Exception('No append type was chosen!') # Stop the task if no amount (or =0) is specified # or if no column is available if not amount and not container.children: raise Exception('No amount was specified!') from_address = task.from_address(task.tablenum, ':all', extended=True) values, cols, rows, labels = from_address rows = int(rows) # get columns chunks = [] for x in range(0, len(values), rows): chunks.append(values[x:x + rows]) if append_type == 'Columns': _cols = container.children[0].ids.columns.children for c in reversed(_cols): labels.append(c.ids.colname.text) _type = c.ids.coltype.text if _type == 'INTEGER': chunks.extend([[0 for _ in range(rows)]]) elif _type == 'REAL': chunks.extend([[0.0 for _ in range(rows)]]) else: chunks.extend([[u'' for _ in range(rows)]]) amount += 1 cols += 1 elif append_type == 'Rows': # append to columns a zero value according # to their type int(amount)-times for r in range(amount): for chunk in chunks: if isinstance(chunk[0], int): chunk.append(0) elif isinstance(chunk[0], float): chunk.append(0.0) else: chunk.append(u'') # increase row count by new rows rows += amount # zip chunks to values, flatten values values = zip(*chunks) values = [v for vals in values for v in vals] # add Table tab_pos = 0 table = task.ids.tablesel.text tabpanel = task.app.root.ids.tabpanel tabpanel_len = len(tabpanel.tab_list) if overwrite: tab_pos = task.tablenum # list of available tabs in Task is 0 -> n (from tables), # but tab_list order is reversed in Kivy, therefore # reverse the index by going backwards with -1 # and increase tab_pos, which is only index of # value order in spinner old_tab = tabpanel.tab_list[-1 - (tab_pos + 1)] tabpanel.remove_widget(old_tab) tabletab = TabbedPanelItem(text=table) tabpanel.add_widget(tabletab, tabpanel_len - 1 - (tab_pos + 1)) else: # if space in name, sql save boom if append_type == 'Columns': table += u'_append_{}_cols'.format(str(amount)) elif append_type == 'Rows': table += u'_append_{}_rows'.format(str(amount)) tabletab = TabbedPanelItem(text=table) tabpanel.add_widget(tabletab, 0) # make new table new_table = ( table, task.tablecls(max_cols=cols, max_rows=rows, pos=task.app.root.pos, size=task.app.root.size, values=values, labels=labels) ) # place newly created table into tab's content if overwrite: task.app.root.tables[tab_pos] = new_table tabletab.content = task.app.root.tables[tab_pos][1] else: task.app.root.tables.append(new_table) tabletab.content = task.app.root.tables[-1][1]
def _save_data(self, wizard, *args): '''Gets data from the wizard, puts them into :mod:`main.Table` and exports them into :ref:`sqlite`. .. versionadded:: 0.1.4 ''' labels = [] types = [] values = [] table_name = wizard.ids.table_name.text if not len(table_name): error = ErrorPop(msg='Please name your data!') error.open() return if not len(wizard.ids.columns.children): error = ErrorPop(msg='There must be at least one column!') error.open() return for child in reversed(wizard.ids.columns.children): child.ids.checklock.dispatch('on_release') for child in reversed(wizard.ids.columns.children): if child.ids.colname.text not in labels: lbl = re.findall(r'([a-zA-Z0-9])', child.ids.colname.text) if not len(lbl): error = ErrorPop(msg='Use only a-z A-Z 0-9 characters!') error.open() return labels.append(''.join(lbl)) else: error = ErrorPop(msg='Each column must have a unique name!') error.open() return types.append(child.ids.coltype.text) column_values = [] for value_wdg in reversed(child.ids.vals.children): column_values.append(value_wdg.ids.value.text) values.append(column_values) max_cols = len(values) max_rows = len(max(values, key=len)) # create table in KrySA, then export tabletab = TabbedPanelItem(text=table_name) self.ids.tabpanel.add_widget(tabletab) _values = values[:] values = [] for i in range(max_rows): for j in range(max_cols): try: values.append(_values[j][i]) except IndexError: if types[j] == 'INTEGER': values.append(0) elif types[j] == 'REAL': values.append(0.0) else: values.append(u'') self.tables.append((table_name, Table(max_cols=max_cols, max_rows=max_rows, pos=self.pos, size=self.size, values=values, labels=labels, types=types))) tabletab.content = self.tables[-1][1] # export to data.sqlite in <project>/data directory data = op.join(self.app.project_dir, 'data') self._export_data([data], 'data.sqlite') self.wiz_newdata.dismiss()
def generate_panel_tab(self, txt): tpi = TabbedPanelItem(text=txt) tpi.content = TextInput(text='Waiting data...', readonly=True) self.panel.add_widget(tpi)
def _manip_append(task, append_type, amount, overwrite, *args): append_type = append_type.text overwrite = overwrite.active amount = int(amount.text) if amount.text else 0 # Stop the task if no amount (or =0) is specified if not amount: return from_address = task.from_address(task.tablenum, ':all', extended=True) values, cols, rows, labels = from_address if append_type == 'Columns': cols += amount return elif append_type == 'Rows': # get columns chunks = [] for x in xrange(0, len(values), rows): chunks.append(values[x:x + rows]) # append to columns a zero value according # to their type int(amount)-times for r in range(amount): for chunk in chunks: if isinstance(chunk[0], int): chunk.append(0) elif isinstance(chunk[0], float): chunk.append(0.0) else: chunk.append(u'') # add Table tab_pos = 0 table = task.ids.tablesel.text tabletab = TabbedPanelItem(text=table) if overwrite: tab_pos = task.tablenum + 1 old_tab = task.app.root.ids.tabpanel.tab_list[tab_pos] task.app.root.ids.tabpanel.remove_widget(old_tab) else: table += ' (append {})'.format(str(amount)) task.app.root.ids.tabpanel.add_widget(tabletab, tab_pos) # zip chunks to values, flatten values values = zip(*chunks) values = [v for vals in values for v in vals] # increase row count by new rows, make new table rows += amount new_table = (table, task.tablecls(max_cols=cols, max_rows=rows, pos=task.app.root.pos, size=task.app.root.size, values=values, labels=labels)) # place newly created table into tab's content if overwrite: task.app.root.tables[tab_pos - 1] = new_table tabletab.content = task.app.root.tables[tab_pos - 1][1] else: task.app.root.tables.append(new_table) tabletab.content = task.app.root.tables[-1][1] else: return