summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2019-05-03 16:31:32 +0200
committerPaweł Redman <pawel.redman@gmail.com>2019-05-03 16:31:32 +0200
commit43da01a538a5c6724505026b4a84b559d5e56219 (patch)
treeb778fab589c30882a769011b23da22e2a434df3f
parentea83137c32be2f7c47e6c4e4bbfaafeb0591db21 (diff)
More ui refactoring
-rw-r--r--src/ui.py217
-rw-r--r--src/ui_table.py6
-rw-r--r--src/ui_widgets.py30
3 files changed, 112 insertions, 141 deletions
diff --git a/src/ui.py b/src/ui.py
index 77f36fc..0077b13 100644
--- a/src/ui.py
+++ b/src/ui.py
@@ -6,35 +6,15 @@ from PyQt5.QtCore import *
import phys, file
+
+
# global GUI-related shit
class GUI:
table = None
monospace = QFont("monospace")
bigfont = QFont("sans-serif", pointSize=10, weight=1000)
-class Pens:
- axes = QPen(Qt.gray)
-
- ellipse = QPen(Qt.black)
- ellipse.setWidth(2)
-
- axis_linear = QPen(QColor(201, 141, 0))
- axis_linear.setWidth(2)
- axis_linear.setStyle(Qt.DashDotLine)
-
- axis_fast = QPen(QColor(51, 87, 123))
- axis_fast.setWidth(2)
- axis_fast.setStyle(Qt.DashDotLine)
-
- axis_slow = QPen(QColor(55, 123, 51))
- axis_slow.setWidth(2)
- axis_slow.setStyle(Qt.DashDotLine)
-
- alpha = QPen(Qt.red)
- theta = QPen(Qt.blue)
- radii = QPen(Qt.black)
- radii.setStyle(Qt.DashDotLine)
from ui_widgets import *
from ui_table import *
@@ -127,79 +107,6 @@ def half_assed_element_deletion(index):
update()
-last_save_path = None
-file_filter = "Wery Omportant Zejta (*.woz)"
-
-def do_save(win, reuse_old):
- global system, last_save_path
-
- if reuse_old and last_save_path:
- path = last_save_path
- else:
- path, _ = QFileDialog.getSaveFileName(win, filter=file_filter)
- if path == "":
- return
-
- try:
- file.save_system(path, system)
- except:
- traceback.print_exc()
-
- last_save_path = path
-
-def do_open(win):
- global system
-
- path, _ = QFileDialog.getOpenFileName(win, filter=file_filter)
- if path == "":
- return
-
- try:
- system = file.open_system(path)
- except:
- traceback.print_exc()
-
- populate_table()
- GUI.table_frame = QFrame()
- GUI.table_frame.setLayout(GUI.table)
- GUI.scroll.setWidget(GUI.table_frame)
- update()
-
-def setup_menubar(win):
- menu = win.menuBar()
-
- # File
- open = QAction("&Open system", win)
- open.setShortcut("Ctrl+O")
- open.triggered.connect(lambda: do_open(win))
- save = QAction("&Save system", win)
- save.setShortcut("Ctrl+S")
- save.triggered.connect(lambda: do_save(win, True))
- save_as = QAction("&Save system as...", win)
- save_as.triggered.connect(lambda: do_save(win, False))
- close = QAction("Exit", win)
- close.setShortcut("Ctrl+Q")
- close.triggered.connect(exit)
-
- file = menu.addMenu("&File")
- file.addAction(open)
- file.addAction(save)
- file.addAction(save_as)
- file.addAction(close)
-
- # System
- add = QAction("&Add a new element", win)
- add.setShortcut("Ctrl+N")
- add.triggered.connect(lambda: half_assed_element_creation())
- clear = QAction("&Remove all elements", win)
- clear.triggered.connect(half_assed_clear)
-
- system = menu.addMenu("&System")
- system.addAction(add)
- system.addAction(clear)
-
- win.statusBar()
-
# FIXME: refactor
#def optimize(which):
# if len(system.elements) == 0:
@@ -232,59 +139,57 @@ def setup_menubar(win):
# GUI.table_rows[op_idx].optbox.angle.edit.setText("%g" % round(opt.x * 180 / np.pi, 3))
class MainWindow(QMainWindow):
+ file_filter = "Wery Omportant Zejta (*.woz)"
+
def __init__(self, system_):
super().__init__()
+ self.last_save_path = None
+
self.statusBar()
self.setWindowTitle("Polarizzazione italiana")
global system
system = system_
- ## Needless to say, I'm getting real tired of this whole Layout/Widget
- ## clusterfuck in Qt
- #root = QVBoxLayout()
- #root_fucking_random_container = QWidget()
- #root_fucking_random_container.setLayout(root)
- #self.setCentralWidget(root_fucking_random_container)
- #
- ## Top bar (input intensity)
- #box = QHBoxLayout()
- #root.addLayout(box)
- #
- #box.addWidget(QLabel("Input intensity"))
- #GUI.input_intensity = QLineEdit("1")
- #GUI.input_intensity.textChanged.connect(self.change_input_intensity)
- #box.addWidget(GUI.input_intensity)
- #
- #hbox = QHBoxLayout()
- #root.addLayout(hbox)
- #
- #rhs = QVBoxLayout()
- #
- #Widocques.image = QImage("jones.jpg")
- #GUI.widok = Widocques()
- #rhs.addWidget(GUI.widok)
- #
- #optbox = QHBoxLayout()
- #rhs.addLayout(optbox)
- #
- #GUI.opt_operand = QComboBox()
- #optbox.addWidget(GUI.opt_operand)
- #button = QPushButton("Find a minimum")
- #button.pressed.connect(lambda: optimize("min"))
- #optbox.addWidget(button)
- #button = QPushButton("Find a maximum")
- #button.pressed.connect(lambda: optimize("max"))
- #optbox.addWidget(button)
- #
- #GUI.table = QTableWidget()
- #populate_table()
- #
- #hbox.addWidget(GUI.scroll)
- #hbox.addLayout(rhs)
-
- setup_menubar(self)
+ # Menu
+ menu_bar = self.menuBar()
+ self.statusBar()
+
+ # Menu - File
+ menu = menu_bar.addMenu("&File")
+
+ act = QAction("&Open system", self)
+ act.setShortcut("Ctrl+O")
+ act.triggered.connect(self.open_system)
+ menu.addAction(act)
+
+ act = QAction("&Save system", self)
+ act.setShortcut("Ctrl+S")
+ act.triggered.connect(lambda: self.save_system(True))
+ menu.addAction(act)
+
+ act = QAction("&Save system as...", self)
+ act.triggered.connect(lambda: self.save_system(False))
+ menu.addAction(act)
+
+ act = QAction("Exit", self)
+ act.setShortcut("Ctrl+Q")
+ act.triggered.connect(exit)
+ menu.addAction(act)
+ # Menu - System
+ menu = menu_bar.addMenu("&System")
+
+ act = QAction("&Add a new element", self)
+ act.setShortcut("Ctrl+N")
+ act.triggered.connect(lambda: half_assed_element_creation())
+ menu.addAction(act)
+
+ act = QAction("&Remove all elements", self)
+ act.triggered.connect(half_assed_clear)
+ menu.addAction(act)
+
+ # Central widget
root = QVBoxLayout()
self.setCentralWidget(LayoutWrapper(root))
@@ -323,3 +228,37 @@ class MainWindow(QMainWindow):
except ValueError:
pass
+ def save_system(self,reuse_old):
+ global system
+
+ if reuse_old and self.last_save_path:
+ path = self.last_save_path
+ else:
+ path, _ = QFileDialog.getSaveFileName(self, \
+ filter=MainWindow.file_filter)
+ if path == "":
+ return
+
+ try:
+ file.save_system(path, system)
+ except:
+ traceback.print_exc()
+
+ self.last_save_path = path
+
+ def open_system(self):
+ global system
+
+ path, _ = QFileDialog.getOpenFileName(self, \
+ filter=MainWindow.file_filter)
+ if path == "":
+ return
+
+ try:
+ system = file.open_system(path)
+ except:
+ traceback.print_exc()
+
+ GUI.table.populate(system)
+ GUI.input_intensity.setText("%g" % system.input_intensity)
+ GUI.do_update()
diff --git a/src/ui_table.py b/src/ui_table.py
index 08b99f3..7640ace 100644
--- a/src/ui_table.py
+++ b/src/ui_table.py
@@ -163,7 +163,7 @@ class SystemTableRow:
def __init__(self, parent, pol, row_number):
self.parent = parent
self.pol = pol
- pol.row = self
+ self.row_number = row_number
self.angle = pol.angle
self.delta = pol.delta
@@ -211,6 +211,10 @@ class SystemTable(QTableWidget):
self.vh = self.verticalHeader()
self.vh.setSectionResizeMode(QHeaderView.ResizeToContents)
+ def renumber_rows(self):
+ for i, row in enumerate(self.rows):
+ row.row_number = i
+
def populate(self, system):
self.system = system
diff --git a/src/ui_widgets.py b/src/ui_widgets.py
index 384b948..42fda7c 100644
--- a/src/ui_widgets.py
+++ b/src/ui_widgets.py
@@ -3,7 +3,35 @@ from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
-from ui import GUI, Pens # the fuck
+from ui import GUI
+
+
+
+class Pens:
+ axes = QPen(Qt.gray)
+
+ ellipse = QPen(Qt.black)
+ ellipse.setWidth(2)
+
+ axis_linear = QPen(QColor(201, 141, 0))
+ axis_linear.setWidth(2)
+ axis_linear.setStyle(Qt.DashDotLine)
+
+ axis_fast = QPen(QColor(51, 87, 123))
+ axis_fast.setWidth(2)
+ axis_fast.setStyle(Qt.DashDotLine)
+
+ axis_slow = QPen(QColor(55, 123, 51))
+ axis_slow.setWidth(2)
+ axis_slow.setStyle(Qt.DashDotLine)
+
+ alpha = QPen(Qt.red)
+ theta = QPen(Qt.blue)
+
+ radii = QPen(Qt.black)
+ radii.setStyle(Qt.DashDotLine)
+
+
class ExpandingSpacer(QSpacerItem):
def __init__(self):