Skip to content

Commit

Permalink
Added a check if pyside6 was installed
Browse files Browse the repository at this point in the history
  • Loading branch information
YHordijk committed Sep 1, 2024
1 parent de98bb3 commit 7dc6c7f
Showing 1 changed file with 71 additions and 66 deletions.
137 changes: 71 additions & 66 deletions src/tcviewer/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from typing import Any, Tuple, List
from PySide6 import *

try:
from PySide6 import *
has_qt = True
except ImportError:
has_qt = False

settings = {
'atom': {
Expand All @@ -14,71 +19,71 @@
},
}


class SettingsTab(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.layout = QtWidgets.QGridLayout()
self.setLayout(self.layout)

def __enter__(self):
return self

def __exit__(self, *args):
...

def add(self, section: str = None, name: str = None, default: Any = None, range: Tuple[float] = None, options: List[str] = None):
row = self.layout.rowCount()
self.layout.addWidget(QtWidgets.QLabel(' ' + name + ':'), row, 0)

def add_checkbox(self, section: str = None, name: str = None, default: bool = True):
row = self.layout.rowCount()
self.layout.addWidget(QtWidgets.QLabel(' ' + name + ':'), row, 0)
widg = QtWidgets.QCheckBox()
widg.setCheckState(QtCore.Qt.CheckState.Checked if default else QtCore.Qt.CheckState.Unchecked)
self.layout.addWidget(widg, row, 1)

def add_spinbox(self, section: str = None, name: str = None, default: float = None, minimum: float = None, maximum: float = None, step: float = None, decimals: int = 2, suffix_text: str = None):
row = self.layout.rowCount()
self.layout.addWidget(QtWidgets.QLabel(' ' + name + ':'), row, 0)
widg = QtWidgets.QDoubleSpinBox()
if default:
widg.setValue(default)
if minimum:
widg.setMinimum(minimum)
if maximum:
widg.setMaximum(maximum)
if step:
widg.setSingleStep(step)
if decimals:
widg.setDecimals(decimals)

self.layout.addWidget(widg, row, 1)

if suffix_text:
self.layout.addWidget(QtWidgets.QLabel(suffix_text), row, 2)



class SettingsWidget(QtWidgets.QTabWidget):
def __init__(self):
super().__init__()

def add_tab(self, tab_name: str):
widg = SettingsTab()
self.addTab(widg, tab_name)
return widg


class DefaultSettings(SettingsWidget):
def __init__(self):
super().__init__()

with self.add_tab('Molecule') as tab:
tab.add_spinbox('Atom', 'Size Ratio', 1/2.4, minimum=0, step=0.05, decimals=3)
tab.add_checkbox('Atom', 'Draw Quadrants', True)
tab.add_spinbox('Atom', 'Quadrant Width', default=0.02, minimum=0, step=0.001, decimals=3, suffix_text='Å')
# self.add_tab('Bond')
if has_qt:
class SettingsTab(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.layout = QtWidgets.QGridLayout()
self.setLayout(self.layout)

def __enter__(self):
return self

def __exit__(self, *args):
...

def add(self, section: str = None, name: str = None, default: Any = None, range: Tuple[float] = None, options: List[str] = None):
row = self.layout.rowCount()
self.layout.addWidget(QtWidgets.QLabel(' ' + name + ':'), row, 0)

def add_checkbox(self, section: str = None, name: str = None, default: bool = True):
row = self.layout.rowCount()
self.layout.addWidget(QtWidgets.QLabel(' ' + name + ':'), row, 0)
widg = QtWidgets.QCheckBox()
widg.setCheckState(QtCore.Qt.CheckState.Checked if default else QtCore.Qt.CheckState.Unchecked)
self.layout.addWidget(widg, row, 1)

def add_spinbox(self, section: str = None, name: str = None, default: float = None, minimum: float = None, maximum: float = None, step: float = None, decimals: int = 2, suffix_text: str = None):
row = self.layout.rowCount()
self.layout.addWidget(QtWidgets.QLabel(' ' + name + ':'), row, 0)
widg = QtWidgets.QDoubleSpinBox()
if default:
widg.setValue(default)
if minimum:
widg.setMinimum(minimum)
if maximum:
widg.setMaximum(maximum)
if step:
widg.setSingleStep(step)
if decimals:
widg.setDecimals(decimals)

self.layout.addWidget(widg, row, 1)

if suffix_text:
self.layout.addWidget(QtWidgets.QLabel(suffix_text), row, 2)



class SettingsWidget(QtWidgets.QTabWidget):
def __init__(self):
super().__init__()

def add_tab(self, tab_name: str):
widg = SettingsTab()
self.addTab(widg, tab_name)
return widg


class DefaultSettings(SettingsWidget):
def __init__(self):
super().__init__()

with self.add_tab('Molecule') as tab:
tab.add_spinbox('Atom', 'Size Ratio', 1/2.4, minimum=0, step=0.05, decimals=3)
tab.add_checkbox('Atom', 'Draw Quadrants', True)
tab.add_spinbox('Atom', 'Quadrant Width', default=0.02, minimum=0, step=0.001, decimals=3, suffix_text='Å')
# self.add_tab('Bond')


if __name__ == '__main__':
Expand Down

0 comments on commit 7dc6c7f

Please sign in to comment.