Akascape / py-window-styles

Customize your python UI window with awesome pre-built windows 11 themes.
Creative Commons Zero v1.0 Universal
324 stars 16 forks source link

How to dynamically remove the border color on a button click?? #6

Closed Zingzy closed 1 year ago

Zingzy commented 1 year ago

After I have applied the border color , i want to remove it when a user clicks a button, any idea how to do it??

Akascape commented 1 year ago

That's the thing I am not working on right now. I have to research about the API on reverting themes back to original.

Zingzy commented 1 year ago

That's the thing I am not working on right now. I have to research about the API on reverting themes back to original.

No like I only want to remove the border color not any other theme

Zingzy commented 1 year ago

That's the thing I am not working on right now. I have to research about the API on reverting themes back to original.

also can you mention the API you use to change the window border color? hopefully I can search about some fixes?

Akascape commented 1 year ago

@Zingzy

No like I only want to remove the border color not any other theme

Yeah, I mean all those options including the themes.

also can you mention the API you use to change the window border color? hopefully I can search about some fixes?

It's the DWMApi https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

Zingzy commented 1 year ago

@Zingzy

No like I only want to remove the border color not any other theme

Yeah, I mean all those options including the themes.

also can you mention the API you use to change the window border color? hopefully I can search about some fixes?

It's the DWMApi https://learn.microsoft.com/en-us/windows/win32/api/dwmapi/nf-dwmapi-dwmsetwindowattribute

also sir do you know any way on how to get the user's accent color?

Akascape commented 1 year ago

@Zingzy I am not sure but DWMGetWindowAttribute or GetThemeSysColor can help. I will try implement this feature later.

Zingzy commented 1 year ago

@Zingzy I am not sure but DWMGetWindowAttribute can help. I will try implement this feature later.

Ok thanks a lot

Akascape commented 1 year ago

Hey bro, need a little help with this issue. I want to get the accent color of windows. I found that GetThemeSysColor attribute can help. Idk, but there can also be a different term for this. Can you help to figure out the correct process of using it with ctypes? I somehow managed to use the term but I don't know how to get the COLOREF value returned.

from ctypes import POINTER, pointer, sizeof, windll, Structure, byref, c_int, c_wchar_p
from ctypes.wintypes import DWORD, ULONG, COLORREF, HANDLE, HWND

...
HWND = windll.user32.GetParent(window.winfo_id())
HTHEME = HANDLE

GetColor = windll.UxTheme.GetThemeSysColor
GetColor.argtypes = [HTHEME, c_int]
GetColor.restype = COLORREF

OpenThemeData = windll.uxtheme.OpenThemeData
OpenThemeData.argtypes = [HWND, c_wchar_p]
OpenThemeData.restype = HTHEME
htheme = OpenThemeData(hWnd, 'Window')
color = GetColor(htheme, c_int(1))
print(color)
Zingzy commented 1 year ago

Hey bro, need a little help with this issue. I want to get the accent color of windows. I found that GetThemeSysColor attribute can help. Idk, but there can also be a different term for this. Can you help to figure out the correct process of using it with ctypes? I somehow managed to use the term but I don't know how I can get the COLOREF value returned.

from ctypes import POINTER, pointer, sizeof, windll, Structure, byref, c_int, c_wchar_p
from ctypes.wintypes import DWORD, ULONG, COLORREF, HANDLE, HWND

...
HWND = windll.user32.GetParent(window.winfo_id())
HTHEME = HANDLE

GetColor = windll.UxTheme.GetThemeSysColor
GetColor.argtypes = [HTHEME, c_int]
GetColor.restype = COLORREF

OpenThemeData = windll.uxtheme.OpenThemeData
OpenThemeData.argtypes = [HWND, c_wchar_p]
OpenThemeData.restype = HTHEME
htheme = OpenThemeData(hWnd, 'Window')
color = GetColor(htheme, c_int(1))
print(color)

Thanks but actually I found a better solution to get the accent color using Registry Keys and about reverting the border color, I detected the original border color of the window and changed it's color to that to remove the custom border

Akascape commented 1 year ago

@Zingzy So what is the method for python (getting the accent color)? I wish we can implement this in the package.

Zingzy commented 1 year ago

@Zingzy So what is the method for python (getting the accent color)? I wish we can implement this in the package.

Should I share the code over here?

Akascape commented 1 year ago

@Zingzy Yeah the process of getting the color from registry with python

Zingzy commented 1 year ago

@Zingzy Yeah the process of getting the color from registry with python

import winreg

def get_accent():
    key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Windows\DWM')
    value, type = winreg.QueryValueEx(key, 'ColorizationAfterglow')
    winreg.CloseKey(key)
    return hex(value)
Akascape commented 1 year ago

@Zingzy Thanks bro, I implemented this successfully.

Zingzy commented 1 year ago

@Zingzy Thanks bro, I implemented this successfully.

No worries! Did you implement it in this library?

Akascape commented 1 year ago

@Zingzy Will update it soon.

Akascape commented 1 year ago

@Zingzy Bro what will be the reg key for default border color?

Zingzy commented 1 year ago

@Zingzy Bro what will be the reg key for default border color?

I didnt use registry to get the default color, I used a color picker application to get the default color (the default color may vary in different versions of windows tho)... Also I think there must be some registry key which contains the default windows border color

Akascape commented 1 year ago

Ok, then no need to add this one.

Akascape commented 1 year ago

@Zingzy Updated, now we have pywinstyles.get_accent_color()

Zingzy commented 1 year ago

@Zingzy Updated, now we have pywinstyles.get_accent_color()

amazing! But you might wanna give me some credits? (its completely upto you tho, I will not mind if you will not 😄)

Akascape commented 1 year ago

@Zingzy Ok, will add your name in that section :) https://github.com/Akascape/py-window-styles/blob/e553549b9681c264226fe2dcc9d22a959a82a3bb/pywinstyles/py_win_style.py#L136C5-L136C61