definite-d / psg_reskinner Goto Github PK
View Code? Open in Web Editor NEWInstantaneous theme changing for PySimpleGUI windows.
License: MIT License
Instantaneous theme changing for PySimpleGUI windows.
License: MIT License
Importing the ttk_part_mapping_dict
from the PySimpleGUI
module results in an Import Error. Seems like removing its import also does not change anything in the codes. I think it just lies there and needs to be removed to fix the Import Error as it does not do anything in the module and PySimpleGUI does not have anything similar to ttk_part_mapping_dict
as per the recent update. And most importantly, Everything works fine as per my tests :>
**Please check if anything breaks on removing that object on your side too. Thanks !
Traceback::
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\psg_reskinner\__init__.py", line 2, in <module>
from .__main__ import reskin, animated_reskin, toggle_transparency, __version__
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\psg_reskinner\__main__.py", line 34, in <module>
from PySimpleGUI.PySimpleGUI import Window, theme_text_color, theme_slider_color, theme_progress_bar_color, \
ImportError: cannot import name 'ttk_part_mapping_dict' from 'PySimpleGUI.PySimpleGUI' (C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\PySimpleGUI\PySimpleGUI.py)
Good afternoon,
I stumbled on your project from the comments on an issue raised in the PSG repository. I wanted to add a 'randomize theme' button in my project and your library serves my needs perfectly.
I found, however, that certain default themes found in PSG break the 'reskin' command. I found this from using the following script:
import PySimpleGUI as sg
from random import *
import psg_reskinner as psgr
def randomize_theme():
new_theme = sg.theme_list()[randrange(0, 154)]
while new_theme in [
"SystemDefaultForReal",
"Default1",
"Default",
"SystemDefault",
"DefaultNoMoreNagging",
"SystemDefault1",
"GrayGrayGray",
]:
new_theme = sg.theme_list()[randrange(0, 154)]
return new_theme
layout = [[sg.T("Hello world!")], [sg.B("Randomize Theme"), sg.B("Exit")]]
window = sg.Window("Random Themes", layout=layout)
while True:
event, values = window.read(300)
if event == sg.WIN_CLOSED or event == "Exit":
break
if event == "Randomize Theme":
new_theme = randomize_theme()
psgr.reskin(
window=window,
new_theme=new_theme,
theme_function=sg.theme,
lf_table=sg.LOOK_AND_FEEL_TABLE,
)
The PSG theme list has 154 different themes, and I went through and wrote down each default theme that gives an error, a list of which is in the previous code block.
The error that I would get is as follows:
Traceback (most recent call last):
File "c:\...\theme_testing.py", line 31, in <module>
psgr.reskin(
File "C:\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\psg_reskinner\__main__.py", line 395, in reskin
window.TKroot.configure(background=new_theme_dict['BACKGROUND'])
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1702, in configure
return self._configure('configure', cnf, kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1264.0_x64__qbz5n2kfra8p0\Lib\tkinter\__init__.py", line 1692, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown color name "1234567890"
I recognize, of course, that this was probably a smaller project and I would hate to dredge up an annoyance for you -- that is to say that this issue is easily worked around for the user. Just thought I would bring it to your attention.
Thanks, and have a pleasant day.
I'd like to inform you, that i found a weird behaviour when using your fine reskinner plugin.
I am using python 3.10.12 , psg 4.61.0.206, tkinter 8.6.12 on a linuxmint 21.3 system.
When i added lines with '---' to my menu definitions, reskin does no longer work for all the widgets that use these menus.
widgets with no such menudef lines work as before and do the reskin.
Just want to inform you about this, because it took me some time to find out.
Workaround is to create the lines in menu with some other character for example unicode U+23E4 Straightness.
Does not look as nice as the dashes, but works. It seems all other characters work as well.
Thank you for your great work.
Hate to open an issue here for something that seems trivial, but it may help others.
Using PySimpleGUI 4.60.4
Using PSG_Reskinner 2.3.5
ImportError: cannot import name 'TITLEBAR_TEXT_KEY' from 'PySimpleGUI.PySimpleGUI'
Getting this error when attempting to run the example and in my own code.
TITLEBAR_TEXT_KEY was added as of 4.60.3.89
Addition of TITLEBAR_TEXT_KEY to provide access to custom titlebar titles
However according to PyLance it doesn't exist.
So I visited ...\site-packages\PySimpleGUI\PySimpleGUI.py
and alas, it doesn't exist.
I added this line back into PySimpleGUI.py
TITLEBAR_TEXT_KEY = '__TITLEBAR TEXT__'
Did PySimpleGUI remove this? What went wrong? I hate modifying modules, but it'll have to do for now.
Hi i run your fine reskinner on linux (pysimplegui tkinter version). Thank you for all that work.
I had to exchange the occurrence of SystemButtonFace etc, with color names known to tk on Linux (gray30, etc). I currently do not know how to get the default theme colors on all Linux Window Managers
Suggested Fix :
if platform.system() == 'Linux':
block with self colors and default colors
I am running with this change now, but scrollbars keep their colors. Any Hint?
They can also not be reconfigured with psg update calls. Otherwise i would do so after reskin.
Traceback (most recent call last):
File "/var/folders/0d/dj43zrpj3kg85hdt91_cjwy00000gp/T/BBEditRunTemp-untitled text 57.py", line 47, in <module>
reskin(window)
File "/Users/alain/Library/Python/3.9/lib/python/site-packages/psg_reskinner/__main__.py", line 84, in reskin
window.TKroot.config(background=theme_background_color())
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1646, in configure
return self._configure('configure', cnf, kw)
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 1636, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown color name "1234567890"
Frames and menus are not reskinned.
I'll be using the same code as my previous issue just for demonstration purposes.
import PySimpleGUI as sg
from random import randrange
import psg_reskinner as psgr
unsafe_themes = [
"SystemDefaultForReal",
"Default1",
"Default",
"SystemDefault",
"DefaultNoMoreNagging",
"SystemDefault1",
"GrayGrayGray",
]
def randomize_theme():
new_theme = sg.theme_list()[randrange(0, 154)]
while new_theme in unsafe_themes:
new_theme = sg.theme_list()[randrange(0, 154)]
return new_theme
layout = [
[sg.T("Hello world!")],
[sg.B("Randomize Theme"), sg.B("Exit")]
]
window = sg.Window("Random Themes", layout=layout)
while True:
event, values = window.read(300)
if event == sg.WIN_CLOSED or event == "Exit":
break
if event == "Randomize Theme":
new_theme = randomize_theme()
psgr.reskin(
window=window,
new_theme=new_theme,
theme_function=sg.theme,
lf_table=sg.LOOK_AND_FEEL_TABLE,
)
Using this code, a small window pops up and clicking the button randomizes the theme to be any of the 'safe' themes within PSG. That's all well and good, but if I were to add a tabgroup in there...
...
tab_layout = [[sg.T("Goodbye!")]]
layout = [
[sg.T("Hello world!")],
[sg.B("Randomize Theme"), sg.B("Exit")],
[sg.TabGroup(
[[sg.Tab(title="tab", layout=tab_layout)]]
)
],
]
The build will compile and launch, but upon pressing the 'randomize theme' button I get the following traceback:
Traceback (most recent call last):
File "c:\...\theme_testing.py", line 43, in <module>
psgr.reskin(
File "C:\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\psg_reskinner\__main__.py", line 416, in reskin
_recurse_menu(element.TKRightClickMenu, new_theme_dict['TEXT_INPUT'], new_theme_dict['INPUT'])
File "C:\...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\psg_reskinner\__main__.py", line 332, in _recurse_menu
for index in range(0, tkmenu.index('end') + 1):
~~~~~~~~~~~~~~~~~~~~^~~
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
Which I can only assume is due to the addition of the tabgroup. This assumption could be wrong, of course, in which case I would welcome correction -- which is why I am offering the entire code here in case it's an error on my end.
Demo code on readme throws an error when tested
new = rc(safethemes)
(line 31)
NameError: name 'safethemes' is not defined
Replacing identified line with new = rc(theme_list())
fixes the issue and runs correctly.
[change: safethemes -> theme_list()]
Alternatively define safethemes list in the demo code.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.