Compare commits
10 Commits
implement-
...
f993220ad6
| Author | SHA1 | Date | |
|---|---|---|---|
| f993220ad6 | |||
| dac342f3ec | |||
| 61ab5a9deb | |||
| b61c52972d | |||
| c80a587cbd | |||
| 0d114a325d | |||
| 9532eb7247 | |||
| 7e9d5bec9b | |||
| 6407cf4229 | |||
| 9ad45ed63f |
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
if [ $VIRTUAL_ENV=="" ]
|
||||
if [ "$VIRTUAL_ENV" == "" ]
|
||||
then
|
||||
source venv/bin/activate
|
||||
fi
|
||||
@@ -11,10 +11,11 @@ if [ "$new_version" != "" ]
|
||||
then
|
||||
echo "$new_version" | tee version.txt
|
||||
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]\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" src/brovski-adress-etiketten-verwaltung.py
|
||||
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
|
||||
mkdir -p deb-package/brovski-adressetiketten/usr/local/bin
|
||||
cp dist/brovski-adress-etiketten-verwaltung deb-package/brovski-adressetiketten/usr/local/bin/brovski-adressetiketten
|
||||
dpkg-deb --build deb-package/brovski-adressetiketten
|
||||
mv deb-package/brovski-adressetiketten.deb ./
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Package: brovski-adressetiketten
|
||||
Version: 0.1.0b
|
||||
Version: 0.2.0b
|
||||
Maintainer: Ovski
|
||||
Architecture: all
|
||||
Description: manage csv files for glables address labels
|
||||
|
||||
@@ -7,19 +7,20 @@ from tkinter import messagebox
|
||||
from tkinter import ttk
|
||||
|
||||
from config import Config
|
||||
from connector import JSONConnector
|
||||
from model import Model
|
||||
from connector import JSONConnector
|
||||
from windows import SettingsWindow, EditRecord, show_error
|
||||
|
||||
|
||||
class Application:
|
||||
def __init__(self):
|
||||
os.chdir(os.getcwd())
|
||||
# tkinter settings
|
||||
x_offset = 700
|
||||
y_offset = 200
|
||||
width = 1050
|
||||
height = 700
|
||||
VERSION = '0.1.0b'
|
||||
VERSION = '0.2.0b'
|
||||
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
|
||||
|
||||
self.root = tk.Tk(className="BrovskiAdressEtiketten")
|
||||
@@ -37,7 +38,7 @@ class Application:
|
||||
self.filter_active = tk.BooleanVar(value=False)
|
||||
|
||||
# model connector
|
||||
self.model = Model(JSONConnector())
|
||||
self.model = Model(JSONConnector(self.config))
|
||||
|
||||
# init paths to json and csv file
|
||||
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
|
||||
@@ -80,7 +81,7 @@ class Application:
|
||||
|
||||
# table content
|
||||
scrollbar = ttk.Scrollbar(data_frame, orient=tk.VERTICAL)
|
||||
self.table = ttk.Treeview(data_frame, yscrollcommand=scrollbar.set, columns=("0", "1", "2", "3", "4"),
|
||||
self.table = ttk.Treeview(data_frame, yscrollcommand=scrollbar.set, columns=("0", "1", "2", "3", "4", "5"),
|
||||
show="headings")
|
||||
scrollbar.config(command=self.table.yview)
|
||||
self.table.heading('0', text="Aktiv")
|
||||
@@ -89,6 +90,7 @@ class Application:
|
||||
self.table.heading('2', text="Name")
|
||||
self.table.heading('3', text="Strasse")
|
||||
self.table.heading('4', text="Plz/Ort")
|
||||
self.table.heading('5', text="Anzahl")
|
||||
self.table.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
||||
scrollbar.pack(side=tk.LEFT, fill=tk.Y)
|
||||
|
||||
@@ -139,7 +141,8 @@ class Application:
|
||||
"firma": "Firma",
|
||||
"name": "Name",
|
||||
"strasse": "Strasse",
|
||||
"plzort": "Plz/Ort"
|
||||
"plzort": "Plz/Ort",
|
||||
"anzahl": "Anzahl"
|
||||
}
|
||||
self.model.create_new(values)
|
||||
self.populate_table()
|
||||
@@ -228,6 +231,8 @@ class Application:
|
||||
field = "strasse"
|
||||
case "#5":
|
||||
field = "plzort"
|
||||
case "#6":
|
||||
field = "anzahl"
|
||||
case _:
|
||||
field = "name"
|
||||
|
||||
@@ -248,13 +253,21 @@ class Application:
|
||||
for address in self.address_list:
|
||||
if address["aktiv"] != "x":
|
||||
continue
|
||||
line = []
|
||||
if address["firma"] != "":
|
||||
line.append(address["firma"])
|
||||
line.append(address["name"])
|
||||
line.append(address["strasse"])
|
||||
line.append(address["plzort"])
|
||||
writer.writerow(line)
|
||||
for index in range(int(address["anzahl"])):
|
||||
line = []
|
||||
if address["firma"] != "":
|
||||
line.append(address["firma"])
|
||||
line.append(address["name"])
|
||||
line.append(address["strasse"])
|
||||
line.append(address["plzort"])
|
||||
writer.writerow(line)
|
||||
# todo: add "absender" to config parameters
|
||||
line = []
|
||||
line.append("Absender:")
|
||||
line.append("Matthias Braun")
|
||||
line.append("Wolfacherweg 1")
|
||||
line.append("5724 Dürrenäsch")
|
||||
writer.writerow(line)
|
||||
except FileNotFoundError:
|
||||
show_error(message_title="Unexpected error",
|
||||
message=f"Could not write file {self.csv_file}",
|
||||
@@ -265,6 +278,7 @@ class Application:
|
||||
if reload:
|
||||
self.address_list = self.model.get_all()
|
||||
if len(self.address_list) == 0:
|
||||
self.delete_all_table_items()
|
||||
return
|
||||
self.delete_all_table_items()
|
||||
for address in self.address_list:
|
||||
@@ -273,7 +287,7 @@ class Application:
|
||||
continue
|
||||
self.table.insert('', 'end', iid=address["record_id"],
|
||||
values=(address["aktiv"], address["firma"], address["name"], address["strasse"],
|
||||
address["plzort"])
|
||||
address["plzort"], address["anzahl"])
|
||||
)
|
||||
self.update_status_bar()
|
||||
|
||||
@@ -290,14 +304,14 @@ class Application:
|
||||
self.table.delete(item)
|
||||
|
||||
def open_window_settings(self):
|
||||
window = SettingsWindow(self, self.root)
|
||||
window = SettingsWindow(self, self.root, self.config)
|
||||
window.wm_transient(self.root)
|
||||
window.wait_visibility()
|
||||
window.grab_set()
|
||||
return window
|
||||
|
||||
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.wait_visibility()
|
||||
window.grab_set()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import os
|
||||
from configparser import ConfigParser
|
||||
from configparser import ConfigParser, NoOptionError, NoSectionError, DuplicateSectionError
|
||||
|
||||
|
||||
class Config:
|
||||
parser: ConfigParser
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, filename: str = "config.ini"):
|
||||
"""
|
||||
Config parser reading config.ini
|
||||
|
||||
@@ -19,7 +19,7 @@ class Config:
|
||||
full_path = os.path.join(home_path, ".config", "brovski-adress-etiketten" )
|
||||
if not os.path.exists(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()
|
||||
|
||||
@@ -32,14 +32,25 @@ class Config:
|
||||
|
||||
def add_section(self, section):
|
||||
self._load()
|
||||
self.parser.add_section(section)
|
||||
try:
|
||||
self.parser.add_section(section)
|
||||
except DuplicateSectionError:
|
||||
return
|
||||
|
||||
self._save()
|
||||
|
||||
def set(self, section: str, option: str, value: str):
|
||||
self._load()
|
||||
self.add_section(section)
|
||||
self.parser.set(section, option, value)
|
||||
self._save()
|
||||
|
||||
def get(self, section: str, option: str):
|
||||
self._load()
|
||||
return self.parser.get(section, option)
|
||||
try:
|
||||
option = self.parser.get(section, option)
|
||||
except NoOptionError:
|
||||
option = ""
|
||||
except NoSectionError:
|
||||
option = ""
|
||||
return option
|
||||
|
||||
@@ -2,12 +2,12 @@ import json
|
||||
import os
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import config
|
||||
from config import Config
|
||||
|
||||
|
||||
class Connector(ABC):
|
||||
def __init__(self):
|
||||
pass
|
||||
def __init__(self, config: Config):
|
||||
self.config = config
|
||||
|
||||
@abstractmethod
|
||||
def get_all(self) -> list:
|
||||
@@ -35,15 +35,17 @@ class Connector(ABC):
|
||||
|
||||
|
||||
class JSONConnector(Connector):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.config = config.Config()
|
||||
def __init__(self, config: Config):
|
||||
super().__init__(config)
|
||||
self.json_path = self.config.get("json", "path")
|
||||
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:
|
||||
return json.load(f)
|
||||
try:
|
||||
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:
|
||||
with open(self.json_file, "r") as f:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from connector import JSONConnector, Connector
|
||||
from connector import Connector
|
||||
|
||||
|
||||
class Model:
|
||||
|
||||
@@ -32,11 +32,11 @@ class Window(tk.Toplevel):
|
||||
|
||||
|
||||
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)
|
||||
self.bind("<Return>", self._update)
|
||||
|
||||
self.model = JSONConnector()
|
||||
self.model = JSONConnector(config)
|
||||
|
||||
record = self.model.get_by_id(record_id)
|
||||
|
||||
@@ -48,6 +48,7 @@ class EditRecord(Window):
|
||||
self.name = tk.StringVar(value=record.get("name"))
|
||||
self.strasse = tk.StringVar(value=record.get("strasse"))
|
||||
self.plz_ort = tk.StringVar(value=record.get("plzort"))
|
||||
self.anzahl = tk.StringVar(value=record.get("anzahl"))
|
||||
|
||||
edit_frame = tk.Frame(self)
|
||||
edit_frame.pack(side=tk.TOP, fill=tk.X, pady=20, padx=20)
|
||||
@@ -56,6 +57,7 @@ class EditRecord(Window):
|
||||
tk.Label(edit_frame, text="Name").grid(row=0, column=2)
|
||||
tk.Label(edit_frame, text="Strasse").grid(row=0, column=3)
|
||||
tk.Label(edit_frame, text="Plz/Ort").grid(row=0, column=4)
|
||||
tk.Label(edit_frame, text="Anzahl").grid(row=0, column=5)
|
||||
edit_aktiv = tk.Checkbutton(edit_frame, variable=self.aktiv, onvalue="x", offvalue="")
|
||||
edit_aktiv.grid(row=1, column=0)
|
||||
edit_firma = tk.Entry(edit_frame, textvariable=self.firma)
|
||||
@@ -66,6 +68,8 @@ class EditRecord(Window):
|
||||
edit_strasse.grid(row=1, column=3)
|
||||
edit_plz_ort = tk.Entry(edit_frame, textvariable=self.plz_ort)
|
||||
edit_plz_ort.grid(row=1, column=4)
|
||||
edit_anzahl = tk.Entry(edit_frame, textvariable=self.anzahl)
|
||||
edit_anzahl.grid(row=1, column=5)
|
||||
|
||||
button_frame = tk.Frame(self)
|
||||
button_frame.pack(side=tk.TOP, pady=10)
|
||||
@@ -80,16 +84,17 @@ class EditRecord(Window):
|
||||
"name": self.name.get(),
|
||||
"strasse": self.strasse.get(),
|
||||
"plzort": self.plz_ort.get(),
|
||||
"anzahl": self.anzahl.get(),
|
||||
}
|
||||
self.model.update_record(new_record)
|
||||
self.close_window()
|
||||
|
||||
|
||||
class SettingsWindow(Window):
|
||||
def __init__(self, parent, root: tk.Tk):
|
||||
def __init__(self, parent, root: tk.Tk, config: Config):
|
||||
super().__init__(parent, root)
|
||||
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.csv_file = tk.StringVar()
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.1.0b
|
||||
0.2.0b
|
||||
|
||||
Reference in New Issue
Block a user