-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathengine.py
More file actions
95 lines (75 loc) · 3.23 KB
/
Copy pathengine.py
File metadata and controls
95 lines (75 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# project: Tkinterlite
# authors: Giuseppe Costanzi (1966bc)
# licence: GPL-3.0-or-later, see LICENSE
# -----------------------------------------------------------------------------
import os
import sys
import subprocess
from dbms import DBMS
from tools import Tools
from config import Config
from events import Events
from windows import Windows
class Engine:
"""The one object every window reaches: it owns the parts, it is none of them.
Composition, not inheritance: Engine is not a database, it has one. Each
part is an attribute, so a call says who does the work -
engine.db.read(...), engine.tools.center_me(...) - and each part can be
built and tested on its own.
"""
def __init__(self, log):
self.log = log
# The settings, read by the Config class from tkinterlite.ini.
self.config = Config(self.get_file("tkinterlite.ini"))
# The database beside the program, wherever it is started from.
self.db = DBMS(self.get_file("northwind.sl3"), log)
# Styles and widget helpers.
self.tools = Tools()
# Who changed what, told to the windows that show it: the Observer.
self.events = Events(log)
# The open windows, one per name: the Singleton pattern, by name.
self.windows = Windows(log)
self.no_selected = "Attention!\nNo record selected!"
self.ask_to_delete = "Delete data?"
self.ask_to_save = "Save data?"
self.abort = "Operation aborted!"
def __str__(self):
return "class: {0}\nparts: log, config, db, tools, events, windows".format(
self.__class__.__name__)
def get_python_version(self,):
return "Python version:\n{0}".format(".".join(map(str, sys.version_info[:3])))
def get_file(self, file):
"""# return full path of the directory where program resides."""
return os.path.join(os.path.dirname(__file__), file)
def open_file(self, path):
"""Open a file with the program the system uses for it, on Linux and Windows.
Popen and not call: call would wait for that program to be closed,
and the whole application would stand still meanwhile. A file that
is not there raises, rather than nothing happening at all.
"""
if not os.path.exists(path):
raise FileNotFoundError("no such file: {0}".format(path))
if os.name == "posix":
subprocess.Popen(["xdg-open", path])
else:
os.startfile(path)
def get_license(self):
"""get license"""
with open(self.get_file("LICENSE"), "r") as f:
v = f.read()
return v
def get_icon(self, which):
"""An icon: its file holds one base64 PNG."""
with open(self.get_file(which), "r") as f:
v = f.readline()
return v
def get_icons(self, which):
"""Every size of an icon: its file holds one base64 PNG per line."""
with open(self.get_file(which), "r") as f:
icons = f.read().split()
return icons
def open_log(self):
"""Open the log file with the program the system uses for text."""
self.open_file(self.log.path)