Skip to content

Commit 4d5efee

Browse files
authored
Merge Windows build system config and better loading into master (#1)
1 parent 0cc5697 commit 4d5efee

File tree

11 files changed

+302
-72
lines changed

11 files changed

+302
-72
lines changed

.appveyor.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
environment:
2+
matrix:
3+
- PYTHON: "C:\\PYTHON38-x64"
4+
build: off
5+
install:
6+
- set PATH=C:\msys64\usr\bin;%PATH%
7+
# Load PGP Keys for Msys64
8+
- bash -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
9+
- bash -lc "curl -O http://repo.msys2.org/msys/x86_64/msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig"
10+
- bash -lc "pacman-key --verify msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz.sig"
11+
- bash -lc "pacman -U --noconfirm --config <(echo) msys2-keyring-r21.b39fb11-1-any.pkg.tar.xz"
12+
# Kill gpg-agent due to bug in MSYS
13+
- TaskKill /IM gpg-agent.exe /F
14+
# Update known packages
15+
- bash -lc "pacman --needed --noconfirm -Syu"
16+
- bash -lc "pacman --needed --noconfirm -Sy"
17+
# Install Python build dependencies
18+
- "%PYTHON%\\python.exe -m pip install scikit-build nose"
19+
# Now using MinGW pkg-config and related executables
20+
- set PATH=C:\msys64\mingw64\bin;%PATH%
21+
# Download Dependencies (dependency walker)
22+
- appveyor DownloadFile https://github.com/lucasg/Dependencies/releases/download/v1.10/Dependencies_x64_Release.zip
23+
- 7z e Dependencies_x64_Release.zip -odeps -y
24+
# Add %PYTHON% to the path for libffi-7.dll
25+
- set PATH=%PYTHON%;C:\msys64\mingw64\lib;%PATH%
26+
build_script:
27+
- "%PYTHON%\\python.exe setup.py build bdist_wheel"
28+
# Simplify PATH so as to test binary distribution
29+
- set PATH=C:\WINDOWS\system32;C:\WINDOWS
30+
test_script:
31+
- "%PYTHON%\\python.exe -m nose"
32+
artifacts:
33+
- path: "/dist/*.whl"
34+
deploy:
35+
provider: GitHub
36+
auth_token:
37+
secure: QimY++/91urL/oMJL/q2zYFqc1C7747HguEaIbPQovtC3zG8CK+TiCmFOCXy1D6e
38+
artifact: "/dist/*.whl"
39+
draft: false
40+
prerelease: false
41+
force_update: true
42+
on:
43+
branch: master
44+
appveyor_repo_tag: true

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,11 @@ MANIFEST
9898
/docs/doxygen/xml
9999
/html
100100
/latex
101+
102+
# GTK Themes and configuration
103+
/gttk/*
104+
!/gttk/__init__.py
105+
!/gttk/gttk.tcl
106+
107+
# Dependencies Program
108+
/deps

CMakeLists.txt

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
CMAKE_MINIMUM_REQUIRED ( VERSION 2.8 )
1+
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
22

33
## ===========================================================================
44
## Project Information
@@ -62,18 +62,18 @@ MESSAGE ( STATUS "===========================================================" )
6262
## ===========================================================================
6363
## Locate Tcl/Tk
6464
## ===========================================================================
65-
MESSAGE ( STATUS "Searching for Tcl/Tk..." )
66-
FIND_PACKAGE ( TCL REQUIRED )
67-
FIND_PACKAGE ( TclStub REQUIRED )
68-
MESSAGE ( STATUS " TCL_TCLSH: " ${TCL_TCLSH} )
69-
MESSAGE ( STATUS " TCL_INCLUDE_PATH: " ${TCL_INCLUDE_PATH} )
70-
MESSAGE ( STATUS " TCL_STUB_LIBRARY: " ${TCL_STUB_LIBRARY} )
71-
MESSAGE ( STATUS " TCL_LIBRARY: " ${TCL_LIBRARY} )
72-
MESSAGE ( STATUS " TK_WISH: " ${TK_WISH} )
73-
MESSAGE ( STATUS " TK_INCLUDE_PATH: " ${TK_INCLUDE_PATH} )
74-
MESSAGE ( STATUS " TK_STUB_LIBRARY: " ${TK_STUB_LIBRARY} )
75-
MESSAGE ( STATUS " TTK_STUB_LIBRARY: " ${TTK_STUB_LIBRARY} )
76-
MESSAGE ( STATUS " TK_LIBRARY: " ${TK_LIBRARY} )
65+
MESSAGE(STATUS "Searching for Tcl/Tk...")
66+
FIND_PACKAGE(TCL REQUIRED)
67+
FIND_PACKAGE(TclStub REQUIRED)
68+
MESSAGE(STATUS " TCL_TCLSH: " ${TCL_TCLSH})
69+
MESSAGE(STATUS " TCL_INCLUDE_PATH: " ${TCL_INCLUDE_PATH})
70+
MESSAGE(STATUS " TCL_STUB_LIBRARY: " ${TCL_STUB_LIBRARY})
71+
MESSAGE(STATUS " TCL_LIBRARY: " ${TCL_LIBRARY})
72+
MESSAGE(STATUS " TK_WISH: " ${TK_WISH})
73+
MESSAGE(STATUS " TK_INCLUDE_PATH: " ${TK_INCLUDE_PATH})
74+
MESSAGE(STATUS " TK_STUB_LIBRARY: " ${TK_STUB_LIBRARY})
75+
MESSAGE(STATUS " TTK_STUB_LIBRARY: " ${TTK_STUB_LIBRARY})
76+
MESSAGE(STATUS " TK_LIBRARY: " ${TK_LIBRARY})
7777
# STRING ( REPLACE stub "" TCL_LIBRARY_STATIC ${TCL_STUB_LIBRARY} )
7878
# STRING ( REPLACE stub "" TK_LIBRARY_STATIC ${TK_STUB_LIBRARY} )
7979
# MESSAGE ( STATUS " TCL_LIBRARY_STATIC: " ${TCL_LIBRARY_STATIC} )
@@ -84,14 +84,14 @@ IF ( WIN32 AND NO_MSVCRT )
8484
STRING ( REPLACE /MDd /MTd CMAKE_C_FLAGS_DEBUG ${CMAKE_C_FLAGS_DEBUG} )
8585
STRING ( REPLACE /MD /MT CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
8686
STRING ( REPLACE /MDd /MTd CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} )
87-
SET ( CMAKE_EXE_LINKER_FLAGS
88-
"${CMAKE_EXE_LINKER_FLAGS} /nodefaultlib:MSVCRT.LIB" )
87+
# SET ( CMAKE_EXE_LINKER_FLAGS
88+
# "${CMAKE_EXE_LINKER_FLAGS} /nodefaultlib:MSVCRT.LIB" )
8989
SET ( CMAKE_EXE_LINKER_FLAGS_RELEASE
9090
"${CMAKE_EXE_LINKER_FLAGS_RELEASE} LIBCMT.LIB" )
9191
SET ( CMAKE_EXE_LINKER_FLAGS_DEBUG
9292
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} LIBCMTD.LIB" )
93-
SET ( CMAKE_SHARED_LINKER_FLAGS
94-
"${CMAKE_SHARED_LINKER_FLAGS} /nodefaultlib:MSVCRT.LIB" )
93+
# SET ( CMAKE_SHARED_LINKER_FLAGS
94+
# "${CMAKE_SHARED_LINKER_FLAGS} /nodefaultlib:MSVCRT.LIB" )
9595
SET ( CMAKE_SHARED_LINKER_FLAGS_RELEASE
9696
"${CMAKE_SHARED_LINKER_FLAGS_RELEASE} LIBCMT.LIB" )
9797
SET ( CMAKE_SHARED_LINKER_FLAGS_DEBUG
@@ -127,6 +127,11 @@ ADD_DEFINITIONS ( -DPACKAGE_VERSION="${PKG_VERSION}" )
127127
INCLUDE_DIRECTORIES ( ${TCL_INCLUDE_PATH} )
128128
INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH} )
129129
INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH}/tk-private/generic/ttk )
130+
IF ( WIN32 ) # Include additional directories for MSYS build
131+
INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH}/tk8.6/tk-private/generic )
132+
INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH}/tk8.6/tk-private/generic/ttk )
133+
INCLUDE_DIRECTORIES ( ${TK_INCLUDE_PATH}/tk8.6/tk-private/win )
134+
ENDIF ( WIN32 )
130135
INCLUDE_DIRECTORIES ( ${PROJECT_SOURCE_DIR}/generic )
131136

132137
## ===========================================================================
@@ -162,15 +167,15 @@ ENDIF ( USE_GNOME )
162167
## ===========================================================================
163168
## Locate GTK...
164169
## ===========================================================================
165-
MESSAGE ( STATUS "Searching for GTK2..." )
170+
MESSAGE(STATUS "Searching for GTK2...")
166171
find_package(PkgConfig REQUIRED)
167172
pkg_check_modules(GTK "gtk+-2.0")
168173
if (GTK_FOUND)
169-
LINK_LIBRARIES( ${GTK_LIBRARIES})
170-
add_definitions(${GTK_CFLAGS} ${GTK_CFLAGS_OTHER})
174+
LINK_LIBRARIES(${GTK_LIBRARIES})
175+
add_definitions(${GTK_CFLAGS} ${GTK_CFLAGS_OTHER})
171176

172-
MESSAGE ( STATUS " GTK 2.x Found!" )
173-
endif()
177+
MESSAGE(STATUS " GTK 2.x Found!")
178+
endif ()
174179

175180
## ===========================================================================
176181
## Target: gttk_Symbols.[h|cpp]
@@ -190,6 +195,7 @@ endif()
190195
# PROPERTIES GENERATED true )
191196

192197
SET ( PKG_TARGET_LIB_NAME ${PKG_NAME} )
198+
193199
## ===========================================================================
194200
## Target: gttk shared library
195201
## ===========================================================================
@@ -231,17 +237,13 @@ ELSE ( LOAD_GTK_DYNAMICALLY )
231237
ENDIF ( UNIX )
232238
ENDIF ( LOAD_GTK_DYNAMICALLY )
233239

234-
FILE ( WRITE library/pkgIndex.tcl
240+
FILE ( WRITE gttk/pkgIndex.tcl
235241
"package ifneeded ttk::theme::gttk ${PKG_VERSION} \\
236242
[list load [file join $dir lib${PKG_NAME}[info sharedlibextension]] gttk]" )
237243

238244
INSTALL ( TARGETS ${PKG_TARGET_LIB_NAME}
239245
RUNTIME DESTINATION ${PKG_TARGET_LIB_NAME}
240246
LIBRARY DESTINATION ${PKG_TARGET_LIB_NAME}
241247
ARCHIVE DESTINATION ${PKG_TARGET_LIB_NAME} )
242-
INSTALL ( FILES library/pkgIndex.tcl library/gttk.tcl
248+
INSTALL ( FILES gttk/pkgIndex.tcl gttk/gttk.tcl
243249
DESTINATION ${PKG_TARGET_LIB_NAME} )
244-
245-
ENABLE_TESTING ( )
246-
ADD_TEST ( demo ${TK_WISH} ${PROJECT_SOURCE_DIR}/demos/demo.tcl )
247-
ADD_TEST ( styles ${TK_WISH} ${PROJECT_SOURCE_DIR}/demos/WidgetStates.tcl )

example.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ def screenshot(self, *args):
8080

8181
if __name__ == '__main__':
8282
sys.path = sys.path[2:]
83-
84-
import gttk
83+
from gttk import GTTK
8584

8685
window = Example()
86+
gttk = GTTK(window)
8787
style = ttk.Style(window)
8888

8989
style.theme_use("gttk")
9090

91-
window.mainloop()
91+
print(gttk.get_theme_colour_keys())
9292

93+
window.mainloop()

generic/gttk_GtkApp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ gttk_WidgetCache **gttk_CreateGtkApp(Tcl_Interp *interp) {
143143
*/
144144
wc->gttk_MainInterp = interp;
145145
wc->gttk_tkwin = Tk_MainWindow(interp);
146-
if (wc->gttk_tkwin != NULL && wc->gttk_MainDisplay == None) {
146+
if (wc->gttk_tkwin != NULL && wc->gttk_MainDisplay == NULL) {
147147
Tk_MakeWindowExist(wc->gttk_tkwin);
148148
wc->gttk_MainDisplay = Tk_Display(wc->gttk_tkwin);
149149
}
150-
if (wc->gttk_MainDisplay == None) {
150+
if (wc->gttk_MainDisplay == NULL) {
151151
Tcl_MutexUnlock(&gttkMutex);
152152
Tcl_Free((char *) wc_array[0]);
153153
Tcl_Free((char *) wc_array[1]);

generic/gttk_Init.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ int gttk_GtkEnum(ClientData clientData, Tcl_Interp *interp,
290290
int gttk_GtkDirectory(ClientData clientData, Tcl_Interp *interp,
291291
int objc, Tcl_Obj *const objv[]) {
292292
static const char *Methods[] = {
293-
"theme", "default_files", (char *) NULL
293+
"theme", "default_files", "module", (char *) NULL
294294
};
295295
enum methods {
296-
THEME, DEFAULT_FILES
296+
THEME, DEFAULT_FILES, MODULE
297297
};
298298
int type;
299299
gchar *dir = NULL, **dirs = NULL;
@@ -332,6 +332,9 @@ int gttk_GtkDirectory(ClientData clientData, Tcl_Interp *interp,
332332
dirs = gttk_gtk_rc_get_default_files();
333333
}
334334
break;
335+
case MODULE:
336+
dir = gtk_rc_get_module_dir();
337+
break;
335338
}
336339
if (dir) {
337340
Tcl_SetResult(interp, (char *) dir, TCL_VOLATILE);

generic/gttk_Utilities.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,13 @@ void gttk_CopyGtkPixmapOnToDrawable(GdkPixmap *gdkDrawable, Drawable d,
281281
GC gc = Tk_GetGC(tkwin, GCForeground | GCBackground | GCGraphicsExposures,
282282
&gcValues);
283283
GdkGC *gdkGC = gttk_gdk_gc_new(gdkDrawable);
284-
HDC hdcSrc = gttk_gdk_win32_hdc_get(gdkDrawable, gdkGC, gc_usage);
284+
HDC hdcSrc = gdk_win32_hdc_get(gdkDrawable, gdkGC, gc_usage);
285285
/* Create a Tk Drawable from the HDC... */
286286
TkWinDrawable gtkD;
287287
gtkD.type = TWD_WINDC;
288288
gtkD.winDC.hdc = hdcSrc;
289289
XCopyArea(Tk_Display(tkwin), (Drawable) &gtkD, d, gc, x, y, w, h, x1, x2);
290-
gttk_gdk_win32_hdc_release(gdkDrawable, gdkGC, gc_usage);
290+
gdk_win32_hdc_release(gdkDrawable, gdkGC, gc_usage);
291291
if (gdkGC) gttk_g_object_unref(gdkGC);
292292
Tk_FreeGC(Tk_Display(tkwin), gc);
293293
#else

gttk/__init__.py

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"""
66
import contextlib
77
import os
8+
import tkinter as tk
89
from tkinter import ttk
10+
from typing import List, Tuple
911

1012

1113
@contextlib.contextmanager
@@ -17,17 +19,51 @@ def chdir(target):
1719
finally:
1820
os.chdir(cwd)
1921

20-
__orig_ttk_Style_init__ = ttk.Style.__init__
2122

23+
class GTTK(object):
24+
"""
25+
Class representing the GTTK extension
26+
"""
2227

23-
def __ttk_Style_init__(self, *args, **kwargs):
24-
__orig_ttk_Style_init__(self, *args, **kwargs)
28+
def __init__(self, window: tk.Tk):
29+
"""
30+
Initialize gttk and load it into a window
2531
26-
folder = os.path.dirname(os.path.abspath(__file__))
32+
:param window: Window with Tk/Tcl interpreter to load gttk for
33+
"""
34+
self.tk = window.tk
35+
folder = os.path.dirname(os.path.abspath(__file__)).replace("\\", "/")
36+
with chdir(folder):
37+
self.tk.eval("set dir {0}; source {0}/pkgIndex.tcl".format(folder))
38+
self.tk.call("package", "require", "ttk::theme::gttk")
39+
print(self.get_current_theme())
2740

28-
with chdir(folder):
29-
self.tk.eval("set dir {0}; source {0}/pkgIndex.tcl".format(folder))
30-
self.tk.call("package", "require", "ttk::theme::gttk")
41+
def get_themes_directory(self) -> str:
42+
"""Return the directory in which GTK looks for installed themes"""
43+
return self.tk.call("ttk::theme::gttk::gtkDirectory", "theme")
3144

45+
def get_default_files(self) -> Tuple[str]:
46+
"""Return the files that GTK parses by default at start-up"""
47+
return self.tk.call("ttk::theme::gttk::gtkDirectory", "default_files")
3248

33-
ttk.Style.__init__ = __ttk_Style_init__
49+
def get_current_theme(self) -> str:
50+
"""Return the name of the currently active GTK theme"""
51+
return self.tk.call("ttk::theme::gttk::currentThemeName")
52+
53+
def get_module_path(self) -> str:
54+
"""Return the name of the module path (theme engines)"""
55+
return self.tk.call("ttk::theme::gttk::gtkDirectory", "module")
56+
57+
def get_gtk_enum_value(self, value: int) -> str:
58+
"""
59+
Return a value of a the GtkPositionType enum
60+
61+
TODO: Extend gttk_GtkEnum in gttk_Init.cpp for more enums
62+
"""
63+
return self.tk.call("ttk::theme::gttk::gtkEnum", "GtkPositionType", 0)
64+
65+
def get_theme_colour(self, name: str) -> str:
66+
return self.tk.call("ttk::theme::gttk::currentThemeColour", name)
67+
68+
def get_theme_colour_keys(self) -> Tuple[str]:
69+
return self.tk.call("ttk::theme::gttk::currentThemeColourKeys")
File renamed without changes.

0 commit comments

Comments
 (0)