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 = SectionTitle('Family:  %s' % family)
        title['bgcolor'] = 'IndianRed'
        title['width'] = '100%'

        self.body.append(title)
        parent_anchor = Anchor('Parents', href='edit.parents.%s' % family)
        self.body.append(SectionTitle(parent_anchor))
        if len(parents):
            plist = UnorderedList()
            for p in parents:
                plist.append(ListItem(p))
            self.body.append(plist)
        vtitle = Anchor('Variables', href='edit.variables.%s' % self.family.current)
        self.body.append(SectionTitle(vtitle))
        if len(erows):
            self.body.append(PVarTable(erows, bgcolor='MistyRose2'))
        self.body.append(Ruler())
        del_anchor = Anchor('delete', href='delete.family.%s' % family)
        self.body.append(del_anchor)
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 = SectionTitle('Family:  %s' % family)
        title['bgcolor'] = 'IndianRed'
        title['width'] = '100%'

        self.body.append(title)
        parent_anchor = Anchor('Parents', href='edit.parents.%s' % family)
        self.body.append(SectionTitle(parent_anchor))
        if len(parents):
            plist = UnorderedList()
            for p in parents:
                plist.append(ListItem(p))
            self.body.append(plist)
        vtitle = Anchor('Variables',
                        href='edit.variables.%s' % self.family.current)
        self.body.append(SectionTitle(vtitle))
        if len(erows):
            self.body.append(PVarTable(erows, bgcolor='MistyRose2'))
        self.body.append(Ruler())
        del_anchor = Anchor('delete', href='delete.family.%s' % family)
        self.body.append(del_anchor)
Esempio n. 3
0
class FamilyParentAssigner(BaseAssigner):
    def __init__(self, parent, family):
        self.app = get_application_pointer()
        self.conn = self.app.conn
        self.family = Family(self.conn)
        self.family.set_family(family)
        BaseAssigner.__init__(self, parent, name='FamilyParentAssigner',
                              udbuttons=False)
        self.connect(self, SIGNAL('okClicked()'), self.slotAssignParents)

    def initView(self):
        family = self.family.current
        all_fams = self.family.all_families()
        assigned_parents = self.family.parents()
        avail_parents = [f for f in all_fams if f not in assigned_parents + [family]]
        abox = self.listBox.availableListBox()
        sbox = self.listBox.selectedListBox()
        for family in assigned_parents:
            self._add_family_to_listbox(sbox, family)
        for family in avail_parents:
            self._add_family_to_listbox(abox, family)
        self.already_assigned = assigned_parents
        
    def _add_family_to_listbox(self, box, family):
        item = QListBoxText(box, family)
        item.family = family

    def slotAssignParents(self):
        sbox = self.listBox.selectedListBox()
        families =[str(sbox.item(n).text()) for n in range(sbox.numRows())]
        # since we're using a SimpleRelation class for
        # family.parents, we don't need to worry about
        # inserting families that are already there
        self.family.delete_parents()
        self.family.insert_parents(families)
Esempio n. 4
0
class FamilyView(ViewBrowser):
    def __init__(self, parent):
        ViewBrowser.__init__(self, parent, FamilyDoc)
        self.app = get_application_pointer()
        self.conn = self.app.conn
        self.family = Family(self.conn)

    def set_family(self, family):
        self.doc.set_family(family)
        self.setText(self.doc.output())
        self.family.set_family(family)

    def resetView(self):
        self.set_family(self.family.current)

    def setSource(self, url):
        action, context, ident = split_url(url)
        if action == 'edit':
            if context == 'variables':
                config = self.family.getVariablesConfig(self.family.current)
                newconfig = config.edit()
                config.update(newconfig)
                self.set_family(ident)
            elif context == 'parents':
                dialog = FamilyParentAssigner(self, ident)
                dialog.connect(dialog, SIGNAL('okClicked()'), self.resetView)
                dialog.show()
            else:
                KMessageBox.error(self,
                                  'unable to edit %s for family' % context)
        elif action == 'delete':
            if context == 'family':
                #KMessageBox.information(self, 'delete family %s is unimplemented' % ident)
                msg = "Really delete family %s" % ident
                answer = KMessageBox.questionYesNo(self, msg)
                if answer == KMessageBox.Yes:
                    self.family.delete_family(ident)
                    msg = "family %s deleted" % ident
                    KMessageBox.information(self, msg)
                    self.parent().parent().refreshListView()
                    self.setText('')
            else:
                KMessageBox.error(self,
                                  'unable to delete %s for family' % context)
        else:
            KMessageBox.error(self, 'action %s unimpletmented' % url)
