Commit 442f3add authored by Béuren Bechlin's avatar Béuren Bechlin

Thread para encontrar portal serial inserida corretamente, finalizado o...

Thread para encontrar portal serial inserida corretamente, finalizado o diálogo para novo log de dados.
parent 30d86633
from json import dump
baud_rate = [300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400,
57600, 115200]
microc = ['Arduino Uno', 'Arduino Duemilanove']
items = {'baud_rate': baud_rate, 'microcontroller': microc}
with open('microcontroller.json', 'w') as f:
dump(items, f)
f.close()
{"baud_rate": [300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200], "microcontroller": ["Arduino Uno", "Arduino Duemilanove"]}
\ No newline at end of file
from json import dump, load
CONFIG_PATH = '../config/'
class ConfigurationManagement(Object):
def __init__(self):
try:
with open((CONFIG_PATH + 'microcontroller.json'), 'r') as f:
config = load(f)
baud_rate = config['baud_rate']
f.close()
except IOError:
baud_rate = [9600, 115220]
self.microc =
......@@ -8,7 +8,7 @@
"""
import sys
import plotview as pw
import newplotview as pw
#from TabWidget import TabWidget
from PyQt4 import QtGui, Qt
......@@ -118,8 +118,8 @@ class MainWindow(QtGui.QMainWindow):
def openFileDialog(self):
file_name = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
'/home')
file_name = QtGui.QFileDialog.getOpenFileNameAndFilter(self, 'Open file',
'/home', 'All files(*.*) ;;Log Files (*.log)', 'Log Files (*.log)')
print(file_name)
def saveLog(self):
......
from PyQt4 import QtGui
class LogSpecWidget(QtGui.QWidget):
def __init__(self, pattern = None):
super(LogSpecWidget, self).__init__(pattern)
vbox = QtGui.QVBoxLayout(self)
hbox = QtGui.QHBoxLayout()
lbl = QtGui.QLabel(self)
lbl.setText('Serial Port:')
self.serial_port_cb = QtGui.QComboBox(self)
self.serial_port_btt = QtGui.QToolButton(self)
self.serial_port_btt.setIcon(QtGui.QIcon('../resources/refresh.png'))
hbox.addWidget(lbl)
hbox.addWidget(self.serial_port_cb)
hbox.addStretch(1)
hbox.addWidget(self.serial_port_btt)
vbox.addLayout(hbox)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
main_w = LogSpecWidget()
main_w.show()
sys.exit(app.exec_())
import sys
sys.path.append('../')
from serialutils import ListSerialPorts
from PyQt4 import QtGui, QtCore
from json import load
RESOURCES_PATH = '../resources/'
CONFIG_PATH = '../config/'
class LogSpecWidget(QtGui.QWidget):
def __init__(self, pattern = None):
super(LogSpecWidget, self).__init__(pattern)
wid_layout = QtGui.QVBoxLayout(self)
vbox = QtGui.QVBoxLayout()
hbox = QtGui.QHBoxLayout()
lbl = QtGui.QLabel(self)
lbl.setText('Serial Port:')
self.serial_ports_cb = QtGui.QComboBox(self)
self.serial_ports_cb.setMinimumWidth(130)
self.info_ser_lbl = QtGui.QLabel(self)
self.info_ser_lbl.setFixedSize(20, 20)
self.refresh_btt = QtGui.QToolButton(self)
self.refresh_btt.setIcon(QtGui.QIcon(RESOURCES_PATH + 'refresh2.png'))
self.refresh_btt.clicked.connect(self.refreshPorts)
hbox.addWidget(lbl)
hbox.addWidget(self.serial_ports_cb)
hbox.addWidget(self.info_ser_lbl)
hbox.addStretch(1)
hbox.addWidget(self.refresh_btt)
vbox.addLayout(hbox)
self.list_ports_thread = ListSerialPorts(self)
self.connect(self.list_ports_thread,
QtCore.SIGNAL("listPortsOut_1arg_list"), self.listPorts)
self.refreshPorts()
lbl = QtGui.QLabel(self)
lbl.setText('Baud Rate:')
self.baud_rate_cb = QtGui.QComboBox(self)
self.baud_rate_cb.setMinimumWidth(60)
try:
with open((CONFIG_PATH + 'microcontroller.json'), 'r') as f:
config = load(f)
baud_rate = config['baud_rate']
f.close()
except IOError:
baud_rate = [9600, 115220]
for item in baud_rate:
self.baud_rate_cb.addItem(str(item))
hbox = QtGui.QHBoxLayout()
hbox.addWidget(lbl)
hbox.addWidget(self.baud_rate_cb)
hbox.addStretch(1)
vbox.addLayout(hbox)
vbox.addStretch(0.05)
gbox = QtGui.QGroupBox('Serial Comm')
gbox.setLayout(vbox)
wid_layout.addWidget(gbox)
vbox = QtGui.QVBoxLayout()
self.save_file_cb = QtGui.QCheckBox(self)
self.save_file_cb.stateChanged.connect(self.saveAuto)
lbl = QtGui.QLabel(self)
lbl.setText('Save automatically log file')
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.save_file_cb)
hbox.addWidget(lbl)
hbox.addStretch(1)
vbox.addLayout(hbox)
self.file_path_le = QtGui.QLineEdit(self)
self.file_path_le.setMinimumWidth(120)
lbl = QtGui.QLabel(self)
lbl.setText('File Name:')
self.file_explorer_btt = QtGui.QToolButton(self)
self.file_explorer_btt.setIcon(QtGui.QIcon(RESOURCES_PATH + 'folder.png'))
self.file_explorer_btt.clicked.connect(self.fileExplorer)
hbox = QtGui.QHBoxLayout()
hbox.addStretch(0.2)
hbox.addWidget(lbl)
hbox.addWidget(self.file_path_le)
hbox.addWidget(self.file_explorer_btt)
vbox.addLayout(hbox)
self.saveAuto(self.save_file_cb.checkState())
lbl1 = QtGui.QLabel(self)
lbl1.setText('Log Time:')
self.total_time_sb = QtGui.QSpinBox(self)
self.total_time_sb.setMinimumWidth(80)
self.total_time_sb.setSuffix(' s')
self.unlimeted_time_cb = QtGui.QCheckBox(self)
self.unlimeted_time_cb.stateChanged.connect(self.unlimetedTime)
lbl2 = QtGui.QLabel(self)
lbl2.setText('UNLIMETED')
hbox = QtGui.QHBoxLayout()
hbox.addWidget(lbl1)
hbox.addWidget(self.total_time_sb)
hbox.addStretch(1)
hbox.addWidget(self.unlimeted_time_cb)
hbox.addWidget(lbl2)
vbox.addLayout(hbox)
vbox.addStretch(0.05)
self.unlimetedTime(self.unlimeted_time_cb.checkState())
gbox = QtGui.QGroupBox('File and Timming')
gbox.setLayout(vbox)
wid_layout.addWidget(gbox)
self.ok_btt = QtGui.QPushButton("OK")
self.cancel_btt = QtGui.QPushButton("Cancel")
hbox = QtGui.QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(self.ok_btt)
hbox.addWidget(self.cancel_btt)
wid_layout.addLayout(hbox)
def refreshPorts(self):
busy = QtGui.QMovie(RESOURCES_PATH + 'busy2.gif')
busy.setScaledSize(QtCore.QSize(20,20))
self.info_ser_lbl.setMovie(busy)
busy.start()
self.list_ports_thread.start()
def fileExplorer(self):
file_name = QtGui.QFileDialog.getSaveFileNameAndFilter(self, 'Save file as',
'/home', 'All files(*.*);;Log Files (*.log);;Plain Text(*.txt)', 'Log Files (*.log)')
print(file_name)
self.file_path_le.setText(file_name[0])
def saveAuto(self, state):
if not state:
self.file_explorer_btt.setDisabled(True)
self.file_path_le.setDisabled(True)
else:
self.file_explorer_btt.setDisabled(False)
self.file_path_le.setDisabled(False)
def unlimetedTime(self, state):
if not state:
self.total_time_sb.setDisabled(False)
else:
self.total_time_sb.setDisabled(True)
def listPorts(self, ports):
if not ports:
image = QtGui.QPixmap(RESOURCES_PATH + 'error_red.png')
image = image.scaledToHeight(20)
self.info_ser_lbl.setPixmap(image)
self.serial_ports_cb.clear()
self.serial_ports_cb.setDisabled(True)
elif (len(ports) == 1):
image = QtGui.QPixmap(RESOURCES_PATH + 'check_green.png')
image = image.scaledToHeight(20)
self.info_ser_lbl.setPixmap(image)
self.serial_ports_cb.clear()
self.serial_ports_cb.addItem(ports[0])
self.serial_ports_cb.setDisabled(True)
else:
image = QtGui.QPixmap(RESOURCES_PATH + 'warning_shield.png')
image = image.scaledToHeight(20)
self.info_ser_lbl.setPixmap(image)
self.serial_ports_cb.clear()
for item in ports:
self.serial_ports_cb.addItem(item)
self.serial_ports_cb.setDisabled(False)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
main_w = LogSpecWidget()
main_w.show()
sys.exit(app.exec_())
......@@ -9,7 +9,6 @@ from PyQt4 import QtGui
class NewPlotWindow(QtGui.QWidget):
def __init__(self, pattern = None):
self.state = True
super(NewPlotWindow, self).__init__()
self.splitter = QtGui.QSplitter(self)
self.plot_widget = PlotWidget(self)
......
<?xml version="1.0" ?><svg height="24" version="1.1" width="24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><g transform="translate(0 -1028.4)"><path d="m22 12c0 5.523-4.477 10-10 10-5.5228 0-10-4.477-10-10 0-5.5228 4.4772-10 10-10 5.523 0 10 4.4772 10 10z" fill="#27ae60" transform="translate(0 1029.4)"/><path d="m22 12c0 5.523-4.477 10-10 10-5.5228 0-10-4.477-10-10 0-5.5228 4.4772-10 10-10 5.523 0 10 4.4772 10 10z" fill="#2ecc71" transform="translate(0 1028.4)"/><path d="m16 1037.4-6 6-2.5-2.5-2.125 2.1 2.5 2.5 2 2 0.125 0.1 8.125-8.1-2.125-2.1z" fill="#27ae60"/><path d="m16 1036.4-6 6-2.5-2.5-2.125 2.1 2.5 2.5 2 2 0.125 0.1 8.125-8.1-2.125-2.1z" fill="#ecf0f1"/></g></svg>
\ No newline at end of file
<?xml version="1.0" ?><svg height="24" version="1.1" width="24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><g transform="translate(0 -1028.4)"><path d="m22 12c0 5.523-4.477 10-10 10-5.5228 0-10-4.477-10-10 0-5.5228 4.4772-10 10-10 5.523 0 10 4.4772 10 10z" fill="#c0392b" transform="translate(0 1029.4)"/><path d="m22 12c0 5.523-4.477 10-10 10-5.5228 0-10-4.477-10-10 0-5.5228 4.4772-10 10-10 5.523 0 10 4.4772 10 10z" fill="#e74c3c" transform="translate(0 1028.4)"/><path d="m7.0503 1037.8 3.5357 3.6-3.5357 3.5 1.4142 1.4 3.5355-3.5 3.536 3.5 1.414-1.4-3.536-3.5 3.536-3.6-1.414-1.4-3.536 3.5-3.5355-3.5-1.4142 1.4z" fill="#c0392b"/><path d="m7.0503 1036.8 3.5357 3.6-3.5357 3.5 1.4142 1.4 3.5355-3.5 3.536 3.5 1.414-1.4-3.536-3.5 3.536-3.6-1.414-1.4-3.536 3.5-3.5355-3.5-1.4142 1.4z" fill="#ecf0f1"/></g></svg>
\ No newline at end of file
<?xml version="1.0" ?><svg height="24" version="1.1" width="24" xmlns="http://www.w3.org/2000/svg" xmlns:cc="http://creativecommons.org/ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><g transform="translate(0 -1028.4)"><path d="m3 1031.4v10c0 4.2 3.6322 8 9 10 5.368-2 9-5.8 9-10v-10h-18z" fill="#95a5a6"/><path d="m3 1030.4v10c0 4.2 3.6322 8 9 10 5.368-2 9-5.8 9-10v-10h-18z" fill="#ecf0f1"/><path d="m3 1030.4v10c0 4.2 3.6322 8 9 10v-20h-9z" fill="#bdc3c7"/><path d="m5 1032.4v8c0 3.4 2.8251 6.4 7 8 4.175-1.6 7-4.6 7-8v-8h-14z" fill="#f39c12"/><path d="m12 1032.4v16c4.175-1.6 7-4.6 7-8v-8h-7z" fill="#f1c40f"/><path d="m12 1034.4c-0.552 0-1 0.4-1 1l0.5 7h1l0.5-7c0-0.6-0.448-1-1-1zm0 9c-0.552 0-1 0.4-1 1 0 0.5 0.448 1 1 1s1-0.5 1-1c0-0.6-0.448-1-1-1z" fill="#34495e"/></g></svg>
\ No newline at end of file
import sys
import glob
import serial
import sys, glob, serial
from PyQt4 import QtGui, QtCore
class ListSerialPorts(QtCore.QThread):
def __init__(self, pattern = None):
super(ListSerialPorts, self).__init__(pattern)
def run(self):
# CALLBACK by default.
if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith ('linux'):
temp_list = glob.glob ('/dev/tty[A-Za-z]*')
result = []
for a_port in temp_list:
try:
s = serial.Serial(a_port)
s.close()
result.append(a_port)
except serial.SerialException:
pass
self.emit(QtCore.SIGNAL("listPortsOut_1arg_list"), result)
def serial_ports():
""" Lists serial port names
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ZetCode PyQt4 tutorial
In this example, we receive data from
a QtGui.QInputDialog dialog.
author: Jan Bodnar
website: zetcode.com
last edited: October 2011
"""
import sys
from PyQt4 import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.btn = QtGui.QPushButton('Dialog', self)
self.btn.move(20, 20)
self.btn.clicked.connect(self.showDialog)
self.le = QtGui.QLineEdit(self)
self.le.move(130, 22)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Input dialog')
self.show()
def showDialog(self):
text, ok = QtGui.QInputDialog.getText(self, 'Input Dialog',
'Enter your name:')
if ok:
self.le.setText(str(text))
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
from PyQt4 import QtGui
class UploadWind(QtGui.QWidget):
def __init__(self):
super(UploadWind, self).__init__()
self.initUI()
def initUI(self):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment