Ejemplo n.º 1
0
class EnvironmentEditor(_EnvironmentEditor):
    def __init__(self, conn, suite, name='EnvironmentEditor'):
        self.menu = make_menu(['update', 'create'], self.env_command)
        _EnvironmentEditor.__init__(self, conn, name=name)
        self.suite = suite
        self.traitparent = TraitParent(self.conn, self.suite)
        self.current_trait = None
        self.reset_rows()
        w, h = map(int, config.get_list('env_editor_size', section='management_gui'))
        self.set_size_request(w, h)
        
    def reset_rows(self):
        rows = self.main.select(fields=['trait'], table=ujoin(self.suite, 'traits'))
        self.set_rows(rows)
        self.set_row_select(self.trait_selected)

    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
        environ = TraitEnvironment(self.conn, self.suite, trait)
        self.environ = self.traitparent.get_environment([self.current_trait])
        self.sections = dict([(k, v.keys()) for k,v in self.environ])
        self.remove_page('Environment')
        self.record = RecordBox(environ, name=self.current_trait)
        self.append_page(self.record, 'Environment')
        self.pages['Environment'].connect('button_press_event', self.box_pressed)
        #self.menu.connect('populate', self.populate_menu, self.menu)
        self.record.connect_entries('populate-popup', self.populate_menu, self.menu)
        

    def make_new_variable(self, *args):
        d = self.dialogs['create']
        environ = TraitEnvironment(self.conn, self.suite, self.current_trait)
        environ.update(dict([(d['name'], d['value'])]))

    def remove_item(self, *args):
        d = self.dialogs['remove']
        name = d.get_selected_data()[0].name
        environ = TraitEnvironment(self.conn, self.suite, self.current_trait)
        del environ[name]
        dialogs.Message('%s deleted' %name)
        self.destroy_dialog(d)
        
    def update_environment(self):
        environ = TraitEnvironment(self.conn, self.suite, self.current_trait)
        environ.update(self.record)

    def env_command(self, menuitem, command):
        if command == 'update':
            dialogs.Message('updating %s' % self.current_trait)
            self.update_environment()
        elif command == 'create':
            self.ask_new_entry()
        else:
            dialogs.Message('ack')
Ejemplo n.º 2
0
class _ProfileEnvironment(Environment):
    def __init__(self, conn, profile):
        self.suite = get_suite(conn, profile)
        self.profile = profile
        Environment.__init__(self, conn, 'profile_variables', 'trait')
        self.traitparent = TraitParent(self.conn, self.suite)

    def set_trait(self, trait):
        self.set_main(trait)
        self.traitparent.set_trait(trait)

    def _single_clause_(self):
        return Eq('profile', self.profile) & Eq('trait', self.__main_value__)

    def __setitem__(self, key, value):
        try:
            self.cursor.insert(
                data={
                    'profile': self.profile,
                    'trait': self.__main_value__,
                    self.__key_field__: key,
                    self.__value_field__: value
                })
        except OperationalError:
            self.cursor.update(data={self.__value_field__: value},
                               clause=self._double_clause_(key))

    def _make_superdict__orig_(self):
        clause = Eq('profile', self.profile)
        superdict = {}
        traits = [
            row.trait
            for row in self.cursor.select(fields=['trait'], clause=clause)
        ]
        for trait in traits:
            self.set_trait(trait)
            items = [(trait + '_' + key, value) for key, value in self.items()]
            superdict.update(dict(items))
        return superdict

    def _make_superdict_(self):
        clause = Eq('profile', self.profile)
        return Environment._make_superdict_(self, clause)

    def _get_defaults_(self, trait):
        return self.traitparent.get_environment([trait])

    def _update_defaults_(self, trait):
        for trait, data in self._get_defaults_(trait):
            self.set_trait(trait)
            self.update(data)
