Skip to content

Commit

Permalink
Merge pull request #38 from clodman84/main
Browse files Browse the repository at this point in the history
bringing new-docs up to date with main
  • Loading branch information
clodman84 authored Sep 8, 2024
2 parents ce9145f + 3498fe2 commit 8bd942e
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Application/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def get_file_name(id):
"SELECT hoscode, roomno FROM students WHERE idno = ?", (id,)
)
hoscode, roomno = cursor.fetchone()
return f"{hoscode}_{roomno}_{'{}'}_{'{:2d}'}_{'{}'}_{id[2:4]}{id[-4:]}"
return f"{hoscode}_{roomno}_{'{}'}{'{:02}'}_{'{}'}_{id[2:4]}{id[-4:]}"


def set_nick(nick, id):
Expand Down
2 changes: 1 addition & 1 deletion Application/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def copy_images(counters: list[Counter], path: Path):
file_name_base = get_file_name(id)
for i in range(count):
file_name = (
file_name_base.format(path.name, index, i + 1)
file_name_base.format(path.name, index + 1, i + 1)
+ images[index].suffix
)
logger.debug(file_name)
Expand Down
2 changes: 1 addition & 1 deletion GUI/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .bill import BillingWindow, show_all_nicks
from .image import ImageWindow
from .music import MusicVisualiser
from .utils import Logger, modal_message
from .utils import Logger, logger_stress_test, modal_message
12 changes: 10 additions & 2 deletions GUI/bill.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ def __init__(self, roll: str, path: Path):
self.path = path
self.num_rows = 45


with dpg.window(
width=625,
height=436,
label=f"Billing Window {self.path.name}",
no_resize=True,
no_close=True,
):

) as self.window:
with dpg.group(horizontal=True):
dpg.add_text("Search")
input = dpg.add_input_text(width=250)
Expand Down Expand Up @@ -211,7 +213,11 @@ def same_as(self, index):
write(self.ids_per_roll, self.roll)
logger.debug(timer)
self.show_selected_ids()


def close(self):
dpg.delete_item(self.window)



def show_all_nicks():
nicks = db.get_all_nicks()
Expand Down Expand Up @@ -239,3 +245,5 @@ def show_all_nicks():
with dpg.table_row():
for j in range(len(headers_2)):
dpg.add_text(nicks[i][j])


3 changes: 2 additions & 1 deletion GUI/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def setup(self):
label=self.path.name,
width=self.window_dimensions[0],
height=self.window_dimensions[1],
on_close=self.billing_window.close,
)
with dpg.child_window(parent=self.parent):
indicator = dpg.add_loading_indicator()
Expand Down Expand Up @@ -128,7 +129,7 @@ def open(self, index: int):
self.billing_window.load(index)

def next(self):
if self.current_image < self.image_manager.end_index:
if self.current_image < self.image_manager.end_index - 1:
self.open(self.current_image + 1)
else:
self.open(0)
Expand Down
130 changes: 127 additions & 3 deletions GUI/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import logging
import math
import threading

import dearpygui.dearpygui as dpg

from Application.utils import Singleton

MODAL_HIDDEN_LIST = []

logger = logging.getLogger("GUI.Utils")


def modal_message(message):
"""When you need a popup"""
Expand Down Expand Up @@ -31,16 +37,16 @@ def modal_message(message):
dpg.configure_item(warning, pos=newPos)


class Logger(logging.Handler):
class Logger(logging.Handler, metaclass=Singleton):
"""Snazzy"""

def __init__(self, parent):
def __init__(self):
super().__init__()
self.log_level = 0
self._auto_scroll = True
self.count = 0
self.flush_count = 1000
self.window_id = parent
self.window_id = dpg.add_window(height=350, width=350, label="Logger")

