Skip to content

Commit

Permalink
added export button
Browse files Browse the repository at this point in the history
  • Loading branch information
clodman84 committed May 27, 2024
1 parent 7782397 commit e57d0e8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from .images import Image, ImageManager
from .music import DJ
from .search import SearchMachine
from .store import load, write
from .store import copy_images, load, write
from .utils import ShittyMultiThreading, SimpleTimer
9 changes: 9 additions & 0 deletions Application/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,14 @@ def read_mess_list(path: Path):
connection.commit()


def get_file_name(id):
with ConnectionPool() as db:
cursor = db.execute(
"SELECT hoscode, roomno FROM students WHERE idno = ?", (id,)
)
hoscode, roomno = cursor.fetchone()
return f"{hoscode}_{roomno}_{'{}'}_{'{}'}_{id[2:4]}{id[-4:]}"


# this is out here on purpose there must be a better way but idc
setup_db()
19 changes: 19 additions & 0 deletions Application/store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import json
import logging
import os
from collections import Counter
from pathlib import Path
from shutil import copy

from .database import get_file_name

logger = logging.getLogger("Core.Store")

Expand All @@ -16,3 +20,18 @@ def load(roll: str):
if path.exists():
with open(path) as file:
return [Counter(i) for i in json.load(file)]


def copy_images(counters: list[Counter], path: Path):
if not Path(f"./Data/{path.name}").exists():
os.mkdir(Path(f"./Data/{path.name}"))
images = sorted(path.iterdir())
for index, image in enumerate(counters):
for id, count in image.items():
file_name_base = get_file_name(id)
for i in range(count):
file_name = (
file_name_base.format(path.name, i + 1) + images[index].suffix
)
logger.debug(file_name)
copy(images[index], Path(f"./Data/{path.name}") / file_name)
Binary file modified Data/data.db
Binary file not shown.
15 changes: 12 additions & 3 deletions GUI/bill.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import collections
import logging
from pathlib import Path

import dearpygui.dearpygui as dpg

from Application import SearchMachine, load, write
from Application import SearchMachine, copy_images, load, write
from Application.utils import SimpleTimer
from GUI.utils import modal_message

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


class BillingWindow:
"""Tags and stores images. There is no real ImageManager equivalent for BillingWindow, so this does everything"""

def __init__(self, roll: str):
def __init__(self, roll: str, path: Path):
# List of things the BilledWindow knows about:
# 1. The cam and roll that it is responsible for

Expand All @@ -24,9 +26,12 @@ def __init__(self, roll: str):
self.ids_per_roll = load(roll) or [collections.Counter() for _ in range(40)]
self.search_machine = SearchMachine()
self.current_index = 0
self.path = path

with dpg.window(width=625, height=436, label="Billing Window", no_resize=True):
input = dpg.add_input_text()
with dpg.group(horizontal=True):
input = dpg.add_input_text()
dpg.add_button(label="Export", callback=self.export)
with dpg.group(horizontal=True):
with dpg.child_window(width=350) as self.suggestions_panel:
with dpg.table(policy=dpg.mvTable_SizingFixedFit):
Expand Down Expand Up @@ -57,6 +62,10 @@ def __init__(self, roll: str):
dpg.set_item_callback(input, self.suggest)
self.show_selected_ids()

def export(self):
copy_images(self.ids_per_roll, self.path)
modal_message("Roll Exported!")

def suggest(self, sender, app_data, user_data):
if len(app_data) > 0:
matches = self.search_machine.search(app_data)
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def make_image_window(path: Path):
image_manager = Application.ImageManager(
mode="offline", roll=path.name, path=path
)
billing_window = GUI.BillingWindow(roll="30R")
billing_window = GUI.BillingWindow(roll="30R", path=path)
GUI.ImageWindow(image_window, billing_window, image_manager)


Expand Down

0 comments on commit e57d0e8

Please sign in to comment.