[core] add debugging around click events
log commandline outputs and errors. allow input handlers to be configured as "waiting" for debugging purposes. see #628
This commit is contained in:
parent
02a80840a1
commit
a697500491
3 changed files with 16 additions and 5 deletions
|
@ -36,20 +36,20 @@ def __event_id(obj_id, button):
|
|||
return "{}::{}".format(obj_id, button_name(button))
|
||||
|
||||
|
||||
def __execute(cmd):
|
||||
def __execute(cmd, wait=False):
|
||||
try:
|
||||
util.cli.execute(cmd, wait=False, shell=True)
|
||||
util.cli.execute(cmd, wait=wait, shell=True)
|
||||
except Exception as e:
|
||||
logging.error("failed to invoke callback: {}".format(e))
|
||||
|
||||
|
||||
def register(obj, button=None, cmd=None):
|
||||
def register(obj, button=None, cmd=None, wait=False):
|
||||
event_id = __event_id(obj.id if obj is not None else "", button)
|
||||
logging.debug("registering callback {}".format(event_id))
|
||||
if callable(cmd):
|
||||
core.event.register(event_id, cmd)
|
||||
else:
|
||||
core.event.register(event_id, lambda _: __execute(cmd))
|
||||
core.event.register(event_id, lambda _: __execute(cmd, wait))
|
||||
|
||||
|
||||
def trigger(event):
|
||||
|
|
|
@ -7,6 +7,8 @@ import core.input
|
|||
import core.widget
|
||||
import core.decorators
|
||||
|
||||
import util.format
|
||||
|
||||
try:
|
||||
error = ModuleNotFoundError("")
|
||||
except Exception as e:
|
||||
|
@ -211,7 +213,14 @@ class Module(core.input.Object):
|
|||
]
|
||||
for action in actions:
|
||||
if self.parameter(action["name"]):
|
||||
core.input.register(self, action["id"], self.parameter(action["name"]))
|
||||
core.input.register(
|
||||
self,
|
||||
action["id"],
|
||||
self.parameter(action["name"]),
|
||||
util.format.asbool(
|
||||
self.parameter("{}-wait".format(action["name"]), False)
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class Error(Module):
|
||||
|
|
|
@ -45,10 +45,12 @@ def execute(
|
|||
out, _ = proc.communicate()
|
||||
if proc.returncode != 0:
|
||||
err = "{} exited with code {}".format(cmd, proc.returncode)
|
||||
logging.warning(err)
|
||||
if ignore_errors:
|
||||
return (proc.returncode, err) if return_exitcode else err
|
||||
raise RuntimeError(err)
|
||||
res = out.decode("utf-8")
|
||||
logging.debug(res)
|
||||
return (proc.returncode, res) if return_exitcode else res
|
||||
return (0, "") if return_exitcode else ""
|
||||
|
||||
|
|
Loading…
Reference in a new issue