Skip to content

Commit 6f9988a

Browse files
committed
fix: invoking gui interface twice
1 parent 5f39ed7 commit 6f9988a

3 files changed

Lines changed: 23 additions & 9 deletions

File tree

docs/Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## unreleased
44
* enh: config file union support
5+
* fix: invoking gui interface twice
56

67
## 1.2.1 (2025-10-24)
78
* deps (tyro): ready for 0.10

mininterface/_lib/cli_parser.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,7 @@ def annot(type_form):
245245
kwargs, None if helponly else m, args, type_form, env_classes, _custom_registry, annot, _req_fields
246246
)
247247

248-
# Why setting m.env instead of putting into into a constructor of a new get_interface() call?
249-
# 1. Getting the interface is a costly operation
250-
# 2. There is this bug so that we need to use single interface:
251-
# TODO
252-
# As this works badly, lets make sure we use single interface now
253-
# and will not need the second one.
254-
# get_interface("gui")
255-
# m = get_interface("gui")
256-
# m.select([1,2,3])
248+
# Make the interface ready for the user
257249
m.env = env
258250
except SystemExit as exception:
259251
# --- (C) The dialog missing section ---

mininterface/_tk_interface/adaptor.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,35 @@ class TkAdaptor(Tk, RichUiAdaptor, BackendAdaptor):
3232
facet: TkFacet
3333
settings: GuiSettings
3434

35+
_instance = None
36+
""" singleton """
37+
38+
def __new__(cls, *args, **kwargs):
39+
# Singleton.
40+
# Why enforcing singleton?
41+
# Invoking second tk would mean a strange second window
42+
# and non-responding tkinter variables in the second invocation.
43+
# get_interface("gui")
44+
# m = get_interface("gui")
45+
# m.select([1,2,3]) # cannot choose the value
46+
if cls._instance is None:
47+
return Tk.__new__(cls)
48+
return cls._instance
49+
3550
def __init__(self, *args):
51+
if self._instance:
52+
return
53+
else:
54+
self.__class__._instance = self
55+
3656
BackendAdaptor.__init__(self, *args)
3757

3858
try:
3959
Tk.__init__(self)
4060
except TclError:
4161
# even when installed the libraries are installed, display might not be available, hence tkinter fails
4262
raise InterfaceNotAvailable
63+
self._initialized = True
4364

4465
self.params = None
4566
self._result = None

0 commit comments

Comments
 (0)