Ejemplo n.º 3
0
class _ProfileEnvironment(Environment):
    def __init__(self, conn, profile):
        self.suite = get_suite(conn, profile)
        self.profile = profile
        Environment.__init__(self, conn, 'profile_variables', 'trait')
        self.traitparent = TraitParent(self.conn, self.suite)
        
    def set_trait(self, trait):
        self.set_main(trait)
        self.traitparent.set_trait(trait)
        
    def _single_clause_(self):
        return Eq('profile', self.profile) & Eq('trait', self.__main_value__)
    
    def __setitem__(self, key, value):
        try:
            self.cursor.insert(data={'profile' : self.profile,
                                     'trait' : self.__main_value__,
                                     self.__key_field__ : key,
                                     self.__value_field__ : value})
        except OperationalError:
            self.cursor.update(data={self.__value_field__ : value},
                               clause=self._double_clause_(key))
            
        
    def _make_superdict__orig_(self):
        clause = Eq('profile', self.profile)
        superdict = {}
        traits = [row.trait for row in self.cursor.select(fields=['trait'], clause=clause)]
        for trait in traits:
            self.set_trait(trait)
            items = [(trait + '_' + key, value) for key, value in self.items()]
            superdict.update(dict(items))
        return superdict

    def _make_superdict_(self):
        clause = Eq('profile', self.profile)
        return Environment._make_superdict_(self, clause)
    
    def _get_defaults_(self, trait):
        return self.traitparent.get_environment([trait])

    def _update_defaults_(self, trait):
        for trait, data in self._get_defaults_(trait):
            self.set_trait(trait)
            self.update(data)
Ejemplo n.º 4
0
class TemplateEnvironment(ScrolledWindow):
    def __init__(self, conn):
        ScrolledWindow.__init__(self)
        self.conn = conn
        self.editor = TemplateEditor()
        self.menu = SimpleMenu()
        self.editor.connect('populate-popup', self.populate_menu, self.menu)
        self.add_with_viewport(self.editor)
        self.show()

    def set_suite(self, suite):
        self.suite = suite
        self.__set_suitecursors__()

    def __set_suitecursors__(self):
        self.traitparent = TraitParent(self.conn, self.suite)
        self.traittemplate = TraitTemplate(self.conn, self.suite)
        self.traitpackage = TraitPackage(self.conn, self.suite)

    def set_trait(self, trait):
        self.trait = trait
        self.traitparent.set_trait(trait)
        self.traittemplate.set_trait(trait)
        self.traitpackage.set_trait(trait)
        self.__set_environment__()

    def __set_environment__(self):
        self.environ = dict(self.traitparent.get_environment([self.trait]))
        self.sections = dict([(k, v.keys()) for k, v in self.environ.items()])

    def populate_menu(self, widget, mainmenu, tmenu):
        self.__set_environment__()
        populate_menu(mainmenu, '_define_', ['_create_'], self.make_new_tag)
        for section, vars in self.sections.items():
            populate_menu(mainmenu, section, vars, self.make_tag)

    def make_tag(self, menuitem, name, parent):
        parentname = parent.get_name()
        tagname = ujoin(parentname, name)
        self.editor.make_tag(tagname)

    def make_new_tag(self, menuitem, name, parent):
        parentname = parent.get_name()
        if (parentname, name) == ('_define_', '_create_'):
            self.editor.create_new_tag(self.create_entry)

    def create_entry(self, *args):
        var = dict(self.editor.dialogs['create'].items())
        debug('var is %s' % var)
        self.environ[self.trait][var['name']] = var['value']
        tagname = ujoin(self.trait, var['name'])
        self.editor.make_tag(tagname)
        self.editor.destroy_dialog(self.editor.dialogs['create'])

    def preview(self, *args):
        subs = self.traitparent.get_superdict(self.environ.keys())
        self.editor.buffer.set_subs(subs)
        self.editor.preview(*args)

    def set_text(self, text):
        self.editor.buffer.set_text(text)

    def get_text(self):
        return self.editor.get_text()
