Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't touch system-wide files when run as user. #180

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
76 changes: 57 additions & 19 deletions gui/gui
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ from gi.repository import Gtk, Gdk, GdkPixbuf, Pango, GLib, Gio

colour_labels = ["Primary", "Secondary", "Symbol"]


def get_default_colour(colour):
for d in defaults:
if colour == defaults[d]:
Expand All @@ -30,7 +31,7 @@ def get_default_colour(colour):

def gdk_to_hex(gdk_colour):
colours = gdk_colour.to_floats()
return "#" + "".join(["%02x" % (colour * 255) for colour in colours])
return "#" + "".join(["%02x" % int(colour * 255) for colour in colours])


def check_hex(colour):
Expand Down Expand Up @@ -75,6 +76,8 @@ colours = ("Default", "Blue", "Brown", "Green", "Grey", "Orange",
"Pink", "Purple", "Red", "Yellow", "Style 1", "Style 2",
"Style 3", "Style 4", "Style 5", "Style 6", "Custom")

themes = ["Numix", "Numix-Circle", "Numix-Square"]

number_styles = 6
number_colours = 3
default_style = 6
Expand Down Expand Up @@ -111,41 +114,51 @@ else:
colour = "default"
colour_list = defaults["style %s" % (style)]

if len(argv) > 6 and argv[6] in themes:
theme = argv[6]
else:
theme = themes[0]


class NumixFoldersGUI(Gtk.Application):

def __init__(self, style, colour, colour_list):
def __init__(self, style, colour, colour_list, theme):
Gtk.Application.__init__(self,
application_id='org.gnome.numix-folders',
flags=Gio.ApplicationFlags.FLAGS_NONE)
GLib.set_application_name("Numix Folders")
GLib.set_prgname('numix-folders')
self.connect("activate", self.on_activate, style, colour, colour_list)
self.connect("activate", self.on_activate,
style, colour, colour_list, theme)

def exit(self, *args):
self.quit()

def on_activate(self, app, style, colour, colour_list):
self.win = Gtk.ApplicationWindow(Gtk.WindowType.TOPLEVEL, application=app)
def on_activate(self, app, style, colour, colour_list, theme):
self.win = Gtk.ApplicationWindow(
type=Gtk.WindowType.TOPLEVEL, application=app)
self.win.set_title("Numix Folders")
self.win.set_icon_name('numix-folders')
self.win.set_border_width(18)
self.win.set_resizable(False)
self.win.set_wmclass("numix-folders", "Numix Folders")
self.win.set_position(Gtk.WindowPosition.CENTER)
self.theme = theme
self.colour = colour_list
self.global_colour = colour
self.style = style

# boxes
vboxall = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vboxmain = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hboxpreview = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=30)
hboxpreview = Gtk.Box(
orientation=Gtk.Orientation.HORIZONTAL, spacing=30)
hboxcombo = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
hboxentry = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
hboxcolour = [] # filled later
vboxcolours = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hboxcolours = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
hboxthemes = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.win.add(vboxall)

# preview pixmap
Expand Down Expand Up @@ -209,7 +222,8 @@ class NumixFoldersGUI(Gtk.Application):
self.colourentries = []
self.colourlabels = []
for i in range(number_colours):
hboxcolour.append(Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12))
hboxcolour.append(
Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=12))
self.colourbuttons.append(Gtk.ColorButton())
self.colourbuttons[i].set_color(Gdk.color_parse(self.colour[i]))
self.colourentries.append(Gtk.Entry())
Expand All @@ -220,20 +234,33 @@ class NumixFoldersGUI(Gtk.Application):
self.colourentries[i].set_max_width_chars(7)
self.colourlabels.append(Gtk.Label())
self.colourlabels[i].set_text(colour_labels[i])
self.colourentries[i].modify_font(Pango.FontDescription('monospace'))
self.colourentries[i].modify_font(
Pango.FontDescription('monospace'))
hboxcolour[i].pack_end(self.colourentries[i], False, False, 0)
hboxcolour[i].pack_end(self.colourbuttons[i], False, False, 0)
if Gtk.get_major_version() >= 3 and Gtk.get_minor_version() >= 12:
hboxcolour[i].pack_end(self.colourlabels[i], False, False, 6)

# comboboxentrytheme
themes_store = Gtk.ListStore(str)
for t in themes:
themes_store.append([t])
self.themes_combo = Gtk.ComboBox.new_with_model(themes_store)
renderer_text = Gtk.CellRendererText()
self.themes_combo.pack_start(renderer_text, True)
self.themes_combo.add_attribute(renderer_text, "text", 0)
ind = themes.index(self.theme)
self.themes_combo.set_active(ind)
hboxthemes.pack_start(self.themes_combo, False, False, 0)

for hbox in hboxcolour[::-1]:
vboxcolours.pack_end(hbox, False, False, 5)
hboxcolours.pack_start(vboxcolours, False, False, 30)

# buttons
buttonok = Gtk.Button("_Apply", use_underline=True)
buttonok = Gtk.Button(label="_Apply", use_underline=True)
buttonok.get_style_context().add_class("suggested-action")
buttonclose = Gtk.Button("_Cancel", use_underline=True)
buttonclose = Gtk.Button(label="_Cancel", use_underline=True)
buttonclose.get_style_context().add_class("destructive-action")

# header bar
Expand All @@ -259,12 +286,12 @@ class NumixFoldersGUI(Gtk.Application):
hboxbuttons.set_margin_top(18)
vboxall.pack_end(hboxbuttons, False, False, 6)


# packing
vboxall.pack_start(vboxmain, False, False, 0)
vboxmain.pack_start(hboxpreview, True, True, 15)
vboxmain.pack_start(hboxcombo, False, False, 25)
vboxmain.pack_start(hboxcolours, False, False, 0)
vboxmain.pack_start(hboxthemes, False, False, 0)

# connect signals
self.colours_combo.connect("changed", self.combo_changed_colour)
Expand All @@ -273,6 +300,7 @@ class NumixFoldersGUI(Gtk.Application):
but.connect("color_set", self.colourbutton_changed, j)
for j, ent in enumerate(self.colourentries):
ent.connect("changed", self.entry_changed, j)
self.themes_combo.connect("changed", self.combo_changed_theme)
buttonok.connect("clicked", self.on_ok_clicked)
buttonclose.connect("clicked", self.exit)

Expand All @@ -287,11 +315,11 @@ class NumixFoldersGUI(Gtk.Application):
self.update_small_preview()
self.colours_combo.handler_block_by_func(self.combo_changed_colour)
self.colours_combo.set_active(indcol)
self.colours_combo.handler_unblock_by_func(self.combo_changed_colour)
self.colours_combo.handler_unblock_by_func(
self.combo_changed_colour)
self.win.show_all()
self.add_window(self.win)


def set_sensitive(self, style):
for i in range(1, number_colours):
if style_fixed[style][1][i]:
Expand Down Expand Up @@ -346,6 +374,11 @@ class NumixFoldersGUI(Gtk.Application):
if self.global_colour == "custom":
self.update_preview(self.style, self.colour)

def combo_changed_theme(self, widget):
ind = widget.get_active()
theme = themes[ind]
self.theme = str(theme)

def colourbutton_changed(self, widget, arg):
colour = widget.get_color()
self.colour[arg] = gdk_to_hex(colour)
Expand Down Expand Up @@ -373,9 +406,11 @@ class NumixFoldersGUI(Gtk.Application):
except:
return
self.colour[arg] = entry
self.colourbuttons[arg].handler_block_by_func(self.colourbutton_changed)
self.colourbuttons[arg].handler_block_by_func(
self.colourbutton_changed)
self.colourbuttons[arg].set_color(colour)
self.colourbuttons[arg].handler_unblock_by_func(self.colourbutton_changed)
self.colourbuttons[arg].handler_unblock_by_func(
self.colourbutton_changed)

colour = get_default_colour(tuple(self.colour))
self.global_colour = colour
Expand All @@ -401,7 +436,7 @@ class NumixFoldersGUI(Gtk.Application):
svg = svg.replace("replacecolour%s" % (k+1), col)
loader = GdkPixbuf.PixbufLoader()
loader.write(svg.encode())
loader.set_size(96,96)
loader.set_size(96, 96)
loader.close()
pixbuf = loader.get_pixbuf()
self.image.set_from_pixbuf(pixbuf)
Expand All @@ -411,7 +446,8 @@ class NumixFoldersGUI(Gtk.Application):
for i in range(number_styles):
if self.global_colour == "default":
colours = defaults["style "+str(i+1)]
elif self.global_colour == "custom" or self.global_colour.startswith("style"):
elif self.global_colour == "custom" \
or self.global_colour.startswith("style"):
colours = self.colour
else:
colours = list(defaults[self.global_colour])
Expand All @@ -431,7 +467,8 @@ class NumixFoldersGUI(Gtk.Application):
if i != default_style-1:
self.style_store.append([pixbuf, " Style %s" % int(i+1)])
else:
self.style_store.append([pixbuf, " Style %s *" % int(i+1)])
self.style_store.append(
[pixbuf, " Style %s *" % int(i+1)])
else:
self.style_store[int(i)][0] = pixbuf

Expand All @@ -443,8 +480,9 @@ class NumixFoldersGUI(Gtk.Application):
print(colour)
for i in range(number_colours):
print(self.colour[i].replace("#", ""))
print(self.theme)
self.quit()


win = NumixFoldersGUI(style, colour, colour_list)
win = NumixFoldersGUI(style, colour, colour_list, theme)
win.run(None)
Loading