This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
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
105 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import random | ||
from PySide2 import Qt, QtCore, QtWidgets, QtGui | ||
import serial | ||
from serial.tools import list_ports | ||
|
||
class MainView(QtWidgets.QWidget): | ||
def __init__(self, toolbar): | ||
super(MainView, self).__init__() | ||
|
||
availablePorts = list_ports.comports() | ||
|
||
portsString = ''.join([p.device + '\n' for p in availablePorts]) | ||
|
||
self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир"] | ||
|
||
|
||
self.toolbar = toolbar | ||
|
||
|
||
self.button = QtWidgets.QPushButton("Click me!") | ||
self.text = QtWidgets.QLabel("Text") | ||
self.text.setAlignment(QtCore.Qt.AlignCenter) | ||
|
||
|
||
|
||
self.dropdown = QtWidgets.QComboBox() | ||
self.dropdown.addItems([p.device for p in availablePorts]) | ||
self.toolbar.addWidget(QtWidgets.QLabel("Select COM Port:")) | ||
self.toolbar.addWidget(self.dropdown) | ||
|
||
|
||
self.layout = QtWidgets.QVBoxLayout() | ||
self.layout.addWidget(self.text) | ||
self.layout.addWidget(self.button) | ||
self.setLayout(self.layout) | ||
|
||
self.button.clicked.connect(self.magic) | ||
|
||
|
||
|
||
|
||
def magic(self): | ||
self.text.setText(random.choice(self.hello)) |
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
""" Some utility functions for PyQt widgets """ | ||
|
||
from PySide2.QtGui import QPalette, QColor | ||
from PySide2 import QtWidgets | ||
|
||
def set_background_color(widget, color: str): | ||
""" set widget color to color: str""" | ||
pal = QPalette() | ||
# set black background | ||
pal.setColor(QPalette.Background, QColor(color)) | ||
widget.setAutoFillBackground(True) | ||
widget.setPalette(pal) | ||
|
||
def set_button_color(button, color: str): | ||
""" set button color to color: str""" | ||
pal = button.palette() | ||
pal.setColor(QPalette.Button, QColor(color)) | ||
button.setAutoFillBackground(True) | ||
button.setPalette(pal) | ||
button.update() | ||
|
||
def bold_label(text, size=13): | ||
""" Create a label with font-weight bold """ | ||
label = QtWidgets.QLabel(text) | ||
label.setStyleSheet("font-weight: bold; font-size: {}px".format(size)) | ||
label.update() | ||
return label | ||
|
||
def spacer(): | ||
""" Returns empty widget that expands to all available space """ | ||
s = QtWidgets.QWidget() | ||
s.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) | ||
return s | ||
|
||
|
||
|
||
class Row(QtWidgets.QWidget): | ||
"""Easily add widgets in a horizontal layout""" | ||
|
||
def __init__(self, *widgets): | ||
super().__init__() | ||
layout = QtWidgets.QHBoxLayout(self) | ||
layout.setContentsMargins(0, 0, 0, 0) | ||
for w in widgets: | ||
layout.addWidget(w) | ||
|
||
class Column(QtWidgets.QWidget): | ||
"""Easily add widgets in a vertical layout""" | ||
|
||
def __init__(self, *widgets): | ||
super().__init__() | ||
layout = QtWidgets.QVBoxLayout(self) | ||
layout.setContentsMargins(0, 0, 0, 0) | ||
for w in widgets: | ||
layout.addWidget(w) |