Пример #1
0
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_src_id = BasicEntry()
        self.filter_src_title = BasicEntry()
        self.filter_src_author = BasicEntry()
        self.filter_src_abbr = BasicEntry()
        self.filter_src_pub = BasicEntry()
        self.filter_src_note = BasicEntry()
        self.filter_id = gtk.Entry()
        self.filter_page = gtk.Entry()
        self.filter_date = DateEntry(uistate, [])

        self.filter_conf = gtk.ComboBox()
        model = gtk.ListStore(str)
        for conf_value in sorted(confidence.keys()):
            model.append((confidence[conf_value], ))
        self.filter_conf.set_model(model)
        self.filter_conf.set_active(2)  # gen.lib.Citation.CONF_NORMAL

        self.filter_note = gtk.Entry()

        self.filter_regex = gtk.CheckButton(_('Use regular expressions'))

        self.generic = gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Citation")
Пример #2
0
class CitationSidebarFilter(SidebarFilter):
    def __init__(self, dbstate, uistate, clicked):
        self.clicked_func = clicked
        self.filter_src_id = BasicEntry()
        self.filter_src_title = BasicEntry()
        self.filter_src_author = BasicEntry()
        self.filter_src_abbr = BasicEntry()
        self.filter_src_pub = BasicEntry()
        self.filter_src_note = BasicEntry()
        self.filter_id = gtk.Entry()
        self.filter_page = gtk.Entry()
        self.filter_date = DateEntry(uistate, [])

        self.filter_conf = gtk.ComboBox()
        model = gtk.ListStore(str)
        for conf_value in sorted(confidence.keys()):
            model.append((confidence[conf_value], ))
        self.filter_conf.set_model(model)
        self.filter_conf.set_active(2)  # gen.lib.Citation.CONF_NORMAL

        self.filter_note = gtk.Entry()

        self.filter_regex = gtk.CheckButton(_('Use regular expressions'))

        self.generic = gtk.ComboBox()

        SidebarFilter.__init__(self, dbstate, uistate, "Citation")

    def create_widget(self):
        cell = gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.generic.pack_start(cell, True)
        self.generic.add_attribute(cell, 'text', 0)
        self.on_filters_changed('Citation')

        cell = gtk.CellRendererText()
        cell.set_property('width', self._FILTER_WIDTH)
        cell.set_property('ellipsize', self._FILTER_ELLIPSIZE)
        self.filter_conf.pack_start(cell, True)
        self.filter_conf.add_attribute(cell, 'text', 0)

        self.add_text_entry(_('Source: ID'), self.filter_src_id)
        self.add_text_entry(_('Source: Title'), self.filter_src_title)
        self.add_text_entry(_('Source: Author'), self.filter_src_author)
        self.add_text_entry(_('Source: Abbreviation'), self.filter_src_abbr)
        self.add_text_entry(_('Source: Publication'), self.filter_src_pub)
        self.add_text_entry(_('Source: Note'), self.filter_src_note)
        self.add_text_entry(_('Citation: ID'), self.filter_id)
        self.add_text_entry(_('Citation: Volume/Page'), self.filter_page)
        self.add_text_entry(_('Citation: Date'), self.filter_date)
        self.add_entry(_('Citation: Minimum Confidence|Min. Conf.'),
                       self.filter_conf)
        self.add_text_entry(_('Citation: Note'), self.filter_note)
        self.add_filter_entry(_('Custom filter'), self.generic)
        self.add_entry(None, self.filter_regex)

    def clear(self, obj):
        self.filter_src_id.set_text('')
        self.filter_src_title.set_text('')
        self.filter_src_author.set_text('')
        self.filter_src_abbr.set_text('')
        self.filter_src_pub.set_text('')
        self.filter_src_note.set_text('')
        self.filter_id.set_text('')
        self.filter_page.set_text('')
        self.filter_date.set_text('')
        self.filter_conf.set_active(2)
        self.filter_note.set_text('')
        self.generic.set_active(0)

    def get_filter(self):
        src_id = unicode(self.filter_src_id.get_text()).strip()
        src_title = unicode(self.filter_src_title.get_text()).strip()
        src_author = unicode(self.filter_src_author.get_text()).strip()
        src_abbr = unicode(self.filter_src_abbr.get_text()).strip()
        src_pub = unicode(self.filter_src_pub.get_text()).strip()
        src_note = unicode(self.filter_src_note.get_text()).strip()
        gid = unicode(self.filter_id.get_text()).strip()
        page = unicode(self.filter_page.get_text()).strip()
        date = unicode(self.filter_date.get_text()).strip()
        model = self.filter_conf.get_model()
        node = self.filter_conf.get_active_iter()
        conf_name = model.get_value(node, 0)  # The value is actually the text
        conf = 2
        for i in confidence.keys():
            if confidence[i] == conf_name:
                conf = i
                break
