예제 #1
0
    def init_treeview(self):
        '''
        initialize the gtk.TreeView
        '''
        self.treeview = self.view.widgets.sp_syn_treeview

        def _syn_data_func(column, cell, model, treeiter, data=None):
            v = model[treeiter][0]
            cell.set_property('text', str(v))
            # just added so change the background color to indicate it's new
            if not hasattr(v, 'id') or v.id is None:
                cell.set_property('foreground', 'blue')
            else:
                cell.set_property('foreground', None)

        col = self.view.widgets.syn_column
        col.set_cell_data_func(self.view.widgets.syn_cell, _syn_data_func)

        utils.clear_model(self.treeview)
        tree_model = gtk.ListStore(object)
        for syn in self.model._synonyms:
            tree_model.append([syn])
        self.treeview.set_model(tree_model)
        self.view.connect(self.treeview, 'cursor-changed',
                          self.on_tree_cursor_changed)
예제 #2
0
    def init_treeview(self):
        '''
        initialize the gtk.TreeView
        '''
        self.treeview = self.view.widgets.sp_syn_treeview

        def _syn_data_func(column, cell, model, treeiter, data=None):
            v = model[treeiter][0]
            cell.set_property('text', str(v))
            # just added so change the background color to indicate it's new
            if not hasattr(v, 'id') or v.id is None:
                cell.set_property('foreground', 'blue')
            else:
                cell.set_property('foreground', None)

        col = self.view.widgets.syn_column
        col.set_cell_data_func(self.view.widgets.syn_cell, _syn_data_func)

        utils.clear_model(self.treeview)
        tree_model = gtk.ListStore(object)
        for syn in self.model._synonyms:
            tree_model.append([syn])
        self.treeview.set_model(tree_model)
        self.view.connect(self.treeview, 'cursor-changed',
                          self.on_tree_cursor_changed)
예제 #3
0
 def idle_callback(values):
     completion = widget.get_completion()
     utils.clear_model(completion)
     completion_model = gtk.ListStore(object)
     for v in values:
         completion_model.append([v])
     completion.set_model(completion_model)
예제 #4
0
    def _populate_worker(self, results, check_for_kids=False):
        """
        Generator function for adding the search results to the
        model. This method is usually called by self.populate_results()
        """
        nresults = len(results)
        model = gtk.TreeStore(object)
        model.set_default_sort_func(lambda *args: -1)
        model.set_sort_column_id(-1, gtk.SORT_ASCENDING)
        utils.clear_model(self.results_view)

        groups = []

        # sort by type so that groupby works properly
        results = sorted(results, key=lambda x: type(x))

        for key, group in itertools.groupby(results, key=lambda x: type(x)):
            # return groups by type and natural sort each of the
            # groups by their strings
            groups.append(sorted(group, key=utils.natsort_key, reverse=True))

        # sort the groups by type so we more or less always get the
        # results by type in the same order
        groups = sorted(groups, key=lambda x: type(x[0]), reverse=True)

        chunk_size = 100
        update_every = 200
        steps_so_far = 0

        # iterate over slice of size "steps", yield after adding each
        # slice to the model
        #for obj in itertools.islice(itertools.chain(*groups), 0,None, steps):
        #for obj in itertools.islice(itertools.chain(results), 0,None, steps):

        added = set()
        for obj in itertools.chain(*groups):
            if obj in added:  # only add unique object
                continue
            else:
                added.add(obj)
            parent = model.prepend(None, [obj])
            obj_type = type(obj)
            if check_for_kids:
                kids = self.view_meta[obj_type].get_children(obj)
                if len(kids) > 0:
                    model.prepend(parent, ['-'])
            elif self.view_meta[obj_type].children is not None:
                model.prepend(parent, ['-'])
            #steps_so_far += chunk_size
            steps_so_far += 1
            if steps_so_far % update_every == 0:
                percent = float(steps_so_far)/float(nresults)
                if 0 < percent < 1.0:
                    bauble.gui.progressbar.set_fraction(percent)
                yield
        self.results_view.freeze_child_notify()
        self.results_view.set_model(model)
        self.results_view.thaw_child_notify()
