class VenvView(Frame): ASCII_TITLE = """ venv-clean Select the environments that you want to delete, and press the bottom delete button when you're ready """ ASCII_TITLE_HEIGHT = 6 def __init__(self, screen, path): super(VenvView, self).__init__(screen, screen.height, screen.width, hover_focus=False, can_scroll=True, reduce_cpu=True, has_border=True) self.selected_size = 0 self.size_found = 0 self.path = path self.venvs = self.__find_venvs(self.path) self.set_visual_theme() # Top bar, logo & summary self.layout_top = Layout([1, 1]) self.add_layout(self.layout_top) logo = TextBox(height=self.ASCII_TITLE_HEIGHT, as_string=True, disabled=True) logo.value = self.ASCII_TITLE self.layout_top.add_widget(logo, 1) self.layout_top.add_widget(Label(''), 0) self.layout_top.add_widget(Label('SUMMARY'), 0) self.label_size_found = Text('Total: ', disabled=True) self.label_size_selected = Text('To Free: ', disabled=True) self.layout_top.add_widget(self.label_size_found, 0) self.layout_top.add_widget(self.label_size_selected, 0) self.__update_sizes() # Main list of environments self.layout_main = Layout([80, 20], fill_frame=True) self.add_layout(self.layout_main) self.__draw_list() # Bottom buttons self.layout_bottom = Layout([1, 1]) self.add_layout(self.layout_bottom) self.layout_bottom.add_widget(Divider(), 0) self.layout_bottom.add_widget(Divider(), 1) self.layout_bottom.add_widget(Button('Delete', self._delete), 0) self.layout_bottom.add_widget(Button('Quit', self._quit), 1) self.fix() def __draw_list(self): self.layout_main.clear_widgets() self.layout_main.reset() self.layout_main.add_widget(Label('Path found'), 0) self.layout_main.add_widget(Label('Size MB'), 1) self.layout_main.add_widget(Divider(), 0) self.layout_main.add_widget(Divider(), 1) for v in self.venvs: self.layout_main.add_widget(v['checkbox'], 0) self.layout_main.add_widget(Label(str(v['size'])), 1) self.fix() def __update_sizes(self): self.label_size_found.value = '{:.2f}MB'.format(self.size_found) self.label_size_selected.value = '{:.2f}MB'.format(self.selected_size) def _reload_items(self): self.selected_size = 0 self.size_found = 0 self.venvs = self.__find_venvs(self.path) self.reset() self.__draw_list() self.__update_sizes() def __calculate_selected_size(self): self.selected_size = 0 for v in self.venvs: if v['checkbox'].value: self.selected_size += float(v['size']) self.__update_sizes() def _delete(self): for v in self.venvs: if v['checkbox'].value: delete_folder(v['location']) self._reload_items() @staticmethod def _quit(): raise StopApplication('Bye!') def set_visual_theme(self): self.set_theme('monochrome') frame_items = ('selected_focus_field', 'selected_focus_control', 'focus_button') for key in frame_items: self.palette[key] = (Screen.COLOUR_BLACK, Screen.A_BOLD, Screen.COLOUR_WHITE) def __find_venvs(self, path): self.size_found = 0 venvs = find_virtualenvs(path) for v in venvs: v['checkbox'] = CheckBox(v['location'], on_change=self.__calculate_selected_size) self.size_found += float(v['size']) return venvs
class QueryEditorView(BaseScreen): _title = "Query Editor" def __init__(self, *args, **kwargs): self.query_specific_layout = None self.query_specific_layout_footer = None super().__init__(*args, **kwargs) self._on_query_type_change() def _compose_layout(self): self._compose_actions_layout() self._compose_query_common_layout() self._compose_query_specific_layout() def _compose_actions_layout(self): actions_layout = Layout([3, 2, 4, 3]) self.add_layout(actions_layout) actions_layout.add_widget( Button(text="Save & Go back", on_click=self._model.save_go_back), 0 ) actions_layout.add_widget( Button(text="Execute", on_click=self._model.execute), 1 ) if self._model.last_peer_address: actions_layout.add_widget( Button( text=f"Exec @ {self._model.last_peer_address}", on_click=self._model.execute_at_last_peer, ), 2, ) actions_layout.add_widget(Button(text="Cancel", on_click=self._model.cancel), 3) def _compose_query_common_layout(self): divider_layout = Layout([1]) self.add_layout(divider_layout) divider_layout.add_widget(Divider()) divider_layout.add_widget(DynamicLabel(name="proto_status")) self._compose_created_time_layout() common_layout = Layout([5, 13]) self.add_layout(common_layout) common_layout.add_widget(Label("Creator account id"), 0) common_layout.add_widget( Text( name=".payload.meta.creator_account_id", validator=account_id_validator ), 1, ) common_layout.add_widget(Label("Query counter"), 0) common_layout.add_widget( Text(name=".payload.meta.query_counter", validator=uint32_validator), 1 ) common_layout.add_widget(Label("Query type"), 0) common_layout.add_widget( DropdownList( options=self._model.query_type_options, on_change=self._on_query_type_change, name="query_type", ), 1, ) self._compose_signature_layout() def _compose_signature_layout(self): signature_layout = Layout([5, 9, 4]) self.add_layout(signature_layout) signature_layout.add_widget(Label("Signature"), 0) signature_layout.add_widget(DynamicLabel("signature_status"), 1) signature_layout.add_widget(Button("Sign", on_click=self._model.sign), 2) def _compose_created_time_layout(self): time_layout = Layout([5, 9, 4]) self.add_layout(time_layout) time_layout.add_widget(Label("Created time"), 0) time_layout.add_widget( Text(name=".payload.meta.created_time", validator=uint64_validator), 1 ) time_layout.add_widget( Button("Use Now", on_click=lambda: 0), 2 # TODO: implement ) def _compose_query_specific_layout(self): divider_layout = Layout([1]) self.add_layout(divider_layout) divider_layout.add_widget(Divider()) self.query_specific_layout = Layout(ProtoLayoutComposer.layout_columns[0]) self.query_specific_layout_footer = Layout( ProtoLayoutComposer.layout_columns[1] ) self.add_layout(self.query_specific_layout) self.add_layout(self.query_specific_layout_footer) self._reset_query_specific_layout() def _reset_query_specific_layout(self): if not self.query_specific_layout: # weird asciimatics behaviour when resizing the terminal return self.query_specific_layout.clear_widgets() self.query_specific_layout_footer.clear_widgets() ProtoLayoutComposer.compose_on_layouts( [self.query_specific_layout, self.query_specific_layout_footer], self._model.payload_proxy, prefix=".payload." + self._data["query_type"], ) self.fix() def reset(self): super().reset() self._reset_query_specific_layout() def _on_query_type_change(self): self.update_data() self._reset_query_specific_layout()