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

Dev into master #9

Merged
merged 3 commits into from
Sep 21, 2020
Merged
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
Next Next commit
Added Saving Settings via settings.yml
  • Loading branch information
Skiller9090 committed Sep 14, 2020
commit 59256ee980130d4dd07724731c3f303225a19cad
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.Venv/
venv/
Venv/
.venv
.venv
settings.yml
3 changes: 2 additions & 1 deletion lucifer/ArgParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def check_gui(self):

else:
self.luciferManager.colorama.init(autoreset=True)
print(self.luciferManager.termcolor.colored("Lucifer Prototype 2", "red", attrs=["bold", "underline"]))
print(self.luciferManager.termcolor.colored(self.luciferManager.version,
"red", attrs=["bold", "underline"]))
self.luciferManager.main_shell = Shell(self.luciferManager.next_shell_id, self.luciferManager)
self.luciferManager.next_shell_id += 1
self.luciferManager.main_shell.spawn()
Expand Down
34 changes: 29 additions & 5 deletions lucifer/Errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ def __str__(self):
return "Argument Undefined: " + str(self.message)


def checkErrors(e):
class LuciferFileNotFound(BaseLuciferError):
def __str__(self):
"""Error Output"""
return "File Does Not Exist: " + str(self.message)


class LuciferSettingNotFound(BaseLuciferError):
def __str__(self):
"""Error Output"""
return "Lucifer Setting Not Found: " + str(self.message)


def checkErrors(e, ModuleError=False):
try:
raise e
except IncompatibleSystemError:
Expand All @@ -41,8 +53,20 @@ def checkErrors(e):
pass
except ArgumentUndefinedError:
print(e)
except LuciferFileNotFound:
print(e)
raise e
# except LuciferSettingNotFound:
# print(e)
# print("If Error Continues Try Removing 'settings.yml'")
except Exception as err:
notifier.notify(err)
print("The following error has occurred" +
" and has been reported to the devs: ")
raise err
if not ModuleError:
notifier.notify(err)
print("The following error has occurred" +
" and has been reported to the devs: ")
raise err
else:
notifier.notify(err)
print("The Following Error Occurred In Current Module, Reported To Devs...\n"+str(err))


Copy link

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

2 changes: 1 addition & 1 deletion lucifer/GUI/Console.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, luciferManager, parent, GUI, *args, **kwargs):
# self.luciferManager.stderr = TextRedirect(self.ConsoleBox, "stderr")
sys.stdout = self.luciferManager.stdout
sys.stderr = self.luciferManager.stderr
print("Lucifer Prototype 2")
print(self.luciferManager.version)
print(f"{self.shell.program_name}|" +
f"{self.shell.module if '.py' not in self.shell.module else self.shell.module.replace('.py', '')}" +
f"|{self.shell.id}> ", end="")
Expand Down
16 changes: 16 additions & 0 deletions lucifer/GUI/GUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Copy link

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

3 changes: 3 additions & 0 deletions lucifer/GUI/Settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import tkinter as tk
from tkinter import ttk, font as tk_fonts
import lucifer.Settings


class Settings(tk.Tk):
Expand Down Expand Up @@ -87,6 +88,8 @@ def apply_settings(self):
self.parent.view_settings.apply_view_settings()
self.LuciferGui.font = self.parent.font_settings.current_font
self.LuciferGui.update_font()
lucifer.Settings.update_setting("gui.font.name", self.LuciferGui.font[0])
lucifer.Settings.update_setting("gui.font.size", self.LuciferGui.font[1])

def exit(self):
self.parent.destroy()
Expand Down
1 change: 1 addition & 0 deletions lucifer/Manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, auto_vars=False):
self.gui_thread_free = True
self.stdout = sys.stdout
self.stderr = sys.stderr
self.version = "Prototype 2"

def end(self, *args, **kwargs):
sys.stderr = sys.__stderr__
Expand Down
61 changes: 61 additions & 0 deletions lucifer/Settings.py
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:
Copy link
Owner Author

Choose a reason for hiding this comment

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

Copy link
Owner Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

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)
2 changes: 1 addition & 1 deletion lucifer/Shell/_Module.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def run_module(self, *args, **kwargs):
else:
print("Please Select A Module First!")
except Exception as e:
checkErrors(e)
checkErrors(e, ModuleError=True)


def describe_module(self, *args, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
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