with dpg.group(horizontal=True, parent=self.window_id):
dpg.add_checkbox(
Expand Down Expand Up @@ -127,3 +133,121 @@ def emit(self, record):
def clear_log(self):
dpg.delete_item(self.filter_id, children_only=True)
self.count = 0


# I did not write the donut code

theta_spacing = 0.07
phi_spacing = 0.02

R1 = 1
R2 = 2
K2 = 5

screen_width = 35
screen_height = 35

# Calculate K1 based on screen size: the maximum x-distance occurs roughly at
# the edge of the torus, which is at x=R1+R2, z=0. we want that to be
# displaced 3/8ths of the width of the screen, which is 3/4th of the way from
# the center to the side of the screen.
# screen_width*3/8 = K1*(R1+R2)/(K2+0)
# screen_width*K2*3/(8*(R1+R2)) = K1

K1 = screen_width * K2 * 3 / (8 * (R1 + R2))


def render_frame(A, B):
# Precompute sines and cosines of A and B
cosA = math.cos(A)
sinA = math.sin(A)
cosB = math.cos(B)
sinB = math.sin(B)

char_output = []
zbuffer = []

for i in range(screen_height + 1):
char_output.append([" "] * (screen_width + 0))
zbuffer.append([0] * (screen_width + 0))

# theta goes around the cross-sectional circle of a torus
theta = 0
while theta < 2 * math.pi:
theta += theta_spacing

# Precompute sines and cosines of theta
costheta = math.cos(theta)
sintheta = math.sin(theta)

# phi goes around the center of revolution of a torus
phi = 0
while phi < 2 * math.pi:
phi += phi_spacing

# Precompute sines and cosines of phi
cosphi = math.cos(phi)
sinphi = math.sin(phi)

# the x,y coordinate of the circle,
# before revolving (factored out of the above equations)
circlex = R2 + R1 * costheta
circley = R1 * sintheta

# final 3D (x,y,z) coordinate after rotations, directly from our math above
x = circlex * (cosB * cosphi + sinA * sinB * sinphi) - circley * cosA * sinB
y = circlex * (sinB * cosphi - sinA * cosB * sinphi) + circley * cosA * cosB
z = K2 + cosA * circlex * sinphi + circley * sinA
ooz = 1 / z

# x and y projection. y is negated here, because y goes up in
# 3D space but down on 2D displays.
xp = int(screen_width / 2 + K1 * ooz * x)
yp = int(screen_height / 2 - K1 * ooz * y)

# Calculate luminance
L = (
cosphi * costheta * sinB
- cosA * costheta * sinphi
- sinA * sintheta
+ cosB * (cosA * sintheta - costheta * sinA * sinphi)
)

# L ranges from -sqrt(2) to +sqrt(2). If it's < 0, the surface is
# pointing away from us, so we won't bother trying to plot it.
if L > 0:
# Test against the z-buffer. Larger 1/z means the pixel is closer to
# the viewer than what's already plotted.
if ooz > zbuffer[xp][yp]:
zbuffer[xp][yp] = ooz
luminance_index = (
L * 8
) # this brings L into the range 0..11 (8*sqrt(2) = 11.3)

# Now we lookup the character corresponding
# to the luminance and plot it in our output
char_output[xp][yp] = ".,-~:;=!*#$@"[int(luminance_index)]

# Now, dump char_output to the screen.
# Bring cursor to "home" location, in just about any currently-used terminal emulation mode
frame = ""
for i in range(screen_height):
for j in range(screen_width):
frame += char_output[i][j]
frame += "\n"
logger.debug(frame)


def logger_stress_test():
L = Logger()

def task():
A = 1.0
B = 1.0
for _ in range(250):
render_frame(A, B)
A += 0.08
B += 0.03

t = threading.Thread(target=task)
t.start()
Binary file added dopylogofinal.ico
Binary file not shown.
Binary file added dopylogofinal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 0 additions & 18 deletions goals.md

This file was deleted.

15 changes: 9 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def main():
dpg.add_menu_item(
label="Show Performance Metrics", callback=dpg.show_metrics
)
dpg.add_menu_item(
label="Logger Stress Test", callback=GUI.logger_stress_test
)
with dpg.menu(label="Dev"):
dpg.add_menu_item(
label="Spawn Billing Window",
Expand All @@ -91,18 +94,18 @@ def main():
),
)
dpg.add_menu_item(label="Show GUI Demo", callback=demo.show_demo)

dpg.add_button(
label="Music",
callback=lambda: GUI.MusicVisualiser(
"./Data/Audio/clodman.mp3"
).start(),
)
with dpg.window(height=350, width=350, label="Logger") as logger_window:
log = GUI.Logger(parent=logger_window)
log.setFormatter(formatter)
core_logger.addHandler(log)
gui_logger.addHandler(log)

log = GUI.Logger()
log.setFormatter(formatter)
core_logger.addHandler(log)
gui_logger.addHandler(log)

dpg.setup_dearpygui()
dpg.set_primary_window("Primary Window", True)
dpg.set_viewport_vsync(False)
Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[project]
name = "UNF-v3"
version = "0.2.0-beta"
description = "DoPy Billing Software"

[tool.cxfreeze]
executables = [
{script = "main.py", base = "gui", icon="dopylogofinal"}
]

[tool.cxfreeze.build_exe]
optimize = 2
17 changes: 0 additions & 17 deletions setup.py

This file was deleted.

12 changes: 0 additions & 12 deletions style.md

This file was deleted.

0 comments on commit 8bd942e

Please sign in to comment.