Compare commits
13 Commits
9ea44933a6
...
beta-0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d114a325d | |||
| 9532eb7247 | |||
| 7e9d5bec9b | |||
| 6407cf4229 | |||
| 9ad45ed63f | |||
| 3224c1c2aa | |||
| ca88c4d229 | |||
| 12d0d7034f | |||
| 2d840d6ad4 | |||
| 0ae2c7e559 | |||
| 96995f1e80 | |||
| ec130fcee9 | |||
| 95ed06df45 |
@@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
if [ $VIRTUAL_ENV=="" ]
|
if [ "$VIRTUAL_ENV" == "" ]
|
||||||
then
|
then
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
fi
|
fi
|
||||||
@@ -11,8 +11,8 @@ if [ "$new_version" != "" ]
|
|||||||
then
|
then
|
||||||
echo "$new_version" | tee version.txt
|
echo "$new_version" | tee version.txt
|
||||||
fi
|
fi
|
||||||
sed -i "s/VERSION = '[0-9]\.[0-9]\w'/VERSION = '$(cat version.txt)'/g" src/brovski-adress-etiketten-verwaltung.py
|
sed -i "s/VERSION = '[0-9]\.[0-9].[0-9]\w'/VERSION = '$(cat version.txt)'/g" src/brovski-adress-etiketten-verwaltung.py
|
||||||
sed -i "s/Version: [0-9]\.[0-9]\w/Version: $(cat version.txt)/g" deb-package/brovski-adressetiketten/DEBIAN/control
|
sed -i "s/Version: [0-9]\.[0-9].[0-9]\w/Version: $(cat version.txt)/g" deb-package/brovski-adressetiketten/DEBIAN/control
|
||||||
|
|
||||||
pyinstaller --clean --onefile src/brovski-adress-etiketten-verwaltung.py
|
pyinstaller --clean --onefile src/brovski-adress-etiketten-verwaltung.py
|
||||||
cp dist/brovski-adress-etiketten-verwaltung deb-package/brovski-adressetiketten/usr/local/bin/brovski-adressetiketten
|
cp dist/brovski-adress-etiketten-verwaltung deb-package/brovski-adressetiketten/usr/local/bin/brovski-adressetiketten
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Package: brovski-adressetiketten
|
Package: brovski-adressetiketten
|
||||||
Version: 0.6a
|
Version: 0.1.1b
|
||||||
Maintainer: Ovski
|
Maintainer: Ovski
|
||||||
Architecture: all
|
Architecture: all
|
||||||
Description: manage csv files for glables address labels
|
Description: manage csv files for glables address labels
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ import tkinter as tk
|
|||||||
from configparser import NoSectionError, NoOptionError
|
from configparser import NoSectionError, NoOptionError
|
||||||
from tkinter import messagebox
|
from tkinter import messagebox
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
import json
|
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from connector import JSONConnector
|
from model import Model
|
||||||
from windows import SettingsWindow, EditRecord, Window, show_error
|
from windows import SettingsWindow, EditRecord, show_error
|
||||||
|
|
||||||
|
|
||||||
class Application:
|
class Application:
|
||||||
@@ -19,7 +18,7 @@ class Application:
|
|||||||
y_offset = 200
|
y_offset = 200
|
||||||
width = 1050
|
width = 1050
|
||||||
height = 700
|
height = 700
|
||||||
VERSION = '0.6a'
|
VERSION = '0.1.1b'
|
||||||
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
|
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
|
||||||
|
|
||||||
self.root = tk.Tk(className="BrovskiAdressEtiketten")
|
self.root = tk.Tk(className="BrovskiAdressEtiketten")
|
||||||
@@ -37,7 +36,7 @@ class Application:
|
|||||||
self.filter_active = tk.BooleanVar(value=False)
|
self.filter_active = tk.BooleanVar(value=False)
|
||||||
|
|
||||||
# model connector
|
# model connector
|
||||||
self.model = JSONConnector()
|
self.model = Model(self.config)
|
||||||
|
|
||||||
# init paths to json and csv file
|
# init paths to json and csv file
|
||||||
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
|
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
|
||||||
@@ -73,7 +72,7 @@ class Application:
|
|||||||
tk.Button(top_frame, text="Delete", command=self.delete_record, width=button_width).pack(side=tk.LEFT)
|
tk.Button(top_frame, text="Delete", command=self.delete_record, width=button_width).pack(side=tk.LEFT)
|
||||||
tk.Button(top_frame, text="Export CSV", command=self.export_csv, width=button_width).pack(side=tk.LEFT)
|
tk.Button(top_frame, text="Export CSV", command=self.export_csv, width=button_width).pack(side=tk.LEFT)
|
||||||
tk.Button(top_frame, text="Toggle Aktiv", command=self.toggle_active, width=button_width).pack(side=tk.LEFT)
|
tk.Button(top_frame, text="Toggle Aktiv", command=self.toggle_active, width=button_width).pack(side=tk.LEFT)
|
||||||
tk.Checkbutton(top_frame, text="Filter aktive", variable=self.filter_active, command=self.populate_table).pack(
|
tk.Checkbutton(top_frame, text="Filter aktiv", variable=self.filter_active, command=self.populate_table).pack(
|
||||||
side=tk.LEFT)
|
side=tk.LEFT)
|
||||||
tk.Button(top_frame, text="Quit", command=self.on_close, width=button_width).pack(side=tk.RIGHT)
|
tk.Button(top_frame, text="Quit", command=self.on_close, width=button_width).pack(side=tk.RIGHT)
|
||||||
tk.Button(top_frame, text="Settings", command=self.show_settings, width=button_width).pack(side=tk.RIGHT)
|
tk.Button(top_frame, text="Settings", command=self.show_settings, width=button_width).pack(side=tk.RIGHT)
|
||||||
@@ -93,8 +92,10 @@ class Application:
|
|||||||
scrollbar.pack(side=tk.LEFT, fill=tk.Y)
|
scrollbar.pack(side=tk.LEFT, fill=tk.Y)
|
||||||
|
|
||||||
self.table.bind("<ButtonRelease-1>", self.mouse_click)
|
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.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
|
# bottom status bar
|
||||||
tk.Label(bottom_frame, textvariable=self.statusbar).pack(side=tk.LEFT)
|
tk.Label(bottom_frame, textvariable=self.statusbar).pack(side=tk.LEFT)
|
||||||
@@ -156,7 +157,6 @@ class Application:
|
|||||||
if messagebox.askyesno(
|
if messagebox.askyesno(
|
||||||
"Eintrag löschen?",
|
"Eintrag löschen?",
|
||||||
"Willst du diesen Eintrag wirklich löschen?\nDies kann nicht rückgängig gemacht werden"):
|
"Willst du diesen Eintrag wirklich löschen?\nDies kann nicht rückgängig gemacht werden"):
|
||||||
print(type(self.current_record))
|
|
||||||
self.model.delete_by_id(self.current_record)
|
self.model.delete_by_id(self.current_record)
|
||||||
|
|
||||||
self.deselect_tree()
|
self.deselect_tree()
|
||||||
@@ -203,11 +203,13 @@ class Application:
|
|||||||
region = self.table.identify("region", event.x, event.y)
|
region = self.table.identify("region", event.x, event.y)
|
||||||
match region:
|
match region:
|
||||||
case "cell":
|
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):
|
def click_on_header(self, event):
|
||||||
column = self.table.identify_column(event.x)
|
column = self.table.identify_column(event.x)
|
||||||
print(f"col: {column}")
|
|
||||||
if self.last_sort_field == column:
|
if self.last_sort_field == column:
|
||||||
self.sort_order = False if self.sort_order else True
|
self.sort_order = False if self.sort_order else True
|
||||||
else:
|
else:
|
||||||
@@ -231,7 +233,9 @@ class Application:
|
|||||||
self.address_list = self.model.get_all_sorted_by(field, self.sort_order)
|
self.address_list = self.model.get_all_sorted_by(field, self.sort_order)
|
||||||
self.populate_table(reload=False)
|
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.current_record = int(self.table.focus())
|
||||||
self.open_window_edit_records(self.current_record)
|
self.open_window_edit_records(self.current_record)
|
||||||
|
|
||||||
@@ -260,13 +264,13 @@ class Application:
|
|||||||
if reload:
|
if reload:
|
||||||
self.address_list = self.model.get_all()
|
self.address_list = self.model.get_all()
|
||||||
if len(self.address_list) == 0:
|
if len(self.address_list) == 0:
|
||||||
|
self.delete_all_table_items()
|
||||||
return
|
return
|
||||||
self.delete_all_table_items()
|
self.delete_all_table_items()
|
||||||
for address in self.address_list:
|
for address in self.address_list:
|
||||||
# skip inactive records if filter is true
|
# skip inactive records if filter is true
|
||||||
if self.filter_active.get() and address["aktiv"] != "x":
|
if self.filter_active.get() and address["aktiv"] != "x":
|
||||||
continue
|
continue
|
||||||
print(address)
|
|
||||||
self.table.insert('', 'end', iid=address["record_id"],
|
self.table.insert('', 'end', iid=address["record_id"],
|
||||||
values=(address["aktiv"], address["firma"], address["name"], address["strasse"],
|
values=(address["aktiv"], address["firma"], address["name"], address["strasse"],
|
||||||
address["plzort"])
|
address["plzort"])
|
||||||
@@ -286,14 +290,14 @@ class Application:
|
|||||||
self.table.delete(item)
|
self.table.delete(item)
|
||||||
|
|
||||||
def open_window_settings(self):
|
def open_window_settings(self):
|
||||||
window = SettingsWindow(self, self.root)
|
window = SettingsWindow(self, self.root, self.config)
|
||||||
window.wm_transient(self.root)
|
window.wm_transient(self.root)
|
||||||
window.wait_visibility()
|
window.wait_visibility()
|
||||||
window.grab_set()
|
window.grab_set()
|
||||||
return window
|
return window
|
||||||
|
|
||||||
def open_window_edit_records(self, record_id: int):
|
def open_window_edit_records(self, record_id: int):
|
||||||
window = EditRecord(self, self.root, record_id)
|
window = EditRecord(self, self.root, record_id, self.config)
|
||||||
window.wm_transient(self.root)
|
window.wm_transient(self.root)
|
||||||
window.wait_visibility()
|
window.wait_visibility()
|
||||||
window.grab_set()
|
window.grab_set()
|
||||||
@@ -314,6 +318,16 @@ class Application:
|
|||||||
self.address_list.sort(key=lambda x: (x["firma"], x["name"]))
|
self.address_list.sort(key=lambda x: (x["firma"], x["name"]))
|
||||||
self.populate_table()
|
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__':
|
if __name__ == '__main__':
|
||||||
Application()
|
Application()
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
from configparser import ConfigParser
|
from configparser import ConfigParser, NoOptionError, NoSectionError, DuplicateSectionError
|
||||||
|
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
parser: ConfigParser
|
parser: ConfigParser
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, filename: str = "config.ini"):
|
||||||
"""
|
"""
|
||||||
Config parser reading config.ini
|
Config parser reading config.ini
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ class Config:
|
|||||||
full_path = os.path.join(home_path, ".config", "brovski-adress-etiketten" )
|
full_path = os.path.join(home_path, ".config", "brovski-adress-etiketten" )
|
||||||
if not os.path.exists(full_path):
|
if not os.path.exists(full_path):
|
||||||
os.makedirs(full_path)
|
os.makedirs(full_path)
|
||||||
self.config_file = os.path.join(full_path, "config.ini")
|
self.config_file = os.path.join(full_path, filename)
|
||||||
|
|
||||||
self._load()
|
self._load()
|
||||||
|
|
||||||
@@ -32,14 +32,25 @@ class Config:
|
|||||||
|
|
||||||
def add_section(self, section):
|
def add_section(self, section):
|
||||||
self._load()
|
self._load()
|
||||||
self.parser.add_section(section)
|
try:
|
||||||
|
self.parser.add_section(section)
|
||||||
|
except DuplicateSectionError:
|
||||||
|
return
|
||||||
|
|
||||||
self._save()
|
self._save()
|
||||||
|
|
||||||
def set(self, section: str, option: str, value: str):
|
def set(self, section: str, option: str, value: str):
|
||||||
self._load()
|
self._load()
|
||||||
|
self.add_section(section)
|
||||||
self.parser.set(section, option, value)
|
self.parser.set(section, option, value)
|
||||||
self._save()
|
self._save()
|
||||||
|
|
||||||
def get(self, section: str, option: str):
|
def get(self, section: str, option: str):
|
||||||
self._load()
|
self._load()
|
||||||
return self.parser.get(section, option)
|
try:
|
||||||
|
option = self.parser.get(section, option)
|
||||||
|
except NoOptionError:
|
||||||
|
option = ""
|
||||||
|
except NoSectionError:
|
||||||
|
option = ""
|
||||||
|
return option
|
||||||
|
|||||||
@@ -3,11 +3,12 @@ import os
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
import config
|
import config
|
||||||
|
from config import Config
|
||||||
|
|
||||||
|
|
||||||
class Connector(ABC):
|
class Connector(ABC):
|
||||||
def __init__(self):
|
def __init__(self, config: Config):
|
||||||
pass
|
self.config = config
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_all(self) -> list:
|
def get_all(self) -> list:
|
||||||
@@ -29,17 +30,23 @@ class Connector(ABC):
|
|||||||
def create_new(self, values: dict) -> int:
|
def create_new(self, values: dict) -> int:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def get_all_sorted_by(self, field: str, reverse: bool = False) -> list:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class JSONConnector(Connector):
|
class JSONConnector(Connector):
|
||||||
def __init__(self):
|
def __init__(self, config: Config):
|
||||||
super().__init__()
|
super().__init__(config)
|
||||||
self.config = config.Config()
|
|
||||||
self.json_path = self.config.get("json", "path")
|
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:
|
def get_all(self) -> list:
|
||||||
with open(self.json_file, "r") as f:
|
try:
|
||||||
return json.load(f)
|
with open(self.json_file, "r") as f:
|
||||||
|
return json.load(f)
|
||||||
|
except FileNotFoundError:
|
||||||
|
return []
|
||||||
|
|
||||||
def get_all_sorted_by(self, field: str, reverse=False) -> list:
|
def get_all_sorted_by(self, field: str, reverse=False) -> list:
|
||||||
with open(self.json_file, "r") as f:
|
with open(self.json_file, "r") as f:
|
||||||
@@ -78,5 +85,5 @@ class JSONConnector(Connector):
|
|||||||
return next_id
|
return next_id
|
||||||
|
|
||||||
def _write_to_file(self, data):
|
def _write_to_file(self, data):
|
||||||
with open(self.json_file, "w") as f:
|
with open(self.json_file, "w", encoding="UTF-8") as f:
|
||||||
json.dump(data, f, indent=4)
|
json.dump(data, f, indent=4, ensure_ascii=False)
|
||||||
|
|||||||
26
src/model.py
Normal file
26
src/model.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
from config import Config
|
||||||
|
from connector import JSONConnector
|
||||||
|
|
||||||
|
|
||||||
|
class Model:
|
||||||
|
def __init__(self, config: Config):
|
||||||
|
self.connector = JSONConnector(config)
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
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)
|
||||||
@@ -32,11 +32,11 @@ class Window(tk.Toplevel):
|
|||||||
|
|
||||||
|
|
||||||
class EditRecord(Window):
|
class EditRecord(Window):
|
||||||
def __init__(self, parent, root: tk.Tk, record_id: int):
|
def __init__(self, parent, root: tk.Tk, record_id: int, config: Config):
|
||||||
super().__init__(parent, root)
|
super().__init__(parent, root)
|
||||||
self.bind("<Return>", self._update)
|
self.bind("<Return>", self._update)
|
||||||
|
|
||||||
self.model = JSONConnector()
|
self.model = JSONConnector(config)
|
||||||
|
|
||||||
record = self.model.get_by_id(record_id)
|
record = self.model.get_by_id(record_id)
|
||||||
|
|
||||||
@@ -86,10 +86,10 @@ class EditRecord(Window):
|
|||||||
|
|
||||||
|
|
||||||
class SettingsWindow(Window):
|
class SettingsWindow(Window):
|
||||||
def __init__(self, parent, root: tk.Tk):
|
def __init__(self, parent, root: tk.Tk, config: Config):
|
||||||
super().__init__(parent, root)
|
super().__init__(parent, root)
|
||||||
self.geometry(f"500x330+{self.root.winfo_x() + 20}+{self.root.winfo_y() + 20}")
|
self.geometry(f"500x330+{self.root.winfo_x() + 20}+{self.root.winfo_y() + 20}")
|
||||||
self.config = Config()
|
self.config = config
|
||||||
self.json_file = tk.StringVar()
|
self.json_file = tk.StringVar()
|
||||||
self.csv_file = tk.StringVar()
|
self.csv_file = tk.StringVar()
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
0.6a
|
0.1.1b
|
||||||
|
|||||||
Reference in New Issue
Block a user