Skip to content

Commit

Permalink
indicates properly when connection is good or lost
Browse files Browse the repository at this point in the history
  • Loading branch information
ssalenik committed Aug 28, 2012
1 parent f61dc0e commit df7bb37
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions client/python/etherio_gui.py
Expand Up @@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-

import sys
from PySide import QtCore
from PySide.QtCore import *
from PySide.QtGui import *
import unicodedata
Expand All @@ -12,6 +13,8 @@
import socket
from threading import Thread

@QtCore.Slot(bool)

class EIOWindow(QMainWindow):

def __init__(self, parent=None):
Expand Down Expand Up @@ -82,7 +85,7 @@ def __init__(self, parent=None):
self.controller.addQEObserver(self.updateQEs)
self.controller.addADCObserver(self.updateADCs)
self.controller.addDACObserver(self.updateDACs)
self.controller.addTimeOutObserver(self.timeout)
self.controller.timeout.connect(self.timeout)

def connect(self):
if self.connected == False :
Expand Down Expand Up @@ -128,9 +131,9 @@ def updateDACs(self, currentValues):
# TODO: change to using QThreads and signals to accomplish this
def timeout(self, timedout):
if timedout :
None
self.settings.statusLabel.setPixmap(self.settings.redFill)
else:
None
self.settings.statusLabel.setPixmap(self.settings.greenFill)

class EIOSettings(QFrame):

Expand Down Expand Up @@ -322,10 +325,16 @@ def updateValue(self, newValue):
self.value = newValue
self.QuadText.setText("%s" % newValue)

class Controller:
def __init__(self):
class Controller(QtCore.QObject):

# define slots
timeout = QtCore.Signal(bool)

def __init__(self, parent=None):
super(Controller, self).__init__(parent)

self.keepGoing = True # is this necessary?
self.pollRate = 5
self.pollRate = 15

# observers
self.DACObservers = []
Expand Down Expand Up @@ -375,12 +384,10 @@ def pollSocket(self, rcvcallfunction):
while(True):
if self.keepGoing:
try:
rcvcallfunction(TimeOut=0.5/self.pollRate)
for observer in self.TimeOutObservers:
observer(False)
rcvcallfunction(TimeOut=1.0/self.pollRate)
self.timeout.emit(False)
except socket.timeout:
for observer in self.TimeOutObservers:
observer(True)
self.timeout.emit(True)
else:
break

Expand Down

0 comments on commit df7bb37

Please sign in to comment.