Esempio n. 1
0
class FamilyDoc(BaseDocument):
    def __init__(self, app, **atts):
        BaseDocument.__init__(self, app, **atts)
        self.family = Family(self.conn)
        
    def set_family(self, family):
        self.family.set_family(family)
        parents = self.family.parents()
        erows = self.family.environment_rows()
        self.clear_body()
        title = SimpleTitleElement('Family:  %s' % family, bgcolor='IndianRed',
                                   width='100%')
        self.body.appendChild(title)
        self.body.appendChild(SectionTitle('Parents'))
        if len(parents):
            plist = UnorderedList()
            for p in parents:
                plist.appendChild(ListItem(p))
            self.body.appendChild(plist)
        self.body.appendChild(SectionTitle('Variables'))
        if len(erows):
            self.body.appendChild(PVarTable(erows, bgcolor='MistyRose2'))
Esempio n. 2
0
class FamilyDoc(BaseDocument):
    def __init__(self, app, **atts):
        BaseDocument.__init__(self, app, **atts)
        self.family = Family(self.conn)
        
    def set_family(self, family):
        self.family.set_family(family)
        parents = self.family.parents()
        erows = self.family.environment_rows()
        self.clear_body()
        title = SimpleTitleElement('Family:  %s' % family, bgcolor='IndianRed',
                                   width='100%')
        self.body.appendChild(title)
        self.body.appendChild(SectionTitle('Parents'))
        if len(parents):
            plist = UnorderedList()
            for p in parents:
                plist.appendChild(ListItem(p))
            self.body.appendChild(plist)
        self.body.appendChild(SectionTitle('Variables'))
        if len(erows):
            self.body.appendChild(PVarTable(erows, bgcolor='MistyRose2'))
Esempio n. 3
0
class FamilyBrowser(ListNoteBook):
    def __init__(self, conn):
        self.menu = make_menu(['delete'], self.modify_family)
        ListNoteBook.__init__(self)
        self.conn = conn
        self.family = Family(self.conn)
        self.var_menu = make_menu(['edit', 'nothing', 'nothing', 'drop'],
                              self.var_menu_selected)
        self.parent_menu = make_menu(['drop'], self.modify_parent)
        self.reset_rows()
        self.append_page(ScrollCList(rcmenu=self.var_menu), 'environment')
        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', 'family')
            self.trait.delete_parents(parents)
            self.__set_pages(self.current_family)

    def modify_family(self, menuitem, action):
        if action == 'delete':
            trait = self.listbox.get_selected_data()[0].family
            self.trait.delete_family(family)
            self.reset_rows()
            
    def reset_rows(self):
        self.set_rows(self.family.family_rows())
        self.set_row_select(self.family_selected)

    def __set_droptargets__(self, pages):
        set_receive_targets(pages['environment'].listbox,
                            self.drop_variable, TARGETS.get('variable', 'flavor'))
        set_receive_targets(pages['parents'].listbox,
                            self.drop_family, TARGETS.get('family', 'flavor'))

    def set_package(self, menu_item, action):
        packages = self._get_listbox_col_('packages', 'package')
        trait = self.current_family
        self.trait.set_action(action, packages)
        self.__set_pages(self.current_trait)

    def var_menu_selected(self, menu_item, action):
        if action == 'edit':
            config = FamilyVariablesConfig(self.conn, self.current_family)
            newconfig = config.edit()
            config.update(newconfig)
            self.select_family(self.current_family)
        elif action == 'drop':
            pages = dict(self.pages)
            listbox = pages['environment'].listbox
            rows = listbox.get_selected_data()
            data = dict(family=self.current_family)
            for row in rows:
                data['trait'] = row.trait
                data['name'] = row.name
                clause = reduce(and_, [Eq(k, v) for k,v in data.items()])
                self.family.env.cursor.delete(clause=clause)
    

    def pop_mymenu(self, widget, event, menu):
        if right_click_pressed(event):
            menu.popup(None, None, None, event.button, event.time)

    def family_selected(self, listbox, row, column, event):
        family = listbox.get_selected_data()[0].family
        self.select_family(family)
        
    def select_family(self, family):
        self.current_family = family
        self.family.set_family(family)
        self.__set_pages(self.current_family)

    def __set_pages(self, family):
        pages = dict(self.pages)
        pages['environment'].set_rows(self.family.environment_rows())
        pages['environment'].set_select_mode('multi')
        pages['parents'].set_rows(self.family.parents(), ['family'])
        pages['parents'].set_select_mode('multi')
        self.__set_droptargets__(pages)

    def drop_family(self, listbox, context, x, y, selection, targettype, time):
        families = Set(selection.data.split('^&^'))
        self.family.insert_parents(families)
        self.__set_pages(self.current_family)

    def drop_variable(self, listbox, context, x, y, selection, targettype, time):
        table = 'family_environment'
        trips = [x.split('<=>') for x in selection.data.split('^&^')]
        rows = [dict(trait=x[0], name=x[1], value=x[2]) for x in trips]
        print rows
        for r in trips:
            clause = Eq('family', self.current_family)
            clause &= Eq('trait', r[0]) & Eq('name', r[1]) 
            trows = self.family.cursor.select(table=table, clause=clause)
            print 'trows', trows
            if len(trows) == 0:
                data = dict(trait=r[0], name=r[1], value=r[2])
                data['family'] = self.current_family
                print 'data', data
                self.family.cursor.insert(table=table, data=data)        
        self.__set_pages(self.current_family)

    def _get_listbox_col_(self, page, field):
        pages = dict(self.pages)
        return [row[field] for row in pages[page].listbox.get_selected_data()]

    def make_families_window(self):
        rows = self.family.family_rows()
        FamiliesWindow(rows)

    def make_variables_window(self):
        rows = self.family.get_all_defaults()
        VariablesWindow(rows)
