Skip to content

Commit cd69163

Browse files
authored
Merge pull request #18 from littlewhitecloud/main
Add mica alt effect and some small tweaks
2 parents 3be9d09 + 866a94e commit cd69163

File tree

7 files changed

+219
-164
lines changed

7 files changed

+219
-164
lines changed

README.md

+37-27
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,43 @@ python -m pip install win32mica
2525
## Usage:
2626

2727
```python
28-
#####################################################################
29-
# #
30-
# Those examples are oversimplified, please see the examples folder #
31-
# for detailed usage with each UI library. #
32-
# #
33-
#####################################################################
34-
35-
hwnd = qtwindow.winId().__int__() # On a PyQt/PySide window
36-
hwnd = tkwindow.frame() # On a tkinter window
37-
# You'll need to adjust this to your program
38-
39-
from win32mica import MicaMode, ApplyMica
40-
41-
mode = MicaMode.DARK # Dark mode mica effect
42-
mode = MicaMode.LIGHT # Light mode mica effect
43-
mode = MicaMode.AUTO # Apply system theme, and change it if system theme changes
44-
# Choose one of them following your app color scheme
45-
46-
def callbackFunction():
47-
print("Theme has changed!")
48-
49-
win32mica.ApplyMica(HWND=hwnd, ColorMode=mode, onThemeChange=callbackFunction)
50-
51-
# Function arguments:
52-
# HWND -- a handle to a window (it being an integer value)
53-
# ColorMode -- MicaMode.DARK or MicaMode.LIGHT, depending on the preferred UI theme. A boolean value can also be passed, True meaning Dark and False meaning Light
54-
# onThemeChange -- a function without arguments that will be called when the system theme changes. This parameter is effective only if the theme is set to MicaMode.AUTO
28+
######################################################################
29+
# #
30+
# Those examples are oversimplified, please see the examples/ folder #
31+
# for detailed usage with each UI library. #
32+
# #
33+
######################################################################
34+
35+
hwnd = window.winId().__int__() # Get the hWnd of your window
36+
37+
from win32mica import ApplyMica, MicaTheme, MicaStyle
38+
39+
mode = MicaTheme.DARK # Dark mode mica effect
40+
mode = MicaTheme.LIGHT # Light mode mica effect
41+
mode = MicaTheme.AUTO # Apply system theme, and change it if system theme changes
42+
43+
style = MicaStyle.DEFAULT # Default backdrop effect
44+
style = MicaStyle.ALT # Alt backdrop effect
45+
46+
def callbackFunction(NewTheme):
47+
if newTheme == MicaTheme.DARK:
48+
print("Theme has changed to dark!")
49+
else:
50+
print("Theme has changed to light!")
51+
52+
win32mica.ApplyMica(HWND=hwnd, Theme=mode, Style=style, OnThemeChange=callbackFunction)
53+
54+
# Parameters
55+
# ----------
56+
# HWND : int
57+
# The handle to the window on which the effect has to be applied
58+
# Theme : MicaTheme, int
59+
# The theme of the backdrop effect: MicaTheme.DARK, MicaTheme.LIGHT, MicaTheme.AUTO
60+
# Style : MicaStyle, int
61+
# The style of the mica backdrop effect: MicaStyle.DEFAULT, MicaStyle.ALT
62+
# OnThemeChange : function
63+
# A callback function that receives one parameter to call when the system theme changes (will only work if Theme is set to MicaTheme.AUTO)
64+
# The passed parameter will be either MicaTheme.DARK or MicaTheme.LIGHT, corresponding to the new system theme
5565

5666
```
5767

examples/Pyside2.py

-25
This file was deleted.

examples/Pyside6.py

+51-8
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,68 @@
11
import ctypes
22

3-
try:
4-
import win32mica as mc
5-
from PySide6 import QtWidgets, QtCore
6-
except ImportError:
7-
import os
8-
os.system("pip install win32mica PySide2")
3+
from win32mica import ApplyMica, MicaTheme, MicaStyle
4+
from PySide6 import QtWidgets, QtCore
95

106
root = QtWidgets.QApplication()
117
app = QtWidgets.QMainWindow()
128
app.setAttribute(QtCore.Qt.WA_TranslucentBackground)
139
app.setWindowTitle("Qt Dark")
1410
app.setGeometry(100, 100, 300, 200)
15-
mc.ApplyMica(app.winId(), mc.MICAMODE.DARK)
11+
ApplyMica(app.winId(), MicaTheme.DARK, MicaStyle.DEFAULT)
1612
app.show()
1713

1814
app2 = QtWidgets.QMainWindow()
1915
app2.setAttribute(QtCore.Qt.WA_TranslucentBackground)
2016
app2.setWindowTitle("Qt Light")
2117
app2.setGeometry(400, 100, 300, 200)
22-
mc.ApplyMica(app2.winId(), mc.MICAMODE.LIGHT)
18+
ApplyMica(app2.winId(), MicaTheme.LIGHT, MicaStyle.DEFAULT)
2319
app2.show()
2420

21+
app3 = QtWidgets.QMainWindow()
22+
app3.setAttribute(QtCore.Qt.WA_TranslucentBackground)
23+
app3.setWindowTitle("Qt Dark Alt")
24+
app3.setGeometry(100, 330, 300, 200)
25+
ApplyMica(app3.winId(), MicaTheme.DARK, MicaStyle.ALT)
26+
app3.show()
27+
28+
app4 = QtWidgets.QMainWindow()
29+
app4.setAttribute(QtCore.Qt.WA_TranslucentBackground)
30+
app4.setWindowTitle("Qt Light Alt")
31+
app4.setGeometry(400, 330, 300, 200)
32+
ApplyMica(app4.winId(), MicaTheme.LIGHT, MicaStyle.ALT)
33+
app4.show()
34+
35+
app5 = QtWidgets.QMainWindow()
36+
app5.setAttribute(QtCore.Qt.WA_TranslucentBackground)
37+
app5.setWindowTitle("Qt Auto")
38+
app5.setGeometry(700, 100, 300, 200)
39+
40+
label = QtWidgets.QLabel("Change the system theme\nfrom the settings!")
41+
def ApplyStyleSheet(theme):
42+
if theme == MicaTheme.DARK:
43+
label.setStyleSheet("color: white")
44+
else:
45+
label.setStyleSheet("color: black")
46+
47+
ApplyMica(app5.winId(), MicaTheme.AUTO, MicaStyle.DEFAULT, OnThemeChange=ApplyStyleSheet)
48+
app5.show()
49+
app5.setCentralWidget(label)
50+
51+
app6 = QtWidgets.QMainWindow()
52+
app6.setAttribute(QtCore.Qt.WA_TranslucentBackground)
53+
app6.setWindowTitle("Qt Auto Alt")
54+
app6.setGeometry(700, 330, 300, 200)
55+
56+
label2 = QtWidgets.QLabel("Change the system theme\nfrom the settings!")
57+
def ApplyStyleSheet(theme):
58+
if theme == MicaTheme.DARK:
59+
label2.setStyleSheet("color: white")
60+
else:
61+
label2.setStyleSheet("color: black")
62+
63+
ApplyMica(app6.winId(), MicaTheme.AUTO, MicaStyle.ALT, OnThemeChange=ApplyStyleSheet)
64+
app6.show()
65+
app6.setCentralWidget(label2)
66+
67+
2568
root.exec_()

examples/Tkinter.py

-29
This file was deleted.

img/demo.mp4

2.63 MB
Binary file not shown.

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="win32mica",
8-
version="2.0",
8+
version="3.0",
99
author="Martí Climent",
1010
author_email="[email protected]",
1111
description="Apply mica background (if supported) and immersive dark mode to Windows 11 Win32 apps made with python, such as Tkinter or PyQt/PySide apps",

0 commit comments

Comments
 (0)