forked from willm/DDEXUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata_form.py
executable file
·110 lines (99 loc) · 4.78 KB
/
metadata_form.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python3.3
import tkinter.ttk as tk
import tkinter.messagebox as mb
from DDEXUI.ddex.ddex_builder import DDEXBuilder
from DDEXUI.ddex.party import *
from DDEXUI.ddex.validate import Validate
from DDEXUI.party_repository import PartyRepository
from DDEXUI.inputs import *
from DDEXUI.release_window import ProductReleaseWindow
from DDEXUI.batch_generator import BatchGenerator
from DDEXUI.ddex.ddex import generate_batch_id
from DDEXUI.tkinterutil import showerrorbox
import sys
import os
class PartyWindow(tk.tkinter.Toplevel):
def __init__(self, frame, party_type):
#http://tkinter.unpythonic.net/wiki/ModalWindow
self.party_repository = PartyRepository()
self.party_type = party_type
tk.tkinter.Toplevel.__init__(self, frame)
# self.geometry("400x300")
self.transient(frame)
self.focus_set()
#self.grab_set()
message = "Please enter your " + PartyType.reverse_mapping[self.party_type] + " ddex party details. You can apply for a ddex Party id for free at: http://ddex.net/content/implementation-licence-application-form"
text = tk.tkinter.Label(self, height=5, text=message, wraplength=400)
text.grid(row=0, column=0,columnspan=3)
self.party_id = EntryInput(self, "Party Id", Validate().not_empty)
self.party_name = EntryInput(self, "Party Name", Validate().not_empty)
self.party_id.draw(2)
self.party_name.draw(3)
tk.Button(self, text="OK", command=self.save_and_close).grid(row=4, column=0)
frame.wait_window(self)
def save_and_close(self):
if(self.party_id.on_validate() and self.party_name.on_validate()):
party = Party(self.party_id.value(), self.party_name.value(), self.party_type)
self.party_repository.write_party(party)
self.destroy()
class Program:
def __init__(self):
self.party_repository = PartyRepository()
self._ddex_builders = []
self.frame = tk.tkinter.Tk()
self.frame.geometry("600x300")
icon = tk.tkinter.PhotoImage(file=self.get_icon())
self.frame.tk.call("wm", "iconphoto", self.frame._w, icon)
self.frame.title("Metadata Editor")
self.product_list = tk.tkinter.Listbox(self.frame)
self.product_list.bind('<Delete>', lambda x: self.remove_product())
self._root_folder = "out"
self.add_release_button = tk.Button(self.frame, text="Add Product", command=self.create_ddex)
self.button = tk.Button(self.frame, text="OK", command=self.write_ddex)
self.remove_button = tk.Button(self.frame, text="Remove", command=self.remove_product, state="disabled")
self._batch_id = generate_batch_id()
self._batch_generator = BatchGenerator(self._root_folder, self._batch_id)
@showerrorbox
def write_ddex(self):
self.__check_for_party(PartyType.MessageSender)
self.__check_for_party(PartyType.MessageRecipient)
sender = self.party_repository.get_party(PartyType.MessageSender)
recipient = self.party_repository.get_party(PartyType.MessageRecipient)
for builder in self._ddex_builders:
ddex = builder.sender(sender).recipient(recipient)
self._batch_generator.generate(self._ddex_builders)
mb.showinfo("DDEXUI", "your ddex files have been created")
def get_icon(self):
if getattr(sys, 'frozen', False):
resources = os.path.join(os.path.dirname(sys.executable), 'res')
else:
resources = os.path.join(os.path.dirname(__file__), 'res')
return os.path.join(resources, 'favicon.gif')
@showerrorbox
def create_ddex(self):
release_window = ProductReleaseWindow(self.frame, self._root_folder, self._batch_id)
release_window.wait_window()
ddex_builder = release_window.create_ddex()
self._ddex_builders.append(ddex_builder)
self.product_list.insert(tk.tkinter.END, ddex_builder.get_upc())
self.remove_button['state'] = 'enabled'
@showerrorbox
def remove_product(self):
selected = self.product_list.curselection()
if(self.product_list.size() == 0 or len(selected) == 0):
return
self.product_list.delete(selected[0])
self._ddex_builders.pop(int(selected[0]))
if(self.product_list.size() == 0):
self.remove_button['state'] = 'disabled'
def __check_for_party(self, party_type):
if(self.party_repository.get_party(party_type) is None):
PartyWindow(self.frame, party_type)
def main(self):
self.product_list.grid(row=0, column=0)
self.add_release_button.grid(row=1, column=0)
self.remove_button.grid(row=2, column=0)
self.button.grid(row=3, column=0)
self.__check_for_party(PartyType.MessageSender)
self.frame.mainloop()
Program().main()