Skip to content

Commit

Permalink
cs_themes: Frame App and Cinnamon themes, move user themes to the
Browse files Browse the repository at this point in the history
top.

Remove extra padding from Cinnamon and fallback theme thumbnails.
  • Loading branch information
mtwebster committed Jun 28, 2024
1 parent 59451e9 commit 2bfdef2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
Binary file modified data/theme/thumbnail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@
gettext.install("cinnamon", "/usr/share/locale")

class BaseChooserButton(Gtk.Button):
def __init__ (self, has_button_label=False):
def __init__ (self, has_button_label=False, frame=False):
super(BaseChooserButton, self).__init__()
self.has_button_label = has_button_label
self.frame = frame
self.set_valign(Gtk.Align.CENTER)
self.menu = Gtk.Menu()
self.button_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
self.button_image = Gtk.Image()
self.button_box.add(self.button_image)

if self.frame:
f = Gtk.Frame(valign=Gtk.Align.END, halign=Gtk.Align.CENTER)
f.add(self.button_image)
self.button_box.add(f)
else:
self.button_box.add(self.button_image)

if self.has_button_label:
self.button_label = Gtk.Label()
self.button_box.add(self.button_label)
Expand Down Expand Up @@ -58,12 +66,12 @@ def _on_button_clicked(self, widget, event):
self.menu.popup(None, None, self.popup_menu_below_button, self, event.button, event.time)

class PictureChooserButton(BaseChooserButton):
def __init__ (self, num_cols=4, button_picture_size=24, menu_pictures_size=24, has_button_label=False, keep_square=False):
super(PictureChooserButton, self).__init__(has_button_label)
def __init__ (self, num_cols=4, button_picture_width=24, menu_picture_width=24, has_button_label=False, keep_square=False, frame=False):
super(PictureChooserButton, self).__init__(has_button_label, frame)
self.num_cols = num_cols
self.scale = self.get_scale_factor()
self.button_picture_size = button_picture_size
self.menu_pictures_size = menu_pictures_size
self.button_picture_width = button_picture_width
self.menu_picture_width = menu_picture_width
self.keep_square = keep_square
self.row = 0
self.col = 0
Expand All @@ -74,9 +82,9 @@ def __init__ (self, num_cols=4, button_picture_size=24, menu_pictures_size=24, h

self.button_image.set_valign(Gtk.Align.CENTER)
if self.keep_square:
self.button_image.set_size_request(button_picture_size / self.scale, button_picture_size / self.scale)
self.button_image.set_size_request(button_picture_width / self.scale, button_picture_width / self.scale)
else:
self.button_image.set_size_request(-1, button_picture_size / self.scale)
self.button_image.set_size_request(button_picture_width / self.scale, -1)

self.connect_after("draw", self.on_draw)

Expand Down Expand Up @@ -114,8 +122,8 @@ def reset_loading_progress(self):
self.queue_draw()

def create_scaled_surface(self, path):
w = -1 if not self.keep_square else self.button_picture_size * self.scale
h = self.button_picture_size * self.scale
w = self.button_picture_width * self.scale
h = -1 if not self.keep_square else self.button_picture_width * self.scale

try:
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(path, w, h)
Expand Down Expand Up @@ -154,7 +162,7 @@ def clear_menu(self):

def add_picture(self, path, callback, title=None, id=None):
image = Gtk.Image()
image.set_size_request(-1, self.menu_pictures_size / self.scale)
image.set_size_request(self.menu_picture_width / self.scale, -1)

surface = self.create_scaled_surface(path)

Expand All @@ -163,16 +171,23 @@ def add_picture(self, path, callback, title=None, id=None):
else:
image.set_from_icon_name("user-generic", Gtk.IconSize.BUTTON)

if self.frame:
frame = Gtk.Frame(halign=Gtk.Align.CENTER, valign=Gtk.Align.CENTER)
frame.add(image)
menu_image = frame
else:
menu_image = image

menuitem = Gtk.MenuItem()
if title is not None:
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2)
vbox.add(image)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=2, valign=Gtk.Align.END)
vbox.add(menu_image)
label = Gtk.Label()
label.set_text(title)
vbox.add(label)
menuitem.add(vbox)
else:
menuitem.add(image)
menuitem.add(menu_image)
if id is not None:
menuitem.connect('activate', self._on_picture_selected, path, callback, id)
else:
Expand Down
21 changes: 12 additions & 9 deletions files/usr/share/cinnamon/cinnamon-settings/modules/cs_themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ def on_module_selected(self):

self.scale = self.window.get_scale_factor()

