Code Monkey home page Code Monkey logo

win32mica's Introduction

Hi!

Hi, I’m @marticliment (Martí Climent). You can find me at www.marticliment.com

Reach me at [email protected] or by filling this form

My main repos:

  • marticliment/ElevenClock
  • marticliment/WingetUI
  • marticliment/win32mica
  • Guitar Chord Transposer (marticliment/martinet101.github.io)

GitHub Stats

stats

Achievements

win32mica's People

Contributors

littlewhitecloud avatar marticliment avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

win32mica's Issues

Change the ColorMode=MICAMODE.LIGHT but it's still dark!

Not sure if I did something wrong
My code:

def Light():
    app.tk.call("ttk::style", "theme", "use") == "sun-valley-dark"
    app.tk.call("set_theme", "light")
    bg_color = ttk.Style().lookup(".", "background")
    app.wm_attributes("-transparent", bg_color)
    HWND=windll.user32.GetParent(app.winfo_id())
    ApplyMica(HWND, ColorMode=MICAMODE.LIGHT)
    app.update()

def Dark():
    app.tk.call("ttk::style", "theme", "use") == "sun-valley-dark"
    app.tk.call("set_theme", "dark")
    bg_color = ttk.Style().lookup(".", "background")
    app.wm_attributes("-transparent", bg_color)
    HWND=windll.user32.GetParent(app.winfo_id())
    ApplyMica(HWND, ColorMode=MICAMODE.DARK)
    app.update()

Result:

2022-03-07-144115.mp4

Everything works but the I cannot close the thing after restoring a minimised window

I made a tkinter application which uses this beautiful mica style, and everything worked. The mica applies fine, there are no errors related to HWND, but there is this one issue. When I restore a minimised window, there are no hitboxes for any buttons on the titlebar. This isssue is related to #7 where OP was not able to focus his window. The same thing happens here, but the only clickable buttons are the ones I made by myself in python, the close, maximise and minimise buttons don't really work

From #7 , I found out that this issue was a tkinter one, is it the case here too?

yes

From this gif, I was trying to click the minimise button again, but the click is registered on the desktop instead of the app itself

Error when applying mica

Hi! Reallay awsome project!
I get this error when running on tkinter window:
Code:
ApplyMica(HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=True)
Error:

  File "D:\Coding\TimerX\main.py", line 783, in makeWindowsBlur
    ApplyMica(HWND=windll.user32.GetParent(app.winfo_id()), ColorMode=True)
  File "C:\Users\suchi\AppData\Local\Programs\Python\Python310\lib\site-packages\win32mica\__init__.py", line 54, in ApplyMica        
    SetWindowCompositionAttribute(HWND, Wca)
ctypes.ArgumentError: argument 2: <class 'TypeError'>: expected WINDOWCOMPOSITIONATTRIBDATA instance instead of WindowCompositionAttribute

Issue in focus

By clicking on the part where mica is used, the program minimizes. If the topmost attribute is applied, the window loses focus, and the mica effect is no longer visible.

Title bar label background colour

is there a way to stop the background color on the label of the window, i kinda resorted to just leaving the title bar empty because it was annoying.

suggestion: Support win10 acrylic and win7 ground glass

Tips:I'm using translation software

I have tried to add advanced effects to win32 forms, and here are some of my ideas.

  1. Import enum and ctypes modules and related classes to handle Windows API calls and data types.
  2. Define the required enumerations and structs
  3. Use the WindowEffect class to encapsulate the methods and data used to achieve the windowing effect.
  4. Set the AccentState attribute of the accentPolicy structure to the value corresponding to the Aero effect.
  5. Call SetWindowCompositionAttribute function, handle to the window and winCompAttrData structure passed to it.

I will submit my code as an attachment. It contains the simplest way to achieve both effects and was tested on my computer. Unfortunately, it still has a lot of bugs, but I don't have time to fix it. So I'm giving it to you, hoping to provide you with some reference and inspiration.
TEST7.zip

This is the simplest way to call code:
TEST7.WindowEffect().setAeroEffect(HWND)

This is the win7 ground glass effect reference

{639B83E5-A016-47a6-9791-4102BFA0E8FF} {C8CB7B29-0A63-4950-BD40-07290C2FC08A}

It is important to note that these effects are not directly achieved by a single line of code. I also adjusted the color of the controls. In the ground glass effect, the closer the color is to black, the higher the transparency.

At the same time, you can also see that some controls are still white. Also, the buttons in the title bar have become transparent.

This is Windows 10 acrylic effect

{039DEF37-6A3C-4c5d-B9CC-044714E4E2A4}

It is puzzling that this effect has a huge lag in the Windows 10 environment, but not in the Windows 11 environment

ValueError: invalid literal for int() with base 10: '0xa20856'

My code is:

import tkinter
from tkinter import ttk

import sv_ttk
root = tkinter.Tk()
root.geometry('400x100+200+200') # set new geometry
from win32mica import MICAMODE, ApplyMica
import darkdetect # You can pass the darkdetect return value directly, since the ColorMode accepts bool values (True -> dark, False -> light)
mode = darkdetect.isDark()

hwnd = root.frame() # On a tkinter window
ApplyMica(hwnd, mode)

button = ttk.Button(root, text="Click me!")
button.pack()


# This is where the magic happens
if darkdetect.isDark():
  sv_ttk.set_theme("dark")
else:
  sv_ttk.set_theme("light")

root.mainloop()

Applying Win32Mica messed it up.

Is it a bug in Win32Mica, or a bug in my code?

