Exemplo n.º 1
0
    def __init__(self, db, scol=0, order=Gtk.SortType.ASCENDING,
                 search=None, skip=set(),
                 sort_map=None):
        cput = time.clock()
        super(FlatBaseModel, self).__init__()
        #inheriting classes must set self.map to obtain the data
        self.prev_handle = None
        self.prev_data = None

        #GTK3 We leak ref, yes??
        #self.set_property("leak_references", False)

        self.db = db
        #normally sort on first column, so scol=0
        if sort_map:
            #sort_map is the stored order of the columns and if they are
            #enabled or not. We need to store on scol of that map
            self.sort_map = [ f for f in sort_map if f[0]]
            #we need the model col, that corresponds with scol
            col = self.sort_map[scol][1]
        else:
            col = scol
        self.sort_func = lambda x: glocale.sort_key(self.smap[col](x))
        self.sort_col = scol
        self.skip = skip
        self._in_build = False

        self.node_map = FlatNodeMap()
        self.set_search(search)
            
        self._reverse = (order == Gtk.SortType.DESCENDING)

        self.rebuild_data()
        _LOG.debug(self.__class__.__name__ + ' __init__ ' +
                    str(time.clock() - cput) + ' sec')
Exemplo n.º 2
0
 def __init__(self, ref, parent, sortkey, handle, secondary):
     if sortkey:
         self.name = sortkey
         #sortkey must be localized sort, so
         self.sortkey = glocale.sort_key(sortkey)
         if not self.sortkey:
             self.sortkey = glocale.sort_key('')
     else:
         self.name = ''
         self.sortkey = glocale.sort_key('')
     self.ref = ref
     self.handle = handle
     self.secondary = secondary
     self.parent = parent
     self.prev = None
     self.next = None
     self.children = []
Exemplo n.º 3
0
 def __init__(self, ref, parent, sortkey, handle, secondary):
     if sortkey:
         self.name = sortkey
         #sortkey must be localized sort, so
         self.sortkey = glocale.sort_key(sortkey)
         if not self.sortkey:
             self.sortkey = glocale.sort_key('')
     else:
         self.name = ''
         self.sortkey = glocale.sort_key('')
     self.ref = ref
     self.handle = handle
     self.secondary = secondary
     self.parent = parent
     self.prev = None
     self.next = None
     self.children = []
Exemplo n.º 4
0
    def build_columns(self):
        #first the standard text columns with normal method
        EmbeddedList.build_columns(self)

        # now we add the two special columns
        # combobox for type
        colno = len(self.columns)
        name = self._column_combo[0]
        renderer = Gtk.CellRendererCombo()
        renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
        # set up the comboentry editable
        no = NameOriginType()
        self.cmborig = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
        self.cmborigmap = no.get_map().copy()
        #sort the keys based on the value
        keys = sorted(self.cmborigmap,
                      key=lambda x: glocale.sort_key(self.cmborigmap[x]))
        for key in keys:
            if key != no.get_custom():
                self.cmborig.append(row=[key, self.cmborigmap[key]])
        additional = self.dbstate.db.get_origin_types()
        if additional:
            for type in additional:
                if type:
                    self.cmborig.append(row=[no.get_custom(), type])
        renderer.set_property("model", self.cmborig)
        renderer.set_property("text-column", 1)
        renderer.set_property('editable', not self.dbstate.db.readonly)

        renderer.connect('editing_started', self.on_edit_start_cmb, colno)
        renderer.connect('edited', self.on_orig_edited, self._column_combo[3])
        # add to treeview
        column = Gtk.TreeViewColumn(name, renderer, text=self._column_combo[3])
        column.set_resizable(True)
        column.set_sort_column_id(self._column_combo[1])
        column.set_min_width(self._column_combo[2])
        column.set_expand(False)
        self.columns.append(column)
        self.tree.append_column(column)
        # toggle box for primary
        colno += 1
        name = self._column_toggle[0]
        renderer = Gtk.CellRendererToggle()
        renderer.set_property('activatable', True)
        renderer.set_property('radio', True)
        renderer.connect('toggled', self.on_prim_toggled,
                         self._column_toggle[3])
        # add to treeview
        column = Gtk.TreeViewColumn(name,
                                    renderer,
                                    active=self._column_toggle[3])
        column.set_resizable(False)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        column.set_alignment(0.5)
        column.set_sort_column_id(self._column_toggle[1])
        column.set_max_width(self._column_toggle[2])
        self.columns.append(column)
        self.tree.append_column(column)