예제 #5
0
    def _populate_worker(self, results, check_for_kids=False):
        """
        Generator function for adding the search results to the
        model. This method is usually called by self.populate_results()
        """
        nresults = len(results)
        model = gtk.TreeStore(object)
        model.set_default_sort_func(lambda *args: -1)
        model.set_sort_column_id(-1, gtk.SORT_ASCENDING)
        utils.clear_model(self.results_view)

        groups = []

        # sort by type so that groupby works properly
        results = sorted(results, key=lambda x: type(x))

        for key, group in itertools.groupby(results, key=lambda x: type(x)):
            # return groups by type and natural sort each of the
            # groups by their strings
            groups.append(sorted(group, key=utils.natsort_key, reverse=True))

        # sort the groups by type so we more or less always get the
        # results by type in the same order
        groups = sorted(groups, key=lambda x: type(x[0]), reverse=True)

        chunk_size = 100
        update_every = 200
        steps_so_far = 0

        # iterate over slice of size "steps", yield after adding each
        # slice to the model
        #for obj in itertools.islice(itertools.chain(*groups), 0,None, steps):
        #for obj in itertools.islice(itertools.chain(results), 0,None, steps):

        added = set()
        for obj in itertools.chain(*groups):
            if obj in added:  # only add unique object
                continue
            else:
                added.add(obj)
            parent = model.prepend(None, [obj])
            obj_type = type(obj)
            if check_for_kids:
                kids = self.view_meta[obj_type].get_children(obj)
                if len(kids) > 0:
                    model.prepend(parent, ['-'])
            elif self.view_meta[obj_type].children is not None:
                model.prepend(parent, ['-'])
            #steps_so_far += chunk_size
            steps_so_far += 1
            if steps_so_far % update_every == 0:
                percent = float(steps_so_far) / float(nresults)
                if 0 < percent < 1.0:
                    bauble.gui.progressbar.set_fraction(percent)
                yield
        self.results_view.freeze_child_notify()
        self.results_view.set_model(model)
        self.results_view.thaw_child_notify()
예제 #6
0
 def on_table_combo_changed(self, combo, *args):
     """
     Change the table to use for the query
     """
     utils.clear_model(self.prop_tree)
     it = combo.get_active_iter()
     domain = combo.props.model[it][0]
     mapper = class_mapper(self.domain_map[domain])
     model = gtk.TreeStore(str, object)
     root = model.get_iter_root()
     self._insert_props(mapper, model, root)
     self.prop_tree.props.model = model
예제 #7
0
 def on_select(value):
     # populate the propagation browser
     treeview = self.view.widgets.source_prop_treeview
     if not value:
         treeview.props.sensitive = False
         return
     utils.clear_model(treeview)
     model = gtk.ListStore(object)
     for propagation in value.propagations:
         model.append([propagation])
     treeview.set_model(model)
     treeview.props.sensitive = True
예제 #8
0
 def on_table_combo_changed(self, combo, *args):
     """
     Change the table to use for the query
     """
     utils.clear_model(self.prop_tree)
     it = combo.get_active_iter()
     domain = combo.props.model[it][0]
     mapper = class_mapper(self.domain_map[domain])
     model = gtk.TreeStore(str, object)
     root = model.get_iter_root()
     self._insert_props(mapper, model, root)
     self.prop_tree.props.model = model
예제 #9
0
 def on_select(value):
     # populate the propagation browser
     treeview = self.view.widgets.source_prop_treeview
     if not value:
         treeview.props.sensitive = False
         return
     utils.clear_model(treeview)
     model = gtk.ListStore(object)
     for propagation in value.propagations:
         model.append([propagation])
     treeview.set_model(model)
     treeview.props.sensitive = True
예제 #10
0
 def populate_history(self, arg):
     """
     Add the history items to the view.
     """
     session = db.Session()
     utils.clear_model(self.treeview)
     model = gtk.ListStore(str, str, str, str, str)
     for item in session.query(db.History).\
             order_by(db.History.timestamp.desc()).all():
         model.append([item.timestamp, item.operation, item.user,
                       item.tablename, item.values])
     self.treeview.set_model(model)
     session.close()
