Skip to content

Commit 86e6aeb

Browse files
committed
Fix creation of loaders.cache on win32
1 parent 9fd04b0 commit 86e6aeb

File tree

3 files changed

+10
-29
lines changed

3 files changed

+10
-29
lines changed

README.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ gttk = GTTK(window)
7979
style = ttk.Style()
8080
style.theme_use("gttk")
8181
print(gttk.get_current_theme()) # Prints the active GTK theme
82+
gttk.set_gtk_theme("Yaru") # Sets GTK theme, provided by developer
8283
ttk.Button(window, text="Destroy", command=window.destroy).pack()
8384

8485
window.mainloop()
@@ -93,30 +94,6 @@ sys.path = sys.path[2:]
9394
import gttk
9495
```
9596

96-
## Applying themes
97-
Themes are applied in the standard GTK+-2.0 manner: By reading a
98-
resource file. On **Linux**, the GTK libraries that are installed will point
99-
`gttk` in the direction of the globally enabled GTK theme. Currently,
100-
no method for overriding this behaviour is available.
101-
102-
On **Windows**, the behaviour is a little different. GTK will look for
103-
for the configuration files that point it towards the theme to be loaded
104-
in the files reported by
105-
```python
106-
GTTK.get_default_files()
107-
```
108-
and themes should be placed in the folder
109-
```python
110-
GTTK.get_themes_directory()
111-
```
112-
113-
A method for reliably loading user themes is being researched, but for
114-
now this is the way to go. A `gtkrc` file may for example simply be
115-
```gtkrc
116-
gtk-theme-name = "Yaru"
117-
```
118-
where `some_path_here/share/themes/Yaru` is a valid GTK theme folder.
119-
12097
## Screenshots
12198
`gttk` should work with any GTK theme you can throw at it, but below
12299
are the themes Yaru and Adwaita as examples.

gttk/__init__.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,20 @@ def __init__(self, window: tk.Tk, theme: Optional[str] = None, theme_dir_prefix:
5151
# Create loaders.cache on win32 platforms to find pixbuf loaders properly
5252
if "win" in sys.platform:
5353
target = os.path.join(temp_dir, "loaders.cache")
54-
with open(os.path.join(folder, "loaders.cache")) as fi, open(target, "w") as fo:
54+
source = os.path.join(folder, "lib", "gdk-pixbuf-2.0", "2.10.0", "loaders.cache")
55+
with open(os.path.join(source)) as fi, open(target, "w") as fo:
5556
cache = fi.read()
56-
abspath = (os.path.join(folder, "lib", "gdk-pixbuf-2.0", "2.10.0", "loaders") + "\\")\
57-
.replace("\\", "\\\\") # loaders.cache uses double \ everywhere
58-
cache_w_abspaths = cache.replace("\\\\lib", abspath)
57+
# loaders.cache uses double \ everywhere
58+
abspath = (os.path.join(folder, "lib", ) + "\\").replace("\\", "\\\\")
59+
cache_w_abspaths = cache.replace("lib\\\\", abspath)
5960
fo.write(cache_w_abspaths)
6061
# Set GDK_PIXBUF_MODULE_FILE to the path of the new cache file
6162
# GDK_PIXBUF_MODULEDIR does not do anything for plain GDK!
6263
os.environ["GDK_PIXBUF_MODULE_FILE"] = target
6364

65+
# Set GTK_EXE_PREFIX on win32 to ensure theme engine loading
66+
os.environ["GTK_EXE_PREFIX"] = folder
67+
6468
with chdir(folder):
6569
# Evaluate pkgIndex.tcl, Tcl does not handle \ as a pathsep, so with /
6670
self.tk.eval("set dir {0}; source {0}/pkgIndex.tcl".format(folder.replace("\\", "/")))

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def copy_to_target(self, target: str):
159159
specials={
160160
"libpixmap.dll": "/lib/gtk-2.0/2.10.0/engines/",
161161
"libwimp.dll": "/lib/gtk-2.0/2.10.0/engines/",
162-
"loaders.cache": "/"} # loaders.cache is used to specify abspaths to the loaders
162+
"loaders.cache": "/lib/gdk-pixbuf-2.0/2.10.0/"} # loaders.cache is used to specify abspaths to the loaders
163163
specials.update({"libpixbufloader-{}.dll".format(fmt): "/lib/gdk-pixbuf-2.0/2.10.0/loaders/"
164164
for fmt in ["ani", "bmp", "gif", "icns", "ico", "jpeg", "png", "pnm", "qtif", "svg", "tga", "tiff", "xbm", "xpm"]})
165165
DependencyWalker("libgttk.dll", specials=specials).copy_to_target("gttk")

0 commit comments

Comments
 (0)