inkstitch/lib/utils/icons.py

30 wiersze
826 B
Python

Sew Stack first steps (#3133) * handle more recursive cases * scaffolding for stitch layers * scaffolding for SewStack * always use DotDict when parsing json params * add DefaultDotDict + DotDict fixes * first working SewStack (no UI yet) * ignore inkstitch_debug.log and .svg * refactor * early WIP: property grid display temporarily in stitch plan preview * start of sew stack editor extension * add layer properties panel and splitter * spacing and better icon * handle checkbox * add layer action buttons * show selected property help text in an HtmlWindow * rename * rephrase help text for tolerance * refactor into separate file * simplify structure * better property type handling * add randomization button * add random seed re-roll button * simulator preview * update preview in a few more cases * always DotDict * avoid ridiculously slow simulations * preview selected layer or all layers * edit multiple objects and save only modified properties into the SVG * better preview handling * add reverse and jitter * add stitch path jitter * fix types * fix random shuffle button * fixes * fix repeats * type hinting to please pycharm * show layer description * avoid exception in properties with multiple values * fix typing * fix new layer * draw a box around property grid and help box * confirm before closing * rename properties and fix seed * fix close/cancel logic * add buttons to undo changes and reset to default value * set not modified if default is original setting * fix invisible icon * more space for properties * fix random properties * better regulation of simulator rendering speed * Fixed timer being passed a float * fix get_json_param() default handling * fix tests * add checkbox for sew stack only * fix property help * adjustable stitch layer editor help box size, with persistence * repeat exact stitches * "fix" style * adjust for new next_element stuff --------- Co-authored-by: CapellanCitizen <thecapellancitizen@gmail.com>
2025-01-29 17:04:07 +00:00
import os
import wx
from .paths import get_resource_dir
def is_dark_theme():
return wx.SystemSettings().GetAppearance().IsDark()
def load_icon(icon_name, window=None, width=None, height=None):
if window is None and not (width and height):
raise ValueError("load_icon(): must pass a window or width and height")
icon = wx.Image(os.path.join(get_resource_dir("icons"), f"{icon_name}.png"))
if not (width and height):
render = wx.RendererNative.Get()
width = height = render.GetHeaderButtonHeight(window)
icon.Rescale(width, height, wx.IMAGE_QUALITY_HIGH)
if is_dark_theme():
# only way I've found to get a negative image
data = icon.GetDataBuffer()
for i in range(len(data)):
data[i] = 255 - data[i]
return icon.ConvertToBitmap()