Skip to content

Commit

Permalink
Merge pull request #18 from littlewhitecloud/main
Browse files Browse the repository at this point in the history
Add mica alt effect and some small tweaks
  • Loading branch information
marticliment authored Aug 31, 2023
2 parents 3be9d09 + 866a94e commit cd69163
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 164 deletions.
64 changes: 37 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,43 @@ python -m pip install win32mica
## Usage:

```python
#####################################################################
# #
# Those examples are oversimplified, please see the examples folder #
# for detailed usage with each UI library. #
# #
#####################################################################

hwnd = qtwindow.winId().__int__() # On a PyQt/PySide window
hwnd = tkwindow.frame() # On a tkinter window
# You'll need to adjust this to your program

from win32mica import MicaMode, ApplyMica

mode = MicaMode.DARK # Dark mode mica effect
mode = MicaMode.LIGHT # Light mode mica effect
mode = MicaMode.AUTO # Apply system theme, and change it if system theme changes
# Choose one of them following your app color scheme

def callbackFunction():
print("Theme has changed!")

win32mica.ApplyMica(HWND=hwnd, ColorMode=mode, onThemeChange=callbackFunction)

# Function arguments:
# HWND -- a handle to a window (it being an integer value)
# 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
# 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
######################################################################
# #
# Those examples are oversimplified, please see the examples/ folder #
# for detailed usage with each UI library. #
# #
######################################################################

hwnd = window.winId().__int__() # Get the hWnd of your window

from win32mica import ApplyMica, MicaTheme, MicaStyle

mode = MicaTheme.DARK # Dark mode mica effect
mode = MicaTheme.LIGHT # Light mode mica effect
mode = MicaTheme.AUTO # Apply system theme, and change it if system theme changes

style = MicaStyle.DEFAULT # Default backdrop effect
style = MicaStyle.ALT # Alt backdrop effect

def callbackFunction(NewTheme):
if newTheme == MicaTheme.DARK:
print("Theme has changed to dark!")
else:
print("Theme has changed to light!")

win32mica.ApplyMica(HWND=hwnd, Theme=mode, Style=style, OnThemeChange=callbackFunction)

# Parameters
# ----------
# HWND : int
# The handle to the window on which the effect has to be applied
# Theme : MicaTheme, int
# The theme of the backdrop effect: MicaTheme.DARK, MicaTheme.LIGHT, MicaTheme.AUTO
# Style : MicaStyle, int
# The style of the mica backdrop effect: MicaStyle.DEFAULT, MicaStyle.ALT
# OnThemeChange : function
# A callback function that receives one parameter to call when the system theme changes (will only work if Theme is set to MicaTheme.AUTO)
# The passed parameter will be either MicaTheme.DARK or MicaTheme.LIGHT, corresponding to the new system theme

```

Expand Down
25 changes: 0 additions & 25 deletions examples/Pyside2.py

This file was deleted.

59 changes: 51 additions & 8 deletions examples/Pyside6.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,68 @@
import ctypes

try:
import win32mica as mc
from PySide6 import QtWidgets, QtCore
except ImportError:
import os
os.system("pip install win32mica PySide2")
from win32mica import ApplyMica, MicaTheme, MicaStyle
from PySide6 import QtWidgets, QtCore

root = QtWidgets.QApplication()
app = QtWidgets.QMainWindow()
app.setAttribute(QtCore.Qt.WA_TranslucentBackground)
app.setWindowTitle("Qt Dark")
app.setGeometry(100, 100, 300, 200)
mc.ApplyMica(app.winId(), mc.MICAMODE.DARK)
ApplyMica(app.winId(), MicaTheme.DARK, MicaStyle.DEFAULT)
app.show()

app2 = QtWidgets.QMainWindow()
app2.setAttribute(QtCore.Qt.WA_TranslucentBackground)
app2.setWindowTitle("Qt Light")
app2.setGeometry(400, 100, 300, 200)
mc.ApplyMica(app2.winId(), mc.MICAMODE.LIGHT)
ApplyMica(app2.winId(), MicaTheme.LIGHT, MicaStyle.DEFAULT)
app2.show()

app3 = QtWidgets.QMainWindow()
app3.setAttribute(QtCore.Qt.WA_TranslucentBackground)
app3.setWindowTitle("Qt Dark Alt")
app3.setGeometry(100, 330, 300, 200)
ApplyMica(app3.winId(), MicaTheme.DARK, MicaStyle.ALT)
app3.show()

app4 = QtWidgets.QMainWindow()
app4.setAttribute(QtCore.Qt.WA_TranslucentBackground)
app4.setWindowTitle("Qt Light Alt")
app4.setGeometry(400, 330, 300, 200)
ApplyMica(app4.winId(), MicaTheme.LIGHT, MicaStyle.ALT)
app4.show()

app5 = QtWidgets.QMainWindow()
app5.setAttribute(QtCore.Qt.WA_TranslucentBackground)
app5.setWindowTitle("Qt Auto")
app5.setGeometry(700, 100, 300, 200)

label = QtWidgets.QLabel("Change the system theme\nfrom the settings!")
def ApplyStyleSheet(theme):
if theme == MicaTheme.DARK:
label.setStyleSheet("color: white")
else:
label.setStyleSheet("color: black")

ApplyMica(app5.winId(), MicaTheme.AUTO, MicaStyle.DEFAULT, OnThemeChange=ApplyStyleSheet)
app5.show()
app5.setCentralWidget(label)

app6 = QtWidgets.QMainWindow()
app6.setAttribute(QtCore.Qt.WA_TranslucentBackground)
app6.setWindowTitle("Qt Auto Alt")
app6.setGeometry(700, 330, 300, 200)

label2 = QtWidgets.QLabel("Change the system theme\nfrom the settings!")
def ApplyStyleSheet(theme):
if theme == MicaTheme.DARK:
label2.setStyleSheet("color: white")
else:
label2.setStyleSheet("color: black")

ApplyMica(app6.winId(), MicaTheme.AUTO, MicaStyle.ALT, OnThemeChange=ApplyStyleSheet)
app6.show()
app6.setCentralWidget(label2)


root.exec_()
29 changes: 0 additions & 29 deletions examples/Tkinter.py

This file was deleted.

Binary file added img/demo.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="win32mica",
version="2.0",
version="3.0",
author="Martí Climent",
author_email="marticlilop@gmail.com",
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",
Expand Down
Loading

0 comments on commit cd69163

Please sign in to comment.