class TraitDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.trait = Trait(self.conn) def set_trait(self, trait): self.clear_body() self.trait.set_trait(trait) title = SimpleTitleElement('Trait: %s' % trait, bgcolor='IndianRed', width='100%') self.body.appendChild(title) self.body.appendChild(HR()) plist = UnorderedList() parents = self.trait.parents(trait=trait) parent_section = SectionTitle('Parents') parent_section.create_rightside_table() parent_section.append_rightside_anchor( Anchor('hello.there.dude', 'edit')) parent_section.append_rightside_anchor( Anchor('hello.there.dudee', 'edit2')) self.body.appendChild(parent_section) for parent in parents: pp = Anchor('show.parent.%s' % parent, parent) plist.appendChild(ListItem(pp)) self.body.appendChild(plist) ptitle = Anchor('edit.packages.%s' % trait, 'Packages') self.body.appendChild(SectionTitle(ptitle)) rows = self.trait.packages(trait=trait, action=True) self.body.appendChild(PackageTable(rows, bgcolor='SkyBlue3')) ttitle = Anchor('edit.templates.%s' % trait, 'Templates') self.body.appendChild(SectionTitle(ttitle)) rows = self.trait.templates( trait=trait, fields=['package', 'template', 'templatefile']) if len(rows): self.body.appendChild(TemplateTable(rows, bgcolor='DarkSeaGreen3')) self.body.appendChild(SectionTitle('Variables', href='foo.var.ick')) if len(self.trait.environ.keys()): env = TraitEnvTable(trait, self.trait.environ, bgcolor='MistyRose3') self.body.appendChild(env) self.body.appendChild(SectionTitle('Scripts')) slist = UnorderedList() for row in self.trait._scripts.scripts(trait=trait): script = row.script sa = Anchor('show.script.%s' % script, script) slist.appendChild(ListItem(sa)) self.body.appendChild(slist)
class TraitDoc(BaseDocument): def __init__(self, app, **atts): BaseDocument.__init__(self, app, **atts) self.trait = Trait(self.conn) def set_trait(self, trait): self.clear_body() self.trait.set_trait(trait) title = SimpleTitleElement('Trait: %s' % trait, bgcolor='IndianRed', width='100%') self.body.appendChild(title) self.body.appendChild(HR()) plist = UnorderedList() parents = self.trait.parents(trait=trait) parent_section = SectionTitle('Parents') parent_section.create_rightside_table() parent_section.append_rightside_anchor(Anchor('hello.there.dude', 'edit')) parent_section.append_rightside_anchor(Anchor('hello.there.dudee', 'edit2')) self.body.appendChild(parent_section) for parent in parents: pp = Anchor('show.parent.%s' % parent, parent) plist.appendChild(ListItem(pp)) self.body.appendChild(plist) ptitle = Anchor('edit.packages.%s' % trait, 'Packages') self.body.appendChild(SectionTitle(ptitle)) rows = self.trait.packages(trait=trait, action=True) self.body.appendChild(PackageTable(rows, bgcolor='SkyBlue3')) ttitle = Anchor('edit.templates.%s' % trait, 'Templates') self.body.appendChild(SectionTitle(ttitle)) rows = self.trait.templates(trait=trait, fields=['package', 'template', 'templatefile']) if len(rows): self.body.appendChild(TemplateTable(rows, bgcolor='DarkSeaGreen3')) self.body.appendChild(SectionTitle('Variables', href='foo.var.ick')) if len(self.trait.environ.keys()): env = TraitEnvTable(trait, self.trait.environ, bgcolor='MistyRose3') self.body.appendChild(env) self.body.appendChild(SectionTitle('Scripts')) slist = UnorderedList() for row in self.trait._scripts.scripts(trait=trait): script = row.script sa = Anchor('show.script.%s' % script, script) slist.appendChild(ListItem(sa)) self.body.appendChild(slist)
class TraitBrowser(ListNoteBook): def __init__(self, conn, suite): self.menu = make_menu(['delete'], self.modify_trait) ListNoteBook.__init__(self) self.conn = conn self.suite = suite self.trait = Trait(self.conn, self.suite) self.package_menu = make_menu(['install', 'remove', 'purge', 'drop'], self.set_package) self.parent_menu = make_menu(['drop'], self.modify_parent) self.reset_rows() self.append_page(ScrollCList(rcmenu=self.package_menu), 'packages') self.append_page(ScrollCList(rcmenu=self.parent_menu), 'parents') self.set_size_request(400, 300) def modify_parent(self, menuitem, action): if action == 'drop': parents = self._get_listbox_col_('parents', 'trait') self.trait.delete_parents(parents) self.__set_pages(self.current_trait) def modify_trait(self, menuitem, action): if action == 'delete': trait = self.listbox.get_selected_data()[0].trait self.trait.delete_trait(trait) self.reset_rows() def reset_rows(self): self.set_rows(self.trait.get_traits()) self.set_row_select(self.trait_selected) def __set_droptargets__(self, pages): set_receive_targets(pages['packages'].listbox, self.drop_package, TARGETS.get('package', self.suite)) set_receive_targets(pages['parents'].listbox, self.drop_trait, TARGETS.get('trait', self.suite)) def set_package(self, menu_item, action): packages = self._get_listbox_col_('packages', 'package') trait = self.current_trait self.trait.set_action(action, packages) self.__set_pages(self.current_trait) def pop_mymenu(self, widget, event, menu): if right_click_pressed(event): menu.popup(None, None, None, event.button, event.time) def trait_selected(self, listbox, row, column, event): trait = listbox.get_selected_data()[0].trait self.select_trait(trait) def select_trait(self, trait): self.current_trait = trait self.trait.set_trait(trait) self.__set_pages(self.current_trait) def __set_pages(self, trait): pages = dict(self.pages) pages['packages'].set_rows(self.trait.packages(action=True)) pages['packages'].set_select_mode('multi') pages['parents'].set_rows(self.trait.parents(), ['trait']) pages['parents'].set_select_mode('multi') self.__set_droptargets__(pages) def drop_package(self, listbox, context, x, y, selection, targettype, time): packages = Set(selection.data.split('^&^')) self.trait.insert_packages(packages) self.__set_pages(self.current_trait) def drop_trait(self, listbox, context, x, y, selection, targettype, time): traits = selection.data.split('^&^') self.trait.insert_parents(traits) self.__set_pages(self.current_trait) def _get_listbox_col_(self, page, field): pages = dict(self.pages) return [row[field] for row in pages[page].listbox.get_selected_data()] def change_suite(self, suite): self.suite = suite self.trait = Trait(self.conn, self.suite) self.reset_rows()