Esempio n. 5
0
class FamilyView(ViewBrowser):
    def __init__(self, parent):
        ViewBrowser.__init__(self, parent, FamilyDoc)
        self.app = get_application_pointer()
        self.conn = self.app.conn
        self.family = Family(self.conn)

    def set_family(self, family):
        self.doc.set_family(family)
        self.setText(self.doc.output())
        self.family.set_family(family)

    def resetView(self):
        self.set_family(self.family.current)
        

    def setSource(self, url):
        action, context, ident = split_url(url)
        if action == 'edit':
            if context == 'variables':
                config = self.family.getVariablesConfig(self.family.current)
                newconfig = config.edit()
                config.update(newconfig)
                self.set_family(ident)
            elif context == 'parents':
                dialog = FamilyParentAssigner(self, ident)
                dialog.connect(dialog, SIGNAL('okClicked()'), self.resetView)
                dialog.show()
            else:
                KMessageBox.error(self, 'unable to edit %s for family' % context)
        elif action == 'delete':
            if context == 'family':
                #KMessageBox.information(self, 'delete family %s is unimplemented' % ident)
                msg = "Really delete family %s" % ident
                answer = KMessageBox.questionYesNo(self, msg)
                if answer == KMessageBox.Yes:
                    self.family.delete_family(ident)
                    msg = "family %s deleted" % ident
                    KMessageBox.information(self, msg)
                    self.parent().parent().refreshListView()
                    self.setText('')
            else:
                KMessageBox.error(self, 'unable to delete %s for family' % context)
        else:
            KMessageBox.error(self, 'action %s unimpletmented' % url)
Esempio n. 6
0
class FamilyView(ViewBrowser):
    def __init__(self, parent):
        ViewBrowser.__init__(self, parent, FamilyDoc)
        self.app = get_application_pointer()
        self.conn = self.app.conn
        self.family = Family(self.conn)

    def set_family(self, family):
        self.doc.set_family(family)
        self.setText(self.doc.output())
        self.family.set_family(family)

    def setSource(self, url):
        action, context, ident = split_url(url)
        if action == 'edit':
            config = self.family.getVariablesConfig(self.family.current)
            newconfig = config.edit()
            config.update(newconfig)
            self.set_family(ident)
        else:
            KMessageBox.error(self, 'action %s unimpletmented' % url)
Esempio n. 7
0
class FamilyView(ViewBrowser):
    def __init__(self, app, parent):
        ViewBrowser.__init__(self, app, parent, FamilyDoc)
        self.family = Family(self.app.conn)

    def set_family(self, family):
        self.doc.set_family(family)
        self.setText(self.doc.toxml())
        self.family.set_family(family)

    def setSource(self, url):
        action, context, id = str(url).split('.')
        if action == 'show':
            if context == 'parent':
                win = TraitMainWindow(self.app, self.parent(), self.doc.suite)
                win.view.set_trait(id)
            elif context == 'template':
                fid = id.replace(',', '.')
                package, template = fid.split('...')
                win = ViewWindow(self.app, self.parent(), SimpleEdit,
                                 'TemplateView')
                templatefile = self.doc.trait._templates.templatedata(
                    package, template)
                win.view.setText(templatefile)
                win.resize(600, 800)
            elif context == 'script':
                scriptfile = self.doc.trait._scripts.scriptdata(id)
                win = ViewWindow(self.app, self.parent(), SimpleEdit,
                                 'ScriptView')
                win.view.setText(scriptfile)
                win.resize(600, 800)
        elif action == 'edit':
            #KMessageBox.information(self, 'edit the family %s ' % id)
            config = self.family.getVariablesConfig(self.family.current)
            newconfig = config.edit()
            config.update(newconfig)
            self.set_family(id)

        else:
            KMessageBox.information(self, 'called %s' % url)