예제 #11
0
 def on_select(value):
     logger.debug('on select: %s' % value)
     if isinstance(value, StringTypes):
         return
     # populate the propagation browser
     treeview = self.view.widgets.source_prop_treeview
     if not value:
         treeview.props.sensitive = False
         return
     utils.clear_model(treeview)
     model = gtk.ListStore(object)
     for propagation in value.propagations:
         model.append([propagation])
     treeview.set_model(model)
     treeview.props.sensitive = True
예제 #12
0
 def on_select(value):
     logger.debug('on select: %s' % value)
     if isinstance(value, StringTypes):
         return
     # populate the propagation browser
     treeview = self.view.widgets.source_prop_treeview
     if not value:
         treeview.props.sensitive = False
         return
     utils.clear_model(treeview)
     model = gtk.ListStore(object)
     for propagation in value.propagations:
         model.append([propagation])
     treeview.set_model(model)
     treeview.props.sensitive = True
예제 #13
0
 def populate_history(self, arg):
     """
     Add the history items to the view.
     """
     session = db.Session()
     utils.clear_model(self.treeview)
     model = gtk.ListStore(str, str, str, str, str)
     for item in session.query(db.History).\
             order_by(db.History.timestamp.desc()).all():
         model.append([
             item.timestamp, item.operation, item.user, item.tablename,
             item.values
         ])
     self.treeview.set_model(model)
     session.close()
예제 #14
0
    def populate_users_tree(self, only_bauble=True):
        """
        Populate the users tree with the users from the database.

        Arguments:
        - `only_bauble`: Show only those users with at least read
          permissions on the database.
        """
        tree = self.widgets.users_tree
        utils.clear_model(tree)
        model = gtk.ListStore(str)
        for user in get_users():
            if only_bauble and has_privileges(user, "read"):
                model.append([user])
            elif not only_bauble:
                model.append([user])
        tree.set_model(model)
        if len(model) > 0:
            tree.set_cursor("0")
예제 #15
0
 def on_response(button, response):
     self.view.widgets.remove_parent(box)
     box.destroy()
     if response:
         # populate the completions model on the entry so
         # when we set the text it will match the
         # completion and set the value
         completion = self.view.widgets.gen_family_entry.\
             get_completion()
         utils.clear_model(completion)
         model = gtk.ListStore(object)
         model.append([syn.family])
         completion.set_model(model)
         self.view.widgets.gen_family_entry.\
             set_text(utils.utf8(syn.family))
         # the family value should be set properly when the
         # text is set on the entry but it doesn't hurt to
         # duplicate it here
         self.set_model_attr('family', syn.family)
예제 #16
0
    def populate_users_tree(self, only_bauble=True):
        """
        Populate the users tree with the users from the database.

        Arguments:
        - `only_bauble`: Show only those users with at least read
          permissions on the database.
        """
        tree = self.widgets.users_tree
        utils.clear_model(tree)
        model = gtk.ListStore(str)
        for user in get_users():
            if only_bauble and has_privileges(user, 'read'):
                model.append([user])
            elif not only_bauble:
                model.append([user])
        tree.set_model(model)
        if len(model) > 0:
            tree.set_cursor('0')
예제 #17
0
 def on_response(button, response):
     self.view.widgets.remove_parent(box)
     box.destroy()
     if response:
         # populate the completions model on the entry so
         # when we set the text it will match the
         # completion and set the value
         completion = self.view.widgets.gen_family_entry.\
             get_completion()
         utils.clear_model(completion)
         model = gtk.ListStore(object)
         model.append([syn.family])
         completion.set_model(model)
         self.view.widgets.gen_family_entry.\
             set_text(utils.utf8(syn.family))
         # the family value should be set properly when the
         # text is set on the entry but it doesn't hurt to
         # duplicate it here
         self.set_model_attr('family', syn.family)
