diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2019-05-03 16:31:32 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2019-05-03 16:31:32 +0200 |
commit | 43da01a538a5c6724505026b4a84b559d5e56219 (patch) | |
tree | b778fab589c30882a769011b23da22e2a434df3f /src/ui.py | |
parent | ea83137c32be2f7c47e6c4e4bbfaafeb0591db21 (diff) |
More ui refactoring
Diffstat (limited to 'src/ui.py')
-rw-r--r-- | src/ui.py | 217 |
1 files changed, 78 insertions, 139 deletions
@@ -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() |