Skip to content
Snippets Groups Projects
Commit 58329ac4 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Cleanup code to work better with newer Python

parent 38656519
No related branches found
No related tags found
No related merge requests found
...@@ -19,7 +19,7 @@ QUESTIONS = { ...@@ -19,7 +19,7 @@ QUESTIONS = {
class KeybindsWindow(QDialog): class KeybindsWindow(QDialog):
def __init__(self, window): def __init__(self, window):
super(KeybindsWindow, self).__init__() super().__init__()
self._window = window self._window = window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("B-ASIC Keybinds") self.setWindowTitle("B-ASIC Keybinds")
...@@ -59,7 +59,7 @@ class KeybindsWindow(QDialog): ...@@ -59,7 +59,7 @@ class KeybindsWindow(QDialog):
class AboutWindow(QDialog): class AboutWindow(QDialog):
def __init__(self, window): def __init__(self, window):
super(AboutWindow, self).__init__() super().__init__()
self._window = window self._window = window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("About B-ASIC") self.setWindowTitle("About B-ASIC")
...@@ -97,7 +97,7 @@ class AboutWindow(QDialog): ...@@ -97,7 +97,7 @@ class AboutWindow(QDialog):
class FaqWindow(QDialog): class FaqWindow(QDialog):
def __init__(self, window): def __init__(self, window):
super(FaqWindow, self).__init__() super().__init__()
self._window = window self._window = window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("Frequently Asked Questions") self.setWindowTitle("Frequently Asked Questions")
......
...@@ -10,7 +10,7 @@ from b_asic.signal import Signal ...@@ -10,7 +10,7 @@ from b_asic.signal import Signal
class Arrow(QGraphicsLineItem): class Arrow(QGraphicsLineItem):
def __init__(self, source, destination, window, signal=None, parent=None): def __init__(self, source, destination, window, signal=None, parent=None):
super(Arrow, self).__init__(parent) super().__init__(parent)
self.source = source self.source = source
self.signal = Signal(source.port, destination.port) if signal is None else signal self.signal = Signal(source.port, destination.port) if signal is None else signal
self.destination = destination self.destination = destination
......
...@@ -36,7 +36,7 @@ class DragButton(QPushButton): ...@@ -36,7 +36,7 @@ class DragButton(QPushButton):
self._m_drag = False self._m_drag = False
self._mouse_press_pos = None self._mouse_press_pos = None
self._mouse_move_pos = None self._mouse_move_pos = None
super(DragButton, self).__init__(parent) super().__init__(parent)
def contextMenuEvent(self, event): def contextMenuEvent(self, event):
menu = QMenu() menu = QMenu()
...@@ -62,7 +62,7 @@ class DragButton(QPushButton): ...@@ -62,7 +62,7 @@ class DragButton(QPushButton):
self._mouse_press_pos = event.pos() self._mouse_press_pos = event.pos()
self._mouse_move_pos = event.pos() self._mouse_move_pos = event.pos()
super(DragButton, self).mousePressEvent(event) super().mousePressEvent(event)
def mouseMoveEvent(self, event): def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton and self._m_press: if event.buttons() == Qt.LeftButton and self._m_press:
...@@ -78,7 +78,7 @@ class DragButton(QPushButton): ...@@ -78,7 +78,7 @@ class DragButton(QPushButton):
self._window.scene.update() self._window.scene.update()
self._window.graphic_view.update() self._window.graphic_view.update()
super(DragButton, self).mouseMoveEvent(event) super().mouseMoveEvent(event)
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
self._m_press = False self._m_press = False
...@@ -93,7 +93,7 @@ class DragButton(QPushButton): ...@@ -93,7 +93,7 @@ class DragButton(QPushButton):
else: else:
self.select_button(event.modifiers()) self.select_button(event.modifiers())
super(DragButton, self).mouseReleaseEvent(event) super().mouseReleaseEvent(event)
def _toggle_button(self, pressed=False): def _toggle_button(self, pressed=False):
self.pressed = not pressed self.pressed = not pressed
......
...@@ -20,8 +20,8 @@ from b_asic.GUI.utils import decorate_class, handle_error ...@@ -20,8 +20,8 @@ from b_asic.GUI.utils import decorate_class, handle_error
from b_asic.GUI.simulate_sfg_window import SimulateSFGWindow, Plot from b_asic.GUI.simulate_sfg_window import SimulateSFGWindow, Plot
from b_asic.GUI.select_sfg_window import SelectSFGWindow from b_asic.GUI.select_sfg_window import SelectSFGWindow
from b_asic import FastSimulation # from b_asic import FastSimulation
from b_asic.simulation import Simulation from b_asic.simulation import Simulation as FastSimulation
from b_asic.operation import Operation from b_asic.operation import Operation
from b_asic.port import InputPort, OutputPort from b_asic.port import InputPort, OutputPort
from b_asic.signal_flow_graph import SFG from b_asic.signal_flow_graph import SFG
...@@ -30,7 +30,7 @@ import b_asic.core_operations as c_oper ...@@ -30,7 +30,7 @@ import b_asic.core_operations as c_oper
import b_asic.special_operations as s_oper import b_asic.special_operations as s_oper
from b_asic.save_load_structure import * from b_asic.save_load_structure import *
from numpy import linspace import numpy as np
from qtpy.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction,\ from qtpy.QtWidgets import QApplication, QWidget, QMainWindow, QLabel, QAction,\
QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\ QStatusBar, QMenuBar, QLineEdit, QPushButton, QSlider, QScrollArea, QVBoxLayout,\
...@@ -49,7 +49,7 @@ logging.basicConfig(level=logging.INFO) ...@@ -49,7 +49,7 @@ logging.basicConfig(level=logging.INFO)
@decorate_class(handle_error) @decorate_class(handle_error)
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self): def __init__(self):
super(MainWindow, self).__init__() super().__init__()
self.ui = Ui_main_window() self.ui = Ui_main_window()
self.ui.setupUi(self) self.ui.setupUi(self)
self.setWindowIcon(QIcon('small_logo.png')) self.setWindowIcon(QIcon('small_logo.png'))
...@@ -140,7 +140,7 @@ class MainWindow(QMainWindow): ...@@ -140,7 +140,7 @@ class MainWindow(QMainWindow):
10, 10, self.ui.operation_box.width(), self.height()) 10, 10, self.ui.operation_box.width(), self.height())
self.graphic_view.setGeometry(self.ui.operation_box.width( self.graphic_view.setGeometry(self.ui.operation_box.width(
) + 20, 60, self.width() - self.ui.operation_box.width() - 20, self.height()-30) ) + 20, 60, self.width() - self.ui.operation_box.width() - 20, self.height()-30)
super(MainWindow, self).resizeEvent(event) super().resizeEvent(event)
def wheelEvent(self, event): def wheelEvent(self, event):
if event.modifiers() == Qt.ControlModifier: if event.modifiers() == Qt.ControlModifier:
...@@ -355,7 +355,7 @@ class MainWindow(QMainWindow): ...@@ -355,7 +355,7 @@ class MainWindow(QMainWindow):
"""Determine the distance between each port on the side of an operation. """Determine the distance between each port on the side of an operation.
The method returns the distance that each port should have from 0. The method returns the distance that each port should have from 0.
""" """
return [length / 2] if ports == 1 else linspace(0, length, ports) return [length / 2] if ports == 1 else np.linspace(0, length, ports)
def add_ports(self, operation): def add_ports(self, operation):
_output_ports_dist = self._determine_port_distance( _output_ports_dist = self._determine_port_distance(
...@@ -364,12 +364,14 @@ class MainWindow(QMainWindow): ...@@ -364,12 +364,14 @@ class MainWindow(QMainWindow):
55 - 17, operation.operation.input_count) 55 - 17, operation.operation.input_count)
self.portDict[operation] = list() self.portDict[operation] = list()
print(_output_ports_dist)
print(_input_ports_dist)
for i, dist in enumerate(_input_ports_dist): for i, dist in enumerate(_input_ports_dist):
port = PortButton( port = PortButton(
">", operation, operation.operation.input(i), self) ">", operation, operation.operation.input(i), self)
self.portDict[operation].append(port) self.portDict[operation].append(port)
operation.ports.append(port) operation.ports.append(port)
port.move(0, dist) port.move(0, round(dist))
port.show() port.show()
for i, dist in enumerate(_output_ports_dist): for i, dist in enumerate(_output_ports_dist):
...@@ -377,7 +379,7 @@ class MainWindow(QMainWindow): ...@@ -377,7 +379,7 @@ class MainWindow(QMainWindow):
">", operation, operation.operation.output(i), self) ">", operation, operation.operation.output(i), self)
self.portDict[operation].append(port) self.portDict[operation].append(port)
operation.ports.append(port) operation.ports.append(port)
port.move(55 - 12, dist) port.move(55 - 12, round(dist))
port.show() port.show()
def get_operations_from_namespace(self, namespace): def get_operations_from_namespace(self, namespace):
......
...@@ -9,7 +9,7 @@ class PortButton(QPushButton): ...@@ -9,7 +9,7 @@ class PortButton(QPushButton):
connectionRequested = Signal(QPushButton) connectionRequested = Signal(QPushButton)
moved = Signal() moved = Signal()
def __init__(self, name, operation, port, window, parent=None): def __init__(self, name, operation, port, window, parent=None):
super(PortButton, self).__init__(name, operation, parent) super().__init__(name, parent=operation)
self.pressed = False self.pressed = False
self._window = window self._window = window
self.port = port self.port = port
...@@ -30,10 +30,10 @@ class PortButton(QPushButton): ...@@ -30,10 +30,10 @@ class PortButton(QPushButton):
if event.button() == Qt.LeftButton: if event.button() == Qt.LeftButton:
self.select_port(event.modifiers()) self.select_port(event.modifiers())
super(PortButton, self).mousePressEvent(event) super().mousePressEvent(event)
def mouseReleaseEvent(self, event): def mouseReleaseEvent(self, event):
super(PortButton, self).mouseReleaseEvent(event) super().mouseReleaseEvent(event)
def _toggle_port(self, pressed=False): def _toggle_port(self, pressed=False):
self.pressed = not pressed self.pressed = not pressed
...@@ -56,4 +56,3 @@ class PortButton(QPushButton): ...@@ -56,4 +56,3 @@ class PortButton(QPushButton):
for signal in self._window.signalList: for signal in self._window.signalList:
signal.update() signal.update()
...@@ -6,7 +6,7 @@ from qtpy.QtGui import QDoubleValidator ...@@ -6,7 +6,7 @@ from qtpy.QtGui import QDoubleValidator
class PropertiesWindow(QDialog): class PropertiesWindow(QDialog):
def __init__(self, operation, main_window): def __init__(self, operation, main_window):
super(PropertiesWindow, self).__init__() super().__init__()
self.operation = operation self.operation = operation
self._window = main_window self._window = main_window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
...@@ -143,4 +143,4 @@ class PropertiesWindow(QDialog): ...@@ -143,4 +143,4 @@ class PropertiesWindow(QDialog):
self.operation.operation.set_latency_offsets({port: float(self.latency_fields[port].text().replace(",", ".")) if self.latency_fields[port].text() and float(self.latency_fields[port].text().replace(",", ".")) > 0 else None for port in self.latency_fields}) self.operation.operation.set_latency_offsets({port: float(self.latency_fields[port].text().replace(",", ".")) if self.latency_fields[port].text() and float(self.latency_fields[port].text().replace(",", ".")) > 0 else None for port in self.latency_fields})
self.reject() self.reject()
\ No newline at end of file
...@@ -12,7 +12,7 @@ class SelectSFGWindow(QDialog): ...@@ -12,7 +12,7 @@ class SelectSFGWindow(QDialog):
ok = Signal() ok = Signal()
def __init__(self, window): def __init__(self, window):
super(SelectSFGWindow, self).__init__() super().__init__()
self._window = window self._window = window
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
self.setWindowTitle("Select SFG") self.setWindowTitle("Select SFG")
......
...@@ -9,7 +9,7 @@ class ShowPCWindow(QDialog): ...@@ -9,7 +9,7 @@ class ShowPCWindow(QDialog):
pc = Signal() pc = Signal()
def __init__(self, window): def __init__(self, window):
super(ShowPCWindow, self).__init__() super().__init__()
self._window = window self._window = window
self.check_box_dict = dict() self.check_box_dict = dict()
self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint) self.setWindowFlags(Qt.WindowTitleHint | Qt.WindowCloseButtonHint)
......
...@@ -12,7 +12,7 @@ class SimulateSFGWindow(QDialog): ...@@ -12,7 +12,7 @@ class SimulateSFGWindow(QDialog):
simulate = Signal() simulate = Signal()
def __init__(self, window): def __init__(self, window):
super(SimulateSFGWindow, self).__init__() super().__init__()
self._window = window self._window = window
self.properties = dict() self.properties = dict()
self.sfg_to_layout = dict() self.sfg_to_layout = dict()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment