6 Commits

5 changed files with 57 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
Package: brovski-adressetiketten
Version: 0.6a
Version: 0.1.0b
Maintainer: Ovski
Architecture: all
Description: manage csv files for glables address labels

View File

@@ -5,11 +5,11 @@ import tkinter as tk
from configparser import NoSectionError, NoOptionError
from tkinter import messagebox
from tkinter import ttk
import json
from config import Config
from connector import JSONConnector
from windows import SettingsWindow, EditRecord, Window, show_error
from model import Model
from windows import SettingsWindow, EditRecord, show_error
class Application:
@@ -19,7 +19,7 @@ class Application:
y_offset = 200
width = 1050
height = 700
VERSION = '0.6a'
VERSION = '0.1.0b'
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
self.root = tk.Tk(className="BrovskiAdressEtiketten")
@@ -37,7 +37,7 @@ class Application:
self.filter_active = tk.BooleanVar(value=False)
# model connector
self.model = JSONConnector()
self.model = Model(JSONConnector())
# init paths to json and csv file
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
@@ -93,8 +93,10 @@ class Application:
scrollbar.pack(side=tk.LEFT, fill=tk.Y)
self.table.bind("<ButtonRelease-1>", self.mouse_click)
self.table.bind("<Return>", self.mouse_click_double)
self.table.bind("<Return>", self.enter_button)
self.table.bind("<Double-1>", self.mouse_click_double)
self.root.bind("<Up>", self.focus_table)
self.root.bind("<Down>", self.focus_table)
# bottom status bar
tk.Label(bottom_frame, textvariable=self.statusbar).pack(side=tk.LEFT)
@@ -202,7 +204,10 @@ class Application:
region = self.table.identify("region", event.x, event.y)
match region:
case "cell":
self.click_on_cell()
self.edit_selected_record()
def enter_button(self, event):
self.edit_selected_record()
def click_on_header(self, event):
column = self.table.identify_column(event.x)
@@ -229,7 +234,9 @@ class Application:
self.address_list = self.model.get_all_sorted_by(field, self.sort_order)
self.populate_table(reload=False)
def click_on_cell(self):
def edit_selected_record(self):
if self.table.focus() is None or self.table.focus() == "":
return
self.current_record = int(self.table.focus())
self.open_window_edit_records(self.current_record)
@@ -311,6 +318,16 @@ class Application:
self.address_list.sort(key=lambda x: (x["firma"], x["name"]))
self.populate_table()
def focus_table(self, event):
first = self.table.get_children()[0]
last = self.table.get_children()[-1]
goto = last if event.keysym == "Up" else first
if self.table.focus() == "":
self.table.selection_set(goto)
self.table.focus(goto)
self.table.see(goto)
self.table.focus_force()
if __name__ == '__main__':
Application()

View File

@@ -29,13 +29,17 @@ class Connector(ABC):
def create_new(self, values: dict) -> int:
pass
@abstractmethod
def get_all_sorted_by(self, field: str, reverse: bool = False) -> list:
pass
class JSONConnector(Connector):
def __init__(self):
super().__init__()
self.config = config.Config()
self.json_path = self.config.get("json", "path")
self.json_file = os.path.join(self.json_path, "brovski-adress-etiketten-verwaltung.json")
self.json_file = os.path.join(self.json_path, "brovski-adress-etiketten-verwaltung-v7.json")
def get_all(self) -> list:
with open(self.json_file, "r") as f:
@@ -78,5 +82,5 @@ class JSONConnector(Connector):
return next_id
def _write_to_file(self, data):
with open(self.json_file, "w") as f:
json.dump(data, f, indent=4)
with open(self.json_file, "w", encoding="UTF-8") as f:
json.dump(data, f, indent=4, ensure_ascii=False)

24
src/model.py Normal file
View File

@@ -0,0 +1,24 @@
from connector import JSONConnector, Connector
class Model:
def __init__(self, connector: Connector):
self.connector = connector
def get_all(self):
return self.connector.get_all()
def get_all_sorted_by(self, field: str, reverse: bool = False):
return self.connector.get_all_sorted_by(field=field, reverse=reverse)
def get_by_id(self, record_id: int):
return self.connector.get_by_id(record_id)
def delete_by_id(self, record_id: int):
self.connector.delete_by_id(record_id)
def update_record(self, new_record: dict):
self.connector.update_record(new_record)
def create_new(self, record: dict):
self.connector.create_new(record)

View File

@@ -1 +1 @@
0.6a
0.1.0b