Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HyperLinkCtrl breaks layout of panel containing multiple sizers #2686

Closed
arigit opened this issue Feb 2, 2025 · 17 comments
Closed

HyperLinkCtrl breaks layout of panel containing multiple sizers #2686

arigit opened this issue Feb 2, 2025 · 17 comments

Comments

@arigit
Copy link
Contributor

arigit commented Feb 2, 2025

In this simple scenario,

import wx
import wx.lib.agw.hyperlink as hl

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="wxPython Layout Example", size=(400, 200))

        # Main panel
        panel = wx.Panel(self)

        # Vertical BoxSizer
        vbox = wx.BoxSizer(wx.VERTICAL)

        # Horizontal BoxSizer inside the VBox
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        # HyperLinkCtrl inside the HBox
        hyperlink = hl.HyperLinkCtrl(panel, id=wx.ID_ANY, label="Visit wxPython", 
                                     URL="https://www.wxpython.org/")

        # Add HyperLink to HBox
        hbox.Add(hyperlink, flag=wx.ALL, border=10)

        # Add HBox to VBox
        vbox.Add(hbox, flag=wx.ALIGN_CENTER)

        # Set sizer for the panel
        panel.SetSizer(vbox)

        self.Centre()

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

the resulting window shows:

Image

which is totally broken (the window border shows transparent, window controls disappear, the window title shows below the hyperlink.

When using any other widget, for example a StaticText,

import wx
import wx.lib.agw.hyperlink as hl

class MyFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title="wxPython Layout Example", size=(400, 200))

        # Main panel
        panel = wx.Panel(self)

        # Vertical BoxSizer
        vbox = wx.BoxSizer(wx.VERTICAL)

        # Horizontal BoxSizer inside the VBox
        hbox = wx.BoxSizer(wx.HORIZONTAL)

        # HyperLinkCtrl inside the HBox
        #hyperlink = hl.HyperLinkCtrl(panel, id=wx.ID_ANY, label="Visit wxPython", 
        #                             URL="https://www.wxpython.org/")

        hyperlink = wx.StaticText(panel, label="Visit wxPython")

        # Add HyperLink to HBox
        hbox.Add(hyperlink, flag=wx.ALL, border=10)

        # Add HBox to VBox
        vbox.Add(hbox, flag=wx.ALIGN_CENTER)

        # Set sizer for the panel
        panel.SetSizer(vbox)

        self.Centre()

if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame()
    frame.Show()
    app.MainLoop()

then the layout is as correct, as expected:

Image

I ran into this while trying to use HyperLinkCtrl in an complex GUI and it completely broke it.

Environment:
Ubuntu 24.01.1 / LTS using Wayland

apt show python3-wxgtk4.0
Package: python3-wxgtk4.0
Version: 4.2.1+dfsg-3build2

python3 --version
Python 3.12.3

gtk-launch --version
3.24.41

@reticulatus
Copy link
Contributor

Your example looks OK using wxPython 4.2.2 gtk3 (phoenix) wxWidgets 3.2.6 + Python 3.12.3 + Linux Mint 22.1

Image

Mint 22.1 uses X11 by default, not Wayland.

@da-dada
Copy link

da-dada commented Feb 3, 2025

@arigit look ok on Windows as well

@arigit
Copy link
Contributor Author

arigit commented Feb 4, 2025

I tested in a Fedora 41 VM, with the same wxpython version.

python3-wxpython4-0:4.2.1-9.fc41.x86_64
Also on wayland,

loginctl show-session $(awk '/tty/ {print $1}' <(loginctl)) -p Type | awk -F= '{print $2}'
wayland

python3 --version
Python 3.13.1

gtk-launch --version
3.24.43

And here it works well:

Image

It's gtk 3.24 in both (minor versions differ) , slightly newer python in fedora (3.13, vs 3.12 in ubuntu)

@arigit
Copy link
Contributor Author

arigit commented Feb 4, 2025

I tested also in a ubuntu VM, 24.04LTS running wayland, same as my main PC minus the Nvidia proprietary driver, and it works well there too.

Same versions of everything, in this case.

So the problem only manifests on Wayland with the Nvidia proprietary driver (I use for OpenCL/CUDA acceleration mainly).