Exemplo n.º 5
0
    def build_columns(self):
        #first the standard text columns with normal method
        EmbeddedList.build_columns(self)

        # now we add the two special columns
        # combobox for type
        colno = len(self.columns)
        name = self._column_combo[0]
        renderer = Gtk.CellRendererCombo()
        renderer.set_property('ellipsize', Pango.EllipsizeMode.END)
        # set up the comboentry editable
        no = NameOriginType()
        self.cmborig = Gtk.ListStore(GObject.TYPE_INT, GObject.TYPE_STRING)
        self.cmborigmap = no.get_map().copy()
        #sort the keys based on the value
        keys = sorted(self.cmborigmap, key=lambda x: glocale.sort_key(self.cmborigmap[x]))
        for key in keys:
            if key != no.get_custom():
                self.cmborig.append(row=[key, self.cmborigmap[key]])
        additional = self.dbstate.db.get_origin_types()
        if additional:
            for type in additional:
                if type:
                    self.cmborig.append(row=[no.get_custom(), type])
        renderer.set_property("model", self.cmborig)
        renderer.set_property("text-column", 1)
        renderer.set_property('editable', not self.dbstate.db.readonly)

        renderer.connect('editing_started', self.on_edit_start_cmb, colno)
        renderer.connect('edited', self.on_orig_edited, self._column_combo[3])
        # add to treeview
        column = Gtk.TreeViewColumn(name, renderer, text=self._column_combo[3])
        column.set_resizable(True)
        column.set_sort_column_id(self._column_combo[1])
        column.set_min_width(self._column_combo[2])
        column.set_expand(False)
        self.columns.append(column)
        self.tree.append_column(column)
        # toggle box for primary
        colno += 1
        name = self._column_toggle[0]
        renderer = Gtk.CellRendererToggle()
        renderer.set_property('activatable', True)
        renderer.set_property('radio', True)
        renderer.connect( 'toggled', self.on_prim_toggled, self._column_toggle[3])
        # add to treeview
        column = Gtk.TreeViewColumn(name, renderer, active=self._column_toggle[3])
        column.set_resizable(False)
        column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
        column.set_alignment(0.5)
        column.set_sort_column_id(self._column_toggle[1])
        column.set_max_width(self._column_toggle[2])
        self.columns.append(column)
        self.tree.append_column(column)
Exemplo n.º 6
0
    def search_iter_sorted_column_flat(self, selection, cur_iter, text, count,
                                       n):
        """
        Search among the currently set search-column for a cell starting with
        text
        It assumes that this column is currently sorted, and as 
        a LIST_ONLY view it therefore contains index2hndl = model.node_map._index2hndl
        which is a _sorted_ list of (sortkey, handle) tuples
        """
        model = self._treeview.get_model()
        search_column = self._treeview.get_search_column()
        is_tree = not (model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY)

        # If there is a sort_key index, let's use it
        if not is_tree and hasattr(model, "node_map"):
            import bisect
            index2hndl = model.node_map._index2hndl

            # create lookup key from the appropriate sort_func
            # TODO: explicitely announce the data->sortkey func in models
            # sort_key = model.sort_func(text)
            sort_key = glocale.sort_key(text.lower())
            srtkey_hndl = (sort_key, None)
            lo_bound = 0  # model.get_path(cur_iter)
            found_index = bisect.bisect_left(index2hndl,
                                             srtkey_hndl,
                                             lo=lo_bound)
            # if insert position is at tail, no match
            if found_index == len(index2hndl):
                return False
            srt_key, hndl = index2hndl[found_index]
            # Check if insert position match for real
            # (as insert position might not start with the text)
            if not model[found_index][search_column].lower().startswith(
                    text.lower()):
                return False
            found_path = Gtk.TreePath(
                (model.node_map.real_path(found_index), ))
            self._treeview.scroll_to_cell(found_path, None, 1, 0.5, 0)
            selection.select_path(found_path)
            self._treeview.set_cursor(found_path)
            return True
        return False
