-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
2 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
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 |
---|---|---|
|
@@ -2,14 +2,35 @@ | |
# | ||
# (c) 2014 Joost Yervante Damad <[email protected]> | ||
|
||
import sys, time, datetime | ||
import sys, time, datetime, ast | ||
|
||
from PySide import QtGui, QtCore | ||
from PySide.QtCore import Qt | ||
|
||
import ble | ||
from ble import BLE | ||
|
||
class WriteDialog(QtGui.QDialog): | ||
|
||
def __init__(self, parent, chandle, value=''): | ||
super(WriteDialog, self).__init__(parent) | ||
self.chandle = chandle | ||
self.setWindowTitle("Write %d" % (chandle)) | ||
self.resize(640,160) # TODO, there must be a better way to do this | ||
vbox = QtGui.QVBoxLayout() | ||
fl = QtGui.QFormLayout() | ||
self.value_edit = QtGui.QLineEdit() | ||
self.value_edit.setText(str(value)) | ||
fl.addRow("Value:", self.value_edit) | ||
vbox.addLayout(fl) | ||
buttons = QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel | ||
self.button_box = QtGui.QDialogButtonBox(buttons, QtCore.Qt.Horizontal) | ||
self.button_box.accepted.connect(self.accept) | ||
self.button_box.rejected.connect(self.reject) | ||
#self.button_box.button(QtGui.QDialogButtonBox.Ok).setDisabled(True) | ||
vbox.addWidget(self.button_box) | ||
self.setLayout(vbox) | ||
|
||
class Device: | ||
|
||
def __init__(self, ble, handle, mac): | ||
|
@@ -73,6 +94,14 @@ def write(self): | |
if t == 'attr': | ||
chandle = int(parent.child(self.current.row(), 3).data(Qt.DisplayRole)) | ||
print "write to ", chandle | ||
try: | ||
value = self.chandle_to_value_item[chandle].data(Qt.DisplayRole) | ||
except: | ||
value = '' | ||
dialog = WriteDialog(self.view, chandle, value) | ||
if dialog.exec_() != QtGui.QDialog.Accepted: return | ||
value = ast.literal_eval(dialog.value_edit.text()) | ||
self.ble.write_handle(self.handle, chandle, value) | ||
|
||
def primary(self): | ||
self.type = 'primary' | ||
|