Anyone interested in having custom widgets and stylesheets as an extension of wxpython?

Hi wxPython users,

I have been wondering if there is interest in the wxpython community to have custom widgets and a stylesheet language for styling them.

WxPython is great for native GUIs and is honestly the best GUI toolkit I’ve used, however it seems that wxPython isn’t so good for custom GUIs (and obviously, it’s because it’s made for native).

It seems like questions about custom GUIs get asked and wxpython should have a better solution than AUI (not that AUI isn’t customizable as-is) or (for example) “you’ll have to create that from scratch in order to change the border thickness on that widget”.

My idea is to make a custom-widget set and stylesheet language, inspired by CSS, to where the widget styles can be controlled by an external/inline stylesheet.

I know this isn’t exactly the first attempt to do something like this, but I do believe it’s worth another try.

Now, I know that there are those who aren’t in favor of customized widgets, etc, but please hear me out. Native works for a lot of UIs, but for some applications and use-cases it really is needed and it would be great to make creating customized GUIs with wxpython easier. I can see this opening up a lot of use cases and a lot more people using wxpython because of it. And I do want to see wxpython grow: Why should QT users have all the fun with customized GUIs? :wink:

Also, I realize that there is getting to be many more “pure-python widgets” now incuded in wxpython -and this is great. I think this makes for a good opportunity to take those widgets and make the styles controllable via a stylesheet.

This is something I’ve been thinking about since I started using wxpython and have even done some experiments with this (though, not fully realized) in my experimental UI Style Lang project.

Here is an experimental demo example, with UI Style Lang (the custom button demo in the repository):

/* button */
@style button {
  background-color: #F4F4F4;
  top: 20px;
  left: 40px;
  width: 115px;
  height: 35px;
  border-color: #D1D1D1;
  border-size: 2px;
}

@style button:hover {
  background-color: #FDFDFD;
  top: 20px;
  left: 40px;
  width: 115px;
  height: 35px;
  border-color: #D1D1D1;
  border-size: 2px;
}

@style button:press {
  background-color: #D1D1D1;
  top: 20px;
  left: 40px;
  width: 115px;
  height: 35px;
  border-color: #D1D1D1;
  border-size: 2px;
}

Result (button changes color when hovered and clicked, etc):

Now, obviously, the current demo is drawn to a wx.PsuedoDC, but the idea is that the button would be a widget itself and style-able.

Questions you may wonder:

What about actually implementing this? That’s part of the reason I am writing this: in order for this to be implemented we need more than just me doing it.

  • If you’re a wxpython user you already have the skills to help out as you know python and wxpython (I don’t see any need for additional skills to help develop this project at the present moment).
  • If you’re not a wxpython user, but want this functionality, then you can probably still help as you probably know python and at least want to know wxpython.

Now, what about maintenance? Indeed this would take a bit of work to update for new releases, but I think it’s worth it if enough people are interested in using it. So, if you’d be interested in potentially using this project (saying it was implemented), it would be great to know that as well.

So, constructive feedback is welcome! I realize I may have not thought of everything, so please let me know.

Please let me know if you’d be interested in developing and/or using this for your wxpython project(s) as well or if there is an alternative that would be better. @robin, I’d especially like to know your thoughts, if possible. Thanks! :smiley:

I (for one) would love to the ability to use css like instructions to style widgets. I have always thought the web style tools would be very helpful to those of us that program for the desktops.

Hi @jfabiani, thanks for the agreement. That’s a vote +1 for this project!

Me as well. :grinning:

I think it’s a great idea, but it would be a ton of work and lots of reimplementing of existing widgets. Not only the looks, but functionality too, which should match all the functionality of the existing widgets because if there is some subtle feature missing that somebody needs then there will be instant anger. And it would have to support a styleable version of all widgets, because as soon as there are users there will be at least one that absolutely needs to have some other widget supported too and will spout negative comments and rage. It’s not pretty, but that’s the way it is.

1 Like

Indeed.

People get angry at you for not having a feature? That’s sad. :frowning:

I see your point, but I was thinking that it wouldn’t be an “official” wxpython extension right away and would be installed separately (as in, not included with wxpython package) until we figured it had enough stability and widgets to do so.

I also believe that we can make it so that if someone wants to “hook” their own widgets/custom drawing, they can define their own style properties. Thus, if something is not implemented or they need something custom, they can hook the style language into what they create themselves.

Also, its worth noting that this is obviously quite optional: the normal, native widgets can be used and mixed with the styled widgets, etc. It doesn’t always look bad to do that. Or, someone can just use the normal, native widgets and disregard the styled widget extension altogether.

I guess I don’t see a problem as far as having to support all of the widgets. Yes, I think I’d be a bit upset to find that it didn’t support tabs or some other widgets at that exact moment, but it seems to be the same thing with the wx.lib.AGW (and in my case, I ended up doing some hacking and digging to figure out how to get the styling I wanted with AGW). As it is, when you want something you have to do it custom, so I see this as adding value to wxpython rather than causing negative comments, etc. :wink:

Upon rereading it, I see that my comment came off a little harsher than I intended. I mainly wanted to convey how big of a job it would be, and that there will always be somebody who is unhappy with it or think it should be done differently.

Well, there’s always going to be someone who won’t be in favor of it -as you mentioned, so that shouldn’t be a reason to not do it. Indeed, it would be a big job in any case but if there’s enough people working on it then the workload isn’t as much for one person.

Thanks for sharing your thoughts @robin. I appreciate it.