mirror of https://gitlab.com/pamhyr/pamhyr2
stricklers, config: Add stricklers tab in config window.
parent
6c14e5ebf1
commit
70fac8e6e3
|
|
@ -2,10 +2,13 @@
|
||||||
|
|
||||||
from tools import trace, timer
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Model.Saved import SavedStatus
|
||||||
from Model.Stricklers.Stricklers import Stricklers
|
from Model.Stricklers.Stricklers import Stricklers
|
||||||
|
|
||||||
class StricklersList(object):
|
class StricklersList(object):
|
||||||
def __init__(self, status = None):
|
def __init__(self, status = None):
|
||||||
|
if status is None:
|
||||||
|
status = SavedStatus()
|
||||||
self._status = status
|
self._status = status
|
||||||
|
|
||||||
self._stricks = []
|
self._stricks = []
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,16 @@ from config import Config
|
||||||
from View.ASubWindow import ASubWindow
|
from View.ASubWindow import ASubWindow
|
||||||
from View.ListedSubWindow import ListedSubWindow
|
from View.ListedSubWindow import ListedSubWindow
|
||||||
|
|
||||||
|
from View.Stricklers.Table import TableModel
|
||||||
|
from View.Stricklers.translate import *
|
||||||
|
from View.Stricklers.UndoCommand import *
|
||||||
|
|
||||||
from View.Configure.Solver.Window import ConfigureSolverWindow
|
from View.Configure.Solver.Window import ConfigureSolverWindow
|
||||||
|
|
||||||
|
from PyQt5.QtGui import (
|
||||||
|
QKeySequence,
|
||||||
|
)
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
Qt, QVariant, QAbstractTableModel,
|
Qt, QVariant, QAbstractTableModel,
|
||||||
)
|
)
|
||||||
|
|
@ -13,7 +21,7 @@ from PyQt5.QtCore import (
|
||||||
from PyQt5.QtWidgets import (
|
from PyQt5.QtWidgets import (
|
||||||
QDialogButtonBox, QPushButton, QLineEdit,
|
QDialogButtonBox, QPushButton, QLineEdit,
|
||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QComboBox,
|
QComboBox, QUndoStack, QShortcut, QHeaderView,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -71,17 +79,18 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
|
||||||
else:
|
else:
|
||||||
self.conf = conf
|
self.conf = conf
|
||||||
|
|
||||||
|
self.setup_sc()
|
||||||
|
|
||||||
# Solver
|
# Solver
|
||||||
|
table = self.find(QTableView, "tableView_solver")
|
||||||
self.solver_table_model = SolverTableModel(
|
self.solver_table_model = SolverTableModel(
|
||||||
headers = ["name", "type", "description"],
|
headers = ["name", "type", "description"],
|
||||||
rows = conf.solvers.copy()
|
rows = conf.solvers.copy()
|
||||||
)
|
)
|
||||||
self.find(QTableView, "tableView_solver")\
|
table.setModel(self.solver_table_model)
|
||||||
.setModel(self.solver_table_model)
|
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
self.find(QTableView, "tableView_solver")\
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||||
.setSelectionBehavior(QAbstractItemView.SelectRows)
|
table.setAlternatingRowColors(True)
|
||||||
self.find(QTableView, "tableView_solver")\
|
|
||||||
.setAlternatingRowColors(True)
|
|
||||||
|
|
||||||
# Meshing_Tool
|
# Meshing_Tool
|
||||||
self.set_line_edit_text("lineEdit_meshing_tool", self.conf.meshing_tool)
|
self.set_line_edit_text("lineEdit_meshing_tool", self.conf.meshing_tool)
|
||||||
|
|
@ -99,6 +108,18 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
|
||||||
self.find(QTableView, "tableView_solver").resizeColumnsToContents()
|
self.find(QTableView, "tableView_solver").resizeColumnsToContents()
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
|
# Stricklers
|
||||||
|
table = self.find(QTableView, f"tableView_stricklers")
|
||||||
|
self._stricklers = self.conf.stricklers
|
||||||
|
self._stricklers_table = TableModel(
|
||||||
|
data = self._stricklers,
|
||||||
|
undo = self._undo_stack,
|
||||||
|
)
|
||||||
|
table.setModel(self._stricklers_table)
|
||||||
|
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||||
|
table.setAlternatingRowColors(True)
|
||||||
|
|
||||||
# Language
|
# Language
|
||||||
languages = Config.languages()
|
languages = Config.languages()
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
|
|
@ -106,11 +127,25 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
|
||||||
if self.conf.lang == languages[lang]:
|
if self.conf.lang == languages[lang]:
|
||||||
self.set_combobox_text("comboBox_language", lang)
|
self.set_combobox_text("comboBox_language", lang)
|
||||||
|
|
||||||
|
def setup_sc(self):
|
||||||
|
self._undo_stack = QUndoStack()
|
||||||
|
|
||||||
|
self.undo_sc = QShortcut(QKeySequence.Undo, self)
|
||||||
|
self.redo_sc = QShortcut(QKeySequence.Redo, self)
|
||||||
|
self.copy_sc = QShortcut(QKeySequence.Copy, self)
|
||||||
|
self.paste_sc = QShortcut(QKeySequence.Paste, self)
|
||||||
|
|
||||||
def connect(self):
|
def connect(self):
|
||||||
buttons = {
|
buttons = {
|
||||||
|
# Solvers
|
||||||
"pushButton_solver_add": self.add_solver,
|
"pushButton_solver_add": self.add_solver,
|
||||||
"pushButton_solver_del": self.remove_solver,
|
"pushButton_solver_del": self.remove_solver,
|
||||||
"pushButton_solver_edit": self.edit_solver,
|
"pushButton_solver_edit": self.edit_solver,
|
||||||
|
# Stricklers
|
||||||
|
"pushButton_stricklers_add": self.add_stricklers,
|
||||||
|
"pushButton_stricklers_del": self.del_stricklers,
|
||||||
|
"pushButton_stricklers_sort": self.sort_stricklers,
|
||||||
|
# Others
|
||||||
"pushButton_backup_path": lambda: self.file_dialog(
|
"pushButton_backup_path": lambda: self.file_dialog(
|
||||||
select_file = False,
|
select_file = False,
|
||||||
callback = lambda f: self.set_line_edit_text(
|
callback = lambda f: self.set_line_edit_text(
|
||||||
|
|
@ -158,6 +193,8 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
|
||||||
self.conf.save()
|
self.conf.save()
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
|
# Solvers
|
||||||
|
|
||||||
def edit_solver(self):
|
def edit_solver(self):
|
||||||
indexes = self.find(QTableView, "tableView_solver").selectionModel().selectedRows()
|
indexes = self.find(QTableView, "tableView_solver").selectionModel().selectedRows()
|
||||||
for index in indexes:
|
for index in indexes:
|
||||||
|
|
@ -177,3 +214,33 @@ class ConfigureWindow(ASubWindow, ListedSubWindow):
|
||||||
indices = self.find(QTableView, "tableView_solver").selectionModel().selectedRows()
|
indices = self.find(QTableView, "tableView_solver").selectionModel().selectedRows()
|
||||||
for index in sorted(indices):
|
for index in sorted(indices):
|
||||||
self.solver_table_model.removeRow(index)
|
self.solver_table_model.removeRow(index)
|
||||||
|
|
||||||
|
# Stricklers
|
||||||
|
|
||||||
|
def index_selected_rows_strikclers(self):
|
||||||
|
table = self.find(QTableView, f"tableView_stricklers")
|
||||||
|
return list(
|
||||||
|
set(
|
||||||
|
map(
|
||||||
|
lambda i: i.row(),
|
||||||
|
table.selectedIndexes()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def add_stricklers(self):
|
||||||
|
rows = self.index_selected_rows_strikclers()
|
||||||
|
if len(rows) == 0:
|
||||||
|
self._stricklers_table.add(0)
|
||||||
|
else:
|
||||||
|
self._stricklers_table.add(rows[0])
|
||||||
|
|
||||||
|
def del_stricklers(self):
|
||||||
|
rows = self.index_selected_rows_strikclers()
|
||||||
|
if len(rows) == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._stricklers_table.delete(rows)
|
||||||
|
|
||||||
|
def sort_stricklers(self):
|
||||||
|
self._stricklers_table.sort(False)
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,11 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit):
|
||||||
self.lateral.show()
|
self.lateral.show()
|
||||||
|
|
||||||
def open_stricklers(self):
|
def open_stricklers(self):
|
||||||
self.strick = StricklersWindow(study = self.model, parent=self)
|
self.strick = StricklersWindow(
|
||||||
|
study = self.model,
|
||||||
|
config = self.conf,
|
||||||
|
parent=self
|
||||||
|
)
|
||||||
self.strick.show()
|
self.strick.show()
|
||||||
|
|
||||||
# TODO: Delete me !
|
# TODO: Delete me !
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ _translate = QCoreApplication.translate
|
||||||
|
|
||||||
|
|
||||||
class StricklersWindow(ASubMainWindow, ListedSubWindow):
|
class StricklersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
def __init__(self, title="Stricklers", study=None, parent=None):
|
def __init__(self, title="Stricklers", study=None, config=None, parent=None):
|
||||||
title = title + " - " + study.name
|
title = title + " - " + study.name
|
||||||
|
|
||||||
super(StricklersWindow, self).__init__(
|
super(StricklersWindow, self).__init__(
|
||||||
|
|
@ -39,6 +39,7 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
)
|
)
|
||||||
|
|
||||||
self._study = study
|
self._study = study
|
||||||
|
self._config = config
|
||||||
|
|
||||||
self.setup_sc()
|
self.setup_sc()
|
||||||
self.setup_table()
|
self.setup_table()
|
||||||
|
|
@ -59,10 +60,18 @@ class StricklersWindow(ASubMainWindow, ListedSubWindow):
|
||||||
|
|
||||||
for t in ["app", "study"]:
|
for t in ["app", "study"]:
|
||||||
table = self.find(QTableView, f"tableView_{t}")
|
table = self.find(QTableView, f"tableView_{t}")
|
||||||
|
if t == "study":
|
||||||
|
data = self._study.river.striklers
|
||||||
|
else:
|
||||||
|
data = self._config.stricklers
|
||||||
|
|
||||||
|
print(data)
|
||||||
|
|
||||||
self._table[t] = TableModel(
|
self._table[t] = TableModel(
|
||||||
data = self._study.river.striklers,
|
data = data,
|
||||||
undo = self._undo_stack,
|
undo = self._undo_stack,
|
||||||
)
|
)
|
||||||
|
|
||||||
table.setModel(self._table[t])
|
table.setModel(self._table[t])
|
||||||
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||||
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)
|
||||||
|
|
|
||||||
|
|
@ -349,6 +349,66 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_stricklers">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Stricklers</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_7">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_stricklers_add">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>ressources/gtk-add.png</normaloff>ressources/gtk-add.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_stricklers_del">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>ressources/gtk-remove.png</normaloff>ressources/gtk-remove.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_stricklers_sort">
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset>
|
||||||
|
<normaloff>ressources/gtk-sort-ascending.png</normaloff>ressources/gtk-sort-ascending.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QTableView" name="tableView_stricklers"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="tab_language">
|
<widget class="QWidget" name="tab_language">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>Language</string>
|
<string>Language</string>
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="locale">
|
||||||
|
<locale language="English" country="Europe"/>
|
||||||
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget">
|
<widget class="QWidget" name="centralwidget">
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
from Model.Stricklers.StricklersList import StricklersList
|
||||||
|
|
||||||
config_dir = "/.cache/pamhyr/"
|
config_dir = "/.cache/pamhyr/"
|
||||||
config_file = "config.pkl"
|
config_file = "config.pkl"
|
||||||
|
|
||||||
|
|
@ -33,6 +35,9 @@ class Config(object):
|
||||||
# Languages
|
# Languages
|
||||||
self.lang = ""
|
self.lang = ""
|
||||||
|
|
||||||
|
# Stricklers
|
||||||
|
self.stricklers = StricklersList()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def filename(cls):
|
def filename(cls):
|
||||||
return os.environ["HOME"] + config_dir + config_file
|
return os.environ["HOME"] + config_dir + config_file
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue