python-simpletables 0.1.26__py3-none-any.whl → 0.1.27__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- from .table import Table
2
- from .example import ExampleApp
1
+ from .table import Table,Field
2
+
3
3
 
4
4
 
5
5
  #
@@ -0,0 +1,64 @@
1
+ import os,os.path as op,re,json,sqlite3,tkinter as tk,atexit
2
+ from tkinter import ttk
3
+ from . import Table,Field
4
+
5
+ def showid(table,field,value):
6
+ return str(value).rjust(5,"0")
7
+ def showbool(table,field,value):
8
+ return "Да" if value else "Нет"
9
+ class ExampleApp(tk.Tk):
10
+ def __init__(self,database_path):
11
+ conn = sqlite3.connect(database_path)
12
+ with open(op.join(op.dirname(__file__),"__main__.sql"),"r",encoding="utf8") as script:
13
+ for cmd in script.read().split(";"):
14
+ cmd=cmd.strip()
15
+ try: conn.execute(cmd) if cmd else None
16
+ except: print(repr(cmd))
17
+ super().__init__()
18
+ self.geometry("800x560")
19
+ self.minsize(400,300)
20
+ conn = sqlite3.connect(database_path)
21
+ tabs = tk.Frame(self)
22
+ tabs.pack(side="top",fill="x")
23
+ box = tk.Frame(self)
24
+ box.pack(side="top",fill="both",expand=True)
25
+ self.all_tables=[]
26
+ self.all_buttons={}
27
+ selector = lambda name: lambda: self.select_table(name)
28
+ for name,title,fields in [
29
+ ("Customers","Заказчики",[
30
+ Field("id","ID",show=showid,primary=True),
31
+ Field("name","ФИО / Организация"),
32
+ Field("inn","ИНН"),
33
+ Field("addres","Адрес"),
34
+ Field("phone","Телефон"),
35
+ Field("salesman","Продавец?",show=showbool),
36
+ Field("buyer","Покупатель?",show=showbool),
37
+ ]),
38
+ ("Goods","Товары",[
39
+ Field("id","ID",show=showid,primary=True),
40
+ Field("name","Наименование",multiply=2.5),
41
+ Field("price_for_unit","Цена за ед."),
42
+ Field("unit","Ед.изм."),
43
+ ]),
44
+ ]:
45
+ self.all_tables.append(Table(conn,box,name,fields))
46
+ self.all_buttons[name]=tk.Button(tabs,text=title,command=selector(name))
47
+ self.all_buttons[name].pack(side="left")
48
+ self.select_table(self.all_tables[0].name)
49
+ def select_table(self,name):
50
+ res=[t for t in self.all_tables if t.name==name]
51
+ if len(res)!=1: return
52
+ table=res[0]
53
+ for v in self.all_tables:
54
+ v.pack_forget()
55
+ for k,v in self.all_buttons.items():
56
+ v.config(relief="raised")
57
+ self.all_buttons[table.name].config(relief="sunken")
58
+ table.pack(fill="both",expand=True)
59
+ def example_main():
60
+ database=op.join(op.dirname(__file__),"__main__.db")
61
+ ExampleApp(database).mainloop()
62
+
63
+
64
+ if __name__=="__main__": example_main()
@@ -1,13 +1,25 @@
1
1
  import tkinter as tk,json
2
2
  from tkinter import ttk
3
+ from tkinter import messagebox as mb
4
+ from tkinter import simpledialog as sd
5
+ from tkinter import filedialog as fd
6
+ from dataclasses import dataclass
3
7
 
4
8
  def q(s): return json.dumps(s,ensure_ascii=False)
9
+ @dataclass
10
+ class Field:
11
+ name:str
12
+ title:str
13
+ show:object = str
14
+ primary:bool = False
15
+ width:int = 0
16
+ multiply:float = 1
5
17
  class Table(tk.Frame):
6
18
  def __init__(self,conn,master,name,fields):
19
+ self.conn = conn
20
+ self.name = name
21
+ self.fields = fields
7
22
  super().__init__(master)
8
- tk.Label(self,text=name).pack(side="top",fill="x")
9
- self.tree = ttk.Treeview(self,columns=[f.name for f in self.fields],show="headings")
10
- self.tree.pack(side="top",fill="both",expand=True)
11
23
  self.buttons = tk.Frame(self)
12
24
  self.buttons.pack(side="bottom",fill="x")
13
25
  for name,side,cmd in [
@@ -18,29 +30,31 @@ class Table(tk.Frame):
18
30
  ("Импорт из Excel","right",self.ui_import_excel),
19
31
  ("Экспорт в JSON","right",self.ui_export_json),
20
32
  ("Экспорт в Excel","right",self.ui_export_excel),
21
- ]: tk.Button().pack(side=side)
33
+ ]: tk.Button(self.buttons,text=name,command=cmd).pack(side=side)
34
+ self.tree = ttk.Treeview(self,columns=[f.name for f in self.fields],show="headings")
35
+ self.tree.pack(side="bottom",fill="both",expand=True)
36
+ for field in fields:
37
+ self.tree.column(field.name,width=field.width or int(max(30,len(field.title)*8)*field.multiply))
38
+ self.tree.heading(field.name,text=field.title)
22
39
  self.update()
