Skip to content

Commit

Permalink
fix: monet under python3.11 used for gnome 47 by reimporting the unma…
Browse files Browse the repository at this point in the history
…intained material-color-utilities-python as a submodule
  • Loading branch information
hydroxycarbamide committed Nov 6, 2024
1 parent c6f4692 commit 8473eb0
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 42 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "data/submodules"]
path = data/submodules
url = https://github.com/hydroxycarbamide/Submodules
[submodule "gradience/material-color-utilities-python"]
path = gradience/material-color-utilities-python
url = https://github.com/hydroxycarbamide/material-color-utilities-python.git
60 changes: 33 additions & 27 deletions build-aux/flatpak/pypi-dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,6 @@
}
]
},
{
"name": "python3-material-color-utilities-python",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"material-color-utilities-python\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/31/65/a8e0f3e2bad0d4eabeb1931b22cdae08344a955f28022dc83420a128683c/material_color_utilities_python-0.1.5-py2.py3-none-any.whl",
"sha256": "48abd8695a1355ab3ad43fe314ca8664c66282a86fbf94a717571273bf422bdf"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/f9/38/148df33b4dbca3bd069b963acab5e0fa1a9dbd6820f8c322d0dd6faeff96/regex-2024.9.11.tar.gz",
"sha256": "6c188c307e8433bcb63dc1915022deb553b4203a70722fc542c363bf120a01fd"
}
]
},
{
"name": "python3-svglib",
"buildsystem": "simple",
Expand All @@ -58,6 +39,11 @@
"url": "https://files.pythonhosted.org/packages/e7/6b/20c3a4b24751377aaa6307eb230b66701024012c29dd374999cc92983269/lxml-5.3.0.tar.gz",
"sha256": "4e109ca30d1edec1ac60cdbe341905dc3b8f55b16855e03a54aaf59e51ec8c6f"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/a5/26/0d95c04c868f6bdb0c447e3ee2de5564411845e36a858cfd63766bc7b563/pillow-11.0.0.tar.gz",
"sha256": "72bacbaf24ac003fea9bff9837d1eedb6088758d41e100c1552930151f677739"
},
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/73/12/6444906db1bc65d3a8118afb089d53c7eeca0726164f51eb3599de1d0665/reportlab-4.2.5-py3-none-any.whl",
Expand All @@ -80,14 +66,6 @@
}
]
},
{
"name": "python3-yapsy",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"yapsy\" --no-build-isolation"
],
"sources": []
},
{
"name": "python3-Jinja2",
"buildsystem": "simple",
Expand All @@ -107,6 +85,34 @@
}
]
},
{
"name": "python3-Pillow",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"Pillow\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/a5/26/0d95c04c868f6bdb0c447e3ee2de5564411845e36a858cfd63766bc7b563/pillow-11.0.0.tar.gz",
"sha256": "72bacbaf24ac003fea9bff9837d1eedb6088758d41e100c1552930151f677739"
}
]
},
{
"name": "python3-regex",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"regex\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/f9/38/148df33b4dbca3bd069b963acab5e0fa1a9dbd6820f8c322d0dd6faeff96/regex-2024.9.11.tar.gz",
"sha256": "6c188c307e8433bcb63dc1915022deb553b4203a70722fc542c363bf120a01fd"
}
]
},
{
"name": "python3-libsass",
"buildsystem": "simple",
Expand Down
9 changes: 5 additions & 4 deletions gradience/backend/theming/monet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import os

import material_color_utilities_python as monet
from PIL import Image

from svglib.svglib import svg2rlg
from reportlab.graphics import renderPM

from gradience.material_color_utilities_python.utils import theme_utils
from gradience.backend.models.preset import Preset
from gradience.backend.utils.colors import argb_to_color_code

Expand All @@ -48,7 +49,7 @@ def generate_palette_from_image(self, image_path: str) -> dict:
raise ValueError("XML files are unsupported by Gradience's Monet implementation")

try:
monet_img = monet.Image.open(image_path)
monet_img = Image.open(image_path)
except Exception as e:
logging.error("An error occurred while generating a Monet palette.", exc=e)
raise
Expand All @@ -58,10 +59,10 @@ def generate_palette_from_image(self, image_path: str) -> dict:
hsize = int((float(monet_img.size[1]) * float(wpercent)))

monet_img = monet_img.resize(
(basewidth, hsize), monet.Image.Resampling.LANCZOS
(basewidth, hsize), Image.Resampling.LANCZOS
)

self.palette = monet.themeFromImage(monet_img)
self.palette = theme_utils.themeFromImage(monet_img)

return self.palette

Expand Down
52 changes: 45 additions & 7 deletions gradience/backend/utils/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import material_color_utilities_python as monet

from gradience.backend.globals import adw_variables_prefixes, adw_palette_prefixes

from gradience.backend.logger import Logger
Expand Down Expand Up @@ -67,14 +65,14 @@ def argb_to_color_code(argb, alpha=None) -> str:
"""
rgba_base = "rgba({0}, {1}, {2}, {3})"

red = monet.redFromArgb(argb)
green = monet.greenFromArgb(argb)
blue = monet.blueFromArgb(argb)
red = redFromArgb(argb)
green = greenFromArgb(argb)
blue = blueFromArgb(argb)
if not alpha:
alpha = monet.alphaFromArgb(argb)
alpha = alphaFromArgb(argb)

if alpha in (255, 0.0):
return monet.hexFromArgb(argb)
return hexFromArgb(argb)

return rgba_base.format(red, green, blue, alpha)

Expand Down Expand Up @@ -123,3 +121,43 @@ def __update_vars(var_type, variable, color_value):
__update_vars("variable", variable, color_value)

return output


# /**
# * Returns the alpha component of a color in ARGB format.
# */
def alphaFromArgb(argb):
return argb >> 24 & 255


# /**
# * Returns the red component of a color in ARGB format.
# */
def redFromArgb(argb):
return argb >> 16 & 255


# /**
# * Returns the green component of a color in ARGB format.
# */
def greenFromArgb(argb):
return argb >> 8 & 255


# /**
# * Returns the blue component of a color in ARGB format.
# */
def blueFromArgb(argb):
return argb & 255


def hexFromArgb(argb):
r = redFromArgb(argb)
g = greenFromArgb(argb)
b = blueFromArgb(argb)
outParts = [f'{r:x}', f'{g:x}', f'{b:x}']
# Pad single-digit output values
for i, part in enumerate(outParts):
if (len(part) == 1):
outParts[i] = '0' + part
return '#' + ''.join(outParts)
2 changes: 1 addition & 1 deletion gradience/frontend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import threading

from pathlib import Path
from material_color_utilities_python import hexFromArgb
from gi.repository import GObject, Gtk, Gdk, Gio, Adw, GLib

from gradience.backend.globals import presets_dir, get_gtk_theme_dir
Expand All @@ -44,6 +43,7 @@
from gradience.frontend.dialogs.save_dialog import GradienceSaveDialog
from gradience.frontend.widgets.custom_css_group import GradienceCustomCSSGroup

from gradience.backend.utils.colors import hexFromArgb
from gradience.frontend.utils.actions import ActionHelpers
from gradience.frontend.schemas.preset_schema import preset_schema

Expand Down
1 change: 1 addition & 0 deletions gradience/material-color-utilities-python
1 change: 1 addition & 0 deletions gradience/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ moduledir = 'gradience'

subdir('backend')
subdir('frontend')
subdir('material-color-utilities-python/material_color_utilities_python')

gradience_sources = [
'__init__.py'
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
# or more simply, just push and the bot will do this for you.

anyascii
material-color-utilities-python
svglib
yapsy
Jinja2
libsass
Pillow
libsass

0 comments on commit 8473eb0

Please sign in to comment.