-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Settings gui #34
base: master
Are you sure you want to change the base?
Settings gui #34
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
from PySide2.QtWidgets import QMessageBox # type: ignore | ||
import os | ||
import sys | ||
import toml | ||
import functools | ||
from .view_type import ViewType | ||
from PySide2 import QtGui # type: ignore | ||
from PySide2.QtCore import Qt # type: ignore | ||
from PySide2.QtWidgets import QHBoxLayout # type: ignore | ||
from PySide2.QtWidgets import QPushButton # type: ignore | ||
from PySide2.QtWidgets import QCheckBox # type: ignore | ||
from PySide2.QtWidgets import QSpinBox # type: ignore | ||
from PySide2.QtWidgets import QSlider # type: ignore | ||
from PySide2.QtWidgets import QVBoxLayout # type: ignore | ||
from PySide2.QtWidgets import QWidget # type: ignore | ||
from PySide2.QtWidgets import QLabel # type: ignore | ||
|
||
width = 300 | ||
height = 220 | ||
font = 10 | ||
opaci_percent = 100 | ||
opaci = opaci_percent/100 | ||
frame = False | ||
top = False | ||
|
||
class FontSpin(QSpinBox): | ||
def __init__(self): | ||
QSpinBox.__init__(self) | ||
self.setMinimum(5) | ||
self.setMaximum(25) | ||
self.setValue(font) | ||
self.setSingleStep(1) | ||
|
||
|
||
class OpaciSpin(QSpinBox): | ||
def __init__(self): | ||
QSpinBox.__init__(self) | ||
self.setMinimum(1) | ||
self.setMaximum(100) | ||
self.setValue(opaci_percent) | ||
self.setSingleStep(10) | ||
self.setSuffix("%") | ||
class FrameCheck(QCheckBox): | ||
def __init__(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be two empty lines between class definitions. |
||
QCheckBox.__init__(self) | ||
self.setChecked(frame) | ||
|
||
|
||
class TopCheck(QCheckBox): | ||
def __init__(self): | ||
QCheckBox.__init__(self) | ||
self.setChecked(top) | ||
|
||
class ApplyButton(QPushButton): | ||
def __init__(self): | ||
QPushButton.__init__(self) | ||
self.setText("Apply") | ||
|
||
|
||
def Apply(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Method names with small letters. Generally speaking it would be helpful if There's a tox -e flake8 |
||
font = FontSpin.value | ||
opaci_percent = OpaciSpin.value | ||
frame = FrameCheck.checkState | ||
top = TopCheck.checkState | ||
width = TopBar.width_text | ||
Shulqo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
height = TopBar.height_text | ||
self.clicked.connect(Apply) | ||
|
||
|
||
class TopBar(QWidget): | ||
def __init__(self): | ||
QWidget.__init__(self) | ||
self.layout = QHBoxLayout() | ||
self.layout.setSpacing(0) | ||
self.layout.setMargin(0) | ||
|
||
width_name = QLabel() | ||
width_name.setText("Window width: ") | ||
self.layout.addWidget(width_name) | ||
|
||
WidthSlider = QSlider(Qt.Horizontal) | ||
WidthSlider.setMinimum(300) | ||
WidthSlider.setMaximum(1920) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe maximum value should be the maximum width available in user display There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a great idea, I'll look for resolution check, it shouldn't be so hard |
||
WidthSlider.setValue(width) | ||
WidthSlider.setSingleStep(10) | ||
self.layout.addWidget(WidthSlider) | ||
|
||
WidthSlider.valueChanged[int].connect(self.valuechange) | ||
width_text = QLabel() | ||
width_text.setNum(width) | ||
self.layout.addWidget(width_text) | ||
|
||
height_name = QLabel() | ||
height_name.setText("\n Window height: ") | ||
self.layout.addWidget(height_name) | ||
|
||
HeightSlider = QSlider(Qt.Horizontal) | ||
HeightSlider.setMinimum(220) | ||
HeightSlider.setMaximum(1080) | ||
HeightSlider.setValue(height) | ||
HeightSlider.setSingleStep(10) | ||
self.layout.addWidget(HeightSlider) | ||
|
||
HeightSlider.valueChanged[int].connect(self.valuechange) | ||
height_text = QLabel() | ||
height_text.setNum(height) | ||
self.layout.addWidget(height_text) | ||
|
||
self.setLayout(self.layout) | ||
|
||
def valuechange(self, value): | ||
self.__init__(value) # FCK INIT CALLED TWICE, i was looking for solution but can't find anything ;_; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure what you want achieve there ^.^? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to update the value on the screen every time the user move slider that is when the value changes. |
||
|
||
class Settings(QWidget): | ||
def __init__(self): | ||
QWidget.__init__(self) | ||
self.setWindowTitle("Settings") | ||
self.layout = QVBoxLayout() | ||
self.top_bar = TopBar() | ||
self.layout.addWidget(self.top_bar) | ||
|
||
font_name = QLabel() | ||
font_name.setText("Font size:") | ||
self.layout.addWidget(font_name) | ||
self.font_spin = FontSpin() | ||
self.layout.addWidget(self.font_spin) | ||
|
||
opaci_name = QLabel() | ||
opaci_name.setText("Opacity:") | ||
self.layout.addWidget(opaci_name) | ||
self.opaci_spin = OpaciSpin() | ||
self.layout.addWidget(self.opaci_spin) | ||
|
||
frame_name = QLabel() | ||
frame_name.setText("Frameless:") | ||
self.layout.addWidget(frame_name) | ||
self.frame_check = FrameCheck() | ||
self.layout.addWidget(self.frame_check) | ||
|
||
top_name = QLabel() | ||
top_name.setText("Show always on top:") | ||
self.layout.addWidget(top_name) | ||
self.top_check = TopCheck() | ||
self.layout.addWidget(self.top_check) | ||
|
||
self.setLayout(self.layout) | ||
|
||
self.apply_button = ApplyButton() | ||
self.layout.addWidget(self.apply_button) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# problem with importing | ||
# from ..gui.modules.settings import width, height, font, opaci, frame, top | ||
import os | ||
import sys | ||
import toml | ||
|
||
# i want to connect variables from settings to config file and make it update every time any of variables change | ||
CFG_VERSION = '0.7' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, like I wrote in first comment. I think it should be other way around. New class should be introduced and whole config management should be dome via it's instance. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, I will try with this. |
||
|
||
default = """ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about importing setting instead?
from src.utils.config
Generally speaking if we want to introduce GUI based config. I'd suggest to create a
class
for theConfig
.In the
utils.config
we could have module variable withConfig
instance.You could then simply retrieve* and change configurable values and save them through
Config
methods :)