alejandroautalan/pygubu

Open a new frame broken in v0.10

Guiguiolive opened this issue · 5 comments

Hello!

I've been using Pygubu for a long time now, and after updating to the 0.10.9 version, my code to open a new frame is broken while it was working fine with v0.9.8.6

I'm using the code provided as an example here: #132

builder2 = pygubu.Builder()
builder2.add_from_file("myiu.ui")
toplevel2 = tk.Toplevel(self.mainwindow)
frame2 = builder2.get_object('window2', toplevel2)
callbacks = {}
builder2.connect_callbacks(self)

Instead of opening my "window2", it opens a new frame with the root frame in it.

After some testing and opening the UI file with pygubu-designer v0.16, it seems my UI design is now wrongly interpreted by pygubu (and pygubu designer).
Instead of my second window, I have a copy of the root window...

The UI file was originally created with pygubu-designer bundled with the v0.9.8.6 version...

Any idea what change in v0.10 may produce this result?
And is there a way to convert the previously generated XML in the new version without having to redisign everything? :)

Thanks!

Hello Guiguiolive, thanks for trying pygubu.

Hello!

I've been using Pygubu for a long time now, and after updating to the 0.10.9 version, my code to open a new frame is broken while it was working fine with v0.9.8.6

builder2 = pygubu.Builder()
builder2.add_from_file("myiu.ui")
toplevel2 = tk.Toplevel(self.mainwindow)
frame2 = builder2.get_object('window2', toplevel2)
callbacks = {}
builder2.connect_callbacks(self)

Instead of opening my "window2", it opens a new frame with the root frame in it.

After some testing and opening the UI file with pygubu-designer v0.16, it seems my UI design is now wrongly interpreted by pygubu (and pygubu designer).
Instead of my second window, I have a copy of the root window...

The UI file was originally created with pygubu-designer bundled with the v0.9.8.6 version...

Any idea what change in v0.10 may produce this result?
And is there a way to convert the previously generated XML in the new version without having to redisign everything? :)

Thanks!

Some notes first.

  • Opening and saving a UI file from v0.9.8.6 with the last version 0.10.9 will automatically convert the file to the new version.
  • The converted UI file will not open correctly again in the old version.

It will be great if you can paste here your original UI file to see if there are some issues in the conversion process.
Or make a minimal working example so I can see which widgets and code that you are using and is not working in the last version.

Regards
Alejandro A.

Hello Alejandro,

Thanks for the fast response.
So when I try to open my old UI file with the new designer, it overwrites my second window, so if I save, my UI file is converted, but my window is gone.

Here is the original UI file (1500 lines is too much to paste here):
http://sharkou.net/pygubu/viChap.ui

The root window is: "mainwindow"
The second window is: "cmmainwindow"

Thanks... :)

Hi Guiguiolive. Thanks for the file.

Yes, pygubu (the designer) is loading and saving the file incorrectly.
Let me review it and will try to fix this bug.

Just for complete the basic test app, Is this how you are creating the second window? Let me know.

import os
import pygubu


PROJECT_PATH = os.path.dirname(__file__)
PROJECT_UI = os.path.join(PROJECT_PATH, "viChap.ui")
#PROJECT_UI = os.path.join(PROJECT_PATH, "viChap_converted.ui")
#PROJECT_UI = os.path.join(PROJECT_PATH, "viChap_original.ui")


class VichapApp:
    def __init__(self, master=None):
        self.builder = builder = pygubu.Builder()
        builder.add_resource_path(PROJECT_PATH)
        builder.add_from_file(PROJECT_UI)
        self.mainwindow = builder.get_object('mainwindow', master)
        builder.connect_callbacks(self)
    
    def onManagerClicked(self):
        print('onManagerClicked')
        builder2 = pygubu.Builder()
        builder2.add_from_file(PROJECT_UI)
        toplevel2 = tk.Toplevel()
        frame2 = builder2.get_object('cmmainwindow', toplevel2)
        builder2.connect_callbacks(self)
    
    def onClearReportClicked(self):
        pass

    def onResetCandidateClicked(self):
        pass

    def onResetPositionClicked(self):
        pass

    def onAnalyseClicked(self):
        pass

    def onGenerateClicked(self):
        pass

    def onCopyOriginalToThirdClicked(self):
        pass

    def run(self):
        self.mainwindow.mainloop()

if __name__ == '__main__':
    import tkinter as tk
    root = tk.Tk()
    app = VichapApp(root)
    app.run()

Regards
Alejandro A.

Hi Guiguiolive.
I think I found the problem. The bug is that the designer is not enforcing the uniqueness of the widget IDs.
Your UI file has widgets with duplicated IDs.

  • two widgets with same id "contentFrame". You need to change one to "contentFrame2" or different id.
  • two widgets with same id "topFrame". You need to change one to "topFrame2" or different id.

You can change them manually opening the .ui file with a text editor or open it with designer of pygubu v0.9.8.6, modify the widgets IDs and then save.
Once you have changed the widgets IDs, you can open the .ui file with the latest pygubu version, and the layout should be the same.
Try it, and let me know.

Regards
Alejandro A.

Hello Alejandro,

I made sure the IDs were unique and the conversion to the new format went well.
It's working again now.

Thank you for your reactivity!