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

Enforce line length in linter and format code #8

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Make sure you have the following installed:

1. Clone the repository
2. Create a virtual environment with `uv venv --python=$PythonVersion` where `$PythonVersion` is greater than 3.10. Note that there is a bug in Python 3.13 that leads to the core dependency TCL not being installed correctly on Windows.
3. Run `uv sync`
3. Run `uv sync --dev`

To run the project use `uvx tomlscript run`, optionally you can use nodemon for hot reloading with the command `nodemon --exec uvx tomlscript run`.

Expand Down
1 change: 1 addition & 0 deletions napytau/cli/cli_arguments.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from napytau.util.coalesce import coalesce
from argparse import Namespace


class CLIArguments:
def __init__(self, raw_args: Namespace):
self.headless = coalesce(raw_args.headless, False)
Expand Down
13 changes: 10 additions & 3 deletions napytau/cli/parser.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import argparse
from napytau.cli.cli_arguments import CLIArguments


def parse_cli_arguments() -> CLIArguments:
parser = argparse.ArgumentParser(description="Mockup for NaPyTau")
parser.add_argument("--headless", action="store_true", help="Run the application without GUI")
parser.add_argument("--filename", type=str, help="File to ingest (only for mockup, not used in real application)")
parser.add_argument(
"--headless", action="store_true", help="Run the application without GUI"
)
parser.add_argument(
"--filename",
type=str,
help="File to ingest (only for mockup, not used in real application)",
)

return CLIArguments(parser.parse_args())
return CLIArguments(parser.parse_args())
161 changes: 103 additions & 58 deletions napytau/gui/ui_mockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,91 +8,125 @@
from napytau.cli.cli_arguments import CLIArguments
from napytau.core.logic_mockup import logic

customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
customtkinter.set_appearance_mode(
"System"
) # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme(
"blue"
) # Themes: "blue" (standard), "green", "dark-blue"


def plot(value, window) -> Canvas:
# the figure that will contain the plot
fig = Figure(
figsize=(3, 2),
dpi=100,
facecolor="white",
edgecolor="black"
)

fig = Figure(figsize=(3, 2), dpi=100, facecolor="white", edgecolor="black")

# list of squares
y = [(i - 50) ** value for i in range(101)]

# adding the subplot
plot1 = fig.add_subplot(111)

# plotting the graph
plot1.plot(y)

# creating the Tkinter canvas
# containing the Matplotlib figure
canvas = FigureCanvasTkAgg(fig, master=window)
canvas.draw()

return canvas.get_tk_widget()


class App(customtkinter.CTk):
def __init__(self):
super().__init__()

# values

self.tau = tk.IntVar()
self.tau.set(2)

# configure window
self.title("NaPyTau")
self.geometry(f"{1100}x{580}")

# configure grid layout (4x4)
self.grid_columnconfigure(3, weight=1)
self.grid_columnconfigure((1,2), weight=0)
self.grid_columnconfigure((1, 2), weight=0)
self.grid_rowconfigure((0, 1, 2), weight=1)

# create sidebar frame with widgets
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0)
self.sidebar_frame.grid(row=0, column=0, rowspan=4, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(4, weight=1)
self.logo_label = customtkinter.CTkLabel(self.sidebar_frame, text="NaPyTau",
font=customtkinter.CTkFont(size=20, weight="bold"))
self.logo_label = customtkinter.CTkLabel(
self.sidebar_frame,
text="NaPyTau",
font=customtkinter.CTkFont(size=20, weight="bold"),
)
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
self.sidebar_button_1 = customtkinter.CTkButton(self.sidebar_frame, command=self.sidebar_button_event)
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w")
self.sidebar_button_1 = customtkinter.CTkButton(
self.sidebar_frame, command=self.sidebar_button_event
)
self.appearance_mode_label = customtkinter.CTkLabel(
self.sidebar_frame, text="Appearance Mode:", anchor="w"
)
self.appearance_mode_label.grid(row=5, column=0, padx=20, pady=(10, 0))
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame,
values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(
self.sidebar_frame,
values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event,
)
self.appearance_mode_optionemenu.grid(row=6, column=0, padx=20, pady=(10, 10))
self.scaling_label = customtkinter.CTkLabel(self.sidebar_frame, text="UI Scaling:", anchor="w")
self.scaling_label = customtkinter.CTkLabel(
self.sidebar_frame, text="UI Scaling:", anchor="w"
)
self.scaling_label.grid(row=7, column=0, padx=20, pady=(10, 0))
self.scaling_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame,
values=["80%", "90%", "100%", "110%", "120%"],
command=self.change_scaling_event)
self.scaling_optionemenu = customtkinter.CTkOptionMenu(
self.sidebar_frame,
values=["80%", "90%", "100%", "110%", "120%"],
command=self.change_scaling_event,
)
self.scaling_optionemenu.grid(row=8, column=0, padx=20, pady=(10, 20))

# create main entry and button
self.entry = customtkinter.CTkEntry(self, textvariable=self.tau)
self.entry.grid(row=3, column=1, columnspan=2, padx=(20, 0), pady=(20, 20), sticky="nsew")