#        conf = self.citn.get_confidence_level()
        note = unicode(self.filter_note.get_text()).strip()
        regex = self.filter_regex.get_active()
        gen = self.generic.get_active() > 0

        empty = not (src_id or src_title or src_author or src_abbr or src_pub
                     or src_note or gid or page or date or conf or note
                     or regex or gen)
        if empty:
            generic_filter = None
        else:
            generic_filter = GenericCitationFilter()
            if gid:
                rule = RegExpIdOf([gid], use_regex=regex)
                generic_filter.add_rule(rule)

            rule = HasCitation([page, date, conf], use_regex=regex)
            generic_filter.add_rule(rule)

            if src_id:
                rule = RegExpSourceIdOf([src_id], use_regex=regex)
                generic_filter.add_rule(rule)

            rule = HasSource([src_title, src_author, src_abbr, src_pub],
                             use_regex=regex)
            generic_filter.add_rule(rule)

            if note:
                rule = HasNoteRegexp([note], use_regex=regex)
                generic_filter.add_rule(rule)

            if src_note:
                rule = HasSourceNoteRegexp([src_note], use_regex=regex)
                generic_filter.add_rule(rule)

        if self.generic.get_active() != 0:
            model = self.generic.get_model()
            node = self.generic.get_active_iter()
            obj = unicode(model.get_value(node, 0))
            rule = MatchesFilter([obj])
            generic_filter.add_rule(rule)

        return generic_filter

    def on_filters_changed(self, name_space):
        if name_space == 'Citation':
            all_filter = GenericCitationFilter()
            all_filter.set_name(_("None"))
            all_filter.add_rule(Rules.Citation.AllCitations([]))
            self.generic.set_model(build_filter_model('Citation',
                                                      [all_filter]))
            self.generic.set_active(0)