Esempio n. 4
0
class FamilyBrowser(ListNoteBook):
    def __init__(self, conn):
        self.menu = make_menu(['delete'], self.modify_family)
        ListNoteBook.__init__(self)
        self.conn = conn
        self.family = Family(self.conn)
        self.var_menu = make_menu(['edit', 'nothing', 'nothing', 'drop'],
                              self.var_menu_selected)
        self.parent_menu = make_menu(['drop'], self.modify_parent)
        self.reset_rows()
        self.append_page(ScrollCList(rcmenu=self.var_menu), 'environment')
        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', 'family')
            self.trait.delete_parents(parents)
            self.__set_pages(self.current_family)

    def modify_family(self, menuitem, action):
        if action == 'delete':
            trait = self.listbox.get_selected_data()[0].family
            self.trait.delete_family(family)
            self.reset_rows()
            
    def reset_rows(self):
        self.set_rows(self.family.family_rows())
        self.set_row_select(self.family_selected)

    def __set_droptargets__(self, pages):
        set_receive_targets(pages['environment'].listbox,
                            self.drop_variable, TARGETS.get('variable', 'flavor'))
        set_receive_targets(pages['parents'].listbox,
                            self.drop_family, TARGETS.get('family', 'flavor'))

    def set_package(self, menu_item, action):
        packages = self._get_listbox_col_('packages', 'package')
        trait = self.current_family
        self.trait.set_action(action, packages)
        self.__set_pages(self.current_trait)

    def var_menu_selected(self, menu_item, action):
        if action == 'edit':
            config = FamilyVariablesConfig(self.conn, self.current_family)
            newconfig = config.edit()
            config.update(newconfig)
            self.select_family(self.current_family)
        elif action == 'drop':
            pages = dict(self.pages)
            listbox = pages['environment'].listbox
            rows = listbox.get_selected_data()
            data = dict(family=self.current_family)
            for row in rows:
                data['trait'] = row.trait
                data['name'] = row.name
                clause = reduce(and_, [Eq(k, v) for k,v in data.items()])
                self.family.env.cursor.delete(clause=clause)
    

    def pop_mymenu(self, widget, event, menu):
        if right_click_pressed(event):
            menu.popup(None, None, None, event.button, event.time)

    def family_selected(self, listbox, row, column, event):
        family = listbox.get_selected_data()[0].family
        self.select_family(family)
        
    def select_family(self, family):
        self.current_family = family
        self.family.set_family(family)
        self.__set_pages(self.current_family)

    def __set_pages(self, family):
        pages = dict(self.pages)
        pages['environment'].set_rows(self.family.environment_rows())
        pages['environment'].set_select_mode('multi')
        pages['parents'].set_rows(self.family.parents(), ['family'])
        pages['parents'].set_select_mode('multi')
        self.__set_droptargets__(pages)

    def drop_family(self, listbox, context, x, y, selection, targettype, time):
        families = Set(selection.data.split('^&^'))
        self.family.insert_parents(families)
        self.__set_pages(self.current_family)

    def drop_variable(self, listbox, context, x, y, selection, targettype, time):
        table = 'family_environment'
        trips = [x.split('<=>') for x in selection.data.split('^&^')]
        rows = [dict(trait=x[0], name=x[1], value=x[2]) for x in trips]
        print rows
        for r in trips:
            clause = Eq('family', self.current_family)
            clause &= Eq('trait', r[0]) & Eq('name', r[1]) 
            trows = self.family.cursor.select(table=table, clause=clause)
            print 'trows', trows
            if len(trows) == 0:
                data = dict(trait=r[0], name=r[1], value=r[2])
                data['family'] = self.current_family
                print 'data', data
                self.family.cursor.insert(table=table, data=data)        
        self.__set_pages(self.current_family)

    def _get_listbox_col_(self, page, field):
        pages = dict(self.pages)
        return [row[field] for row in pages[page].listbox.get_selected_data()]

    def make_families_window(self):
        rows = self.family.family_rows()
        FamiliesWindow(rows)

    def make_variables_window(self):
        rows = self.family.get_all_defaults()
        VariablesWindow(rows)