Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added application/src/assets/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions application/src/gui/modules/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .views import StatsType

from . import about
from . import settings


class AboutButton(QPushButton):
Expand All @@ -31,6 +32,14 @@ def __init__(self):
self.setToolTip("About")
self.clicked.connect(self.about.show)

class SettingsButton(QPushButton):
def __init__(self):
QPushButton.__init__(self)

self.settings = settings.Settings()
self.setIcon(QtGui.QIcon(assets.path('settings.png')))
self.setToolTip("Settings")
self.clicked.connect(self.settings.show)

class CloseButton(QPushButton):
def __init__(self, is_visible):
Expand Down Expand Up @@ -68,6 +77,9 @@ def __init__(self):
self.about_button = AboutButton()
self.layout.addWidget(self.about_button)

self.settings_button = SettingsButton()
self.layout.addWidget(self.settings_button)

self.close_button = CloseButton(config()['window']['frameless'])
self.layout.addWidget(self.close_button)

Expand Down
149 changes: 149 additions & 0 deletions application/src/gui/modules/settings.py
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
Copy link
Owner

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 the Config.

In the utils.config we could have module variable with Config instance.

You could then simply retrieve* and change configurable values and save them through Config methods :)


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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be two empty lines between class definitions. flake8 should report that.

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():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method names with small letters. Generally speaking it would be helpful if flake8 errors would be fixed :)

There's a tox environment for running flake8 to the project.

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)
Copy link
Owner

Choose a reason for hiding this comment

The 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

Copy link
Author

Choose a reason for hiding this comment

The 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 ;_;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you want achieve there ^.^?

Copy link
Author

Choose a reason for hiding this comment

The 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)
3 changes: 3 additions & 0 deletions application/src/utils/config.py
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'
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I will try with this.


default = """
Expand Down