Exemplo n.º 1
0
    def create_gui(self):
        self.filternames = []
        category = self.uistate.viewmanager.active_page.get_category()
        if category == "People": category = "Person"
        if category.endswith("ies"): category = category[0:-3] + "y"
        if category.endswith("s"): category = category[0:-1]
        self.current_category = category

        glade = Glade(toplevel='dialog1')
        self.dialog = glade.toplevel
        combo_categories = glade.get_child_object("combo_categories")
        self.combo_filters = glade.get_child_object("combo_filters")
        self.add_button = glade.get_child_object("add_button")
        self.edit_button = glade.get_child_object("edit_button")
        self.delete_button = glade.get_child_object("delete_button")

        self.execute_button = glade.get_child_object("execute_button")
        self.update_button = glade.get_child_object("update_button")
        self.close_button = glade.get_child_object("close_button")
        self.box = glade.get_child_object("box")

        if 0: glade.connect_signals(
            {
                'on_filter_changed': self.on_filter_changed,
                'add_new_filter': self.add_new_filter,
                'edit_filter': self.edit_filter,
                'delete_filter': self.delete_filter,
                'execute_clicked': self.execute_clicked,
                'update_clicked': self.update_clicked,
                'close_clicked': self.close_clicked,
                'on_category_changed': self.on_category_changed,
            }
        )
        if 1:
            self.combo_filters.connect("changed", self.on_filter_changed)

            self.add_button.connect("clicked", self.add_new_filter)
            self.edit_button.connect("clicked", self.edit_filter)
            self.delete_button.connect("clicked", self.delete_filter)

            self.execute_button.connect("clicked", self.execute_clicked)
            self.update_button.connect("clicked", self.update_clicked)
            self.close_button.connect("clicked", self.close_clicked)

        for cat in self.categories_translated:
            combo_categories.append_text(cat)
        combo_categories.connect("changed", self.on_category_changed)

        if self.current_category not in self.categories:
            self.current_category = "Person"
        i = self.categories.index(self.current_category)
        combo_categories.set_active(i)

        self.dialog.connect("delete-event", lambda x, y: self.close_clicked(self.dialog))
        self.dialog.show_all()
        return self.dialog
Exemplo n.º 2
0
    def draw_window(self):
        """Draw the dialog box."""

        # Copied from PlaceCleanup:
        # Found out that Glade does not support translations for plugins, so
        # have to do it manually.
        import os
        import locale
        import ctypes
        from gramps.gen.constfunc import win
        base = os.path.dirname(__file__)
        glade_file = base + os.sep + "nameeditortool.glade"
        # This is needed to make gtk.Builder work by specifying the
        # translations directory in a separate 'domain'
        try:
            localedomain = "addon"
            localepath = base + os.sep + "locale"
            if hasattr(locale, 'bindtextdomain'):
                libintl = locale
            elif win():  # apparently wants strings in bytes
                localedomain = localedomain.encode('utf-8')
                localepath = localepath.encode('utf-8')
                libintl = ctypes.cdll.LoadLibrary('libintl-8.dll')
            else:  # mac, No way for author to test this
                libintl = ctypes.cdll.LoadLibrary('libintl.dylib')

            libintl.bindtextdomain(localedomain, localepath)
            libintl.textdomain(localedomain)
            libintl.bind_textdomain_codeset(localedomain, "UTF-8")
            # and finally, tell Gtk Builder to use that domain
            self.top.set_translation_domain("addon")
        except (OSError, AttributeError):
            # Will leave it in English
            print("Localization of PlaceCleanup failed!")

        glade = Glade()
        self.glade = glade
        self.top = glade.toplevel

        columns = [
            (_('Id'), 0, 80),
            (_('Gender'), 1, 100),
            (_('Prefix'), 2, 100),
            (_('Surname'), 3, 200),
            (_('First name'), 4, 200),
            (_('Suffix'), 5, 200),
            (_('Title'), 6, 300),
            (_('Type'), 7, 100),
        ]
        #                   ('',-1,0)]
        self.namelist = MyTreeView()
        self.namemodel = MyListModel(self.namelist,
                                     columns,
                                     event_func=self.cb_double_click)

        find = glade.get_child_object("find")
        find.connect('clicked', self.find_clicked)

        reset = glade.get_child_object("reset")
        reset.connect('clicked', self.reset_clicked)

        self.searchtext = glade.get_child_object("searchtext")
        self.searchtext.connect("key-press-event", self.keypress)

        slist = glade.get_child_object("slist")
        slist.add(self.namelist)
        #self.namelist.connect('button-release-event', self.__button_release)
        select = self.namelist.get_selection()
        select.connect("changed", self.on_selection_changed)

        self.replace_button = glade.get_child_object("replace")
        self.replace_button.connect('clicked', self.replace_clicked)

        button_undo = glade.get_child_object("button_undo")
        button_undo.connect('clicked', self.undo_clicked)

        clear_button = glade.get_child_object("clear_button")
        clear_button.connect('clicked', self.clear_form)

        editgrid = self.glade.get_child_object('editgrid')
        self.special_prefix = self.build_combobox()
        self.special_surname = self.build_combobox()
        self.special_firstname = self.build_combobox()
        self.special_suffix = self.build_combobox()
        self.special_title = self.build_combobox()

        self.old_prefix = self.glade.get_child_object("old_prefix")
        self.old_surname = self.glade.get_child_object("old_surname")
        self.old_firstname = self.glade.get_child_object("old_firstname")
        self.old_suffix = self.glade.get_child_object("old_suffix")
        self.old_title = self.glade.get_child_object("old_title")

        self.new_prefix = self.glade.get_child_object('new_prefix')
        self.new_surname = self.glade.get_child_object('new_surname')
        self.new_firstname = self.glade.get_child_object('new_firstname')
        self.new_suffix = self.glade.get_child_object('new_suffix')
        self.new_title = self.glade.get_child_object("new_title")

        editgrid.attach(self.special_prefix, 2, 1, 1, 1)
        editgrid.attach(self.special_surname, 2, 2, 1, 1)
        editgrid.attach(self.special_firstname, 2, 3, 1, 1)
        editgrid.attach(self.special_suffix, 2, 4, 1, 1)
        editgrid.attach(self.special_title, 2, 5, 1, 1)

        self.use_special = glade.get_child_object("use_special")
        self.use_special.connect('clicked', self.use_special_clicked)

        self.use_regex_checkbox = self.glade.get_child_object("use_regex")

        self.find_use_regex = self.glade.get_child_object("find_regex")

        self.find_all = self.glade.get_child_object("find_all")
        self.find_prefix = self.glade.get_child_object("find_prefix")
        self.find_surname = self.glade.get_child_object("find_surname")
        self.find_firstname = self.glade.get_child_object("find_firstname")
        self.find_suffix = self.glade.get_child_object("find_suffix")
        self.find_title = self.glade.get_child_object("find_title")

        self.find_type = self.glade.get_child_object("find_type")
        self.fill_typecombo(self.find_type)

        self.old_nametype = self.glade.get_child_object("old_nametype")
        self.fill_typecombo(self.old_nametype)

        self.new_nametype = self.glade.get_child_object("new_nametype")
        self.fill_typecombo(self.new_nametype)

        self.type_primary = self.glade.get_child_object("type_primary")
        self.type_alternate = self.glade.get_child_object("type_alternate")

        self.find_all.connect('clicked', self.find_all_clicked)

        self.gender_all = self.glade.get_child_object("gender_all")
        self.gender_male = self.glade.get_child_object("gender_male")
        self.gender_female = self.glade.get_child_object("gender_female")
        self.gender_unknown = self.glade.get_child_object("gender_unknown")

        self.label_count = self.glade.get_child_object("label_count")

        self.help_button = self.glade.get_child_object("help_button")
        self.help_button.connect("clicked", self.show_help)

        self.find_in_progress = True
        self.reset_clicked(None)

        self.find_in_progress = False

        return self.top