예제 #18
0
 def populate_names_combo(self):
     '''
     populates the combo with the list of configuration names
     from the prefs
     '''
     configs = prefs[config_list_pref]
     combo = self.view.widgets.names_combo
     if configs is None:
         self.view.set_sensitive('details_box', False)
         utils.clear_model(combo)
         return
     try:
         model = gtk.ListStore(str)
         for cfg in configs.keys():
             model.append([cfg])
         combo.set_model(model)
     except AttributeError, e:
         # no formatters
         logger.debug(e)
         pass
예제 #19
0
 def populate_names_combo(self):
     '''
     populates the combo with the list of configuration names
     from the prefs
     '''
     configs = prefs[config_list_pref]
     combo = self.view.widgets.names_combo
     if configs is None:
         self.view.widgets.details_box.set_sensitive(False)
         utils.clear_model(combo)
         return
     try:
         model = gtk.ListStore(str)
         for cfg in configs.keys():
             model.append([cfg])
         combo.set_model(model)
     except AttributeError, e:
         # no formatters
         debug(e)
         pass
예제 #20
0
    def refresh_view(self):
        treeview = self.view.widgets.source_prop_treeview
        if not self.model.plant_propagation:
            self.view.widgets.source_prop_plant_entry.props.text = ""
            utils.clear_model(treeview)
            treeview.props.sensitive = False
            return

        parent_plant = self.model.plant_propagation.plant
        # set the parent accession
        self.view.widgets.source_prop_plant_entry.props.text = str(parent_plant)

        if not parent_plant.propagations:
            treeview.props.sensitive = False
            return
        utils.clear_model(treeview)
        model = gtk.ListStore(object)
        for propagation in parent_plant.propagations:
            model.append([propagation])
        treeview.set_model(model)
        treeview.props.sensitive = True
예제 #21
0
    def refresh_view(self):
        treeview = self.view.widgets.source_prop_treeview
        if not self.model.plant_propagation:
            self.view.widgets.source_prop_plant_entry.props.text = ''
            utils.clear_model(treeview)
            treeview.props.sensitive = False
            return

        parent_plant = self.model.plant_propagation.plant
        # set the parent accession
        self.view.widgets.source_prop_plant_entry.props.text = str(
            parent_plant)

        if not parent_plant.propagations:
            treeview.props.sensitive = False
            return
        utils.clear_model(treeview)
        model = gtk.ListStore(object)
        for propagation in parent_plant.propagations:
            model.append([propagation])
        treeview.set_model(model)
        treeview.props.sensitive = True
예제 #22
0
def populate_iconview(gd_client, iconview, tag):
    """
    Get the photos with tag from the PicasaWeb or from the photo cache
    and populate the iconview.

    :param gd_client:
    :param iconview:
    :param tag:
    """
    global iconview_worker
    if iconview_worker:
        iconview_worker.cancel()

    utils.clear_model(iconview)
    model = gtk.ListStore(gtk.gdk.Pixbuf)
    iconview.set_model(model)

    cache = PhotoCache(create=True)  # creates the cache if it doesn't exists

    iconview_worker = thread.GtkWorker(_get_feed_worker, gd_client, tag)
    iconview_worker.connect('published', _on_get_feed_publish, iconview)
    iconview_worker.execute()
    return iconview_worker
예제 #23
0
def populate_iconview(gd_client, iconview, tag):
    """
    Get the photos with tag from the PicasaWeb or from the photo cache
    and populate the iconview.

    :param gd_client:
    :param iconview:
    :param tag:
    """
    global iconview_worker
    if iconview_worker:
        iconview_worker.cancel()

    utils.clear_model(iconview)
    model = gtk.ListStore(gtk.gdk.Pixbuf)
    iconview.set_model(model)

    cache = PhotoCache(create=True) # creates the cache if it doesn't exists

    iconview_worker = thread.GtkWorker(_get_feed_worker, gd_client, tag)
    iconview_worker.connect('published', _on_get_feed_publish, iconview)
    iconview_worker.execute()
    return iconview_worker
