def build(self) -> None: self.modal = None self.style(border=['*'] * 8) master = Frame(self, title='Master').grid(0).style( background_color=Color.LIGHT.reverse(), border_color=Color.PRIMARY.reverse()) Label(master, content='Label:').grid(0, 0).style(Color.DANGER.reverse(), Color.DANGER.reverse()) Button(master, content='Create', command=self.launch_modal).grid(0, 1).style( Color.SUCCESS.reverse(), Color.SUCCESS.reverse()) Frame(master, title='Details').title_style(Color.DANGER()).grid( 1, 0).span(col=3).weight(3).style( background_color=Color.LIGHT.reverse()) world = Frame(self, title='World').title_style(Color.WARNING()).grid(1) Entry(world) Content(self, title='Content').grid(0, 1).span(3).weight(col=3) self.listen('click', self.on_backdrop_click, True)
def build(self) -> None: self.left = Frame(self, title='Left').grid(0, 1) Button(self.left, content='Content UP', command=self.on_click).style(Color.INFO(), Color.DANGER.reverse(), border=[0], align='C').grid(0) Button(self.left, content='MIDDLE UP BUTTON', command=self.on_click).style(Color.WARNING(), border=[0], align='C').grid(1) Button(self.left, content='MIDDLE DOWN BUTTON', command=self.on_click).style(Color.DANGER(), border=[0], align='C').grid(2) Entry( self.left, content= ('Nulla mollis mollis ornare. Cras tempor, metus semper pulvinar ' '\nmattis, metus urna hendrerit orci, eget gravida tellus ' '\nipsum a ex. Donec hendrerit metus vitae hendrerit dictum. ' '\nSed varius venenatis ligula in scelerisque. Donec luctus sem ' '\nnon lorem venenatis, eget lobortis tortor tincidunt. Nunc ' '\nquis venenatis diam. Ut ac aliquam mi, a tempus nunc. Nunc ' '\nluctus vulputate dui malesuada cursus.')).style( Color.LIGHT(), border=[0]).grid(3) self.right = Frame(self, title='Right').grid(0, 2) data = [{'name': 'first'}, {'name': 'second'}, {'name': 'third'}] * 3 Listbox(self.right, data=data, limit=4, item_style=Style(border=[], align='C'))
def build(self) -> None: super().build() self.modal = None frame = Frame( self, title='Role').title_style(Color.SUCCESS()).weight(3, 2) Label(frame, content='Name:').grid(0, 0) self.name = Entry(frame, content=self.role['name']).style( border=[0]).grid(0, 1).weight(col=2) Label(frame, content='Description:').grid(1, 0) self.description = Entry( frame, content=self.role['description']).style( border=[0]).grid(1, 1).weight(col=2) Label(frame, content='ID:').grid(2, 0) Label(frame, content=f'{self.role["id"]}').grid(2, 1) menu = Frame(self, title='Menu').grid(col=1) Button(menu, content='Policies', command=self.on_policies).style(border=[0]) Button(menu, content='Users', command=self.on_users).grid(1).style( Color.SUCCESS(), border=[0]) actions = Frame( self, title='Actions').title_style( Color.WARNING()).grid(1).span(col=2) Button(actions, content='Delete', command=self.on_delete ).style(Color.DANGER()).grid(0, 1) Spacer(actions).grid(0, 2).weight(col=2) Button(actions, content='Save', command=self.on_save ).style(Color.SUCCESS()).grid(0, 3) Button(actions, content='Cancel', command=self.on_cancel ).style(Color.WARNING()).grid(0, 4)
def build(self) -> None: super().build() self.modal = None frame = Frame(self, title='Policy').title_style(Color.SUCCESS()).weight( 4, 2) Label(frame, content='Resource:').grid(0, 0) self.resource = Entry(frame, content=self.policy['resource']).style( border=[0]).grid(0, 1).weight(col=2) Label(frame, content='Privilege:').grid(1, 0) self.privilege = Entry(frame, content=self.policy['privilege']).style( border=[0]).grid(1, 1).weight(col=2) Label(frame, content='Active:').grid(2, 0) self.active = Entry(frame, content=str( self.policy['active'])).style(border=[0]).grid(2, 1).weight(col=2) Label(frame, content='ID:').grid(3, 0) Label(frame, content=f'{self.policy["id"]}').grid(3, 1) menu = Frame(self, title='Menu').grid(col=1) Button(menu, content='Restrictions', command=self.on_restrictions).style(border=[0]) Spacer(menu).grid(1) actions = Frame(self, title='Actions').title_style( Color.WARNING()).grid(1).span(col=2) Button(actions, content='Delete', command=self.on_delete).style(Color.DANGER()).grid(0, 1) Spacer(actions).grid(0, 2).weight(col=2) Button(actions, content='Save', command=self.on_save).style(Color.SUCCESS()).grid(0, 3) Button(actions, content='Cancel', command=self.on_cancel).style(Color.WARNING()).grid(0, 4)
def build(self) -> None: super().build() self.modal = None available_frame = Frame(self, title='Available').weight( 5, 4).grid(0, 0) self.available_search = Entry( available_frame, command=self.on_available_search).listen( 'keydown', self.on_available_search, True).weight( col=2).grid(0, 0) self.available_total = Label( available_frame, content='Total: 0').grid(0, 1) self.available = Listbox( available_frame, command=self.on_select).weight( 9).span(col=2).grid(1) switchers = Frame(self).title_style( Color.SUCCESS()).style(border=[]).weight(5).grid(0, 1) Button(switchers, content='\U000025B6', command=self.on_choose).style( Color.SUCCESS(), border=[], template='{}').grid(0) Button(switchers, content='\U000025C0', command=self.on_clear).style( Color.SUCCESS(), border=[], template='{}').grid(1) Button(switchers, content='\U000023E9', command=self.on_choose_all).style( Color.SUCCESS(), border=[], template='{}').grid(2) Button(switchers, content='\U000023EA', command=self.on_clear_all).style( Color.SUCCESS(), border=[], template='{}').grid(3) chosen_frame = Frame(self, title='Chosen').weight( 5, 4).grid(0, 2) self.chosen_search = Entry(chosen_frame).listen( 'keydown', self.on_chosen_search, True).weight(col=2).grid(0, 0) self.chosen_total = Label( chosen_frame, content='Total: 0').grid(0, 1) self.chosen = Listbox( chosen_frame, command=self.on_select).weight( 9).span(col=2).grid(1) actions = Frame( self, title='Actions').title_style( Color.WARNING()).grid(1).span(col=3) Label(actions, content=f'Role: {self.role["name"]}').grid(0, 2) Spacer(actions).grid(0, 3).weight(col=1) Button(actions, content='Save', command=self.on_save ).style(Color.SUCCESS()).grid(0, 4) Button(actions, content='Cancel', command=self.on_cancel ).style(Color.WARNING()).grid(0, 5)
def build(self) -> None: super().build() frame = Frame(self, title='Credentials').title_style( Color.WARNING()).weight(4, 2) Listbox(frame, data=['ID', 'Type', 'Client', 'Value'], orientation='horizontal').grid(1).span(col=3) self.body = Listbox(frame).grid(3).span(col=3).weight(9)
def build(self) -> None: super().build() frame = Frame(self, title='Tenant').weight(6).title_style(Color.LIGHT()) Label(frame, content='ID:').grid(0, 0) self.id = Entry(frame, content=' ').style(border=[0]).grid(0, 1).weight(col=2) Label(frame, content='Name:').grid(1, 0) self.name = Entry(frame, content=' ').style(border=[0]).grid(1, 1).weight(col=2) actions = Frame(self, title='Actions').grid(1).title_style( Color.WARNING()).weight(3) Spacer(actions).grid(0, 2).weight(col=2) Button(actions, content='Save', command=self.on_save).style(Color.SUCCESS()).grid(0, 3) Button(actions, content='Cancel', command=self.on_cancel).style(Color.WARNING()).grid(0, 4)
def build(self) -> None: super().build() self.modal = None frame = Frame(self, title='Dominion').title_style(Color.SUCCESS()).weight( 4, 2) Label(frame, content='Name:').grid(0, 0) self.name = Entry(frame, content=self.dominion['name']).style( border=[0]).grid(0, 1).weight(col=2) Spacer(frame).grid(2).span(col=2) actions = Frame(self, title='Actions').title_style( Color.WARNING()).grid(1).span(col=2) Button(actions, content='Delete', command=self.on_delete).style(Color.DANGER()).grid(0, 1) Spacer(actions).grid(0, 2).weight(col=2) Button(actions, content='Save', command=self.on_save).style(Color.SUCCESS()).grid(0, 3) Button(actions, content='Cancel', command=self.on_cancel).style(Color.WARNING()).grid(0, 4)
def build(self) -> None: super().build() frame = Frame( self, title='User').title_style(Color.SUCCESS()).weight(6, 3) Label(frame, content='Name:').grid(0, 0) self.name = Entry(frame, content=self.user['name']).style( border=[0]).grid(0, 1).weight(col=2) Label(frame, content='Username:'******'username']).style( border=[0]).grid(1, 1).weight(col=2) Label(frame, content='Email:').grid(2, 0) self.email = Entry(frame, content=self.user['email']).style( border=[0]).grid(2, 1).weight(col=2) Label(frame, content='Password:'******'Attributes:').grid(4, 0) self.attributes = Entry( frame, content=json.dumps( self.user['attributes'], indent=4)).style( border=[0]).grid(4, 1).weight(4, 2) menu = Frame(self, title='Menu').grid(col=1) Button(menu, content='Roles', command=self.on_roles).style(border=[0]) Button(menu, content='Credentials', command=self.on_credentials).style(border=[0]).grid(1) Spacer(menu).grid(2).weight(2) actions = Frame(self, title='Actions').title_style( Color.WARNING()).grid(1).span(col=2) Button(actions, content='Delete', command=self.on_delete ).style(Color.DANGER()).grid(0, 1) Spacer(actions).grid(0, 2).weight(col=2) Button(actions, content='Save', command=self.on_save ).style(Color.SUCCESS()).grid(0, 3) Button(actions, content='Cancel', command=self.on_cancel ).style(Color.WARNING()).grid(0, 4)
def build(self) -> None: super().build() self.modal = None frame = Frame(self, title='Rankings').title_style( Color.WARNING()).weight(4, 2) Button(frame, content='\U00002795 Assign', command=self.on_assign).grid(0, 0) Label(frame, content='"Middle click" to Delete').grid(0, 1) self.header = Listbox( frame, data=['ID', 'Role', 'Dominion'], orientation='horizontal').grid(1).span(col=3) self.body = Listbox(frame, command=self.on_body).grid( 3).span(col=3).weight(9)
def build(self) -> None: super().build() self.modal = None frame = Frame( self, title='Restriction').title_style( Color.SUCCESS()).weight(4, 2) Label(frame, content='Sequence:').grid(0, 0) self.sequence = Entry( frame, content=str(self.restriction['sequence'])).style( border=[0]).grid(0, 1).weight(col=2) Label(frame, content='Name:').grid(1, 0) self.name = Entry(frame, content=self.restriction['name']).style( border=[0]).grid(1, 1).weight(col=2) Label(frame, content='Target:').grid(2, 0) self.target = Entry( frame, content=str(self.restriction['target'])).style( border=[0]).grid(2, 1).weight(col=2) Label(frame, content='Domain:').grid(3, 0) self.domain = Entry( frame, content=str(self.restriction['domain'])).style( border=[0]).grid(3, 1).weight(2, 2) Label(frame, content='ID:').grid(4, 0) Label(frame, content=f'{self.restriction["id"]}').grid(4, 1) actions = Frame( self, title='Actions').title_style( Color.WARNING()).grid(1).span(col=2) Button(actions, content='Delete', command=self.on_delete ).style(Color.DANGER()).grid(0, 1) Spacer(actions).grid(0, 2).weight(col=2) Button(actions, content='Save', command=self.on_save ).style(Color.SUCCESS()).grid(0, 3) Button(actions, content='Cancel', command=self.on_cancel ).style(Color.WARNING()).grid(0, 4)
def build(self) -> None: super().build() self.modal = None frame = Frame( self, title=f'Restrictions for resource: {self.policy["resource"]}' ).title_style(Color.WARNING()).weight(4, 2) Button(frame, content='\U00002795 Create', command=self.on_create).grid(0, 0) Button(frame, content='\U00002716 Cancel', command=self.on_cancel).style(Color.WARNING()).grid(0, 1) Listbox(frame, data=['Sequence', 'Name', 'Target', 'Domain'], orientation='horizontal').grid(1).span(col=3) self.body = Listbox(frame, command=self.on_body ).grid(3).span(col=3).weight(9)
def build(self) -> None: super().build() self.modal = None frame = Frame( self, title=f'Policies for role: {self.role["name"]}').title_style( Color.DANGER()).weight(4, 2) Button(frame, content='\U00002795 Create', command=self.on_create).grid(0, 0) Button(frame, content='\U00002716 Cancel', command=self.on_cancel).style(Color.WARNING()).grid(0, 1) Listbox(frame, data=['Resource', 'Privilege', 'Active'], orientation='horizontal').grid(1).span(col=3) self.body = Listbox(frame, command=self.on_body).grid(3).span(col=3).weight(9)
def _build_menu(self) -> None: self.menu = Frame(self, title='Menu').title_style( Color.PRIMARY()).style(border=[0]).span(2) Listbox(self.menu, data=[ { 'label': '\U0001F6B9 Users', 'tag': 'users' }, { 'label': '\U0001F510 Roles', 'tag': 'roles' }, { 'label': '\U0000269B Dominions', 'tag': 'dominions' }, ], command=self.on_menu_click, fields=['label']) Spacer(self.menu).grid(1).weight(1)
def build(self) -> None: self._build_menu() self._build_status() self.body = Frame(self, border=[0]).title_style( Color.SUCCESS()).style(border=[]).grid(1, 1).weight(9, 5)
class ConsoleApplication(Application): def setup(self, **context) -> 'ConsoleApplication': self.config = context['config'] self.injector = context['injector'] self.session_manager = self.injector['SessionManager'] return super().setup(**context) and self async def prepare(self) -> None: self.session_manager.set_user(self.config['system']) tenancy_informer = self.injector['TenantInformer'] tenants = (await tenancy_informer.search_tenants({"meta": { "domain": [] }}))['data'] tenant_dict = next(iter(tenants), {'name': 'None'}) tenant_manager = self.injector['TenantManager'] self.session_manager.set_user({"data": tenant_dict}) def build(self) -> None: self._build_menu() self._build_status() self.body = Frame(self, border=[0]).title_style( Color.SUCCESS()).style(border=[]).grid(1, 1).weight(9, 5) async def on_menu_click(self, event: Event) -> None: item = event.target.parent.item if item['tag'] == 'users': self.body.clear() UsersScreen(self.body, injector=self.injector).connect() if item['tag'] == 'roles': self.body.clear() RolesScreen(self.body, injector=self.injector).connect() elif item['tag'] == 'dominions': self.body.clear() DominionsScreen(self.body, injector=self.injector).connect() async def on_tenant_switch(self, event: Event) -> None: if event.details.get('name'): self.session_manager.set_user({"data": event.details}) #self.session_manager.set_tenant(event.details) self.connect() def _build_status(self) -> None: self.status = StatusScreen(self, injector=self.injector).grid(0, 1).weight( 1, 5) self.status.listen('tenant_switch', self.on_tenant_switch) def _build_menu(self) -> None: self.menu = Frame(self, title='Menu').title_style( Color.PRIMARY()).style(border=[0]).span(2) Listbox(self.menu, data=[ { 'label': '\U0001F6B9 Users', 'tag': 'users' }, { 'label': '\U0001F510 Roles', 'tag': 'roles' }, { 'label': '\U0000269B Dominions', 'tag': 'dominions' }, ], command=self.on_menu_click, fields=['label']) Spacer(self.menu).grid(1).weight(1)
async def load(self) -> None: Frame(self, title='Loaded').title_style(Color.WARNING()).grid(2) self.render()