Conditions | 5 |
Total Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
1 | |||
9 | def trycatchslot(func): |
||
10 | """ |
||
11 | wrap a at slot. |
||
12 | log and call a method called show_error or a signal |
||
13 | called error in case of error |
||
14 | """ |
||
15 | def wrapper(self, *args): |
||
16 | # filter out excess args as qt signals do |
||
17 | sig = inspect.signature(func) |
||
18 | args = args[:(len(sig.parameters)-1)] |
||
19 | result = None |
||
20 | try: |
||
21 | result = func(self, *args) |
||
22 | except Exception as ex: |
||
23 | logger.exception(ex) |
||
24 | if hasattr(self, "show_error"): |
||
25 | self.show_error(ex) |
||
26 | elif hasattr(self, "error"): |
||
27 | self.error.emit(ex) |
||
28 | else: |
||
29 | logger.warning("Error class % has no member show_error or error", self) |
||
30 | return result |
||
31 | return wrapper |
||
32 | |||
34 |