예제 #24
0
class VernacularNamePresenter(editor.GenericEditorPresenter):
    # TODO: change the background of the entries and desensitize the
    # name/lang entries if the name conflicts with an existing vernacular
    # name for this species
    """
    in the VernacularNamePresenter we don't really use self.model, we
    more rely on the model in the TreeView which are VernacularName
    objects
    """
    def __init__(self, parent):
        '''
        :param parent: the parent SpeciesEditorPresenter
        '''
        super(VernacularNamePresenter, self).__init__(parent.model,
                                                      parent.view)
        self.parent_ref = weakref.ref(parent)
        self.session = parent.session
        self._dirty = False
        self.init_treeview(self.model.vernacular_names)
        self.view.connect('sp_vern_add_button', 'clicked',
                          self.on_add_button_clicked)
        self.view.connect('sp_vern_remove_button', 'clicked',
                          self.on_remove_button_clicked)

    def is_dirty(self):
        """
        @return True or False if the vernacular names have changed.
        """
        return self._dirty

    def on_add_button_clicked(self, button, data=None):
        """
        Add the values in the entries to the model.
        """
        treemodel = self.treeview.get_model()
        column = self.treeview.get_column(0)
        vn = VernacularName()
        self.model.vernacular_names.append(vn)
        treeiter = treemodel.append([vn])
        path = treemodel.get_path(treeiter)
        self.treeview.set_cursor(path, column, start_editing=True)
        if len(treemodel) == 1:
            #self.set_model_attr('default_vernacular_name', vn)
            self.model.default_vernacular_name = vn

    def on_remove_button_clicked(self, button, data=None):
        """
        Removes the currently selected vernacular name from the view.
        """
        tree = self.view.widgets.vern_treeview
        path, col = tree.get_cursor()
        treemodel = tree.get_model()
        vn = treemodel[path][0]

        msg = _('Are you sure you want to remove the vernacular '
                'name <b>%s</b>?') % utils.xml_safe(vn.name)
        if vn.name and not vn in self.session.new and not \
                utils.yes_no_dialog(msg, parent=self.view.get_window()):
            return

        treemodel.remove(treemodel.get_iter(path))
        self.model.vernacular_names.remove(vn)
        utils.delete_or_expunge(vn)
        if not self.model.default_vernacular_name:
            # if there is only one value in the tree then set it as the
            # default vernacular name
            first = treemodel.get_iter_first()
            if first:
                #                 self.set_model_attr('default_vernacular_name',
                #                                     tree_model[first][0])
                self.model.default_vernacular_name = treemodel[first][0]
        self.parent_ref().refresh_sensitivity()
        self._dirty = True

    def on_default_toggled(self, cell, path, data=None):
        """
        Default column callback.
        """
        active = cell.get_active()
        if not active:  # then it's becoming active
            vn = self.treeview.get_model()[path][0]
            self.set_model_attr('default_vernacular_name', vn)
        self._dirty = True
        self.parent_ref().refresh_sensitivity()

    def on_cell_edited(self, cell, path, new_text, prop):
        treemodel = self.treeview.get_model()
        vn = treemodel[path][0]
        if getattr(vn, prop) == new_text:
            return  # didn't change
        setattr(vn, prop, utils.utf8(new_text))
        self._dirty = True
        self.parent_ref().refresh_sensitivity()

    def init_treeview(self, model):
        """
        Initialized the list of vernacular names.

        The columns and cell renderers are loaded from the .glade file
        so we just need to customize them a bit.
        """
        self.treeview = self.view.widgets.vern_treeview
        if not isinstance(self.treeview, gtk.TreeView):
            return

        def _name_data_func(column, cell, model, treeiter, data=None):
            v = model[treeiter][0]
            cell.set_property('text', v.name)
            # just added so change the background color to indicate it's new
            #            if not v.isinstance:
            if v.id is None:  # hasn't been committed
                cell.set_property('foreground', 'blue')
            else:
                cell.set_property('foreground', None)

        column = self.view.widgets.vn_name_column
        #column.set_sizing(gtk.TREE_VIEW_COLUMN_AUTOSIZE)
        cell = self.view.widgets.vn_name_cell
        self.view.widgets.vn_name_column.\
            set_cell_data_func(cell, _name_data_func)
        self.view.connect(cell, 'edited', self.on_cell_edited, 'name')

        def _lang_data_func(column, cell, model, treeiter, data=None):
            v = model[treeiter][0]
            cell.set_property('text', v.language)
            # just added so change the background color to indicate it's new
            #if not v.isinstance:`
            if v.id is None:  # hasn't been committed
                cell.set_property('foreground', 'blue')
            else:
                cell.set_property('foreground', None)

        cell = self.view.widgets.vn_lang_cell
        self.view.widgets.vn_lang_column.\
            set_cell_data_func(cell, _lang_data_func)
        self.view.connect(cell, 'edited', self.on_cell_edited, 'language')

        def _default_data_func(column, cell, model, iter, data=None):
            v = model[iter][0]
            try:
                cell.set_property('active',
                                  v == self.model.default_vernacular_name)
                return
            except AttributeError, e:
                logger.debug("AttributeError %s" % e)
                pass
            cell.set_property('active', False)

        cell = self.view.widgets.vn_default_cell
        self.view.widgets.vn_default_column.\
            set_cell_data_func(cell, _default_data_func)
        self.view.connect(cell, 'toggled', self.on_default_toggled)

        utils.clear_model(self.treeview)

        # add the vernacular names to the tree
        tree_model = gtk.ListStore(object)
        for vn in model:
            tree_model.append([vn])
        self.treeview.set_model(tree_model)

        self.view.connect(self.treeview, 'cursor-changed',
                          self.on_tree_cursor_changed)