Пример #3
0
class SelectMediaDialog:
    def __init__(self, parent, size_calculator):
        self.top = Toplevel(parent)

        # Save our required arguments for later use
        self.size_calculator = size_calculator
        self.result = None

        # Set up the frame itself
        self.create_widgets()

    #region Widget setup

    def create_widgets(self):
        # Item selection
        self.select_items = Label(self.top,
                                  text='Select the items to download:')
        self.select_items.grid(row=0, sticky=W)

        # [x] Download profile pictures
        self.propics_checkbox = CheckBox(self.top,
                                         on_changed=self.refresh_size,
                                         text='Download profile pictures')
        self.propics_checkbox.grid(row=1, sticky=W)

        # [x] Download photos
        self.photos_checkbox = CheckBox(self.top,
                                        on_changed=self.refresh_size,
                                        text='Download photos')
        self.photos_checkbox.grid(row=2, sticky=W)

        # [x] Download documents
        self.docs_checkbox = CheckBox(self.top,
                                      on_changed=self.refresh_size,
                                      text='Download documents')
        self.docs_checkbox.grid(row=3, sticky=W)

        # Extra filters when downloading the selected items
        self.select_extra = Label(self.top, text='Select extra filters:')
        self.select_extra.grid(row=4, sticky=W)

        # Only documents smaller than a given size (in MB)
        self.only_smaller_frame = Frame(self.top)
        self.only_smaller_frame.grid(row=5, sticky=W)

        self.only_smaller_checkbox = CheckBox(
            self.only_smaller_frame,
            on_changed=self.refresh_size,
            text='Only download documents smaller than')
        self.only_smaller_checkbox.grid(row=0, column=0, sticky=W)

        self.only_smaller_entry = Entry(self.only_smaller_frame, width=6)
        self.only_smaller_entry.insert(0, '2')  # 2MB default
        self.only_smaller_entry.grid(row=0, column=1, sticky=W)

        self.only_smaller_units = Label(self.only_smaller_frame, text='MB')
        self.only_smaller_units.grid(row=0, column=2, sticky=W)

        # Do NOT download media before a given date
        self.skip_before_frame = Frame(self.top)
        self.skip_before_frame.grid(row=6, sticky=W)

        self.skip_before_checkbox = CheckBox(
            self.skip_before_frame,
            on_changed=self.refresh_size,
            text='Do not download media before:')
        self.skip_before_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_before_date = DateEntry(self.skip_before_frame)
        self.skip_before_date.grid(row=0, column=1, sticky=W)

        # Do NOT download media after a given date
        self.skip_after_frame = Frame(self.top)
        self.skip_after_frame.grid(row=7, sticky=W)

        self.skip_after_checkbox = CheckBox(
            self.skip_after_frame,
            on_changed=self.refresh_size,
            text='Do not download media after:')
        self.skip_after_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_after_date = DateEntry(self.skip_after_frame)
        self.skip_after_date.grid(row=0, column=1, sticky=W)

        # Label showing the estimated download size (size_calculator(**result))
        self.estimated_size = Label(self.top)
        self.estimated_size.grid(row=8, sticky=W)

        # Frame showing the cancel and OK buttons
        self.cancel_ok_frame = Frame(self.top)
        self.cancel_ok_frame.grid(row=9, sticky=EW)
        self.top.columnconfigure(0, weight=1)

        self.cancel_button = Button(self.cancel_ok_frame,
                                    text='Cancel',
                                    command=self.cancel)
        self.cancel_button.grid(row=0, column=0, sticky=W)

        self.ok_button = Button(self.cancel_ok_frame,
                                text='Accept',
                                command=self.accept)
        self.ok_button.grid(row=0, column=1, sticky=E)

    #endregion

    #region Button actions

    def cancel(self):
        """Gets fired after the Cancel button is clicked"""
        self.top.destroy()

    def accept(self):
        """Gets fired after the Accept button is clicked"""
        self.result = self.get_current_result()
        self.top.destroy()

    def get_current_result(self):
        """Returns the current result dictionary,
           based on the selected items and input fields"""

        # Determine whether there's a maximum size
        docs_max_size = None
        if self.only_smaller_checkbox.is_checked():
            try:
                docs_max_size = float(self.only_smaller_entry.get())
                #          MB ->  KB -> bytes
                docs_max_size *= 1024 * 1024
            except ValueError:
                pass

        # Determine whether there are limit dates
        after_date = None
        if self.skip_before_checkbox.is_checked():
            after_date = self.skip_before_date.get_date()

        before_date = None
        if self.skip_after_checkbox.is_checked():
            before_date = self.skip_after_date.get_date()

        # Build the result dictionary
        return {
            'dl_propics': self.propics_checkbox.is_checked(),
            'dl_photos': self.photos_checkbox.is_checked(),
            'dl_docs': self.docs_checkbox.is_checked(),
            'docs_max_size': docs_max_size,
            'after_date': after_date,
            'before_date': before_date
        }

    #endregion

    #region GUI updating and events

    @staticmethod
    def show_dialog(parent, size_calculator=None):
        """Shows the Select Media Dialog.
           A size_calculator must be given (taking this dialogs result as parameter),
           which returns the estimated download size based on the selection"""
        dialog = SelectMediaDialog(parent, size_calculator=size_calculator)
        parent.wait_window(dialog.top)
        return dialog.result

    def refresh_size(self):
        """Refreshes the size (estimated download size) label"""
        size = self.size_calculator(**self.get_current_result())
        self.estimated_size.config(
            text='Estimated download size: {}'.format(size_to_str(size)))
Пример #4
0
    def create_widgets(self):
        # Item selection
        self.select_items = Label(self.top,
                                  text='Select the items to download:')
        self.select_items.grid(row=0, sticky=W)

        # [x] Download profile pictures
        self.propics_checkbox = CheckBox(self.top,
                                         on_changed=self.refresh_size,
                                         text='Download profile pictures')
        self.propics_checkbox.grid(row=1, sticky=W)

        # [x] Download photos
        self.photos_checkbox = CheckBox(self.top,
                                        on_changed=self.refresh_size,
                                        text='Download photos')
        self.photos_checkbox.grid(row=2, sticky=W)

        # [x] Download documents
        self.docs_checkbox = CheckBox(self.top,
                                      on_changed=self.refresh_size,
                                      text='Download documents')
        self.docs_checkbox.grid(row=3, sticky=W)

        # Extra filters when downloading the selected items
        self.select_extra = Label(self.top, text='Select extra filters:')
        self.select_extra.grid(row=4, sticky=W)

        # Only documents smaller than a given size (in MB)
        self.only_smaller_frame = Frame(self.top)
        self.only_smaller_frame.grid(row=5, sticky=W)

        self.only_smaller_checkbox = CheckBox(
            self.only_smaller_frame,
            on_changed=self.refresh_size,
            text='Only download documents smaller than')
        self.only_smaller_checkbox.grid(row=0, column=0, sticky=W)

        self.only_smaller_entry = Entry(self.only_smaller_frame, width=6)
        self.only_smaller_entry.insert(0, '2')  # 2MB default
        self.only_smaller_entry.grid(row=0, column=1, sticky=W)

        self.only_smaller_units = Label(self.only_smaller_frame, text='MB')
        self.only_smaller_units.grid(row=0, column=2, sticky=W)

        # Do NOT download media before a given date
        self.skip_before_frame = Frame(self.top)
        self.skip_before_frame.grid(row=6, sticky=W)

        self.skip_before_checkbox = CheckBox(
            self.skip_before_frame,
            on_changed=self.refresh_size,
            text='Do not download media before:')
        self.skip_before_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_before_date = DateEntry(self.skip_before_frame)
        self.skip_before_date.grid(row=0, column=1, sticky=W)

        # Do NOT download media after a given date
        self.skip_after_frame = Frame(self.top)
        self.skip_after_frame.grid(row=7, sticky=W)

        self.skip_after_checkbox = CheckBox(
            self.skip_after_frame,
            on_changed=self.refresh_size,
            text='Do not download media after:')
        self.skip_after_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_after_date = DateEntry(self.skip_after_frame)
        self.skip_after_date.grid(row=0, column=1, sticky=W)

        # Label showing the estimated download size (size_calculator(**result))
        self.estimated_size = Label(self.top)
        self.estimated_size.grid(row=8, sticky=W)

        # Frame showing the cancel and OK buttons
        self.cancel_ok_frame = Frame(self.top)
        self.cancel_ok_frame.grid(row=9, sticky=EW)
        self.top.columnconfigure(0, weight=1)

        self.cancel_button = Button(self.cancel_ok_frame,
                                    text='Cancel',
                                    command=self.cancel)
        self.cancel_button.grid(row=0, column=0, sticky=W)

        self.ok_button = Button(self.cancel_ok_frame,
                                text='Accept',
                                command=self.accept)
        self.ok_button.grid(row=0, column=1, sticky=E)