self.icon_chooser = self.create_button_chooser(self.settings, 'icon-theme', 'icons', 'icons', button_picture_size=ICON_SIZE, menu_pictures_size=ICON_SIZE, num_cols=4)
self.cursor_chooser = self.create_button_chooser(self.settings, 'cursor-theme', 'icons', 'cursors', button_picture_size=32, menu_pictures_size=32, num_cols=4)
self.theme_chooser = self.create_button_chooser(self.settings, 'gtk-theme', 'themes', 'gtk-3.0', button_picture_size=35, menu_pictures_size=35, num_cols=4)
self.cinnamon_chooser = self.create_button_chooser(self.cinnamon_settings, 'name', 'themes', 'cinnamon', button_picture_size=60, menu_pictures_size=60*self.scale, num_cols=4)
self.icon_chooser = self.create_button_chooser(self.settings, 'icon-theme', 'icons', 'icons', button_picture_width=ICON_SIZE, menu_picture_width=ICON_SIZE, num_cols=4, frame=False)
self.cursor_chooser = self.create_button_chooser(self.settings, 'cursor-theme', 'icons', 'cursors', button_picture_width=32, menu_picture_width=32, num_cols=4, frame=False)
self.theme_chooser = self.create_button_chooser(self.settings, 'gtk-theme', 'themes', 'gtk-3.0', button_picture_width=125, menu_picture_width=125, num_cols=4, frame=True)
self.cinnamon_chooser = self.create_button_chooser(self.cinnamon_settings, 'name', 'themes', 'cinnamon', button_picture_width=125, menu_picture_width=125*self.scale, num_cols=4, frame=True)

selected_meta_theme = None

Expand Down Expand Up @@ -700,6 +700,9 @@ def refresh_chooser(self, chooser, path_suffix, themes, callback):
else:
if path_suffix == "cinnamon":
chooser.add_picture("/usr/share/cinnamon/theme/thumbnail.png", callback, title="cinnamon", id="cinnamon")
if path_suffix in ["gtk-3.0", "cinnamon"]:
themes = sorted(themes, key=lambda t: (not t[1].startswith(GLib.get_home_dir())))

for theme in themes:
theme_name = theme[0]
theme_path = theme[1]
Expand Down Expand Up @@ -740,19 +743,19 @@ def make_group(self, group_label, widget, add_widget_to_size_group=True):

return box

def create_button_chooser(self, settings, key, path_prefix, path_suffix, button_picture_size, menu_pictures_size, num_cols):
chooser = PictureChooserButton(num_cols=num_cols, button_picture_size=button_picture_size, menu_pictures_size=menu_pictures_size, has_button_label=True)
def create_button_chooser(self, settings, key, path_prefix, path_suffix, button_picture_width, menu_picture_width, num_cols, frame):
chooser = PictureChooserButton(num_cols=num_cols, button_picture_width=button_picture_width, menu_picture_width=menu_picture_width, has_button_label=True, frame=frame)
theme = settings.get_string(key)
self.set_button_chooser(chooser, theme, path_prefix, path_suffix, button_picture_size)
self.set_button_chooser(chooser, theme, path_prefix, path_suffix, button_picture_width)
return chooser

def set_button_chooser(self, chooser, theme, path_prefix, path_suffix, button_picture_size):
def set_button_chooser(self, chooser, theme, path_prefix, path_suffix, button_picture_width):
self.set_button_chooser_text(chooser, theme)
if path_suffix == "cinnamon" and theme == "cinnamon":
chooser.set_picture_from_file("/usr/share/cinnamon/theme/thumbnail.png")
elif path_suffix == "icons":
current_theme = Gtk.IconTheme.get_default()
folder = current_theme.lookup_icon_for_scale("folder", button_picture_size, self.window.get_scale_factor(), 0)
folder = current_theme.lookup_icon_for_scale("folder", button_picture_width, self.window.get_scale_factor(), 0)
if folder is not None:
path = folder.get_filename()
chooser.set_picture_from_file(path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def on_module_selected(self):

self.scale = self.window.get_scale_factor()

self.face_button = PictureChooserButton(num_cols=4, button_picture_size=64, menu_pictures_size=64*self.scale, keep_square=True)
self.face_button = PictureChooserButton(num_cols=4, button_picture_width=64, menu_picture_width=64*self.scale, keep_square=True)
self.face_button.set_alignment(0.0, 0.5)
self.face_button.set_tooltip_text(_("Click to change your picture"))

Expand Down
Binary file modified files/usr/share/cinnamon/thumbnails/cinnamon/unknown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2bfdef2

Please sign in to comment.