-
Notifications
You must be signed in to change notification settings - Fork 77
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
Dev into master #9
Changes from 2 commits
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
.Venv/ | ||
venv/ | ||
Venv/ | ||
.venv | ||
.venv | ||
settings.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from lucifer.GUI.Console import LuciferConsole | ||
from lucifer.GUI.Utils import Closer | ||
from lucifer.GUI.Views import LuciferModulesView, LuciferVarView | ||
from lucifer import Settings | ||
|
||
|
||
class LuciferGui(tk.Frame, Closer, FontFind): | ||
|
@@ -40,6 +41,8 @@ def __init__(self, luciferManager, parent, *args, **kwargs): | |
|
||
self.pack_all() | ||
|
||
self.load_settings() | ||
|
||
def pack_all(self): | ||
self.statusFrame.pack(fill=tk.X, expand=False, side=tk.BOTTOM) | ||
self.mainPane.pack(fill=tk.BOTH, expand=True, side=tk.TOP) | ||
|
@@ -112,3 +115,16 @@ def update_font(self): | |
font=self.font) | ||
if self.toolbar.isSettingsOpen: | ||
self.toolbar.settings_window.update_font() | ||
|
||
def load_settings(self): | ||
if Settings.is_settings(): | ||
font_settings = Settings.get_setting("gui.font") | ||
try: | ||
self.font = (font_settings["name"], font_settings["size"]) | ||
self.update_font() | ||
except TypeError as e: | ||
print("\nProblem Loading 'settings.yml' file, Ignoring user settings.\n" | ||
"To Fix this problem please delete or edit the 'settings.yml' file!") | ||
else: | ||
Settings.create_settings(self.font) | ||
|
||
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. Blank line at end of file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,28 @@ | ||
import pkg_resources | ||
from pkg_resources import DistributionNotFound | ||
from pkg_resources import DistributionNotFound, VersionConflict, require | ||
|
||
|
||
def check_requirements(): | ||
with open("requirements.txt", "r") as f: | ||
packages = f.read().split("\n") | ||
if len(packages) > 0: | ||
not_installed = [] | ||
conflicting_versions = [] | ||
for pkg in packages: | ||
try: | ||
pkg_resources.require(packages) | ||
require(pkg) | ||
except DistributionNotFound as e: | ||
print(f'{e.req} is need for lucifer to run\nPlease install requirements.txt with:\n' | ||
f' pip install -r requirements.txt') | ||
exit(1) | ||
not_installed.append(e.req) | ||
except VersionConflict as e: | ||
conflicting_versions.append((e.req, e.dist)) | ||
|
||
if not_installed or conflicting_versions: | ||
if not_installed: | ||
print("The following packages are needed to be installed to run:") | ||
for pkg in not_installed: | ||
print(f"{pkg}") | ||
if conflicting_versions: | ||
print("The following packages have conflict errors:") | ||
for pkg in conflicting_versions: | ||
print(f"Current: {pkg[1]}, Needed: {pkg[0]}") | ||
print(f'Please install requirements.txt with:\n pip install -r requirements.txt' | ||
f' {"--upgrade" if conflicting_versions else ""}') | ||
exit(1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from yaml import load, dump, Loader, Dumper | ||
from lucifer.Errors import LuciferFileNotFound, LuciferSettingNotFound | ||
from functools import reduce | ||
import operator | ||
import os | ||
|
||
|
||
def is_settings(): | ||
return os.path.isfile("settings.yml") | ||
|
||
|
||
def create_settings(font): | ||
default_settings = { | ||
"gui": { | ||
"font": { | ||
"name": font[0], | ||
"size": font[1] | ||
} | ||
} | ||
} | ||
settings = dump(default_settings, default_flow_style=False) | ||
with open("settings.yml", "w") as f: | ||
f.write(settings) | ||
|
||
|
||
def load_settings(): | ||
if is_settings(): | ||
with open("settings.yml", "r") as f: | ||
file_data = f.read() | ||
data = load(file_data, Loader=Loader) | ||
else: | ||
raise LuciferFileNotFound("settings.yml") | ||
return data | ||
|
||
|
||
def get_setting(setting): | ||
settings = load_settings() | ||
setting_split = setting.split(".") | ||
if settings: | ||
try: | ||
return reduce(operator.getitem, setting_split, settings) | ||
except KeyError as e: | ||
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. Codacy found an issue: local variable 'e' is assigned to but never used (F841) 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. Codacy found an issue: Unused variable 'e' |
||
raise LuciferSettingNotFound(setting) | ||
except TypeError as e: | ||
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. Codacy found an issue: local variable 'e' is assigned to but never used (F841) |
||
raise LuciferSettingNotFound(setting) | ||
else: | ||
print("'settings.yml' file empty, ignoring user settings!") | ||
|
||
|
||
def update_setting(setting, value): | ||
if setting != "": | ||
settings = load_settings() | ||
to_edit = settings | ||
setting_split = setting.split(".") | ||
to_update = setting_split.pop(-1) | ||
for node in setting_split: | ||
settings = settings[node] | ||
settings[to_update] = value | ||
settings = dump(to_edit, default_flow_style=False) | ||
with open("settings.yml", "w") as f: | ||
f.write(settings) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Pillow>=7.2.0 | ||
pybrake>=0.4.6 | ||
pyyaml>=5.3.1 |
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.
Blank line at end of file