Пример #5
0
class SelectMediaDialog:
    def __init__(self, parent, size_calculator):
        self.top = Toplevel(parent)

        # Save our required arguments for later use
        self.size_calculator = size_calculator
        self.result = None

        # Set up the frame itself
        self.create_widgets()

    #region Widget setup

    def create_widgets(self):
        # Item selection
        self.select_items = Label(self.top, text='Select the items to download:')
        self.select_items.grid(row=0, sticky=W)

        # [x] Download profile pictures
        self.propics_checkbox = CheckBox(self.top, on_changed=self.refresh_size,
                                         text='Download profile pictures')
        self.propics_checkbox.grid(row=1, sticky=W)

        # [x] Download photos
        self.photos_checkbox = CheckBox(self.top, on_changed=self.refresh_size,
                                        text='Download photos')
        self.photos_checkbox.grid(row=2, sticky=W)

        # [x] Download documents
        self.docs_checkbox = CheckBox(self.top, on_changed=self.refresh_size,
                                      text='Download documents')
        self.docs_checkbox.grid(row=3, sticky=W)

        # Extra filters when downloading the selected items
        self.select_extra = Label(self.top, text='Select extra filters:')
        self.select_extra.grid(row=4, sticky=W)

        # Only documents smaller than a given size (in MB)
        self.only_smaller_frame = Frame(self.top)
        self.only_smaller_frame.grid(row=5, sticky=W)

        self.only_smaller_checkbox = CheckBox(self.only_smaller_frame,
                                              on_changed=self.refresh_size,
                                              text='Only download documents smaller than')
        self.only_smaller_checkbox.grid(row=0, column=0, sticky=W)

        self.only_smaller_entry = Entry(self.only_smaller_frame, width=6)
        self.only_smaller_entry.insert(0, '2')  # 2MB default
        self.only_smaller_entry.grid(row=0, column=1, sticky=W)

        self.only_smaller_units = Label(self.only_smaller_frame, text='MB')
        self.only_smaller_units.grid(row=0, column=2, sticky=W)

         # Do NOT download media before a given date
        self.skip_before_frame = Frame(self.top)
        self.skip_before_frame.grid(row=6, sticky=W)

        self.skip_before_checkbox = CheckBox(self.skip_before_frame,
                                             on_changed=self.refresh_size,
                                             text='Do not download media before:')
        self.skip_before_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_before_date = DateEntry(self.skip_before_frame)
        self.skip_before_date.grid(row=0, column=1, sticky=W)

         # Do NOT download media after a given date
        self.skip_after_frame = Frame(self.top)
        self.skip_after_frame.grid(row=7, sticky=W)

        self.skip_after_checkbox = CheckBox(self.skip_after_frame,
                                            on_changed=self.refresh_size,
                                            text='Do not download media after:')
        self.skip_after_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_after_date = DateEntry(self.skip_after_frame)
        self.skip_after_date.grid(row=0, column=1, sticky=W)

        # Label showing the estimated download size (size_calculator(**result))
        self.estimated_size = Label(self.top)
        self.estimated_size.grid(row=8, sticky=W)

        # Frame showing the cancel and OK buttons
        self.cancel_ok_frame = Frame(self.top)
        self.cancel_ok_frame.grid(row=9, sticky=EW)
        self.top.columnconfigure(0, weight=1)

        self.cancel_button = Button(self.cancel_ok_frame, text='Cancel', command=self.cancel)
        self.cancel_button.grid(row=0, column=0, sticky=W)

        self.ok_button = Button(self.cancel_ok_frame, text='Accept', command=self.accept)
        self.ok_button.grid(row=0, column=1, sticky=E)

    #endregion

    #region Button actions

    def cancel(self):
        """Gets fired after the Cancel button is clicked"""
        self.top.destroy()

    def accept(self):
        """Gets fired after the Accept button is clicked"""
        self.result = self.get_current_result()
        self.top.destroy()

    def get_current_result(self):
        """Returns the current result dictionary,
           based on the selected items and input fields"""

        # Determine whether there's a maximum size
        docs_max_size = None
        if self.only_smaller_checkbox.is_checked():
            try:
                docs_max_size = float(self.only_smaller_entry.get())
                #          MB ->  KB -> bytes
                docs_max_size *= 1024 * 1024
            except ValueError:
                pass

        # Determine whether there are limit dates
        after_date = None
        if self.skip_before_checkbox.is_checked():
            after_date = self.skip_before_date.get_date()

        before_date = None
        if self.skip_after_checkbox.is_checked():
            before_date = self.skip_after_date.get_date()

        # Build the result dictionary
        return {
            'dl_propics': self.propics_checkbox.is_checked(),
            'dl_photos': self.photos_checkbox.is_checked(),
            'dl_docs': self.docs_checkbox.is_checked(),
            'docs_max_size': docs_max_size,
            'after_date': after_date,
            'before_date': before_date
        }

    #endregion

    #region GUI updating and events

    @staticmethod
    def show_dialog(parent, size_calculator=None):
        """Shows the Select Media Dialog.
           A size_calculator must be given (taking this dialogs result as parameter),
           which returns the estimated download size based on the selection"""
        dialog = SelectMediaDialog(parent, size_calculator=size_calculator)
        parent.wait_window(dialog.top)
        return dialog.result

    def refresh_size(self):
        """Refreshes the size (estimated download size) label"""
        size = self.size_calculator(**self.get_current_result())
        self.estimated_size.config(text='Estimated download size: {}'.format(size_to_str(size)))