예제 #25
0
        results = []
        try:
            results = search.search(text, self.session)
        except ParseException, err:
            error_msg = _('Error in search string at column %s') % err.column
        except (BaubleError, AttributeError, Exception, SyntaxError), e:
            logger.debug(traceback.format_exc())
            error_msg = _('** Error: %s') % utils.xml_safe(e)
            error_details_msg = utils.xml_safe(traceback.format_exc())

        if error_msg:
            bauble.gui.show_error_box(error_msg, error_details_msg)
            return

        # not error
        utils.clear_model(self.results_view)
        self.update_infobox()
        statusbar = bauble.gui.widgets.statusbar
        sbcontext_id = statusbar.get_context_id('searchview.nresults')
        statusbar.pop(sbcontext_id)
        if len(results) == 0:
            model = gtk.ListStore(str)
            msg = bold % cgi.escape(
                _('Couldn\'t find anything for search: "%s"') % text)
            model.append([msg])
            self.results_view.set_model(model)
        else:
            if len(results) > 5000:
                msg = _('This query returned %s results.  It may take a '
                        'long time to get all the data. Are you sure you '
                        'want to continue?') % len(results)
예제 #26
0
        results = []
        try:
            results = search.search(text, self.session)
        except ParseException, err:
            error_msg = _('Error in search string at column %s') % err.column
        except (BaubleError, AttributeError, Exception, SyntaxError), e:
            logger.debug(traceback.format_exc())
            error_msg = _('** Error: %s') % utils.xml_safe(e)
            error_details_msg = utils.xml_safe(traceback.format_exc())

        if error_msg:
            bauble.gui.show_error_box(error_msg, error_details_msg)
            return

        # not error
        utils.clear_model(self.results_view)
        self.update_infobox()
        statusbar = bauble.gui.widgets.statusbar
        sbcontext_id = statusbar.get_context_id('searchview.nresults')
        statusbar.pop(sbcontext_id)
        if len(results) == 0:
            model = gtk.ListStore(str)
            msg = bold % cgi.escape(
                _('Couldn\'t find anything for search: "%s"') % text)
            model.append([msg])
            self.results_view.set_model(model)
        else:
            if len(results) > 5000:
                msg = _('This query returned %s results.  It may take a '
                        'long time to get all the data. Are you sure you '
                        'want to continue?') % len(results)