Exemplo n.º 7
0
    def search_iter_sorted_column_flat(self, selection, cur_iter, text,
                                       count, n):
        """
        Search among the currently set search-column for a cell starting with
        text
        It assumes that this column is currently sorted, and as
        a LIST_ONLY view it therefore contains index2hndl = model.node_map._index2hndl
        which is a _sorted_ list of (sortkey, handle) tuples
        """
        model = self._treeview.get_model()
        search_column = self._treeview.get_search_column()
        is_tree = not (model.get_flags() & Gtk.TreeModelFlags.LIST_ONLY)

        # If there is a sort_key index, let's use it
        if not is_tree and hasattr(model, "node_map"):
            import bisect
            index2hndl = model.node_map._index2hndl

            # create lookup key from the appropriate sort_func
            # TODO: explicitely announce the data->sortkey func in models
            # sort_key = model.sort_func(text)
            sort_key = glocale.sort_key(text.lower())
            srtkey_hndl = (sort_key, "")
            lo_bound = 0  # model.get_path(cur_iter)
            found_index = bisect.bisect_left(index2hndl, srtkey_hndl, lo=lo_bound)
            # if insert position is at tail, no match
            if found_index == len(index2hndl):
                return False
            srt_key, hndl = index2hndl[found_index]
            # Check if insert position match for real
            # (as insert position might not start with the text)
            if not model[found_index][search_column].lower().startswith(text.lower()):
                return False
            found_path = Gtk.TreePath((model.node_map.real_path(found_index),))
            self._treeview.scroll_to_cell(found_path, None, 1, 0.5, 0)
            selection.select_path(found_path)
            self._treeview.set_cursor(found_path)
            return True
        return False
Exemplo n.º 8
0
    def __init__(self, db, uistate, track, handle_list, filtname, namespace):

        ManagedWindow.__init__(self, uistate, track, self)

        self.db = db
        self.filtname = filtname
        self.namespace = namespace
        self.define_glade('test', RULE_GLADE,)
        self.set_window(
            self.get_widget('test'),
            self.get_widget('test_title'),
            _('Filter Test'))
        self.setup_configs('interface.showresults', 450, 400)

        render = Gtk.CellRendererText()

        tree = self.get_widget('list')
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        tree.set_model(model)

        column_n = Gtk.TreeViewColumn(_('Name'), render, text=0)
        tree.append_column(column_n)

        column_n = Gtk.TreeViewColumn(_('ID'), render, text=1)
        tree.append_column(column_n)

        self.get_widget('test_close').connect('clicked', self.close)

        new_list = sorted(
                        (self.sort_val_from_handle(h) for h in handle_list),
                        key=lambda x: glocale.sort_key(x[0])
                        )

        for s_, handle in new_list:
            name, gid = self.get_name_id(handle)
            model.append(row=[name, gid])

        self.show()
Exemplo n.º 9
0
    def __init__(self, db, uistate, track, handle_list, filtname, namespace):

        ManagedWindow.__init__(self, uistate, track, self)

        self.db = db
        self.filtname = filtname
        self.namespace = namespace
        self.define_glade('test', RULE_GLADE,)
        self.set_window(
            self.get_widget('test'),
            self.get_widget('test_title'),
            _('Filter Test'))
        self.setup_configs('interface.showresults', 450, 400)

        render = Gtk.CellRendererText()

        tree = self.get_widget('list')
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING)
        tree.set_model(model)

        column_n = Gtk.TreeViewColumn(_('Name'), render, text=0)
        tree.append_column(column_n)

        column_n = Gtk.TreeViewColumn(_('ID'), render, text=1)
        tree.append_column(column_n)

        self.get_widget('test_close').connect('clicked', self.close)

        new_list = sorted(
                        (self.sort_val_from_handle(h) for h in handle_list),
                        key=lambda x: glocale.sort_key(x[0])
                        )

        for s_, handle in new_list:
            name, gid = self.get_name_id(handle)
            model.append(row=[name, gid])

        self.show()