23
40
  def update(self):
24
- conn.execute(f"SELECT * FROM {q(self.name)}")
41
+ self.tree.delete(*self.tree.get_children())
42
+ for raw in self.conn.execute(f"SELECT * FROM {q(self.name)}").fetchall():
43
+ values = [e.show(self,e,raw[i]) for i,e in enumerate(self.fields)]
44
+ self.tree.insert("","end",values=values)
25
45
  def ui_create(self): pass
26
46
  def ui_create(self): pass
27
47
  def ui_edit(self): pass
28
48
  def ui_delete(self): pass
29
49
  def ui_import_json(self): pass
30
- def ui_import_excel(self): pass
50
+ def ui_import_excel(self):
51
+ file = fd.askopenfile(title="Имортировать файл",filetypes=[
52
+ ("Таблицы","*.xlsx","*.xls","*.csv"),
53
+ ("Все файлы","*"),
54
+ ])
31
55
  def ui_export_json(self): pass
32
56
  def ui_export_excel(self): pass
33
57
 
34
- class Example(tk.Tk):
35
- def __init__(self,database_path):
36
- super().__init__()
37
- self.geometry("600x480")
38
- self.conn = sqlite3.connect(database_path)
39
- tabs = tk.Frame(self)
40
- tabs.pack(side="top",fill="x")
41
- box = tk.Frame(self)
42
- box.pack(side="top",fill="both",expand=True)
43
-
44
58
 
45
59
 
46
60
 
@@ -1,6 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_simpletables
3
- Version: 0.1.26
3
+ Version: 0.1.27
4
4
  Summary: Simple connection between SQL and tkinter.
5
5
  Author-email: Захар Васильев <vasilyev.zakhar@gmail.com>
6
6
  License: MIT
7
+ Requires-Dist: pandas
@@ -0,0 +1,8 @@
1
+ python_simpletables/__init__.py,sha256=tT2si4YdJPkxm4gGLVUfI7ORt-VM86_O0bFdgYXMyyo,41
2
+ python_simpletables/__main__.py,sha256=SmrDS11Gp4UDBLA42owx14IOoYF1PCrSFdt2QaKBzbk,2704
3
+ python_simpletables/app.py,sha256=V9baO6lyOzlNZjue3DHGeaKZGJTm9KUTwGkxIX5p_kk,1753
4
+ python_simpletables/table.py,sha256=GfpIlX-2Dx5BdCX9EWV-4ye8SFYdhXgzlYGNgfQTKAQ,2387
5
+ python_simpletables-0.1.27.dist-info/METADATA,sha256=jLNRjmb0Y3LikHJPTUiyRfAUVZzgqv2ZsFnoPJHgGxs,228
6
+ python_simpletables-0.1.27.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
+ python_simpletables-0.1.27.dist-info/top_level.txt,sha256=WhVQcD7ccNKNb-lZhcmTM0kTkcbxh7tE11YiN1ZwE9E,20
8
+ python_simpletables-0.1.27.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- import os,os.path as op,re,json,sqlite3,tkinter as tk
2
- from tkinter import ttk
3
-
4
-
5
- class ExampleApp(tk.Tk):
6
- def __init__(self,database_path):
7
- super().__init__()
8
- self.geometry("600x480")
9
- conn = sqlite3.connect(database_path)
10
- tabs = tk.Frame(self)
11
- tabs.pack(side="top",fill="x")
12
- box = tk.Frame(self)
13
- box.pack(side="top",fill="both",expand=True)
14
-
@@ -1,8 +0,0 @@
1
- python_simpletables/__init__.py,sha256=AGLvgmI8B9GWWnD3vd0RwEdl1d8B7PPSnwOSwJywEBM,66
2
- python_simpletables/app.py,sha256=V9baO6lyOzlNZjue3DHGeaKZGJTm9KUTwGkxIX5p_kk,1753
3
- python_simpletables/example.py,sha256=EHVorbtL1Oqq9VI_11LVFij4yYUpf3DW43c-B29Gi9c,423
4
- python_simpletables/table.py,sha256=AqgUmAuEXlwEkOGk8LOf3GCwQfJKShKIo4xCmjD_pXY,1758
5
- python_simpletables-0.1.26.dist-info/METADATA,sha256=BvhzgmBEbqm4PUxYWbHaIKo4QjwEnBTZvPafyLvkUno,205
6
- python_simpletables-0.1.26.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
7
- python_simpletables-0.1.26.dist-info/top_level.txt,sha256=WhVQcD7ccNKNb-lZhcmTM0kTkcbxh7tE11YiN1ZwE9E,20
8
- python_simpletables-0.1.26.dist-info/RECORD,,