Esempio n. 8
0
class FamilyParentAssigner(BaseAssigner):
    def __init__(self, parent, family):
        self.app = get_application_pointer()
        self.conn = self.app.conn
        self.family = Family(self.conn)
        self.family.set_family(family)
        BaseAssigner.__init__(self,
                              parent,
                              name='FamilyParentAssigner',
                              udbuttons=False)
        self.connect(self, SIGNAL('okClicked()'), self.slotAssignParents)

    def initView(self):
        family = self.family.current
        all_fams = self.family.all_families()
        assigned_parents = self.family.parents()
        avail_parents = [
            f for f in all_fams if f not in assigned_parents + [family]
        ]
        abox = self.listBox.availableListBox()
        sbox = self.listBox.selectedListBox()
        for family in assigned_parents:
            self._add_family_to_listbox(sbox, family)
        for family in avail_parents:
            self._add_family_to_listbox(abox, family)
        self.already_assigned = assigned_parents

    def _add_family_to_listbox(self, box, family):
        item = QListBoxText(box, family)
        item.family = family

    def slotAssignParents(self):
        sbox = self.listBox.selectedListBox()
        families = [str(sbox.item(n).text()) for n in range(sbox.numRows())]
        # since we're using a SimpleRelation class for
        # family.parents, we don't need to worry about
        # inserting families that are already there
        self.family.delete_parents()
        self.family.insert_parents(families)
Esempio n. 9
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)
        vtitle = Anchor("edit.variables.%s" % self.family.current, "Variables")
        self.body.appendChild(SectionTitle(vtitle))
        if len(erows):
            self.body.appendChild(PVarTable(erows, bgcolor="MistyRose2"))
Esempio n. 10
0
class FamilyView(ViewBrowser):
    def __init__(self, app, parent):
        ViewBrowser.__init__(self, app, parent, FamilyDoc)
        self.family = Family(self.app.conn)
        
    def set_family(self, family):
        self.doc.set_family(family)
        self.setText(self.doc.toxml())
        self.family.set_family(family)
        
    def setSource(self, url):
        action, context, id = str(url).split('.')
        if action == 'show':
            if context == 'parent':
                win = TraitMainWindow(self.app, self.parent(), self.doc.suite)
                win.view.set_trait(id)
            elif context == 'template':
                fid = id.replace(',', '.')
                package, template = fid.split('...')
                win = ViewWindow(self.app, self.parent(), SimpleEdit, 'TemplateView')
                templatefile = self.doc.trait._templates.templatedata(package, template)
                win.view.setText(templatefile)
                win.resize(600, 800)
            elif context == 'script':
                scriptfile = self.doc.trait._scripts.scriptdata(id)
                win = ViewWindow(self.app, self.parent(), SimpleEdit, 'ScriptView')
                win.view.setText(scriptfile)
                win.resize(600, 800)
        elif action == 'edit':
            #KMessageBox.information(self, 'edit the family %s ' % id)
            config = self.family.getVariablesConfig(self.family.current)
            newconfig = config.edit()
            config.update(newconfig)
            self.set_family(id)
            
                
        else:
            KMessageBox.information(self, 'called %s' % url)
Esempio n. 11
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)
        vtitle = Anchor('edit.variables.%s' % self.family.current, 'Variables')
        self.body.appendChild(SectionTitle(vtitle))
        if len(erows):
            self.body.appendChild(PVarTable(erows, bgcolor='MistyRose2'))
Esempio n. 12
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):
        raise Error, 'this call (set_package) is not needed in Family'
        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 = self.family.getVariablesConfig(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()
            for row in rows:
                self.family.deleteVariable(row.trait, row.name, self.current_family)
            
    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]
        for r in trips:
            trait, name, value = r
            self.family.insertVariable(trait, name, value, family=self.current_family)
        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)