self.main_button_1 = customtkinter.CTkButton(master=self, fg_color="transparent", border_width=2,
text="calc",
text_color=("gray10", "#DCE4EE"), command=self.calc)
self.main_button_1.grid(row=3, column=3, padx=(20, 20), pady=(20, 20), sticky="nsew")

self.entry.grid(
row=3, column=1, columnspan=2, padx=(20, 0), pady=(20, 20), sticky="nsew"
)

self.main_button_1 = customtkinter.CTkButton(
master=self,
fg_color="transparent",
border_width=2,
text="calc",
text_color=("gray10", "#DCE4EE"),
command=self.calc,
)
self.main_button_1.grid(
row=3, column=3, padx=(20, 20), pady=(20, 20), sticky="nsew"
)

# create line graph

self.line_graph = plot(self.tau.get(), self)
self.line_graph.grid(row=2, column=3, columnspan=1, rowspan=1, padx=(0, 20), pady=(20, 0), sticky="nsew")

self.line_graph.grid(
row=2,
column=3,
columnspan=1,
rowspan=1,
padx=(0, 20),
pady=(20, 0),
sticky="nsew",
)

# create slider and progressbar frame
self.slider_progressbar_frame = customtkinter.CTkFrame(self, fg_color="transparent")
self.slider_progressbar_frame.grid(row=2, column=2, padx=(20, 0), pady=(20, 0), sticky="nsew")
self.slider_progressbar_frame = customtkinter.CTkFrame(
self, fg_color="transparent"
)
self.slider_progressbar_frame.grid(
row=2, column=2, padx=(20, 0), pady=(20, 0), sticky="nsew"
)
self.slider_progressbar_frame.grid_columnconfigure(0, weight=1)
self.slider_progressbar_frame.grid_rowconfigure(4, weight=1)
self.slider_2 = customtkinter.CTkSlider(
Expand All @@ -101,40 +135,51 @@ def __init__(self):
from_=2,
to=5,
number_of_steps=3,
orientation="vertical")
self.slider_2.grid(row=0, column=1, rowspan=5, padx=(10, 10), pady=(10, 10), sticky="ns")

orientation="vertical",
)
self.slider_2.grid(
row=0, column=1, rowspan=5, padx=(10, 10), pady=(10, 10), sticky="ns"
)

# create textbox
self.label = customtkinter.CTkLabel(self, width=200)
self.label.grid(row=2, column=1, columnspan=1, padx=(20, 0), pady=(20, 0), sticky="nsew")

self.label.grid(
row=2, column=1, columnspan=1, padx=(20, 0), pady=(20, 0), sticky="nsew"
)

# set default values
self.appearance_mode_optionemenu.set("Dark")
self.scaling_optionemenu.set("100%")
self.slider_2.configure(command=self.use_slider_value)
self.label.configure(text= "Result: ")
self.label.configure(text="Result: ")

def change_appearance_mode_event(self, new_appearance_mode: str):
customtkinter.set_appearance_mode(new_appearance_mode)

def change_scaling_event(self, new_scaling: str):
new_scaling_float = int(new_scaling.replace("%", "")) / 100
customtkinter.set_widget_scaling(new_scaling_float)

def sidebar_button_event(self):
print("sidebar_button click")

def use_slider_value(self, _value):
self.calc()




def calc(self):
entry_value = self.tau.get()

self.label.configure(text=f"Result: {logic(entry_value)}")
self.line_graph = plot(int(entry_value), self)
self.line_graph.grid(row=2, column=3, columnspan=1, rowspan=1, padx=(0, 20), pady=(20, 0), sticky="nsew")
self.line_graph.grid(
row=2,
column=3,
columnspan=1,
rowspan=1,
padx=(0, 20),
pady=(20, 0),
sticky="nsew",
)


def init(cli_arguments: CLIArguments):
Expand Down
5 changes: 4 additions & 1 deletion napytau/headless/headless_mockup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from napytau.cli.cli_arguments import CLIArguments
from napytau.ingest.ingest_mockup import ingest_file


def init(cli_arguments: CLIArguments):
print("running headless mockup")
if cli_arguments.has_filename():
print(f"{cli_arguments.get_filename()}:\n{ingest_file(cli_arguments.get_filename())}")
print(
f"{cli_arguments.get_filename()}:\n{ingest_file(cli_arguments.get_filename())}"
)
2 changes: 1 addition & 1 deletion napytau/ingest/ingest_mockup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ def ingest_file(filename):
# Ingest data from a file
with open(filename) as f:
data = f.read()
return data
return data
3 changes: 2 additions & 1 deletion napytau/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
from headless.headless_mockup import init as init_headless
from cli.parser import parse_cli_arguments


def main():
args = parse_cli_arguments()

if args.headless:
init_headless(args)
else:
Expand Down
2 changes: 1 addition & 1 deletion napytau/util/coalesce.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ def coalesce(*args):
for arg in args:
if arg is not None:
return arg
return None
return None
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ build-backend = "setuptools.build_meta"
[tool.tomlscript]
run= "uv run napytau/main.py"
test = "uv run pytest -rA"
lint = "uv run ruff check"
lint-fix = "uv run ruff check --fix"
lint = "uv run ruff check --config ruff.toml"
lint-fix = "uv run ruff check --config ruff.toml --fix"
format = "uv run ruff format"

[dependency-groups]
dev = [
Expand Down
Loading