parent
70767c2bb6
commit
bfe6321c2f
@ -2,11 +2,12 @@
|
|||||||
import gi
|
import gi
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import pathlib
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib, Pango
|
from gi.repository import Gtk, Gdk, GdkPixbuf, Gio, GLib, Pango
|
||||||
|
|
||||||
klipperscreendir = os.getcwd()
|
klipperscreendir = pathlib.Path(__file__).parent.resolve().parent
|
||||||
|
|
||||||
class KlippyGtk:
|
class KlippyGtk:
|
||||||
labels = {}
|
labels = {}
|
||||||
@ -110,7 +111,7 @@ class KlippyGtk:
|
|||||||
def ImageLabel(self, image_name, text, size=20, style=False, width_scale=.32, height_scale=.32):
|
def ImageLabel(self, image_name, text, size=20, style=False, width_scale=.32, height_scale=.32):
|
||||||
box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15)
|
box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15)
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
"%s/styles/%s/images/%s.svg" % (klipperscreendir, self.theme, str(image_name)),
|
os.path.join(klipperscreendir, "styles", self.theme, "images", str(image_name) + ".svg"),
|
||||||
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||||
|
|
||||||
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
||||||
@ -129,7 +130,7 @@ class KlippyGtk:
|
|||||||
def ImageMenuButton(self, image_name, text, size=20, style=False, width_scale=.32, height_scale=.32, popover=False):
|
def ImageMenuButton(self, image_name, text, size=20, style=False, width_scale=.32, height_scale=.32, popover=False):
|
||||||
box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15)
|
box1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=15)
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
"%s/styles/%s/images/%s.svg" % (klipperscreendir, self.theme, str(image_name)),
|
os.path.join(klipperscreendir, "styles", self.theme, "images", str(image_name) + ".svg"),
|
||||||
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||||
|
|
||||||
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
image = Gtk.Image.new_from_pixbuf(pixbuf)
|
||||||
@ -147,7 +148,7 @@ class KlippyGtk:
|
|||||||
|
|
||||||
def Image(self, image_name, style=False, width_scale=1, height_scale=1):
|
def Image(self, image_name, style=False, width_scale=1, height_scale=1):
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
"%s/styles/%s/images/%s" % (klipperscreendir, self.theme, str(image_name)),
|
os.path.join(klipperscreendir, "styles", self.theme, "images", str(image_name)),
|
||||||
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
int(round(self.img_width * width_scale)), int(round(self.img_height * height_scale)), True)
|
||||||
|
|
||||||
return Gtk.Image.new_from_pixbuf(pixbuf)
|
return Gtk.Image.new_from_pixbuf(pixbuf)
|
||||||
@ -197,10 +198,10 @@ class KlippyGtk:
|
|||||||
|
|
||||||
def ButtonImage(self, image_name, label=None, style=None, width_scale=1.38, height_scale=1.38,
|
def ButtonImage(self, image_name, label=None, style=None, width_scale=1.38, height_scale=1.38,
|
||||||
position=Gtk.PositionType.TOP, word_wrap=True):
|
position=Gtk.PositionType.TOP, word_wrap=True):
|
||||||
filename = "%s/styles/%s/images/%s.svg" % (klipperscreendir, self.theme, str(image_name))
|
filename = os.path.join(klipperscreendir, "styles", self.theme, "images", str(image_name) + ".svg")
|
||||||
if not os.path.exists(filename):
|
if not os.path.exists(filename):
|
||||||
logging.error("Unable to find button image (theme, image): (%s, %s)" % (self.theme, str(image_name)))
|
logging.error("Unable to find button image (theme, image): (%s, %s)" % (self.theme, str(image_name)))
|
||||||
filename = "%s/styles/%s/images/%s.svg" % (klipperscreendir, self.theme, "warning")
|
filename = os.path.join(klipperscreendir, "styles", self.theme, "images", "warning.svg")
|
||||||
|
|
||||||
b = Gtk.Button(label=label)
|
b = Gtk.Button(label=label)
|
||||||
|
|
||||||
@ -270,7 +271,7 @@ class KlippyGtk:
|
|||||||
|
|
||||||
|
|
||||||
def ToggleButtonImage(self, image_name, label, style=False, width_scale=1.38, height_scale=1.38):
|
def ToggleButtonImage(self, image_name, label, style=False, width_scale=1.38, height_scale=1.38):
|
||||||
filename = "%s/styles/%s/images/%s.svg" % (klipperscreendir, self.theme, str(image_name))
|
filename = os.path.join(klipperscreendir, "styles", self.theme, "images", str(image_name) + ".svg")
|
||||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(
|
||||||
filename,
|
filename,
|
||||||
int(round(self.img_width * width_scale)),
|
int(round(self.img_width * width_scale)),
|
||||||
|
@ -5,6 +5,7 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
|
import pathlib
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
@ -19,6 +20,8 @@ SCREEN_BLANKING_OPTIONS = [
|
|||||||
"14400", # 4 Hours
|
"14400", # 4 Hours
|
||||||
]
|
]
|
||||||
|
|
||||||
|
klipperscreendir = pathlib.Path(__file__).parent.resolve().parent
|
||||||
|
|
||||||
class ConfigError(Exception):
|
class ConfigError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -29,7 +32,7 @@ class KlipperScreenConfig:
|
|||||||
do_not_edit_prefix = "#~#"
|
do_not_edit_prefix = "#~#"
|
||||||
|
|
||||||
def __init__(self, configfile, screen=None):
|
def __init__(self, configfile, screen=None):
|
||||||
self.default_config_path = "%s/ks_includes/%s" % (os.getcwd(), "defaults.conf")
|
self.default_config_path = os.path.join(klipperscreendir, "ks_includes", "defaults.conf")
|
||||||
self.config = configparser.ConfigParser()
|
self.config = configparser.ConfigParser()
|
||||||
self.config_path = self.get_config_file_location(configfile)
|
self.config_path = self.get_config_file_location(configfile)
|
||||||
logging.debug("Config path location: %s" % self.config_path)
|
logging.debug("Config path location: %s" % self.config_path)
|
||||||
@ -146,7 +149,7 @@ class KlipperScreenConfig:
|
|||||||
# {"": {"section": "main", "name": _(""), "type": ""}}
|
# {"": {"section": "main", "name": _(""), "type": ""}}
|
||||||
]
|
]
|
||||||
|
|
||||||
lang_path = os.path.join(os.getcwd(), 'ks_includes/locales')
|
lang_path = os.path.join(klipperscreendir, "ks_includes", "locales")
|
||||||
langs = [d for d in os.listdir(lang_path) if not os.path.isfile(os.path.join(lang_path, d))]
|
langs = [d for d in os.listdir(lang_path) if not os.path.isfile(os.path.join(lang_path, d))]
|
||||||
langs.sort()
|
langs.sort()
|
||||||
lang_opt = self.configurable_options[3]['language']['options']
|
lang_opt = self.configurable_options[3]['language']['options']
|
||||||
@ -154,7 +157,7 @@ class KlipperScreenConfig:
|
|||||||
for lang in langs:
|
for lang in langs:
|
||||||
lang_opt.append({"name": lang, "value": lang})
|
lang_opt.append({"name": lang, "value": lang})
|
||||||
|
|
||||||
t_path = os.path.join(os.getcwd(), 'styles')
|
t_path = os.path.join(klipperscreendir, 'styles')
|
||||||
themes = [d for d in os.listdir(t_path) if (not os.path.isfile(os.path.join(t_path, d)) and d != "z-bolt")]
|
themes = [d for d in os.listdir(t_path) if (not os.path.isfile(os.path.join(t_path, d)) and d != "z-bolt")]
|
||||||
themes.sort()
|
themes.sort()
|
||||||
theme_opt = self.configurable_options[8]['theme']['options']
|
theme_opt = self.configurable_options[8]['theme']['options']
|
||||||
@ -237,7 +240,7 @@ class KlipperScreenConfig:
|
|||||||
def get_config_file_location(self, file):
|
def get_config_file_location(self, file):
|
||||||
logging.info("Passed config file: %s" % file)
|
logging.info("Passed config file: %s" % file)
|
||||||
if not path.exists(file):
|
if not path.exists(file):
|
||||||
file = "%s/%s" % (os.getcwd(), self.configfile_name)
|
file = os.path.join(klipperscreendir, self.configfile_name)
|
||||||
if not path.exists(file):
|
if not path.exists(file):
|
||||||
file = os.path.expanduser("~/") + "klipper_config/%s" % (self.configfile_name)
|
file = os.path.expanduser("~/") + "klipper_config/%s" % (self.configfile_name)
|
||||||
if not path.exists(file):
|
if not path.exists(file):
|
||||||
|
16
screen.py
16
screen.py
@ -18,7 +18,7 @@ import signal
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
|
import pathlib
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
from gi.repository import Gtk, Gdk, GLib, Pango
|
from gi.repository import Gtk, Gdk, GLib, Pango
|
||||||
@ -55,7 +55,7 @@ PRINTER_BASE_STATUS_OBJECTS = [
|
|||||||
'webhooks'
|
'webhooks'
|
||||||
]
|
]
|
||||||
|
|
||||||
klipperscreendir = os.getcwd()
|
klipperscreendir = pathlib.Path(__file__).parent.resolve()
|
||||||
|
|
||||||
class KlipperScreen(Gtk.Window):
|
class KlipperScreen(Gtk.Window):
|
||||||
""" Class for creating a screen for Klipper via HDMI """
|
""" Class for creating a screen for Klipper via HDMI """
|
||||||
@ -440,21 +440,21 @@ class KlipperScreen(Gtk.Window):
|
|||||||
|
|
||||||
def init_style(self):
|
def init_style(self):
|
||||||
style_provider = Gtk.CssProvider()
|
style_provider = Gtk.CssProvider()
|
||||||
|
css = open(os.path.join(klipperscreendir, "styles", "base.css"))
|
||||||
css = open(klipperscreendir + "/styles/base.css")
|
|
||||||
css_base_data = css.read()
|
css_base_data = css.read()
|
||||||
css.close()
|
css.close()
|
||||||
css = open(klipperscreendir + "/styles/%s/style.css" % (self.theme))
|
css = open(os.path.join(klipperscreendir, "styles", self.theme, "style.css"))
|
||||||
css_data = css_base_data + css.read()
|
css_data = css_base_data + css.read()
|
||||||
css.close()
|
css.close()
|
||||||
|
|
||||||
f = open(klipperscreendir + "/styles/base.conf")
|
f = open(os.path.join(klipperscreendir, "styles", "base.conf"))
|
||||||
style_options = json.load(f)
|
style_options = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
if os.path.exists(klipperscreendir + "/styles/%s/style.conf" % (self.theme)):
|
theme_style_conf = os.path.join(klipperscreendir, "styles", self.theme, "style.conf")
|
||||||
|
if os.path.exists(theme_style_conf):
|
||||||
try:
|
try:
|
||||||
f = open(klipperscreendir + "/styles/%s/style.conf" % (self.theme))
|
f = open(theme_style_conf)
|
||||||
style_options.update(json.load(f))
|
style_options.update(json.load(f))
|
||||||
f.close()
|
f.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user