settings: Screen blanking settings

This commit is contained in:
Jordan Ruthe 2021-01-24 11:01:37 -05:00
parent 874dd509bf
commit d6bf77870b
5 changed files with 60 additions and 15 deletions

View File

@ -1,5 +1,8 @@
## Changelog
#### 2021 01 21
* Configure screen blanking from settings panel
#### 2021 01 21
* !! Important. matchbox-keyboard must be installed. Install script has changed to include this
* Added onscreen keyboard

View File

@ -10,6 +10,15 @@ from os import path
logger = logging.getLogger("KlipperScreen.config")
SCREEN_BLANKING_OPTIONS = [
"300", #5 Minutes
"900", #15 Minutes
"1800", #30 Minutes
"3600", #1 Hour
"7200", #2 Hours
"14400", #4 Hours
]
class ConfigError(Exception):
pass
@ -19,8 +28,9 @@ class KlipperScreenConfig:
do_not_edit_line = "#~# --- Do not edit below this line. This section is auto generated --- #~#"
do_not_edit_prefix = "#~#"
def __init__(self, configfile, lang=None):
def __init__(self, configfile, lang=None, screen=None):
_ = lang.gettext
_n = lang.ngettext
self.configurable_options = [
{"invert_x": {"section": "main", "name": _("Invert X"), "type": "binary", "value": "False"}},
@ -32,10 +42,27 @@ class KlipperScreenConfig:
{"name": _("Duration Only"), "value": "duration"},
{"name": _("Filament Used"), "value": "filament"},
{"name": _("Slicer"), "value": "slicer"}
]}},
{"screen_blanking": {"section": "main", "name": _("Screen Blanking Time"), "type": "dropdown",
"value": "3600", "callback": screen.set_screenblanking_timeout, "options":[
{"name": _("Off"), "value": "off"}
]}}
#{"": {"section": "main", "name": _(""), "type": ""}}
]
index = self.configurable_options.index(
[i for i in self.configurable_options if list(i)[0]=="screen_blanking"][0])
for num in SCREEN_BLANKING_OPTIONS:
hour = int(int(num)/3600)
if hour > 0:
name = str(hour) + " " + _n("hour","hours", hour)
else:
name = str(int(int(num)/60)) + " " + _("minutes")
self.configurable_options[index]['screen_blanking']['options'].append({
"name": name,
"value": num
})
self.default_config_path = "%s/ks_includes/%s" % (os.getcwd(), self.configfile_name)
self.config = configparser.ConfigParser()
self.config_path = self.get_config_file_location(configfile)

View File

@ -100,16 +100,12 @@ class Printer:
self.set_dev_stat(x, "temperature", d["temperature"])
if "webhooks" in data or "idle_timeout" in data or "pause_resume" in data or "print_stats" in data:
logger.debug("Evaluating state: %s" % data)
logger.debug("State info: %s %s %s" % (self.data['webhooks'], self.data['idle_timeout'],
self.data['print_stats']))
self.evaluate_state()
def evaluate_state(self):
wh_state = self.data['webhooks']['state'].lower() # possible values: startup, ready, shutdown, error
idle_state = self.data['idle_timeout']['state'].lower() # possible values: Idle, printing, ready
print_state = self.data['print_stats']['state'].lower() # possible values: complete, paused, printing, standby
logger.debug("State evaluations: %s %s %s" % (wh_state, idle_state, print_state))
if wh_state == "ready":
new_state = "ready"

View File

@ -128,7 +128,8 @@ class SettingsPanel(ScreenPanel):
if opt['value'] == self._config.get_config()[option['section']].get(opt_name, option['value']):
dropdown.set_active(i)
i += 1
dropdown.connect("changed", self.on_dropdown_change, option['section'], opt_name)
dropdown.connect("changed", self.on_dropdown_change, option['section'], opt_name,
option['callback'] if "callback" in option else None)
#dropdown.props.relief = Gtk.ReliefStyle.NONE
dropdown.set_entry_text_column(0)
dev.add(dropdown)
@ -178,7 +179,7 @@ class SettingsPanel(ScreenPanel):
self.content.add(self.labels[self.menu[-1]])
self.content.show_all()
def on_dropdown_change(self, combo, section, option):
def on_dropdown_change(self, combo, section, option, callback=None):
tree_iter = combo.get_active_iter()
if tree_iter is not None:
model = combo.get_model()
@ -186,6 +187,9 @@ class SettingsPanel(ScreenPanel):
logger.debug("[%s] %s changed to %s" % (section, option, value))
self._config.set(section, option, value)
self._config.save_user_config_options()
if callback is not None:
callback(value)
def switch_config_option(self, switch, gparam, section, option):
logger.debug("[%s] %s toggled %s" % (section, option, switch.get_active()))

View File

@ -81,7 +81,7 @@ class KlipperScreen(Gtk.Window):
configfile = os.path.normpath(os.path.expanduser(args.configfile))
self.lang = gettext.translation('KlipperScreen', localedir='ks_includes/locales', fallback=True)
self._config = KlipperScreenConfig(configfile, self.lang)
self._config = KlipperScreenConfig(configfile, self.lang, self)
self.printer = Printer({
"software_version": "Unknown"
}, {
@ -151,13 +151,14 @@ class KlipperScreen(Gtk.Window):
self._ws.initial_connect()
# Disable DPMS
os.system("/usr/bin/xset -display :0 s off")
os.system("/usr/bin/xset -display :0 -dpms")
os.system("/usr/bin/xset -display :0 s noblank")
self.set_screenblanking_timeout(self._config.get_main_config_option('screen_blanking'))
# Change cursor to blank
self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.BLANK_CURSOR))
return
def ws_subscribe(self):
requested_updates = {
"objects": {
@ -203,7 +204,6 @@ class KlipperScreen(Gtk.Window):
logger.exception(msg)
raise Exception(msg)
def show_panel(self, panel_name, type, title, remove=None, pop=True, **kwargs):
if panel_name not in self.panels:
self.panels[panel_name] = self._load_panel(type, self, title)
@ -215,6 +215,7 @@ class KlipperScreen(Gtk.Window):
self.panels[panel_name].initialize(panel_name)
except:
del self.panels[panel_name]
logger.exception("Unable to load panel %s" % type)
self.show_error_modal("Unable to load panel %s" % type)
return
@ -388,6 +389,20 @@ class KlipperScreen(Gtk.Window):
self.subscriptions.pop(i)
return
def set_screenblanking_timeout(self, time):
logger.debug("Changing screenblanking to: %s" % time)
if time == "off":
os.system("/usr/bin/xset -display :0 s off")
os.system("/usr/bin/xset -display :0 s noblank")
return
time = int(time)
if time < 0:
return
os.system("/usr/bin/xset -display :0 s on")
os.system("/usr/bin/xset -display :0 s %s" % time)
def state_disconnected(self):
_ = self.lang.gettext
logger.debug("### Going to disconnected")
@ -561,9 +576,9 @@ class KlipperScreen(Gtk.Window):
env = os.environ.copy()
env["MB_KBD_CONFIG"] = "/home/pi/.matchbox/keyboard.xml"
env["MB_KBD_CONFIG"] = "ks_includes/locales/keyboard.xml"
#p = subprocess.Popen(["matchbox-keyboard", "--xid"], stdout=subprocess.PIPE,
# stderr=subprocess.PIPE, env=env)
p = subprocess.Popen(["onboard", "--xid"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen(["matchbox-keyboard", "--xid"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE, env=env)
#p = subprocess.Popen(["onboard", "--xid"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
xid = int(p.stdout.readline())
logger.debug("XID %s" % xid)
logger.debug("PID %s" % p.pid)