Not sure how to pygubu please with inheritence and spawning new windows #233
Answered
by
alejandroautalan
coffeelover1010
asked this question in
Q&A
-
Hi, can anyone tell me under the hood why code1 spawns new windows for me and code 2 doesn't? code1
code2
|
Beta Was this translation helpful? Give feedback.
Answered by
alejandroautalan
Feb 9, 2024
Replies: 1 comment 3 replies
-
Hello @coffeelover1010 thanks for trying pygubu. This is my answer: Code1 class PyGubuBuilder:
def __init__(self, ui_filename):
self.builder = pygubu.Builder()
self.builder.add_resource_path(PROJECT_PATH)
self.builder.add_from_file(PROJECT_PATH / ui_filename)
self.toplevel1 = self.builder.get_object('toplevel1') # <- Creating the toplevel
self.builder.connect_callbacks(self) # <- Connecting callbacks after all
# widgets created. OK
# the button is connected and works Code2 class PyGubuBuilder:
def __init__(self, ui_filename):
self.builder = pygubu.Builder()
self.builder.add_resource_path(PROJECT_PATH)
self.builder.add_from_file(PROJECT_PATH / ui_filename)
self.builder.connect_callbacks(self) # <- Calling connect here does nothing because
# No widget was created yet.
# the button is created later. Solution for code 2 class PyGubuBuilder:
def __init__(self, ui_filename):
self.builder = pygubu.Builder()
self.builder.add_resource_path(PROJECT_PATH)
self.builder.add_from_file(PROJECT_PATH / ui_filename)
self.builder.connect_callbacks(self)
class MyUI(PyGubuBuilder):
def __init__(self):
super().__init__('pygubu2.ui')
self.toplevel1 = self.builder.get_object('toplevel1')
self.builder.connect_callbacks(self) # <- Connect callbacks
class App(PyGubuBuilder):
def __init__(self):
super().__init__('pygubu.ui')
self.mainwindow = self.builder.get_object('toplevel1')
self.builder.connect_callbacks(self) # <- Connect callbacks
self.myui = []
def command_new_ui(self):
self.myui.append(MyUI()) Remember that connect_callbacks should be called after all related widgets have been created. Regards |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
coffeelover1010
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @coffeelover1010 thanks for trying pygubu.
This is my answer:
Code1
Code2