Weirdly enough, it only impacts this particular widget. When this widget is present in the window (it doesn't matter what other widgets are in the same window), they layout breaks, the border becomes transparent etc.

@swt2c swt2c changed the title HyperLilnkCtrl break layout of panel containing multiple sizers HyperLinkCtrl break layout of panel containing multiple sizers Feb 4, 2025
@infinity77
Copy link
Contributor

Out of curiosity, does it happen also with the C++ version of HyperLinkCtrl (under wx.adv)?

@reticulatus
Copy link
Contributor

The test I ran previously was on an all AMD PC.

I have just run the example code on a PC that has an NVIDIA GeForce RTX 3060 Ti graphics card and is using NVIDIA driver 550.120. The display from the example looks identical to what I got on the AMD PC. The PC with NVIDIA is running the same versions of Python, wxPython and Mint as the AMD PC.

Both PCs have GTK 3.24.41

@arigit
Copy link
Contributor Author

arigit commented Feb 5, 2025

@infinity77 the wx.adv version works!

with

        hyperlinkPlusPlus = wx.adv.HyperlinkCtrl(panel, id=wx.ID_ANY, label="Visit wxPython", 
                                     url="https://www.wxpython.org/")     

Image

it works well.

With import wx.lib.agw.hyperlink as hl

Image

it breaks.

This is in my original setup with the nvidia proprietary driver:

Image

It's a desktop card and the 565 has been working really well. Prior drivers had some basic issues with wayland.

Next I will downgrade the driver to 550 and retest.

@arigit
Copy link
Contributor Author

arigit commented Feb 5, 2025

@reticulatus I tested with:

NVIDIA-SMI 550.144.03 Driver Version: 550.144.03 CUDA Version: 12.4

the version that installs when I do apt install nvidia-driver-550, seems to be a bit newer vs. yours.

The result is the same as above,

  • wx.lib.agw.hyperlink: broken
  • wx.adv.HyperlinkCtrl: works

Same GTK version:

gtk-launch --version
3.24.41
gtk4-launch --version
4.14.2

So no difference vs. nvidia version 565

@da-dada
Copy link

da-dada commented Feb 6, 2025

@arigit if the functionality required is covered by https://docs.python.org/3/library/webbrowser.html then it would be the preferred choice: no jumping in & out of different libraries !

@arigit
Copy link
Contributor Author

arigit commented Feb 7, 2025

@da-dada since I needed this to run in linux PCs I do not manage nor know details in advance, I opted for using the below construct that I hope has more chances to 'just work' anywhere:

        self.hyperlink_regex = wx.StaticText(panel, label="More Info")
        self.hyperlink_regex.SetForegroundColour(
            wx.LIGHT_GREY
        )  # Make it look like a hyperlink
        hyperlink_regex_font = self.hyperlink_regex.GetFont()
        self.hyperlink_regex.SetFont(
            hyperlink_regex_font.Underlined()
        )  # Underline to look like a link
        self.hyperlink_regex.SetCursor(wx.Cursor(wx.CURSOR_HAND))
        self.hyperlink_regex.Bind(wx.EVT_LEFT_DOWN, self.open_hyperlink_regex)

...

    def open_hyperlink_regex(self, event):
        """Open the hyperlink in a web browser."""
        webbrowser.open(
            "https://link-to-info.com"
        )


@da-dada
Copy link

da-dada commented Feb 7, 2025

@arigit yes, but you should give it a try with the exception webbrowser.Error since you are going to the outside
BTW I think the problem is the GenStaticText of wx.lib.stattext and you could test it by just changing that with wx.StaticText in GenStaticText temporarily

@arigit
Copy link
Contributor Author

arigit commented Feb 7, 2025

Great recco, thanks @da-dada ! adopted.

I need a bit more guidance on this,

BTW I think the problem is the GenStaticText of wx.lib.stattext and you could test it by just changing that with wx.StaticText in GenStaticText temporarily

this is to attempt to get wx.lib.agw.hyperlink to work, correct?
How do I do the change you suggest so I can test, can you post the one-liner/snippet that I need to add?

@da-dada
Copy link

da-dada commented Feb 7, 2025

@arigit No, it would just be a hint for @infinity77 where the problem comes from
so go into Python313\Lib\site-packages\wx\lib\agw\hyperlink.py and change line 125
from wx.lib.stattext import GenStaticText as StaticText into
from wx import StaticText
(but don't forget to reset it before leaving)

@arigit
Copy link
Contributor Author

arigit commented Feb 8, 2025

@da-dada I tried the change in my ubuntu 24.04 installation,

the file is here:

pwd
/usr/lib/python3/dist-packages/wx/lib/agw
#from wx.lib.stattext import GenStaticText as StaticText
from wx import StaticText

I can confirm it worked - magic! Thanks!

Image

@arigit
Copy link
Contributor Author

arigit commented Feb 8, 2025

I can submit a PR for this if it helps

@infinity77
Copy link
Contributor

While this seems to fix the issue on your machine, I believe we have to see whether the change to GenStaticText to wx.StaticText does not mess up things on Windows.

wx.StaticText is kind of a special beast, as it’s not a real control on Linux machines - it’s just a label drawn by its parent. On Windows it is a real widget and a native one, so it’s possible that some methods that are currently inherited from GenStaticText (OnPaint, DoGetBestSize, etc…) may misbehave. If everything works all right on Windows (and on Mac, since we’re here), then by all means go ahead 😊.

@arigit
Copy link
Contributor Author

arigit commented Feb 8, 2025

@infinity77 Tested in Windows11:

Before the change:

Image

Image

After the change:
(file: "C:\Users\myuser\AppData\Local\Programs\Python\Python313\Lib\site-packages\wx\lib\agw\hyperlink.py")

Image

No issue.
Mac OS: (sequoia / macbook)
Before:

Image

After:
hyperlink File modified:
pwd
/Users/My.User/Library/Python/3.13/lib/python/site-packages/wx/lib/agw

Image

@arigit arigit changed the title HyperLinkCtrl break layout of panel containing multiple sizers HyperLinkCtrl breaks layout of panel containing multiple sizers Feb 9, 2025
@swt2c swt2c closed this as completed in a7bc011 Feb 9, 2025
swt2c added a commit that referenced this issue Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants