|
| 1 | +import logging |
1 | 2 | import subprocess
|
2 | 3 |
|
3 |
| -from i3configger.base import log |
| 4 | +log = logging.getLogger(__name__) |
| 5 | + |
| 6 | + |
| 7 | +def configure(args): |
| 8 | + I3.set_msg_type(args.i3_refresh_msg) |
| 9 | + log.info(f'set i3 refresh method to {I3.refresh.__name__}', ) |
| 10 | + Notify.set_notify_command(args.notify) |
| 11 | + log.info(f'set notify method to {Notify.send.__name__}', ) |
| 12 | + |
| 13 | + |
| 14 | +def communicate(msg='new config active', refresh=False): |
| 15 | + if refresh: |
| 16 | + I3.refresh() |
| 17 | + StatusBar.refresh() |
| 18 | + Notify.send(msg) |
4 | 19 |
|
5 | 20 |
|
6 | 21 | class I3:
|
@@ -38,30 +53,30 @@ def _send_i3_msg(cls, msg):
|
38 | 53 | return True
|
39 | 54 |
|
40 | 55 | @classmethod
|
41 |
| - def get_config_errors(cls, path): |
| 56 | + def get_config_error_report(cls, path): |
| 57 | + cmd = ['i3', '-C', '-c', str(path)] |
42 | 58 | try:
|
43 |
| - subprocess.check_output(['i3', '-C', '-c', str(path)]) |
44 |
| - return None |
| 59 | + return subprocess.check_output(cmd).decode() |
45 | 60 | except subprocess.CalledProcessError as e:
|
46 | 61 | return e.output
|
47 | 62 |
|
48 | 63 |
|
49 | 64 | class Notify:
|
50 | 65 | @classmethod
|
51 | 66 | def set_notify_command(cls, notify):
|
52 |
| - if not notify: |
53 |
| - log.debug("do not send notifications") |
54 |
| - cls.send = cls.nop |
| 67 | + cls.send = cls.notify_send if notify else cls.nop |
55 | 68 |
|
56 | 69 | @classmethod
|
57 |
| - def send(cls, msg, urgency='low'): |
| 70 | + def notify_send(cls, msg, urgency='low'): |
58 | 71 | subprocess.check_call([
|
59 | 72 | 'notify-send', '-a', 'i3configger', '-t', '1', '-u', urgency, msg])
|
60 | 73 |
|
61 | 74 | @staticmethod
|
62 | 75 | def nop(*args, **kwargs):
|
63 | 76 | pass
|
64 | 77 |
|
| 78 | + send = notify_send |
| 79 | + |
65 | 80 |
|
66 | 81 | class StatusBar:
|
67 | 82 | @classmethod
|
|
0 commit comments