Code Monkey home page Code Monkey logo

Comments (9)

rdbende avatar rdbende commented on June 22, 2024

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

from ttkstyles.

RedFantom avatar RedFantom commented on June 22, 2024

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.

from ttkstyles.

rdbende avatar rdbende commented on June 22, 2024

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. 👍

from ttkstyles.

RedFantom avatar RedFantom commented on June 22, 2024

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!

from ttkstyles.

rdbende avatar rdbende commented on June 22, 2024

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?

from ttkstyles.

RedFantom avatar RedFantom commented on June 22, 2024

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.

from ttkstyles.

rdbende avatar rdbende commented on June 22, 2024

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.

from ttkstyles.

RedFantom avatar RedFantom commented on June 22, 2024

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!

from ttkstyles.

rdbende avatar rdbende commented on June 22, 2024

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.

from ttkstyles.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.