Skip to content

Commit

Permalink
color indicate when values are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
andete committed Mar 7, 2014
1 parent ee848cc commit 4c6fa55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def read_handles(self, handle, h1, h2):
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, h1))

def handle_attclient_attribute_value(self, sender, args):
print args
#print args
chandle = args['atthandle']
handle = args['connection']
t = args['type']
Expand Down
18 changes: 16 additions & 2 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def _add(text, slot = None):
self.current = None
self.chandle_to_value_item = {}
self.chandle_to_uuid = {}
self.chandle_to_timer = {}
self.chandle_stored_background = {}

def row_changed(self, current, previous):
self.current = current
Expand Down Expand Up @@ -178,16 +180,28 @@ def s(x):
except:
name = ''
svalue = s('')
self.chandle_stored_background[char] = svalue.background()
self.chandle_to_value_item[char] = svalue
self.chandle_to_uuid[char] = uuid
self.chandle_to_timer[char] = QtCore.QTimer()
self.chandle_to_timer[char].setSingleShot(True)
self.chandle_to_timer[char].timeout.connect(lambda: self.value_is_older(char))
self.model.item(self.scan_pos).appendRow([s("attr"), s(uuids), s(name), s(str(char)), svalue])
#self.view.expandAll()

def value_is_older(self, chandle):
svalue = self.chandle_to_value_item[chandle]
svalue.setBackground(self.chandle_stored_background[chandle])

def attr_value(self, chandle, t, value):
print chandle, t, value
uuid = self.chandle_to_uuid[chandle]
s = self.ble.uuid.value_to_string_by_uuid(uuid, value)
self.chandle_to_value_item[chandle].setData(s, Qt.DisplayRole)
# TODO temporarely change background to green, and start timer
# to change it back
svalue = self.chandle_to_value_item[chandle]
svalue.setData(s, Qt.DisplayRole)
svalue.setBackground(QtGui.QBrush(Qt.green))
self.chandle_to_timer[chandle].start(500.0)

class MainWin(QtGui.QMainWindow):

Expand Down

0 comments on commit 4c6fa55

Please sign in to comment.