Пример #6
0
    def create_widgets(self):
        # Item selection
        self.select_items = Label(self.top, text='Select the items to download:')
        self.select_items.grid(row=0, sticky=W)

        # [x] Download profile pictures
        self.propics_checkbox = CheckBox(self.top, on_changed=self.refresh_size,
                                         text='Download profile pictures')
        self.propics_checkbox.grid(row=1, sticky=W)

        # [x] Download photos
        self.photos_checkbox = CheckBox(self.top, on_changed=self.refresh_size,
                                        text='Download photos')
        self.photos_checkbox.grid(row=2, sticky=W)

        # [x] Download documents
        self.docs_checkbox = CheckBox(self.top, on_changed=self.refresh_size,
                                      text='Download documents')
        self.docs_checkbox.grid(row=3, sticky=W)

        # Extra filters when downloading the selected items
        self.select_extra = Label(self.top, text='Select extra filters:')
        self.select_extra.grid(row=4, sticky=W)

        # Only documents smaller than a given size (in MB)
        self.only_smaller_frame = Frame(self.top)
        self.only_smaller_frame.grid(row=5, sticky=W)

        self.only_smaller_checkbox = CheckBox(self.only_smaller_frame,
                                              on_changed=self.refresh_size,
                                              text='Only download documents smaller than')
        self.only_smaller_checkbox.grid(row=0, column=0, sticky=W)

        self.only_smaller_entry = Entry(self.only_smaller_frame, width=6)
        self.only_smaller_entry.insert(0, '2')  # 2MB default
        self.only_smaller_entry.grid(row=0, column=1, sticky=W)

        self.only_smaller_units = Label(self.only_smaller_frame, text='MB')
        self.only_smaller_units.grid(row=0, column=2, sticky=W)

         # Do NOT download media before a given date
        self.skip_before_frame = Frame(self.top)
        self.skip_before_frame.grid(row=6, sticky=W)

        self.skip_before_checkbox = CheckBox(self.skip_before_frame,
                                             on_changed=self.refresh_size,
                                             text='Do not download media before:')
        self.skip_before_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_before_date = DateEntry(self.skip_before_frame)
        self.skip_before_date.grid(row=0, column=1, sticky=W)

         # Do NOT download media after a given date
        self.skip_after_frame = Frame(self.top)
        self.skip_after_frame.grid(row=7, sticky=W)

        self.skip_after_checkbox = CheckBox(self.skip_after_frame,
                                            on_changed=self.refresh_size,
                                            text='Do not download media after:')
        self.skip_after_checkbox.grid(row=0, column=0, sticky=W)

        self.skip_after_date = DateEntry(self.skip_after_frame)
        self.skip_after_date.grid(row=0, column=1, sticky=W)

        # Label showing the estimated download size (size_calculator(**result))
        self.estimated_size = Label(self.top)
        self.estimated_size.grid(row=8, sticky=W)

        # Frame showing the cancel and OK buttons
        self.cancel_ok_frame = Frame(self.top)
        self.cancel_ok_frame.grid(row=9, sticky=EW)
        self.top.columnconfigure(0, weight=1)

        self.cancel_button = Button(self.cancel_ok_frame, text='Cancel', command=self.cancel)
        self.cancel_button.grid(row=0, column=0, sticky=W)

        self.ok_button = Button(self.cancel_ok_frame, text='Accept', command=self.accept)
        self.ok_button.grid(row=0, column=1, sticky=E)
