-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jamesridgway/james/command-improvements
Improving error handling for command control
- Loading branch information
Showing
4 changed files
with
35 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
import logging | ||
import os | ||
from subprocess import Popen, DEVNULL | ||
|
||
from devdeck_core.controls.deck_control import DeckControl | ||
|
||
|
||
class CommandControl(DeckControl): | ||
def __init__(self, key_no, **kwargs): | ||
self.__logger = logging.getLogger('devdeck') | ||
super().__init__(key_no, **kwargs) | ||
|
||
def initialize(self): | ||
with self.deck_context() as context: | ||
with context.renderer() as r: | ||
r.image(os.path.expanduser(self.settings['icon'])).end() | ||
|
||
def pressed(self): | ||
Popen(self.settings['command'], stdout=DEVNULL, stderr=DEVNULL) | ||
try: | ||
Popen(self.settings['command'], stdout=DEVNULL, stderr=DEVNULL) | ||
except Exception as ex: | ||
self.__logger.error("Error executing command %s: %s", self.settings['command'], str(ex)) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import logging | ||
|
||
|
||
class InfoFilter(logging.Filter): | ||
def filter(self, rec): | ||
return rec.levelno in (logging.DEBUG, logging.INFO) |