Exemplo n.º 10
0
    def __init__(self, db, uistate, scol=0, order=Gtk.SortType.ASCENDING,
                 search=None, skip=set(),
                 sort_map=None):
        cput = time.clock()
        GObject.GObject.__init__(self)
        BaseModel.__init__(self)
        #inheriting classes must set self.map to obtain the data
        self.prev_handle = None
        self.prev_data = None

        #GTK3 We leak ref, yes??
        #self.set_property("leak_references", False)

        self.db = db
        #normally sort on first column, so scol=0
        if sort_map:
            #sort_map is the stored order of the columns and if they are
            #enabled or not. We need to store on scol of that map
            self.sort_map = [ f for f in sort_map if f[0]]
            #we need the model col, that corresponds with scol
            col = self.sort_map[scol][1]
        else:
            col = scol
        # get the function that maps data to sort_keys
        self.sort_func = lambda x: glocale.sort_key(self.smap[col](x))
        self.sort_col = scol
        self.skip = skip
        self._in_build = False

        self.node_map = FlatNodeMap()
        self.set_search(search)

        self._reverse = (order == Gtk.SortType.DESCENDING)

        self.rebuild_data()
        _LOG.debug(self.__class__.__name__ + ' __init__ ' +
                    str(time.clock() - cput) + ' sec')
Exemplo n.º 11
0
 def by_value(self, val):
     """
     Method for sorting keys based on the values.
     """
     return glocale.sort_key(self.mapping[val])
Exemplo n.º 12
0
 def __by_value_key(self, first):
     """
     Method for sorting keys based on the values.
     """
     return glocale.sort_key(self.mapping[first])
Exemplo n.º 13
0
    def __init__(self, dbstate, uistate, track, handle_list, filtname, namespace):
        ManagedWindow.__init__(self, uistate, track, self)

        self.dbstate = dbstate
        self.db = dbstate.db
        self.filtname = filtname
        self.namespace = namespace
        self.category_info = get_category_info(self.db, namespace)
        glade = Glade(toplevel='test')

        test_title = glade.get_child_object('test_title')
        title = "{namespace}: {filtname} ({n} {objects})".format(
            namespace=_(namespace),
            filtname=filtname,
            objects=_("objects"),
            n=len(handle_list))
        test_title.set_label(title)

        self.set_window(
            glade.get_child_object('test'),
            None,
            _('Filter Test'))

        render = Gtk.CellRendererText()

        self.treeview = glade.get_child_object('list')
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_STRING, object)
        self.treeview.set_model(model)

        col = Gtk.TreeViewColumn(_('ID'), render, text=0)
        col.set_clickable(True)
        col.set_resizable(True)
        col.set_sort_column_id(0)
        self.treeview.append_column(col)

        if self.namespace == "Event":
            col = Gtk.TreeViewColumn(_('Type'), render, text=1)
            col.set_clickable(True)
            col.set_resizable(True)
            col.set_sort_column_id(1)
            self.treeview.append_column(col)

            col = Gtk.TreeViewColumn(_('Description'), render, text=2)
            col.set_clickable(True)
            col.set_resizable(True)
            col.set_sort_column_id(3)
            self.treeview.append_column(col)
        elif self.namespace == "Citation":
            col = Gtk.TreeViewColumn(_('Page'), render, text=1)
            col.set_clickable(True)
            col.set_resizable(True)
            col.set_sort_column_id(1)
            self.treeview.append_column(col)

            col = Gtk.TreeViewColumn(_('Source'), render, text=2)
            col.set_clickable(True)
            col.set_resizable(True)
            col.set_sort_column_id(3)
            self.treeview.append_column(col)
        else:
            col = Gtk.TreeViewColumn(_('Name'), render, text=1)
            col.set_clickable(True)
            col.set_resizable(True)
            col.set_sort_column_id(1)
            self.treeview.append_column(col)

        self.treeview.connect("button-press-event", self.button_press)

        glade.get_child_object('test_close').connect('clicked', self.close)
        glade.get_child_object('open_button').connect('clicked', self.open_object)

        new_list = sorted(
                        (self.sort_val_from_handle(h) for h in handle_list),
                        key=lambda x: glocale.sort_key(x[0])
                        )

        for s_, handle in new_list:
            gid, name, name2, obj = self.get_obj(handle)
            model.append(row=[gid, name, name2, obj])

        glade.get_child_object('open_button').set_sensitive(len(new_list) > 0)
        self.show()
