Commit 610200c7 authored by Béuren Bechlin's avatar Béuren Bechlin

Inciando repositóro com janela principal já criada. Criando janela para inicar novas medidas.

parents
*.pyc
*/*.pyc
__pycache__/
Interface gráfica para visualizar dados enviados via porta serial em tempo real.
**Em Construção**
### Dependências
* Python 3.x
* PyQt4
* pyqtgraph
### Concluído
* Janela Inicial
### Próximos Passos
* Janela de _novo log_
#!/usr/bin/python3.4
# -*- coding: utf-8 -*-
"""
Init GUI
"""
import sys
from PyQt4.QtGui import QApplication
from mainwind import MainWindow
def main():
app = QApplication(sys.argv)
main_w = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
#!/usr/bin/python3.4
# -*- coding: utf-8 -*-
"""
Based on:
-- ZetCode PyQt4 tutorial
"""
import sys
import plotview as pw
#from TabWidget import TabWidget
from PyQt4 import QtGui, Qt
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.initUI()
def initUI(self):
### SET ICON
self.setWindowIcon(QtGui.QIcon('resources/icon.png'))
### CENTRAL FRAME
self.central_frame = QtGui.QGraphicsView()
self.setCentralWidget(self.central_frame)
### ACTIONS
self.exit_app_act = QtGui.QAction(QtGui.QIcon('resources/exit.png'),
'Exit', self)
self.exit_app_act.setShortcut('Esc')
self.exit_app_act.setStatusTip('Exit')
self.exit_app_act.triggered.connect(self.close)
self.open_file_act = QtGui.QAction(QtGui.QIcon('resources/open.png'),
'Open', self)
self.open_file_act.setShortcut('Ctrl+o')
self.open_file_act.setStatusTip('Open log file')
self.open_file_act.triggered.connect(self.openFileDialog)
self.save_log_act = QtGui.QAction(QtGui.QIcon('resources/save.png'),
'Save Log', self)
self.save_log_act.setShortcut('Ctrl+s')
self.save_log_act.setStatusTip('Save current log')
self.save_log_act.triggered.connect(self.saveLog)
self.new_log_act = QtGui.QAction(QtGui.QIcon('resources/play.png'),
'New Log', self)
self.new_log_act.setShortcut('Ctrl+l')
self.new_log_act.setStatusTip('Create new log')
self.new_log_act.triggered.connect(self.newLog)
### STATUS BAR
self.status_bar = self.statusBar()
### MENU
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu('File')
file_menu.addAction(self.open_file_act)
file_menu.addSeparator()
file_menu.addAction(self.exit_app_act)
log_menu = menu_bar.addMenu('Log')
log_menu.addAction(self.new_log_act)
log_menu.addAction(self.save_log_act)
### TOOLBAR
open_file_toolbar = self.addToolBar('Open')
open_file_toolbar.addAction(self.open_file_act)
open_file_toolbar.setMovable(False)
open_file_toolbar.addSeparator()
new_log_toolbar = self.addToolBar('New Log')
new_log_toolbar.addAction(self.new_log_act)
new_log_toolbar.setMovable(False)
save_log_toolbar = self.addToolBar('Save Log')
save_log_toolbar.addAction(self.save_log_act)
save_log_toolbar.setMovable(False)
save_log_toolbar.addSeparator()
exit_app_toolbar = self.addToolBar('Exit')
exit_app_toolbar.addAction(self.exit_app_act)
exit_app_toolbar.setMovable(False)
self.resize(750, 450)
self.centerWindow()
self.setWindowTitle('Fisiolog')
self.show()
def centerWindow(self):
qr = self.frameGeometry()
cp = QtGui.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def closeEvent(self, event):
"""
reply = QtGui.QMessageBox.question(self, 'Message',
"Are you sure to quit?", QtGui.QMessageBox.Yes |
QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
event.accept()
else:
event.ignore()
"""
pass
def openFileDialog(self):
file_name = QtGui.QFileDialog.getOpenFileName(self, 'Open file',
'/home')
print(file_name)
def saveLog(self):
pass
def newLog(self):
self.status_bar.showMessage("Serial Port not specified")
from PyQt4 import QtGui
class StatusPlotWidget(QtGui.QWidget):
def __init__(self, pattern = None):
super(StatusPlotWidget, self).__init__(pattern)
wid = QtGui.QWidget(pattern)
vbox = QtGui.QVBoxLayout(wid)
hbox = QtGui.QHBoxLayout(wid)
time_lbl1 = QtGui.QLabel(wid)
time_lbl1.setText('Current Time: ')
self.curr_time = QtGui.QLabel(wid)
self.curr_time.setText('00.00 s')
time_lbl2 = QtGui.QLabel(wid)
time_lbl2.setText('Total Time: ')
self.total_time = QtGui.QLabel(wid)
self.total_time.setText('00.00 s')
hbox.addWidget(time_lbl1)
hbox.addWidget(self.curr_time)
hbox.addStretch(1)
hbox.addWidget(time_lbl2)
hbox.addWidget(self.total_time)
vbox.addLayout(hbox)
self.progress_bar = QtGui.QProgressBar(wid)
self.progress_bar.setFixedHeight(40)
vbox.addWidget(self.progress_bar)
vbox.addStretch(1)
self.ok_stop_btt = QtGui.QPushButton("OK")
self.cancel_btt = QtGui.QPushButton("Cancel")
hbox = QtGui.QHBoxLayout(wid)
hbox.addStretch(1)
hbox.addWidget(self.ok_stop_btt)
hbox.addWidget(self.cancel_btt)
vbox.addLayout(hbox)
#wid.setLayout(vbox)
wid.show()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
main_w = StatusPlotWidget()
#main_w.show()
sys.exit(app.exec_())
#!/usr/bin/python3.4
# -*- coding: utf-8 -*-
"""
Real time plot widget
"""
import pyqtgraph as pg
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)
self.splitter.addWidget(self.plot_widget)
self.splitter_btt = QtGui.QToolButton(self.splitter)
self.splitter_btt.clicked.connect(lambda: self.splitterButton())
self.splitter_btt.setArrowType(QtCore.Qt.RightArrow)
self.splitter_btt.setFixedWidth(20)
self.splitter.addWidget(self.splitter_btt)
self.dock_widget = self.initDockWidget()
self.splitter.addWidget(QtGui.QTextEdit(self))
self.splitter.handle(0).setEnabled(False)
self.splitter.handle(1).setEnabled(False)
self.splitter.handle(2).setEnabled(False)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.splitter)
self.setLayout(layout)
def initDockWidget(self):
main_frame = QtGui.QWidget(self)
main_frame.setFixedWidth(300)
layout = QtGui.QVBoxLayout(main_frame)
tabs = QtGui.QTabWidget(main_frame)
tabs.addTab(log_prop, "Log Specification")
tabs.addTab(plot_prop, "Plot Properties")
status = self.initStatusWidget()
main_layout.addWidget(tabs)
main_layout.addStretch(1)
main_layout.addWidget(status)
main_frame.setLayout(main_layout)
return main_frame
def initLogSpecWidget(self):
widget = QtGui.QWiget(self.dock_widget)
vbox = QtGui.QVBoxLayout(widget)
hbox = QtGui.QHBoxLayout(widget)
lbl = QtGui.QLabel(status)
lbl.setText("Serial Port:")
self.serial_cb = QtGui.QComboBox()
self.serial_btt = QtGui.QToolButton()
self.serial_btt.setIcon(QtGui.QIcon('resources/play.png'))
self.serial_btt.clicked.connect()
def initStatusWidget(self):
status = QtGui.QWidget(self.dock_widget)
vbox = QtGui.QVBoxLayout(status)
hbox = QtGui.QHBoxLayout(status)
time_lbl1 = QtGui.QLabel(status)
time_lbl2.setText('Current Time: ')
self.curr_time = QtGui.QLabel(status)
self.curr_time.setText('00.00 s')
time_lbl1 = QtGui.QLabel(status)
time_lbl1.setText('Total Time: ')
self.total_time = QtGui.QLabel(status)
self.total_time.setText('00.00 s')
hbox.addWidget(time_lbl1)
hbox.addWidget(self.curr_time)
hbox.addStretch(1)
hbox.addWidget(time_lbl2)
hbox.addWidget(self.total_time)
vbox.addLayout(hbox)
self.progress_bar = QtGui.QProgressBar(status)
self.progress_bar.setFixedHeight(40)
vbox.addWidget(self.progress_bar)
vbox.addStretch(1)
self.ok_stop_btt = QtGui.QPushButton("OK")
self.cancel_btt = QtGui.QPushButton("Cancel")
hbox = QtGui.QHBoxLayout(status)
hbox.addStretch(1)
hbox.addWidget(self.ok_stop_btt)
hbox.addWidget(self.cancel_btt)
vbox.addLayout(hbox)
status.setLayout(vbox)
return status
def splitterButton(self):
if (self.state == True):
self.splitter.setSizes([0, 1, 1])
self.splitter_btt.setArrowType(QtCore.Qt.LeftArrow)
self.state = False
else:
self.splitter.setSizes([1, 1, 1])
self.splitter_btt.setArrowType(QtCore.Qt.RightArrow)
self.state = True
class OkStopButton(QtGui.QPushButton):
def __init__(self):
super(OkStopButton, self).__init__()
class PlotWidget(pg.GraphicsLayoutWidget):
def __init__(self):
super(PlotWidget, self).__init__()
self.initPlot()
def initPlot(self):
self.setBackground('w')
http://www.pyqtgraph.org/
http://www.pyqtgraph.org/documentation/index.html
http://www.pyqtgraph.org/documentation/plotting.html
http://doc.qt.io/qt-5/statemachine-api.html
http://zetcode.com/
import sys
import glob
import serial
def serial_ports():
""" Lists serial port names
:raises EnvironmentError:
On unsupported or unknown platforms
:returns:
A list of the serial ports available on the system
coded by Thomas
gihub: tfeldmann
"""
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
return result
if __name__ == '__main__':
print(serial_ports())
from PyQt4 import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self):
self.state = True
QtGui.QWidget.__init__(self)
self.splitter = QtGui.QSplitter(self)
self.splitter.setFrameShape(QtGui.QFrame.NoFrame)
self.splitter.addWidget(QtGui.QTextEdit(self))
self.splitter_btt = QtGui.QToolButton(self.splitter)
self.splitter_btt.clicked.connect(lambda: self.splitterButton())
self.splitter_btt.setArrowType(QtCore.Qt.LeftArrow)
self.splitter_btt.setFixedWidth(20)
self.splitter.addWidget(self.splitter_btt)
self.splitter.addWidget(QtGui.QTextEdit(self))
self.splitter.handle(0).setEnabled(False)
self.splitter.handle(1).setEnabled(False)
self.splitter.handle(2).setEnabled(False)
self.splitter.setOpaqueResize(False)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.splitter)
self.setLayout(layout)
def splitterButton(self):
if (self.state == True):
self.splitter.setSizes([0, 1, 1])
self.splitter_btt.setArrowType(QtCore.Qt.RightArrow)
self.state = False
else:
self.splitter.setSizes([1, 1, 1])
self.splitter_btt.setArrowType(QtCore.Qt.LeftArrow)
self.state = True
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.setGeometry(500, 300, 300, 300)
window.show()
sys.exit(app.exec_())
import math, random, sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Window(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.thread = Worker()
label = QLabel(self.tr("Number of stars:"))
self.spinBox = QSpinBox()
self.spinBox.setMaximum(10000)
self.spinBox.setValue(100)
self.startButton = QPushButton(self.tr("&Start"))
self.viewer = QLabel()
self.viewer.setFixedSize(300, 300)
self.connect(self.thread, SIGNAL("finished()"), self.updateUi)
self.connect(self.thread, SIGNAL("terminated()"), self.updateUi)
self.connect(self.thread, SIGNAL("output(QRect, QImage)"), self.addImage)
self.connect(self.startButton, SIGNAL("clicked()"), self.makePicture)
layout = QGridLayout()
layout.addWidget(label, 0, 0)
layout.addWidget(self.spinBox, 0, 1)
layout.addWidget(self.startButton, 0, 2)
layout.addWidget(self.viewer, 1, 0, 1, 3)
self.setLayout(layout)
self.setWindowTitle(self.tr("Simple Threading Example"))
def makePicture(self):
self.spinBox.setReadOnly(True)
self.startButton.setEnabled(False)
pixmap = QPixmap(self.viewer.size())
pixmap.fill(Qt.black)
self.viewer.setPixmap(pixmap)
self.thread.render(self.viewer.size(), self.spinBox.value())
def addImage(self, rect, image):
pixmap = self.viewer.pixmap()
painter = QPainter()
painter.begin(pixmap)
painter.drawImage(rect, image)
painter.end()
self.viewer.update(rect)
def updateUi(self):
self.spinBox.setReadOnly(False)
self.startButton.setEnabled(True)
class Worker(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
self.size = QSize(0, 0)
self.stars = 0
self.path = QPainterPath()
angle = 2*math.pi/5
self.outerRadius = 20
self.innerRadius = 8
self.path.moveTo(self.outerRadius, 0)
for step in range(1, 6):
self.path.lineTo(
self.innerRadius * math.cos((step - 0.5) * angle),
self.innerRadius * math.sin((step - 0.5) * angle)
)
self.path.lineTo(
self.outerRadius * math.cos(step * angle),
self.outerRadius * math.sin(step * angle)
)
self.path.closeSubpath()
def __del__(self):
self.exiting = True
self.wait()
def render(self, size, stars):
self.size = size
self.stars = stars
self.start()
def run(self):
# Note: This is never called directly. It is called by Qt once the
# thread environment has been set up.
random.seed()
n = self.stars
width = self.size.width()
height = self.size.height()
while not self.exiting and n > 0:
image = QImage(self.outerRadius * 2, self.outerRadius * 2,
QImage.Format_ARGB32)
image.fill(qRgba(0, 0, 0, 0))
x = random.randrange(0, width)
y = random.randrange(0, height)
angle = random.randrange(0, 360)
red = random.randrange(0, 256)
green = random.randrange(0, 256)
blue = random.randrange(0, 256)
alpha = random.randrange(0, 256)
painter = QPainter()
painter.begin(image)
painter.setRenderHint(QPainter.Antialiasing)
painter.setPen(Qt.NoPen)
painter.setBrush(QColor(red, green, blue, alpha))
painter.translate(self.outerRadius, self.outerRadius)
painter.rotate(angle)
painter.drawPath(self.path)
painter.end()
self.emit(SIGNAL("output(QRect, QImage)"),
QRect(x - self.outerRadius, y - self.outerRadius,
self.outerRadius * 2, self.outerRadius * 2), image)
n -= 1
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
ZetCode PyQt4 tutorial
In this program, we can press on a button
with a left mouse click or drag and drop the
button with the right mouse click.
author: Jan Bodnar
website: zetcode.com
last edited: October 2013
"""
import sys
from PyQt4 import QtCore, QtGui
class Button(QtGui.QPushButton):
def __init__(self, title, parent):
super(Button, self).__init__(title, parent)
def mouseMoveEvent(self, e):
if e.buttons() != QtCore.Qt.RightButton:
return
mimeData = QtCore.QMimeData()
drag = QtGui.QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(e.pos() - self.rect().topLeft())
dropAction = drag.start(QtCore.Qt.MoveAction)
def mousePressEvent(self, e):
super(Button, self).mousePressEvent(e)
if e.button() == QtCore.Qt.LeftButton:
print 'press'
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.setAcceptDrops(True)
self.button = Button('Button', self)
self.button.move(100, 65)
self.setWindowTitle('Click or Move')
self.setGeometry(300, 300, 280, 150)
self.show()
def dragEnterEvent(self, e):
e.accept()
def dropEvent(self, e):
position = e.pos()
self.button.move(position)
e.setDropAction(QtCore.Qt.MoveAction)
e.accept()
def main():
app = QtGui.QApplication([])
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