EDIT: Here is the backlog appearing when running the script:

Traceback (most recent call last):
  File "C:\Users\tyler\fluent-tkinter.py", line 12, in <module>
    ApplyMica(hwnd, mode)
  File "C:\Users\tyler\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\win32mica\__init__.py", line 18, in ApplyMica
    HWND = int(HWND)
ValueError: invalid literal for int() with base 10: '0xa20856'

Compiling with cx_Freeze

Hello! I am using win32mica in a program, and when running the program from the .py file, everything works flawlessly. But when i compile the program to an execuetable using cx_Freeze, win32mica throws the following error:

Win32Mica Error: win32 version 9200 is not supported

What does that mean and how do i fix it?

DeprecationWarning

DeprecationWarning: 'exec_' will be removed in the future. Use 'exec' instead.
root.exec_()

Something wrong on tkinter window (Win11 23H2)

Edition	Windows 11 Home
Version	23H2
Installed on	‎11/‎13/‎2023
OS build	22631.3007
Experience	Windows Feature Experience Pack 1000.22681.1000.0

Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32

Should be like:
image

But actually:
image

Not sure what problem it is (the window will show like normal only when screenshot tool is used)

Test code:

pip install customtkinter, win32mica
import customtkinter
import os
from win32mica import ApplyMica, MicaTheme, MicaStyle
from ctypes import windll


class App(customtkinter.CTk):
    def __init__(self):
        super().__init__()
        self.hwnd = windll.user32.GetParent(self.winfo_id())
        
        # 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!")

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

        self.title("image_example.py")
        self.geometry("700x450")

        # set grid layout 1x2
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(1, weight=1)

        # create navigation frame
        self.navigation_frame = customtkinter.CTkFrame(self, corner_radius=0)
        self.navigation_frame.grid(row=0, column=0, sticky="nsew")
        self.navigation_frame.grid_rowconfigure(4, weight=1)

        self.navigation_frame_label = customtkinter.CTkLabel(self.navigation_frame, text="  Image Example", compound="left", font=customtkinter.CTkFont(size=15, weight="bold"))
        self.navigation_frame_label.grid(row=0, column=0, padx=20, pady=20)

        self.home_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, border_spacing=10, text="Home", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.home_button_event)
        self.home_button.grid(row=1, column=0, sticky="ew")

        self.frame_2_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, border_spacing=10, text="Frame 2", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.frame_2_button_event)
        self.frame_2_button.grid(row=2, column=0, sticky="ew")

        self.frame_3_button = customtkinter.CTkButton(self.navigation_frame, corner_radius=0, height=40, border_spacing=10, text="Frame 3", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.frame_3_button_event)
        self.frame_3_button.grid(row=3, column=0, sticky="ew")

        self.appearance_mode_menu = customtkinter.CTkOptionMenu(self.navigation_frame, values=["Light", "Dark", "System"],
                                                                command=self.change_appearance_mode_event)
        self.appearance_mode_menu.grid(row=6, column=0, padx=20, pady=20, sticky="s")

        # create home frame
        self.home_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent")
        self.home_frame.grid_columnconfigure(0, weight=1)

        self.home_frame_large_image_label = customtkinter.CTkLabel(self.home_frame, text="")
        self.home_frame_large_image_label.grid(row=0, column=0, padx=20, pady=10)

        self.home_frame_button_1 = customtkinter.CTkButton(self.home_frame, text="")
        self.home_frame_button_1.grid(row=1, column=0, padx=20, pady=10)
        self.home_frame_button_2 = customtkinter.CTkButton(self.home_frame, text="CTkButton", compound="right")
        self.home_frame_button_2.grid(row=2, column=0, padx=20, pady=10)
        self.home_frame_button_3 = customtkinter.CTkButton(self.home_frame, text="CTkButton", compound="top")
        self.home_frame_button_3.grid(row=3, column=0, padx=20, pady=10)
        self.home_frame_button_4 = customtkinter.CTkButton(self.home_frame, text="CTkButton", anchor="w")
        self.home_frame_button_4.grid(row=4, column=0, padx=20, pady=10)

        # create second frame
        self.second_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent")

        # create third frame
        self.third_frame = customtkinter.CTkFrame(self, corner_radius=0, fg_color="transparent")

        # select default frame
        self.select_frame_by_name("home")

    def select_frame_by_name(self, name):
        # set button color for selected button
        self.home_button.configure(fg_color=("gray75", "gray25") if name == "home" else "transparent")
        self.frame_2_button.configure(fg_color=("gray75", "gray25") if name == "frame_2" else "transparent")
        self.frame_3_button.configure(fg_color=("gray75", "gray25") if name == "frame_3" else "transparent")

        # show selected frame
        if name == "home":
            self.home_frame.grid(row=0, column=1, sticky="nsew")
        else:
            self.home_frame.grid_forget()
        if name == "frame_2":
            self.second_frame.grid(row=0, column=1, sticky="nsew")
        else:
            self.second_frame.grid_forget()
        if name == "frame_3":
            self.third_frame.grid(row=0, column=1, sticky="nsew")
        else:
            self.third_frame.grid_forget()

    def home_button_event(self):
        self.select_frame_by_name("home")

    def frame_2_button_event(self):
        self.select_frame_by_name("frame_2")

    def frame_3_button_event(self):
        self.select_frame_by_name("frame_3")

    def change_appearance_mode_event(self, new_appearance_mode):
        customtkinter.set_appearance_mode(new_appearance_mode)


if __name__ == "__main__":
    app = App()
    app.mainloop()


Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.