Commit 110416af82c99ebc09f4d070e2c50213fbb4c397
Committed by
Thiago Franco de Moraes
1 parent
5e6e840f
Exists in
master
PLH stylus button can be used in PCs without serial ports (#113)
* PLH stylus button can be used in PCs without serial ports * Message box for communication error
Showing
1 changed file
with
18 additions
and
16 deletions
Show diff stats
invesalius/data/trigger.py
| ... | ... | @@ -33,20 +33,21 @@ class Trigger(threading.Thread): |
| 33 | 33 | threading.Thread.__init__(self) |
| 34 | 34 | self.trigger_init = None |
| 35 | 35 | self.stylusplh = False |
| 36 | + self.COM = False | |
| 37 | + self.nav_id = nav_id | |
| 36 | 38 | self.__bind_events() |
| 37 | 39 | try: |
| 38 | 40 | import serial |
| 39 | 41 | |
| 40 | 42 | self.trigger_init = serial.Serial('COM1', baudrate=9600, timeout=0) |
| 41 | - self.nav_id = nav_id | |
| 42 | - self._pause_ = False | |
| 43 | - self.start() | |
| 43 | + self.COM = True | |
| 44 | 44 | |
| 45 | - except ImportError: | |
| 46 | - print 'PySerial library not installed. Please install to use Trigger option.' | |
| 45 | + except: | |
| 46 | + wx.MessageBox(_('Connection with port COM1 failed'), _('Communication error'), wx.OK | wx.ICON_ERROR) | |
| 47 | + self.COM = False | |
| 47 | 48 | |
| 48 | - except serial.serialutil.SerialException: | |
| 49 | - print 'Connection with port COM1 failed.' | |
| 49 | + self._pause_ = False | |
| 50 | + self.start() | |
| 50 | 51 | |
| 51 | 52 | def __bind_events(self): |
| 52 | 53 | Publisher.subscribe(self.OnStylusPLH, 'PLH Stylus Button On') |
| ... | ... | @@ -59,15 +60,16 @@ class Trigger(threading.Thread): |
| 59 | 60 | |
| 60 | 61 | def run(self): |
| 61 | 62 | while self.nav_id: |
| 62 | - self.trigger_init.write('0') | |
| 63 | - sleep(0.3) | |
| 64 | - lines = self.trigger_init.readlines() | |
| 65 | - # Following lines can simulate a trigger in 3 sec repetitions | |
| 66 | - # sleep(3) | |
| 67 | - # lines = True | |
| 68 | - if lines: | |
| 69 | - wx.CallAfter(Publisher.sendMessage, 'Create marker') | |
| 70 | - sleep(0.5) | |
| 63 | + if self.COM: | |
| 64 | + self.trigger_init.write('0') | |
| 65 | + sleep(0.3) | |
| 66 | + lines = self.trigger_init.readlines() | |
| 67 | + # Following lines can simulate a trigger in 3 sec repetitions | |
| 68 | + # sleep(3) | |
| 69 | + # lines = True | |
| 70 | + if lines: | |
| 71 | + wx.CallAfter(Publisher.sendMessage, 'Create marker') | |
| 72 | + sleep(0.5) | |
| 71 | 73 | |
| 72 | 74 | if self.stylusplh: |
| 73 | 75 | wx.CallAfter(Publisher.sendMessage, 'Create marker') | ... | ... |