Exemplo n.º 3
0
    def __create_gui(self):
        # type: () -> Gtk.Widget
        glade = Glade(toplevel="main", also_load=["help_window", "adjustment1"])
        glade.set_translation_domain(None)

        self.title = glade.get_child_object("title")

        self.label_filter = glade.get_child_object("label_filter")
        self.label_statements = glade.get_child_object("label_statements")

        self.initial_statements = glade.get_child_object("initial_statements")
        self.statements = glade.get_child_object("statements")
        self.filter = glade.get_child_object("filter")
        self.expressions = glade.get_child_object("expressions")

        self.all_objects = glade.get_child_object("all_objects")
        self.filtered_objects = glade.get_child_object("filtered_objects")
        self.selected_objects = glade.get_child_object("selected_objects")

        self.unwind_lists = glade.get_child_object("unwind_lists")
        self.commit_checkbox = glade.get_child_object("commit_checkbox")
        self.summary_checkbox = glade.get_child_object("summary_checkbox")

        self.btn_execute = glade.get_child_object("btn_execute")
        self.btn_csv = glade.get_child_object("btn_csv")
        self.btn_copy = glade.get_child_object("btn_copy")
        self.btn_close = glade.get_child_object("btn_close")
        self.btn_load = glade.get_child_object("btn_load")
        self.btn_save = glade.get_child_object("btn_save")
        self.btn_save_as_filter = glade.get_child_object("btn_save_as_filter")
        self.btn_clear = glade.get_child_object("btn_clear")
        self.btn_help = glade.get_child_object("btn_help")

        self.btn_font = glade.get_child_object("btn_font")
        self.btn_font.set_label("Select font")

        self.attributes_list = glade.get_child_object("attributes_list")

        self.statusmsg = glade.get_child_object("statusmsg")
        self.errormsg = self.statusmsg

        self.output_window = glade.get_child_object("output_window")
        self.help_window = glade.get_object("help_window")
        self.help_notebook = glade.get_object("help_notebook")
        self.help_win = None

        self.selected_objects.set_active(True)
        self.btn_execute.connect("clicked", self.__execute)
        self.btn_csv.connect("clicked", self.download)
        self.btn_copy.connect("clicked", self.copy)
        self.btn_close.connect("clicked", self.__close)
        self.btn_load.connect("clicked", self.load)
        self.btn_save.connect("clicked", self.save)
        self.btn_save_as_filter.connect("clicked", self.save_as_filter)
        self.btn_clear.connect("clicked", self.clear)
        self.btn_help.connect("clicked", self.help)
        self.btn_font.connect("font-set", self.set_font)

        self.btn_csv.hide()
        self.listview = None

        ver = (Gtk.get_major_version(),Gtk.get_minor_version())
        if ver >= (3, 22):
            self.initial_statements_window = glade.get_child_object("initial_statements_window")
            self.statements_window = glade.get_child_object("statements_window")
            self.initial_statements_window.set_max_content_height(200)             
            self.initial_statements_window.set_propagate_natural_height(True)             
            self.statements_window.set_propagate_natural_height(True)             
            self.statements_window.set_max_content_height(200)             

        return glade.toplevel
Exemplo n.º 4
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()