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

Making this ready for publication #1

Open
7 of 21 tasks
RedFantom opened this issue Feb 28, 2021 · 9 comments
Open
7 of 21 tasks

Making this ready for publication #1

RedFantom opened this issue Feb 28, 2021 · 9 comments

Comments

@RedFantom
Copy link
Member

RedFantom commented Feb 28, 2021

So, I thought I'd add a TODO list of what I'd still like to do with this package before I think it's ready for publication. Feel free to add your own points, @rdbende , so we can discuss them here!

TODO List

  • Font support
    • Integration with tkextrafont
    • RedFantom/extrafont: Travis-CI & AppVeyor building
    • Publication of tkextrafont to PyPI from that repository
  • SVG Theme Support with tksvg/Tk 8.7
    • Implement CI building for TkinterEP/python-tksvg
    • Create at least one scalable SVG theme for hi-res displays
    • Publication of tksvg to PyPI from that repository
  • Better logging configurability
    • TBD
  • Python or CSS theme support
    Support for defining themes in Python, CSS or some other additional method. Could work in conjunction with the GTK theme parser.
  • Support for loading a PNG theme as a GIF theme
    Investigate the possibility of loading PNG images into PhotoImages and dropping the alpha channel from them on-the-fly to improve application performance while removing the need for separate GIF-based themes.
  • Put everything under unit tests

Themes ready at release
These are all themes I'd like to have in a separate repository. Whether they should also be PyPI packages is TBD.

Stretch Goals

Suspended Features

  • GTK-theme support
    Either take the GTK theme parser from thettkstyles/gtk directory where it currently resides and make it suitable for parsing arbitrary GTK themes or drop the idea completely
@rdbende
Copy link
Member

rdbende commented Mar 18, 2021

Support for loading a PNG theme as a GIF theme

I finally find the way for this: https://www.tcl.tk/man/tcl/TkCmd/photo.htm#M39. I don't know that Tk has transparency control, because Tkinter does not support it (along with many other useful features), but we can do it with tk.call.

self.tk.call(self.name, 'transparency', 'get', x, y) # Returns a boolean indicating if the pixel at (x, y) is transparent.
self.tk.call(self.name, 'transparency', 'set', x, y, is_transparent) # Makes the pixel at (x,y) transparent if boolean is true

@RedFantom
Copy link
Member Author

That is certainly an interesting feature, but that's not necessarily how I intended to implement that feature. The key problem with PNG themes over GIF themes is performance due to the alpha channel. There can be transparency in the image, but a full alpha channel with varying opacity is too much. Therefore, what I thought could work is the following:

  • Modify the theme.tcl file to no longer read the images from disk.
  • Read the PNG images with Python.
  • Use PIL/pillow to remove the alpha channel from these images by mixing them with the proper background color for the theme.
  • Write the output images in GIF and base64 format to an output buffer.
  • Evaluate the output buffer in Tcl to create an image array.
  • Evaluate the modified theme.tcl file to create the theme with the in-memory GIF images.

However, I am rather curious if the method that you suggest can also provide the performance improvement that removing the alpha channel from the PNG images would have. I have relatively little time again now, so I'll probably not get around to it for a bit. However, I have implemented the build system for tksvg and published it to PyPI, so if you want to try building an SVG azure theme, that should now be possible with Tkinter.

@rdbende
Copy link
Member

rdbende commented Mar 19, 2021

Okay, I read on and found out that you don't even have to check the transparency per pixel and remove it, but you can go straight to the write method so you can save it in either png or gif format. Of course, we can also make base64 with the base64 module. The other very good thing is that it gives all the alpha channel parts the background you specified.
EDIT: The only problem is that it doesn't completely overwrite them with the given color, but it basically puts a layer of the color you gave behind the transparent part

self.tk.call(self.name, 'write', filename, '-format', format, '-background', color)

I installed tksvg 3 days ago, I really love it, and started to create the SVG Azure theme. 👍

@RedFantom
Copy link
Member Author

If that command can do what I think it might, that would be an absolutely awesomely useful thing. I'm going to try it soon!

I'm glad you like tksvg. If you find any issues or need a different version built (like for Python 3.9 or something like that) just let me know and I will set it up. I'm really looking forward to how the SVG theme is going to turn out!

Also, if you want me to direct my attention to a specific thing, please let me know. I'm currently focused on getting tkextrafont and tksvg on PyPI properly so that this project can get a move on with SVG themes and custom fonts, but if you would like me to look at your PR in ttkwidgets first, just say the word. My time is limited, and I have to make choices, but if you want me to take a look at something feel free to ask!

@rdbende
Copy link
Member

rdbende commented Mar 21, 2021

I have no issues with tksvg, it works perfectly fine, it's just so slow to save all SVG separately from Inkscape :(

I stopped working on the NumberEntry widget, and rather started to implement the suggestions I made for Color and Fontchooser.
I'm wondering, would it be a good idea to create eg and repr dunders for the NumberEntry, to use it easier in comparisons and mathematical calculations?

@RedFantom
Copy link
Member Author

Now that tkextrafont and tksvg have automatic wheel building and CI and are on PyPI, the integration with this repository can begin! I won't be doing that today, but I hope I will have time to do that soon.

Isn't there some way to call InkScape from the command line and export the SVG images in that way? That's more of a Linux-y thing to do, maybe, but with PowerShell there should be lots of options, right? InkScape does appear to have some support for it.

I'm not sure about adding an __eq__ method to NumberEntry, as that will be very unlogical if you want to, say, do procedural generation of the widgets and then some other operations with it. A modified __repr__ sounds fine though, although I'd recommend sticking closely to the default format if you can.

@rdbende
Copy link
Member

rdbende commented Mar 21, 2021

I saw your work on tkextrafont in the afternoon and I've already installed it. I love it!
It's so much simpler and more Pythonic with a Font object.

@RedFantom
Copy link
Member Author

I've been following your work on tkextrafont all afternoon and I've already installed it. I love it. It's so much simpler than the old one (actually a line, but it's also more consistent with the simple Font).

I'm glad you like it! The Font class wasn't entirely my own idea. I actually came up with it after I saw the SvgImage class in answer by j4321 on StackOverflow.

I just thought I'd let you know: I've been extraordinarily busy the past few days and it looks like I will be for what looks like at least until next week. I'll have barely any time and energy to spend on any of these projects. Maybe I'll find a gap to review the PRs on ttkwidgets, but I'm not counting on it. I hope you understand.

Your input has been really valuable so far, so I'm looking forward to seeing whether you can get an SVG version of the theme to work!

@rdbende
Copy link
Member

rdbende commented Jul 13, 2023

Create at least one scalable SVG theme for hi-res displays

image

This would work I guess, though I don't have a hi-res display, and with this 200% global scaling it doesn't look too good.

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

2 participants