Exemplo n.º 14
0
    def add_menu_options(self, menu):
        """
        Add options to the menu for the statistics report.
        """

        ################################
        category_name = _("Report Options")
        add_option = partial(menu.add_option, category_name)
        ################################

        self.__filter = FilterOption(_("Filter"), 0)
        self.__filter.set_help(_("Determines what people are included "
                                 "in the report."))
        add_option("filter", self.__filter)
        self.__filter.connect('value-changed', self.__filter_changed)

        self.__pid = PersonOption(_("Filter Person"))
        self.__pid.set_help(_("The center person for the filter."))
        menu.add_option(category_name, "pid", self.__pid)
        self.__pid.connect('value-changed', self.__update_filters)

        sortby = EnumeratedListOption(_('Sort chart items by'),
                                      _options.SORT_VALUE)
        for item_idx in range(len(_options.opt_sorts)):
            item = _options.opt_sorts[item_idx]
            sortby.add_item(item_idx, item[2])
        sortby.set_help(_("Select how the statistical data is sorted."))
        add_option("sortby", sortby)

        reverse = BooleanOption(_("Sort in reverse order"), False)
        reverse.set_help(_("Check to reverse the sorting order."))
        add_option("reverse", reverse)

        this_year = time.localtime()[0]
        year_from = NumberOption(_("People Born After"),
                                 1700, 1, this_year)
        year_from.set_help(_("Birth year from which to include people."))
        add_option("year_from", year_from)

        year_to = NumberOption(_("People Born Before"),
                               this_year, 1, this_year)
        year_to.set_help(_("Birth year until which to include people"))
        add_option("year_to", year_to)

        no_years = BooleanOption(_("Include people without known birth years"),
                                 False)
        no_years.set_help(_("Whether to include people without "
                            "known birth years."))
        add_option("no_years", no_years)

        gender = EnumeratedListOption(_('Genders included'),
                                      Person.UNKNOWN)
        for item_idx in range(len(_options.opt_genders)):
            item = _options.opt_genders[item_idx]
            gender.add_item(item[0], item[2])
        gender.set_help(_("Select which genders are included into "
                          "statistics."))
        add_option("gender", gender)

        bar_items = NumberOption(_("Max. items for a pie"), 8, 0, 20)
        bar_items.set_help(_("With fewer items pie chart and legend will be "
                             "used instead of a bar chart."))
        add_option("bar_items", bar_items)

        ################################
        category_name = _("Report Options (2)")
        add_option = partial(menu.add_option, category_name)
        ################################

        self._nf = stdoptions.add_name_format_option(menu, category_name)
        self._nf.connect('value-changed', self.__update_filters)

        self.__update_filters()

        stdoptions.add_private_data_option(menu, category_name)

        stdoptions.add_living_people_option(menu, category_name)

        stdoptions.add_localization_option(menu, category_name)

        ################################
        # List of available charts on separate option tabs
        ################################

        idx = 0
        third = (len(_Extract.extractors) + 1) // 3
        chart_types = []
        for (chart_opt, ctuple) in _Extract.extractors.items():
            chart_types.append((_(ctuple[1]), chart_opt, ctuple))
        sorted_chart_types = sorted(chart_types,
                                    key=lambda x: glocale.sort_key(x[0]))
        for (translated_option_name, opt_name, ctuple) in sorted_chart_types:
            if idx >= (third * 2):
                category_name = _("Charts 3")
            elif idx >= third:
                category_name = _("Charts 2")
            else:
                category_name = _("Charts 1")
            opt = BooleanOption(translated_option_name, False)
            opt.set_help(_("Include charts with indicated data."))
            menu.add_option(category_name, opt_name, opt)
            idx += 1

        # Enable a couple of charts by default
        menu.get_option_by_name("data_gender").set_value(True)
        menu.get_option_by_name("data_ccount").set_value(True)
        menu.get_option_by_name("data_bmonth").set_value(True)