Ejemplo n.º 5
0
class EnvironmentEditor(_EnvironmentEditor):
    def __init__(self, conn, suite, name='EnvironmentEditor'):
        self.menu = make_menu(['update', 'create'], self.env_command)
        _EnvironmentEditor.__init__(self, conn, name=name)
        self.suite = suite
        self.traitparent = TraitParent(self.conn, self.suite)
        self.current_trait = None
        self.reset_rows()
        w, h = map(
            int, config.get_list('env_editor_size', section='management_gui'))
        self.set_size_request(w, h)

    def reset_rows(self):
        rows = self.main.select(fields=['trait'],
                                table=ujoin(self.suite, 'traits'))
        self.set_rows(rows)
        self.set_row_select(self.trait_selected)

    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
        environ = TraitEnvironment(self.conn, self.suite, trait)
        self.environ = self.traitparent.get_environment([self.current_trait])
        self.sections = dict([(k, v.keys()) for k, v in self.environ])
        self.remove_page('Environment')
        self.record = RecordBox(environ, name=self.current_trait)
        self.append_page(self.record, 'Environment')
        self.pages['Environment'].connect('button_press_event',
                                          self.box_pressed)
        #self.menu.connect('populate', self.populate_menu, self.menu)
        self.record.connect_entries('populate-popup', self.populate_menu,
                                    self.menu)

    def make_new_variable(self, *args):
        d = self.dialogs['create']
        environ = TraitEnvironment(self.conn, self.suite, self.current_trait)
        environ.update(dict([(d['name'], d['value'])]))

    def remove_item(self, *args):
        d = self.dialogs['remove']
        name = d.get_selected_data()[0].name
        environ = TraitEnvironment(self.conn, self.suite, self.current_trait)
        del environ[name]
        dialogs.Message('%s deleted' % name)
        self.destroy_dialog(d)

    def update_environment(self):
        environ = TraitEnvironment(self.conn, self.suite, self.current_trait)
        environ.update(self.record)

    def env_command(self, menuitem, command):
        if command == 'update':
            dialogs.Message('updating %s' % self.current_trait)
            self.update_environment()
        elif command == 'create':
            self.ask_new_entry()
        else:
            dialogs.Message('ack')
Ejemplo n.º 6
0
class TemplateEnvironment(ScrolledWindow):
    def __init__(self, conn):
        ScrolledWindow.__init__(self)
        self.conn = conn
        self.editor = TemplateEditor()
        self.menu = SimpleMenu()
        self.editor.connect('populate-popup', self.populate_menu, self.menu)
        self.add_with_viewport(self.editor)
        self.show()
        
    def set_suite(self, suite):
        self.suite = suite
        self.__set_suitecursors__()

    def __set_suitecursors__(self):
        self.traitparent = TraitParent(self.conn, self.suite)
        self.traittemplate = TraitTemplate(self.conn, self.suite)
        self.traitpackage = TraitPackage(self.conn, self.suite)
        
    def set_trait(self, trait):
        self.trait = trait
        self.traitparent.set_trait(trait)
        self.traittemplate.set_trait(trait)
        self.traitpackage.set_trait(trait)
        self.__set_environment__()

    def __set_environment__(self):
        self.environ = dict(self.traitparent.get_environment([self.trait]))
        self.sections = dict([(k, v.keys()) for k,v in self.environ.items()])

    def populate_menu(self, widget, mainmenu, tmenu):
        self.__set_environment__()
        populate_menu(mainmenu, '_define_', ['_create_'], self.make_new_tag)
        for section, vars in self.sections.items():
            populate_menu(mainmenu, section, vars, self.make_tag)

    def make_tag(self, menuitem, name, parent):
        parentname = parent.get_name()
        tagname = ujoin(parentname, name)
        self.editor.make_tag(tagname)

    def make_new_tag(self, menuitem, name, parent):
        parentname = parent.get_name()
        if (parentname, name) == ('_define_', '_create_'):
            self.editor.create_new_tag(self.create_entry)
            
    def create_entry(self, *args):
        var = dict(self.editor.dialogs['create'].items())
        debug('var is %s' % var)
        self.environ[self.trait][var['name']] = var['value']
        tagname = ujoin(self.trait, var['name'])
        self.editor.make_tag(tagname)
        self.editor.destroy_dialog(self.editor.dialogs['create'])

    def preview(self, *args):
        subs = self.traitparent.get_superdict(self.environ.keys())
        self.editor.buffer.set_subs(subs)
        self.editor.preview(*args)

    def set_text(self, text):
        self.editor.buffer.set_text(text)

    def get_text(self):
        return self.editor.get_text()