Compare commits
8 Commits
2d840d6ad4
...
beta-0.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d114a325d | |||
| 9532eb7247 | |||
| 7e9d5bec9b | |||
| 6407cf4229 | |||
| 9ad45ed63f | |||
| 3224c1c2aa | |||
| ca88c4d229 | |||
| 12d0d7034f |
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
if [ $VIRTUAL_ENV=="" ]
|
||||
if [ "$VIRTUAL_ENV" == "" ]
|
||||
then
|
||||
source venv/bin/activate
|
||||
fi
|
||||
@@ -11,8 +11,8 @@ 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
|
||||
cp dist/brovski-adress-etiketten-verwaltung deb-package/brovski-adressetiketten/usr/local/bin/brovski-adressetiketten
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Package: brovski-adressetiketten
|
||||
Version: 0.7a
|
||||
Version: 0.1.1b
|
||||
Maintainer: Ovski
|
||||
Architecture: all
|
||||
Description: manage csv files for glables address labels
|
||||
|
||||
@@ -7,7 +7,7 @@ from tkinter import messagebox
|
||||
from tkinter import ttk
|
||||
|
||||
from config import Config
|
||||
from connector import JSONConnector
|
||||
from model import Model
|
||||
from windows import SettingsWindow, EditRecord, show_error
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ class Application:
|
||||
y_offset = 200
|
||||
width = 1050
|
||||
height = 700
|
||||
VERSION = '0.7a'
|
||||
VERSION = '0.1.1b'
|
||||
title = f"Brovski Adress-Etiketten Verwaltung {VERSION}"
|
||||
|
||||
self.root = tk.Tk(className="BrovskiAdressEtiketten")
|
||||
@@ -36,7 +36,7 @@ class Application:
|
||||
self.filter_active = tk.BooleanVar(value=False)
|
||||
|
||||
# model connector
|
||||
self.model = JSONConnector()
|
||||
self.model = Model(self.config)
|
||||
|
||||
# init paths to json and csv file
|
||||
self.json_file_name = "brovski-adress-etiketten-verwaltung.json"
|
||||
@@ -264,6 +264,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:
|
||||
@@ -289,14 +290,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()
|
||||
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
|
||||
|
||||
@@ -3,11 +3,12 @@ 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:
|
||||
@@ -29,17 +30,23 @@ 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()
|
||||
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:
|
||||
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:
|
||||
@@ -78,5 +85,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)
|
||||
|
||||
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):
|
||||
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)
|
||||
|
||||
@@ -86,10 +86,10 @@ class EditRecord(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.7a
|
||||
0.1.1b
|
||||
|
||||
Reference in New Issue
Block a user