Exemplo n.º 15
0
    def add_menu_options(self, menu):
        """
        Add options to the menu for the statistics report.
        """

        ################################
        category_name = _("Report Options")
        add_option = partial(menu.add_option, category_name)
        ################################

        self.__filter = FilterOption(_("Filter"), 0)
        self.__filter.set_help(_("Determines what people are included "
                                 "in the report."))
        add_option("filter", self.__filter)
        self.__filter.connect('value-changed', self.__filter_changed)

        self.__pid = PersonOption(_("Filter Person"))
        self.__pid.set_help(_("The center person for the filter."))
        menu.add_option(category_name, "pid", self.__pid)
        self.__pid.connect('value-changed', self.__update_filters)

        sortby = EnumeratedListOption(_('Sort chart items by'),
                                      _options.SORT_VALUE)
        for item_idx in range(len(_options.opt_sorts)):
            item = _options.opt_sorts[item_idx]
            sortby.add_item(item_idx, item[2])
        sortby.set_help(_("Select how the statistical data is sorted."))
        add_option("sortby", sortby)

        reverse = BooleanOption(_("Sort in reverse order"), False)
        reverse.set_help(_("Check to reverse the sorting order."))
        add_option("reverse", reverse)

        this_year = time.localtime()[0]
        year_from = NumberOption(_("People Born After"),
                                 1700, 1, this_year)
        year_from.set_help(_("Birth year from which to include people."))
        add_option("year_from", year_from)

        year_to = NumberOption(_("People Born Before"),
                               this_year, 1, this_year)
        year_to.set_help(_("Birth year until which to include people"))
        add_option("year_to", year_to)

        no_years = BooleanOption(_("Include people without known birth years"),
                                 False)
        no_years.set_help(_("Whether to include people without "
                            "known birth years."))
        add_option("no_years", no_years)

        gender = EnumeratedListOption(_('Genders included'),
                                      Person.UNKNOWN)
        for item_idx in range(len(_options.opt_genders)):
            item = _options.opt_genders[item_idx]
            gender.add_item(item[0], item[2])
        gender.set_help(_("Select which genders are included into "
                          "statistics."))
        add_option("gender", gender)

        bar_items = NumberOption(_("Max. items for a pie"), 8, 0, 20)
        bar_items.set_help(_("With fewer items pie chart and legend will be "
                             "used instead of a bar chart."))
        add_option("bar_items", bar_items)

        ################################
        category_name = _("Report Options (2)")
        add_option = partial(menu.add_option, category_name)
        ################################

        self._nf = stdoptions.add_name_format_option(menu, category_name)
        self._nf.connect('value-changed', self.__update_filters)

        self.__update_filters()

        stdoptions.add_private_data_option(menu, category_name)

        stdoptions.add_living_people_option(menu, category_name)

        stdoptions.add_localization_option(menu, category_name)

        ################################
        # List of available charts on separate option tabs
        ################################

        idx = 0
        third = (len(_Extract.extractors) + 1) // 3
        chart_types = []
        for (chart_opt, ctuple) in _Extract.extractors.items():
            chart_types.append((_(ctuple[1]), chart_opt, ctuple))
        sorted_chart_types = sorted(chart_types,
                                    key=lambda x: glocale.sort_key(x[0]))
        for (translated_option_name, opt_name, ctuple) in sorted_chart_types:
            if idx >= (third * 2):
                category_name = _("Charts 3")
            elif idx >= third:
                category_name = _("Charts 2")
            else:
                category_name = _("Charts 1")
            opt = BooleanOption(translated_option_name, False)
            opt.set_help(_("Include charts with indicated data."))
            menu.add_option(category_name, opt_name, opt)
            idx += 1

        # Enable a couple of charts by default
        menu.get_option_by_name("data_gender").set_value(True)
        menu.get_option_by_name("data_ccount").set_value(True)
        menu.get_option_by_name("data_bmonth").set_value(True)
Exemplo n.º 16
0
 def by_value(self, val):
     """
     Method for sorting keys based on the values.
     """
     return glocale.sort_key(self.mapping[val])
Exemplo n.º 17
0
 def __by_value_key(self, first):
     """
     Method for sorting keys based on the values.
     """
     return glocale.sort_key(self.mapping[first])