def window_closing(self, sender, args): if not self._commited: if self._reserved_key: try: kdb.release_key(self._conn, self._reserved_key, category=self._cat) except System.TimeoutException as toutex: forms.alert(toutex.Message) except Exception: pass try: kdb.end_edit(self._conn) except System.TimeoutException as toutex: forms.alert(toutex.Message) except Exception: pass
def pick_key(self, sender, args): # remove previously reserved if self._reserved_key: try: kdb.release_key(self._conn, self._reserved_key, category=self._cat) except System.TimeoutException as toutex: forms.alert(toutex.Message) return try: categories = kdb.get_categories(self._conn) keynotes = kdb.get_keynotes(self._conn) locks = kdb.get_locks(self._conn) except System.TimeoutException as toutex: forms.alert(toutex.Message) return # collect existing keys reserved_keys = [x.key for x in categories] reserved_keys.extend([x.key for x in keynotes]) reserved_keys.extend([x.LockTargetRecordKey for x in locks]) # ask for a unique new key new_key = forms.ask_for_unique_string( prompt='Enter a Unique Key', title=self.Title, reserved_values=reserved_keys, owner=self) if new_key: try: kdb.reserve_key(self._conn, new_key, category=self._cat) except System.TimeoutException as toutex: forms.alert(toutex.Message) return self._reserved_key = new_key # set the key value on the button self.active_key = new_key