Implement record locking for native gui

This commit is contained in:
thooge committed 2026-11-04 17:21:39 +01:00
1 parent 1a6674c819
commit 669c15109a
16 files changed
+162 -66

No files matched your search

+4 -24
View File
@@ -18,8 +18,6 @@ class InventoryView(View):
self.inv = inventory.Inventory(context.db) # current record
self.newrecord = False
self.token = None # record locking
self.timer_id = None
# Inventory gets vessel assignment via
# - storage direct
@@ -73,10 +71,6 @@ class InventoryView(View):
# restore previous selected row
selection.select_iter(treeiter)
def lock_timer(self):
self.context.db.lock_refresh(self.token)
return True # continue timer
def on_page_activated(self):
print("Inventory activated")
@@ -180,20 +174,13 @@ class InventoryView(View):
invid = treeview.get_value(self.tree['inventory'], 0)
if invid is None:
return
self.token = self.context.db.lock_acquire('inventory', invid, self.user.user_id)
if self.token is None:
gtkutils.messagebox(
_("Record is locked!\n"
"Edit prohibited."), title="YMS"
)
return
self.timer_id = GLib.timeout_add(120000, self.lock_timer) # 2 minutes lock refresh timer
self.newrecord = False
self.label['title_edit'].set_text(_("Edit Inventory"))
if not self.record_lock('inventory', invid):
return
self.inv.load(invid)
self.edit_record()
self.topwidget.set_visible_child(self.box['inv_edit'])
# TODO start timer to refresh record lock
def on_but_detail_clicked(self, widget):
invid = treeview.get_value(self.tree['inventory'], 0)
@@ -262,22 +249,15 @@ class InventoryView(View):
print(self.inv)
if not self.inv.save():
pass
self.record_unlock()
if self.newrecord:
self.load_list()
self.newrecord = False
else:
pass
# TODO aktuelle Listenzeile aktualisieren!
self.display_record()
self.topwidget.set_visible_child(self.box['inv_detail'])
def on_but_cancel_clicked(self, widget):
if not self.newrecord:
if self.timer_id is not None:
# remove locking timer
GLib.source_remove(self.timer_id)
self.timer_id = None
if not self.token is None:
if not self.context.db.lock_release(self.token):
print("Error while releasing lock!")
self.record_unlock()
self.topwidget.set_visible_child(self.box['inventory'])