Пример #7
0
    def __init__(self, namespace, dbstate, uistate, track, filterdb, val,
                 label, update, filter_name):
        ManagedWindow.ManagedWindow.__init__(self, uistate, track, EditRule)
        self.width_key = "interface.edit-rule-width"
        self.height_key = "interface.edit-rule-height"
        self.namespace = namespace
        self.dbstate = dbstate
        self.db = dbstate.db
        self.filterdb = filterdb
        self.update_rule = update
        self.filter_name = filter_name

        self.active_rule = val
        self.define_glade('rule_editor', const.RULE_GLADE)
        
        self.set_window(self.get_widget('rule_editor'),
                        self.get_widget('rule_editor_title'),label)
        self.window.hide()
        self.valuebox = self.get_widget('valuebox')
        self.rname = self.get_widget('ruletree')
        self.rule_name = self.get_widget('rulename')

        self.notebook = gtk.Notebook()
        self.notebook.set_show_tabs(0)
        self.notebook.set_show_border(0)
        self.notebook.show()
        self.valuebox.add(self.notebook)
        self.page_num = 0
        self.page = []
        self.class2page = {}
        the_map = {}

        if self.namespace == 'Person':
            class_list = Rules.Person.editor_rule_list
        elif self.namespace == 'Family':
            class_list = Rules.Family.editor_rule_list
        elif self.namespace == 'Event':
            class_list = Rules.Event.editor_rule_list
        elif self.namespace == 'Source':
            class_list = Rules.Source.editor_rule_list
        elif self.namespace == 'Citation':
            class_list = Rules.Citation.editor_rule_list
        elif self.namespace == 'Place':
            class_list = Rules.Place.editor_rule_list
        elif self.namespace == 'MediaObject':
            class_list = Rules.MediaObject.editor_rule_list
        elif self.namespace == 'Repository':
            class_list = Rules.Repository.editor_rule_list
        elif self.namespace == 'Note':
            class_list = Rules.Note.editor_rule_list
        
        for class_obj in class_list:
            arglist = class_obj.labels
            vallist = []
            tlist = []
            pos = 0
            l2 = gtk.Label(class_obj.name)
            l2.set_alignment(0, 0.5)
            l2.show()
            c = gtk.TreeView()
            c.set_data('d', pos)
            c.show()
            the_map[class_obj] = c
            # Only add a table with parameters if there are any parameters
            if arglist:
                table = gtk.Table(3, len(arglist))
            else:
                table = gtk.Table(1, 1)
            table.set_border_width(6)
            table.set_col_spacings(6)
            table.set_row_spacings(6)
            table.show()
            for v in arglist:
                l = gtk.Label(v)
                l.set_alignment(1, 0.5)
                l.show()
                if v == _('Place:'):
                    t = MyPlaces([])
                elif v in [_('Reference count:'),
                            _('Number of instances:')
                            ]:
                    t = MyInteger(0, 999)
                elif v == _('Reference count must be:'):
                    t = MyLesserEqualGreater()
                elif v == _('Number must be:'):
                    t = MyLesserEqualGreater(2)
                elif v == _('Number of generations:'):
                    t = MyInteger(1, 32)
                elif v == _('ID:'):
                    t = MyID(self.dbstate, self.uistate, self.track, 
                             self.namespace)
                elif v == _('Source ID:'):
                    t = MySource(self.dbstate, self.uistate, self.track)
                elif v == _('Filter name:'):
                    t = MyFilters(self.filterdb.get_filters(self.namespace),
                                  self.filter_name)
                # filters of another namespace, name may be same as caller!
                elif v == _('Person filter name:'):
                    t = MyFilters(self.filterdb.get_filters('Person'))
                elif v == _('Event filter name:'):
                    t = MyFilters(self.filterdb.get_filters('Event'))
                elif v == _('Source filter name:'):
                    t = MyFilters(self.filterdb.get_filters('Source'))
                elif v == _('Repository filter name:'):
                    t = MyFilters(self.filterdb.get_filters('Repository'))
                elif v == _('Place filter name:'):
                    t = MyFilters(self.filterdb.get_filters('Place'))
                elif v in _name2typeclass:
                    additional = None
                    if v == _('Personal event:'):
                        additional = self.db.get_person_event_types()
                    elif v == _('Family event:'):
                        additional = self.db.get_family_event_types()
                    elif v == _('Event type:'):
                        additional = (self.db.get_person_event_types() +
                                      self.db.get_family_event_types())
                    elif v == _('Personal attribute:'):
                        additional = self.db.get_person_attribute_types()
                    elif v == _('Family attribute:'):
                        additional = self.db.get_family_attribute_types()
                    elif v == _('Media attribute:'):
                        additional = self.db.get_media_attribute_types()
                    elif v == _('Relationship type:'):
                        additional = self.db.get_family_relation_types()
                    elif v == _('Note type:'):
                        additional = self.db.get_note_types()
                    elif v == _('Name type:'):
                        additional = self.db.get_name_types()
                    elif v == _('Surname origin type:'):
                        additional = self.db.get_origin_types()
                    t = MySelect(_name2typeclass[v], additional)
                elif v == _('Inclusive:'):
                    t = MyBoolean(_('Include original person'))
                elif v == _('Case sensitive:'):
                    t = MyBoolean(_('Use exact case of letters'))
                elif v == _('Regular-Expression matching:'):
                    t = MyBoolean(_('Use regular expression'))
                elif v == _('Include Family events:'):
                    t = MyBoolean(_('Also family events where person is '
                                    'wife/husband'))
                elif v == _('Primary Role:'):
                    t = MyBoolean(_('Only include primary participants'))
                elif v == _('Tag:'):
                    taglist = ['']
                    taglist = taglist + [tag.get_name() for tag in dbstate.db.iter_tags()]
                    t = MyList(taglist, taglist)
                elif v == _('Confidence level:'):
                    t = MyList(map(str, range(5)), 
                               [Utils.confidence[i] for i in range(5)])
                elif v == _('Date:'):
                    t = DateEntry(self.uistate, self.track)
                elif v == _('Day of Week:'):
                    days_of_week = long_days[2:] + long_days[1:2]
                    t = MyList(map(str, range(7)), days_of_week)
                else:                    
                    t = MyEntry()
                tlist.append(t)
                table.attach(l, 1, 2, pos, pos+1, gtk.FILL, 0, 5, 5)
                table.attach(t, 2, 3, pos, pos+1, gtk.EXPAND|gtk.FILL, 0, 5, 5)
                pos += 1

            use_regex = None
            if class_obj.allow_regex:
                use_regex = gtk.CheckButton(_('Use regular expressions'))
                tip = _('Interpret the contents of string fields as regular '
                        'expressions.\n'
                        'A decimal point will match any character. '
                        'A question mark will match zero or one occurences '
                        'of the previous character or group. '
                        'An asterisk will match zero or more occurences. '
                        'A plus sign will match one or more occurences. '
                        'Use parentheses to group expressions. '
                        'Specify alternatives using a vertical bar. '
                        'A caret will match the start of a line. '
                        'A dollar sign will match the end of a line.')
                use_regex.set_tooltip_text(tip)
                table.attach(use_regex, 2, 3, pos, pos+1, gtk.FILL, 0, 5, 5)

            self.page.append((class_obj, vallist, tlist, use_regex))

            # put the table into a scrollable area:
            scrolled_win = gtk.ScrolledWindow()
            scrolled_win.add_with_viewport(table)
            scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
            scrolled_win.show()
            self.notebook.append_page(scrolled_win, gtk.Label(class_obj.name))
            self.class2page[class_obj] = self.page_num
            self.page_num = self.page_num + 1
        self.page_num = 0
        self.store = gtk.TreeStore(gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
        self.selection = self.rname.get_selection()
        col = gtk.TreeViewColumn(_('Rule Name'), gtk.CellRendererText(), 
                                 text=0)
        self.rname.append_column(col)
        self.rname.set_model(self.store)

        prev = None
        last_top = None

        top_level = {}
        top_node = {}

        #
        # If editing a rule, get the name so that we can select it later
        #
        sel_node = None
        if self.active_rule is not None:
            self.sel_class = self.active_rule.__class__
        else:
            self.sel_class = None

        keys = sorted(the_map, by_rule_name, reverse=True)
        catlist = sorted(set(class_obj.category for class_obj in keys))

        for category in catlist:
            top_node[category] = self.store.insert_after(None, last_top)
            top_level[category] = []
            last_top = top_node[category]
            self.store.set(last_top, 0, category, 1, None)

        for class_obj in keys:
            category = class_obj.category
            top_level[category].append(class_obj.name)
            node = self.store.insert_after(top_node[category], prev)
            self.store.set(node, 0, class_obj.name, 1, class_obj)

            # if this is an edit rule, save the node
            if class_obj == self.sel_class:
                sel_node = (top_node[category], node)

        if sel_node:
            self.select_iter(sel_node)
            page = self.class2page[self.active_rule.__class__]
            self.notebook.set_current_page(page)
            self.display_values(self.active_rule.__class__)
            (class_obj, vallist, tlist, use_regex) = self.page[page]
            r = self.active_rule.values()
            for i in range(0, min(len(tlist), len(r))):
                tlist[i].set_text(r[i])
            if class_obj.allow_regex:
                use_regex.set_active(self.active_rule.use_regex)
            
        self.selection.connect('changed', self.on_node_selected)
        self.rname.connect('button-press-event', self._button_press)
        self.rname.connect('key-press-event', self._key_press)
        self.get_widget('rule_editor_ok').connect('clicked', self.rule_ok)
        self.get_widget('rule_editor_cancel').connect('clicked', self.close_window)
        self.get_widget('rule_editor_help').connect('clicked', self.on_help_clicked)

        self._set_size()
        self.show()