# Object attributes \*uistate\* and \*dbstate\*

**URL:** <https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109>\
**Category:** Development\
**Tags:** hacks\
**Created:** [February 2, 2026, 2:26pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109 "2026-02-02T14:26:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pgerlier](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@pgerlier](https://gramps.discourse.group/u/pgerlier)\
**Post date:** [February 2, 2026, 2:26pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/1 "2026-02-02T14:26:48Z")

</div>

Continuing to explore the relationships between the various Python objects making up Gramps, I am trying to retrieve a “genealogical object” (e.g. a Note, Person, Family, Repo, …) from a UI widget containing data to be “annotated”.

My goal requires both the association between the “genealogical object” and the UI and the association with the database.

I have solved (or I hope so) the first part by retrieving a Python object in the GTK hierarchy with attribute _uistate_. The attribute for the DB is _dbstate_.

Can I assume that the _uistate_-object has always also a _dbstate_ attribute or should I query this attribute independently?

I don’t think performance will be impacted if I play safe with two queries but it would be nicer (though less explicit) with a single query.

---

<div class="post-metadata">

**Author:** ![kku](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@kku](https://gramps.discourse.group/u/kku)\
**Post date:** [February 2, 2026, 2:55pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/2 "2026-02-02T14:55:20Z")

</div>

Since `uistate` and `dbstate` are essential objects for almost any operation they are often stored in the same object (e.g. in a gramplet or a tool object). But I don’t think that is a rule. For example, a “selector” object has only the `uistate` and `db` attributes, no `dbstate`:

```python
from gramps.gui.selectors.selectperson import SelectPerson
sel = SelectPerson(dbstate, uistate)
print(sel.uistate) # OK
print(sel.db) # OK
print(sel.dbstate) # fails: no attribute 'dbstate'

```

Did I understand your question correctly?

---

<div class="post-metadata">

**Author:** ![pgerlier](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@pgerlier](https://gramps.discourse.group/u/pgerlier)\
**Post date:** [February 3, 2026, 9:46am UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/3 "2026-02-03T09:46:30Z")

</div>

> [@kku](#):
>
> Did I understand your question correctly?

Yes, at least partially.

Your example also shows that programming is not consistent: `db` is an attribute of `dbstate`. Therefore, returning `db` only is a restriction, preventing other interactions. There may be reasons to provide only `db`; but are they documented?

I see in the code for `SelectPerson` that `dbstate` is indeed used in _\_\_init\_\__ to create auxiliary tools, like the search bar. Restriction on `db` is perhaps motivated by its single use in _get\_model\_class()_ where the class only needs the DB.

I’ll get inspiration from `SelectPerson` to see what fits my need: I want to access the DB and I don’t think I have to bother for the rest of the state.

---

<div class="post-metadata">

**Author:** ![romjerome](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/romjerome/32/1489_2.png) [@romjerome](https://gramps.discourse.group/u/romjerome)\
**Post date:** [February 3, 2026, 10:18am UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/4 "2026-02-03T10:18:58Z")

</div>

I just played with quick access, then addons without large coding experience. So, you can take it like a naïve (naive) workflow as I needed to test more and limit most abstraction stuff.

I dislike the UI process, but once you have to manage more than one box and use window, maybe you will have to set something like `parent=self.uistate.window`. I fill it because it is the Gramps / Gtk environment, otherwise I do not really care of `uistate` except maybe once there is an `user` interaction. As a dirty shortcut, if the user/client needs to see, set or clic during the runtime, then maybe I need to take time for looking at `uistate`, sure it is `ui` but all of this might be also hidden or automatic for having a more basic playground.

Then I trust `gen/db/read.py` (or `dummy` one) for the `dbstate`.

More direct, if I only want to access to a distant DB object (raw record, serialization), then there is maybe a lazy way with a hierarchical/factory logic (namespace & co):

`for {object} in db.iter_{objects}(): # that's a sample, replace {object}`

`for ref in person.serialize()[-1]:`

etc.

I did not look at changes on Selectors design and code, but they are maybe not the best place for finding any global or logical code!

Many minor exceptions or design issues when I looked at:

> **[GEPS 041: New Selector - Gramps](https://www.gramps-project.org/wiki/index.php/GEPS_041:_New_Selector)**

---

<div class="post-metadata">

**Author:** ![pgerlier](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@pgerlier](https://gramps.discourse.group/u/pgerlier)\
**Post date:** [February 4, 2026, 10:27am UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/5 "2026-02-04T10:27:07Z")

</div>

> [@romjerome](#):
>
> Then I trust `gen/db/read.py` (or `dummy` one) for the `dbstate`.

I feel like I am following a wrong track: I try to find in the parent chain an object connected to the DB and “steal” its `dbstate`. It is very likely that the DB-connected object has a low relationship to my goal. It is then possible that its `dbstate` might not be (theoretically) exactly relevant.

Since I need a synthesis across several Gramps genealogical objects (external though remotely related to my current Note), is there a possibility to open a (read-only) connection to the DB, without relating it to currently “active” objects?

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 4, 2026, 1:16pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/6 "2026-02-04T13:16:27Z")

</div>

It sounds like your are getting the “handle” from the Active object. But you can the Handle in a variety of other ways. The most obvious by asking for the handle(s) of the object(s) with particular Gramps ID.

And with the handle, you can directly access the object’s data. And a little less directly the data of all the secondary object for that object.

---

<div class="post-metadata">

**Author:** ![emyoulation](https://yyz2.discourse-cdn.com/free1/user_avatar/gramps.discourse.group/emyoulation/32/67_2.png) [@emyoulation](https://gramps.discourse.group/u/emyoulation)\
**Post date:** [February 4, 2026, 5:42pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/7 "2026-02-04T17:42:27Z")

</div>

@pgerlier

Would the [Simple Access](https://gramps-project.org/docs/simple.html#module-gramps.gen.simple._simpleaccess) from the Simple Classes allow you to side-step any of this labor?

---

<div class="post-metadata">

**Author:** ![pgerlier](https://avatars.discourse-cdn.com/v4/letter/p/41988e/32.png) [@pgerlier](https://gramps.discourse.group/u/pgerlier)\
**Post date:** [February 4, 2026, 5:48pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/8 "2026-02-04T17:48:22Z")

</div>

I vaguely remembered having seen that and use cases in the code. Thanks for refreshing my memory.

**EDIT:**  
I looked at the _SimpleAccess_ class. Unfortunately, I bump into my initial problem: instantiation of the class requires a database argument. It all boils down to database retrieval.

I am not satisfied with my present trick of finding an “object” owning a `dbstate` attribute but this seems the only way.

Incidentally, I don’t understand why there is no “global data” module for exposing “universally needed” properties like `dbstate`. Since it is used nearly everywhere, a simple `import` would be better than contorting retrieving and storing it in all objects. After all, Gramps allows only one tree to be open at any time. Consequently, there is no risk with a common variable.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/gramps/original/1X/2ac1e712b7adf612e31ca08a55419f4cf37c0158.png) [@system](https://gramps.discourse.group/u/system)\
**Post date:** [March 6, 2026, 5:49pm UTC](https://gramps.discourse.group/t/object-attributes-uistate-and-dbstate/9109/9 "2026-03-06T17:49:21Z")

</div>

Closed on March 6, 2026, 5:49pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
