-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEschaton.py
1546 lines (1478 loc) · 50.6 KB
/
Eschaton.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
# BY Tizian Pessel
# CONTACT [email protected]
# LICENSE do not distribute
# VER 1
prog_version = "1.0.0"
# DATE 17.07.2015
# http://www.way2python.de/unsortiert/tkwidgetprint.py
import win32ui, win32print, win32con
import Image as Img
import ImageWin, ImageGrab
import MySQLdb as mdb
from Tkinter import *
import random, string
import tkMessageBox
import ConfigParser
import PIL.ImageTk
import tkFileDialog
import PIL.Image
import base64
import hashlib
import shutil
import ftplib
import urllib
import time
import sha
import ttk
import os
def mdb_error(e=False):
if e == False:
pass
eno = str(e).split(",")[0].replace("(", "")
if eno == "2003":
tkMessageBox.showerror(title="CR_CONN_HOST_ERROR",
message="Kann nicht zum MySQL-Server verbinden.")
config_exit()
else:
tkMessageBox.showerror(title="ERROR",
message="Undefinierter MDB Error: "+e)
def config_exit(NONE=[]):
global root, con
if con != "":
con.close()
root.destroy()
os._exit(0)
def db_execute(sql):
global con, cur, settings, account
try:
cur.execute(sql)
except mdb.Error, e:
print "MDB ERROR: ", e
except mdb.Warning, e:
print "MDB WARNING: ", e
if sql.split(" ")[0].upper() != "SHOW":
con.commit()
# Logging
#TODO: Logging ins Rechteabfragesystem einbauen.
def db(action="", arg1=False, arg2=False, arg3=False, arg4=False):
global con, cur, settings, account
if con == "":
try:
con = mdb.connect(settings["db_server"], settings["db_user"], settings["db_password"], settings["db_name"]);
except mdb.Error as e:
mdb_error(e)
cur = con.cursor()
#----
do = action.split("|")[0]
if len(action.split("|")) > 1:
com = action.split("|")[1]
columns = com.split("}")[0].split(" ")
word = com.split("}")[1]
text = " WHERE "
for i in columns:
text = text + " `"+i+"` LIKE '%"+word+"%' OR"
filter = text[:-3]
else:
filter = False
if do == "account_check":
sql = "SELECT `password` FROM `user` WHERE `username`='" + arg1 + "'" #TODO: Passwort verschlüsseln
db_execute(sql)
fetch = cur.fetchall()
if fetch == ():
return False
elif fetch[0][0] == arg2:
return True
else:
return False
elif do == "init_settings":
sql = "SELECT * FROM `settings` WHERE 1"
db_execute(sql)
for i in cur.fetchall():
settings[i[0]] = i[1]
return True
elif do == "get_user_name":
sql = "SELECT `name` FROM `user` WHERE `ID`='" + arg1 + "'"
db_execute(sql)
fetch = cur.fetchone()
if fetch == None:
return ""
else:
return fetch[0]
elif do == "get_user_username":
sql = "SELECT `username` FROM `user` WHERE `ID`='" + arg1 + "'"
db_execute(sql)
return cur.fetchone()[0]
elif do == "get_user_jobs":
roles = db(action="get_user_roles", arg1=arg1)
sql = "SELECT * FROM `jobs` WHERE "
for r in roles:
sql = sql + "`for_ID` LIKE '%{0}%' OR ".format(r)
sql = sql[:-4] + ";"
db_execute(sql)
return cur.fetchall()
elif do == "get_user":
sql = "SELECT * FROM `user` WHERE `username`='" + arg1 + "'"
db_execute(sql)
return cur.fetchone()
elif do == "get_users":
sql = "SELECT `ID`,`username`,`name`,`imagefiletype`,`roles`,`created`,`created_by`, `usergroup` FROM `user`"
if filter == False:
db_execute(sql)
return cur.fetchall()
else:
sql = sql + filter
db_execute(sql)
return cur.fetchall()
elif do == "get_user_id":
sql = "SELECT `ID` FROM `user` WHERE `username`='" + arg1 + "'"
db_execute(sql)
return cur.fetchone()[0]
elif do == "get_roles_name":
sql = "SELECT `rolename` FROM `roles` WHERE `ID`='" + arg1 + "'"
db_execute(sql)
return cur.fetchone()
elif do == "get_roles":
sql = "SELECT * FROM `roles` WHERE 1"
db_execute(sql)
return cur.fetchall()
elif do == "get_user_roles":
sql = "SELECT `roles` FROM `user` WHERE `ID`='" + arg1 + "'"
db_execute(sql)
return cur.fetchall()[0][0].replace(" ", "").split(",")
elif do == "get_user_image":
sql = "SELECT `image`,`imagefiletype` FROM `user` WHERE `ID`='{0}'".format(arg1)
db_execute(sql)
image = cur.fetchone()
if image[0] == "":# Keine Datei in der DB
return "./images/noavatar.png"
file = "{0}.{1}".format(image[0], image[1])
if os.path.isfile(file) == True:# Datei bereits geladen
return "./images/cache/{0}".format(file)
else: #Datei laden
ftp_download(image)
return "./images/cache/{0}".format(file)
elif do == "get_nodes":
sql = "SELECT `ID`, `name`,`adress`,`created`,`created_by`,`image`,`imagefiletype` FROM `nodes` WHERE 1;"
db_execute(sql)
return cur.fetchall()
# SET section
elif do == "set_image":
max = {"user":(160, 160),
"nodes":(300, 200)}
arg1 = make_thumnail(arg1, (max[arg3][0], max[arg3][1]))
hash, mime = ftp_upload(arg1)
sql = "UPDATE `{3}` SET `image`='{0}', `imagefiletype`='{1}' WHERE `ID`='{2}'".format(hash, mime, arg2, arg3)
db_execute(sql)
elif do == "set_user_username":
sql = "UPDATE `user` SET `username`='{0}' WHERE `ID`='{1}'".format(arg1, arg2)
db_execute(sql)
if arg2 == account[0]: #Logout bei ändern von eigenen Daten!
tkMessageBox.showinfo(title="Hinweis", message="Änderung erfolgreich!\nAus Sicherheitsgründen werden Sie jetzt ausgeloggt!")
account_logout()
return cur.fetchone()
elif do == "set_user_password" or do == "set_user_passwort":
sql = "UPDATE `user` SET `password`='{0}' WHERE `ID`='{1}'".format(arg1, arg2)
db_execute(sql)
if arg2 == account[0]: #Logout bei ändern von eigenen Daten!
tkMessageBox.showinfo(title="Hinweis", message="Änderung erfolgreich!\nAus Sicherheitsgründen werden Sie jetzt ausgeloggt!")
account_logout()
return cur.fetchone()
elif do == "set_user_name":
sql = "UPDATE `user` SET `name`='{0}' WHERE `ID`='{1}'".format(arg1, arg2)
db_execute(sql)
if arg2 == account[0]:
tkMessageBox.showinfo(title="Hinweis", message="Änderung erfolgreich!\nAus Sicherheitsgründen werden Sie jetzt ausgeloggt!")
account_logout()
return cur.fetchone()
elif do == "set_user_roles":
if len(arg1) > 0:
sql = "UPDATE `user` SET `roles`='"
for i in arg1:
sql = sql + i + ", "
sql = sql[:-2] + "' WHERE `ID`='{0}'".format(arg2)
else:
sql = "UPDATE `user` SET `roles`='' WHERE `ID`='{0}'".format(arg2)
db_execute(sql)
if arg2 == account[0]: #Logout bei ändern von eigenen Daten!
tkMessageBox.showinfo(title="Hinweis", message="Änderung erfolgreich!\nAus Sicherheitsgründen werden Sie jetzt ausgeloggt!")
account_logout()
return cur.fetchone()
elif do == "set_job_mark":
sql = "SELECT `done` FROM `jobs` WHERE `ID`='{0}';".format(arg1)
db_execute(sql)
sql = "UPDATE `jobs` SET `done` = '{0}' WHERE `ID` = '{1}';".format("0" if int(cur.fetchone()[0]) == 1 else "1", arg1)
db_execute(sql)
# INSERT section
elif do == "insert_user":
sql = "INSERT INTO `user` (`ID`, `username`, `password`, `name`, `image`, `imagefiletype`, `roles`, `created`, `created_by`) VALUES (NULL, '{username}', '{pw}', '{name}', NULL, '', '', CURRENT_TIMESTAMP, '{by}');".format(**arg1)
db_execute(sql)
return
elif do == "insert_job":
sql = "INSERT INTO `eschaton`.`jobs` (`ID`, `name`, `description`, `priority`, `for_ID`, `done`, `created`, `created_by`) VALUES (NULL, '{name}', '{desc}', '{prio}', '{for}', '0', CURRENT_TIMESTAMP, '{by}');".format(**arg1)
db_execute(sql)
return
# DELETE section
elif do == "delete_user":
sql = "INSERT INTO `user_deleted` SELECT*, CURRENT_TIME(), '{0}' FROM `user` WHERE `ID`='{1}'".format(account[0], arg1)
db_execute(sql)
sql = "DELETE FROM `user` WHERE `ID`='{0}';".format(arg1)
db_execute(sql)
if arg1 == account[0]: #Logout bei ändern von eigenen Daten!
tkMessageBox.showinfo(title="Hinweis", message="Änderung erfolgreich!\nAus Sicherheitsgründen werden Sie jetzt ausgeloggt!")
account_logout()
return
elif do == "delete_job":
sql = "INSERT INTO `jobs_deleted` SELECT*, CURRENT_TIME(), '{0}' FROM `jobs` WHERE `ID`='{1}'".format(account[0], arg1)
db_execute(sql)
sql = "DELETE FROM `jobs` WHERE `ID`='{0}';".format(arg1)
db_execute(sql)
return
elif do == "delete_user_image":
sql = "UPDATE `user` SET `image`='', `imagefiletype`='' WHERE `ID`='{0}'".format(arg1)
db_execute(sql)
return
else:
return
def ftp_upload(file):
#ftp Create and Login
ftp = ftplib.FTP("192.168.3.47")
ftp.login("eschaton", "test123")
#file
mime = os.path.splitext(file)[1].replace(".", "")
f = open(file, "rb")
#gethash
hash = hashlib.sha224(f.read()).hexdigest()
#file
f.close()
f = open(file, "rb")
#upload
ftp.storbinary("STOR {0}".format(hash), f, 1024)
f.close()
return hash, mime
def ftp_download(file):
if type(file) == vartype["str"]:
file = file.split(".")
#file=[filename, filetype]
#ftp Create and Login
ftp = ftplib.FTP("192.168.3.47")
ftp.login("eschaton", "test123")
#file
f = open("./images/cache/{0}.{1}".format(file[0], file[1]), "wb")
#download
ftp.retrbinary("RETR {0}".format(file[0]), f.write)
f.close()
return
def clear_cache():
shutil.rmtree("./images/cache", ignore_errors=True)
os.makedirs("./images/cache")
def make_thumnail(infile, size):
#Workaround, weil das fileobject von Image nicht geschlossen wird
#temp_file = "./images/cache/{0}.cache".format(str(int(time.time())))
outfile = "./images/cache/temp.jpg"
if infile != outfile:
im = Img.open(infile)
im.thumbnail(size, Img.ANTIALIAS)
im.save(outfile, "JPEG")
#
#
f = open(outfile, "rb")
hash = hashlib.sha224(f.read()).hexdigest()
newname = outfile.replace("temp", hash)
f.close()
if os.path.isfile(newname) == True:# Datei bereits vorhanden
os.remove(newname)
os.rename(outfile, newname)
return newname
def account_login(NONE=[]):
global account, objects
if db(action="account_check", arg1=objects[2].get(), arg2=objects[3].get()) == True:
id = str(db(action="get_user_id", arg1=objects[2].get()))
user_name = db(action="get_user_name", arg1=id)
account = [id, objects[2].get(), user_name]
root.title("Eschaton Client - {0}".format(user_name))
tab_open_login()
elif objects[2].get() == "" and objects[3].get() == "":
pass
else:
tkMessageBox.showerror(title="Login Fehler", message="Kein Account konnte diesem Passwort zugeordnet werden.\nBitte überprüfen Sie Ihre Eingaben.")
def account_logout(NONE=[]):
global account, objects
account = [0, "", "", ""]
tab_open_login()
root.title("Eschaton Client - Kein Benutzer")
tkMessageBox.showinfo(title="Logout", message="Sie wurden erfolgreich ausgeloggt!")
def init_vars():
global tab_buttons, frames, geo, pad, tab_button_names, objects, active_tab, active_tab_widget, active_tab_name, con, account, tag, settings, vartype
tab_button_names = [
"Aufträge",
"Lager",
"Produkte",
"Standorte",
"Mitarbeiter",
"Einstellungen",
"Login"
]
objects = []
active_tab = -1
active_tab_widget = None
active_tab_name = ""
# id, username, readable_name
account = [0, "", "", ""]
con = ""
tag = {}
init_settings()
#System
vartype = {"str":"",
"tuple":(0, 1),
"list":[],
"int":0,
"float":1.0,
"bool":True}
def init_settings():
global settings
settings = {
"db_server":"192.168.3.47",
"db_user":"root",
"db_password":"test123",
"db_name":"eschaton",
"node_id":1,
"sql_log_UPDATE":"0",
"sql_log_INSERT":"0",
"sql_log_DELETE":"0",
"sql_log_SHOW":"0",
"bg_color":"#FFFFFF",
"bg_color_button":"#999999",
"bg_color_list":"#AEAEAE",
}
def init_window():
global tab_buttons, frames, c, geo, settings, root, style
#Styles
style = ttk.Style()
style.configure('TFrame', background=settings["bg_color"], relief="groove", borderwidth=5)
style.configure('TLabelframe', background=settings["bg_color"], relief="raised", borderwidth=50)
style.configure('TLabelframe.Label', background=settings["bg_color"], foreground="#000000")
style.configure('TButton', relief="flat", borderwidth=0,
background="#FFFFFF",
activebackground="#FF0000",
foreground="#00FF00",
highlightbackground="#0000FF",
highlightcolor="#F00F0F",
overrelief="sunken"
)
root.configure(bg=settings["bg_color"])
main_frame.config(bg=settings["bg_color"])
button_frame.config(bg=settings["bg_color"])
query_frame.config(bg=settings["bg_color"])
for i in frames.keys():
frames[i].config(bg=settings["bg_color"])
hub.select(len(tab_button_names)-1) #Call Login Tab
change_tab()
def destroy_objects(classes=["all"], object=None):
global objects, tag, frames
if object != None:
object.destroy()
objects.pop(objects.index(object))
tag.pop(object)
for i in tag.keys():
if tag[i] == object:
tag.pop(i)
return
for j in classes:
if j == "all":
for i in objects:
i.destroy()
objects = []
tag = {}
if j == "mitarbeiter_treeview_entry":
try:
object = tag["mitarbeiter_edit_entry"]
object.destroy()
objects.pop(objects.index(object))
tag.pop(object)
for i in tag.keys():
if tag[i] == object:
tag.pop(i)
except:
pass
def treeview(instance=False, action=False, options=False):
global settings, objects, tag, global_treeview_instance
if instance == False and action != "create":
print "Treeview(): Keine Instanz übergeben!"
return
if action == False:
print "Treeview(): Keine Aktion übergeben!"
return
if options == False:
print "Treeview(): Keine Optionen übergeben!"
return
o = options.copy()
#---
if action == "create":
#Create Instance
cols = []
for i in o["columns"]:
cols.append(i[0])
if cols[0] != "#0" and cols[0] != "":
print "Treeview(): Erste Spalte ist nicht als '#0' definiert!"
cols_rest = cols
cols_rest.pop(0)
if o.has_key("selectmode") == True: #extended, browse, none
sel = o["selectmode"]
else:
sel = "browse"
tree = ttk.Treeview(o["parent"], height=o["height"], columns=(cols_rest), selectmode=sel)
#Setting Columns
for i in o["columns"]:
tree.column(i[0], width=i[1])
tree.heading(i[0], text=i[2])
#Inserting Rows
n = 0
tree.tag_configure(0, background=settings["bg_color_list"])
tree.tag_configure(1, background=settings["bg_color"])
tree.tag_configure("no_edit", background="#FFFFFF", foreground=settings["bg_color_button"])
tree.tag_configure("fg_red", foreground="#ee9090")
tree.tag_configure("fg_green", foreground="#008844")
for i in o["rows"]:
if i[0] == "":
iid = str(i[1])
level = "parent"
else:
iid = None
level = "child"
vals = []
first = 1
for j in i[2]:
if first == 1:
first = 0
continue
vals.append(j)
vals = tuple(vals)
if len(i) > 4:
op = i[4]
else:
op = True
if iid != None:
op = False
#Tagging
taggs = []
if level == "parent":
taggs.append(n)
if n == 0:
n = 1
else:
n = 0
if len(i) > 3:
for k in i[3]:
taggs.append(k)
taggs = tuple(taggs)
if len(i) > 5:
tree.insert(str(i[0]), "end", iid, text=i[2][0], values=vals, tags=taggs, open=op, image=i[5])
else:
tree.insert(str(i[0]), "end", iid, text=i[2][0], values=vals, tags=taggs, open=op)
#Placing
if o["manager"] == "grid":
if o.has_key("row") == False:
o.update({"row":1})
if o.has_key("column") == False:
o.update({"column":1})
if o.has_key("columnspan") == False:
o.update({"columnspan":1})
if o.has_key("sticky") == False:
o.update({"sticky":"NESW"})
tree.grid(row=o["row"], column=o["column"], padx=4, pady=2, columnspan=o["columnspan"], sticky=o["sticky"])
elif o["manager"] == "place":
if o.has_key("x") == False:
print "Treeview(): Als Manager wurde 'place' gewählt. Schlüssel 'x' wurde nicht übergeben!"
return
if o.has_key("y") == False:
print "Treeview(): Als Manager wurde 'place' gewählt. Schlüssel 'y' wurde nicht übergeben!"
return
tree.place(x=o["x"], y=o["y"])
else:
tree.pack()
#Filter
if o["filter"] == True:
if o.has_key("query_count") == False:
print "Treeview(): Ein Filter wurde gewählt. Schlüssel 'query_count' wurde nicht übergeben!"
return
e = Entry(query_frame)
e.grid(row=1, column=1, padx=4, pady=2, columnspan=1, sticky="W")
objects.append(e)
tag.update({"filter":e})
b = Button(query_frame, padx=4, pady=2, text="Filtern", command=lambda: button_press(id="treeview_filter"))
b.grid(row=1, column=2, padx=4, pady=2, columnspan=1, sticky="W")
objects.append(b)
s = ttk.Separator(query_frame,orient=VERTICAL)
s.grid(row=1, column=3, padx=4, pady=2, columnspan=1, sticky="W")
objects.append(s)
l = Label(query_frame, bg=settings["bg_color"], padx=4, pady=2, text="Ergebnisse: "+str(o["query_count"]))
l.grid(row=1, column=4, padx=4, pady=2, columnspan=1, sticky="W")
objects.append(l)
#Binds
tree.bind("<Delete>", treeview_key_event_delete)
#
objects.append(tree)
global_treeview_instance = tree
return tree
def action_buttons(action=False, functions=False):
global objects, settings, actionbutton
if action == False:
return
if action == "create":
actionbutton = {}
# Standartbuttons
if functions == False:
functions = "AD"
#Bilder
act_buttons = {
"img_file_add":"./images/plus.png",
"img_file_rem":"./images/bin.png",
"img_file_edit":"./images/pencil.png",
"img_file_prin":"./images/printer.png",
"img_file_mark":"./images/checkmark.png",
"img_file_none":"./images/info.png"}
n = 0
for i in functions:
i = i.upper()
type = "none"
n = n + 1
if i == "A":
type = "add"
if i == "R" or i == "D":
type = "rem"
if i == "P":
type = "prin"
if i == "M" or i == "F":
type = "mark"
if i == "E":
type = "edit"
if i == "S":
sep = ttk.Separator(button_frame, orient=VERTICAL)
sep.grid(row=2, column=n, padx=0, pady=0, sticky="NS")
objects.append(sep)
continue
root.update()
image = PIL.ImageTk.PhotoImage(PIL.Image.open(act_buttons["img_file_{0}".format(type)]))
but = Button(button_frame, image=image, bg=settings["bg_color"], text="action_{0}".format(type), relief=FLAT, width=80, height=45)
but.image = image
but.grid(row=2, column=n, padx=0, pady=0, sticky="NW")
objects.append(but)
actionbutton[type] = but
del but
return
def treeview_get_selection_info(event=False): #TODO: IndexError wenn man auf bereits vorhandenes entry klickt
global tree
if event == False:
dict = {
"id":tree.selection()[0],
"text":tree.item(tree.selection()[0])["values"][0],
"rowname":str(tree.item(tree.selection()[0])["text"]).split(":")[0].lower(),
"index":tree.index(tree.selection()[0]),
"parent":tree.parent(tree.selection()[0])} if len(tree.selection()) != 0 else False
elif event == "Mitarbeiter":
dict = {
"id":tree.selection()[0],} if len(tree.selection()) != 0 else False
else:
dict = {
"id":tree.selection()[0],
"row":tree.identify_row(event.y),
"column":tree.identify_column(event.x),
"x":tree.bbox(tree.identify_row(event.y), tree.identify_column(event.x))[0],
"y":tree.bbox(tree.identify_row(event.y), tree.identify_column(event.x))[1],
"width":tree.bbox(tree.identify_row(event.y),tree.identify_column(event.x))[2],
"text":tree.item(tree.selection()[0])["values"][0],
"rowname":str(tree.item(tree.selection()[0])["text"]).split(":")[0].lower(),
"index":tree.index(tree.selection()[0]),
"parent":tree.parent(tree.selection()[0])} if len(tree.selection()) != 0 else False
return dict
def entry_popup_button_image():
global popup, popup_objects
filepath = tkFileDialog.askopenfilename(parent=popup, filetypes=[("JPEG", ".jpg"), ("PNG", ".png"), ("GIF", ".gif")])
if filepath != False:
dateiname = filepath.split("/")[len(filepath.split("/"))-1]
for i in popup_objects.keys():
if i.split("_")[0] == "imagebutton":
popup_objects[i].config(text=dateiname)
popup_objects.update({"file_"+i.split("_")[1]:filepath})
def entry_popup_return(event):
global popup_objects, popup_results, account, popup
for i in popup_objects.keys():
if i.split("_")[0] == "entry":
popup_results.update({i.split("_")[1]:popup_objects[i].get()})
elif i.split("_")[0] == "text":
popup_results.update({i.split("_")[1]:popup_objects[i].get("1.0", END)})
elif i.split("_")[0] == "file":
if type(popup_objects[i]) != type(False):
f = str(mdb.escape_string(open(popup_objects[i], "rb").read()))
popup_results.update({i.split("_")[1]:popup_objects[i]})
if i.split("_")[0] == "number":
popup_results.update({i.split("_")[1]:popup_objects[i].get()})
else:
pass
popup_results.update({"by":str(account[0])})
#
if tab_button_names[active_tab] == "Mitarbeiter":
if popup_results["username"] != "" and popup_results["pw"] != "" and popup_results["name"] != "":
db(action="insert_user", arg1=popup_results)
if popup_results["photo"] != "":
userid = db(action="get_user", arg1=popup_results["username"])[0]
db(action="set_image", arg1=popup_results["photo"], arg2=userid, arg3="user")
pass
else:
tkMessageBox.showerror(title="Fehler", message="Bitte füllen sie alle Angaben aus, die mit * gekennzeichnet sind!")
popup.focus()
return
tab_open_mitarbeiter()
elif tab_button_names[active_tab] == "Aufträge":
if popup_results["name"] != "" and popup_results["prio"] != "" and popup_results["for"] != "":
db(action="insert_job", arg1=popup_results)
else:
tkMessageBox.showerror(title="Fehler", message="Bitte füllen sie alle Angaben aus, die mit * gekennzeichnet sind!")
popup.focus()
return
tab_open_auftraege()
popup.destroy()
return
def entry_popup_esc(event):
global popup
text = "Sind Sie sicher, dass Sie das Fenster schließen möchten?\nAlle nicht gespeicherten Änderungen gehen verloren!"
if tkMessageBox.askyesno(title="Bitte bestätigen!", message=text) == True:
popup.destroy()
def entry_popup(options=False):
global settings, popup, root, popup_objects, popup_results
if options == False:
return popup_results
else:
o = options.copy()
popup_objects = {}
popup_results = {}
#Toplevel window
popup = Toplevel()
popup.title("Eingabe")
fpopup = Frame(popup, width=popup.winfo_width(), height=popup.winfo_height(), bg=settings["bg_color"])
fpopup.pack()
# Elements
for i in o.keys():
if i.split("_")[0] != "type":
if o.has_key("type_"+i) == False:
o.update({"type_"+i:"normal"})
n = 0
first = 0
for i in o.keys():
if i.split("_")[0] != "type" and i.split("_")[0] != "option":
n = n + 1
lab = Label(fpopup, bg=settings["bg_color"], text=o[i]+":")
lab.grid(row=n, column=1, padx=20, pady=5, sticky="NW")
#
if o["type_"+i] == "password":
e = Entry(fpopup, show="*", width=30)
popup_objects.update({"entry_"+i:e})
elif o["type_"+i] == "big":
e = Text(fpopup, height=4, width=30, relief=SUNKEN)
popup_objects.update({"text_"+i:e})
elif o["type_"+i] == "image":
e = Button(fpopup, text="Datei", command=entry_popup_button_image, bg=settings["bg_color"])
popup_objects.update({"imagebutton_"+i:e})
popup_objects.update({"file_"+i:False})
elif o["type_"+i] == "slider":
option = o["option_"+i].split("-")
e = Scale(fpopup, from_=option[0], to=option[1], orient=HORIZONTAL,
bg=settings["bg_color"], #weiß
troughcolor=settings["bg_color_list"], #grau
activebackground=settings["bg_color_button"], #grau
highlightbackground=settings["bg_color"], #weiß
)
popup_objects.update({"number_"+i:e})
else:
e = Entry(fpopup, width=30)
popup_objects.update({"entry_"+i:e})
e.grid(row=n, column=2, padx=20, pady=5, sticky="NW")
if first == 0:
e.focus()
first = 1
but = Button(fpopup, text=" Fertig ", command=lambda: entry_popup_return(event=False))
but.grid(row=n+1, column=3, padx=20, pady=5, sticky="NW")
hin = Label(fpopup, bg=settings["bg_color"], text="mit * gekennzeichnete Felder müssen ausgefüllt werden", fg=settings["bg_color_list"])
hin.grid(row=n+1, column=1, padx=20, pady=5, columnspan=2, sticky="NW")
#----------------------------
#popup.bind("<Return>", entry_popup_return)
popup.bind("<Escape>", entry_popup_esc)
popup.grab_set()
popup.mainloop()
def role_popup_refresh_lb():
global popup, lb_server, lb_account, popup_id
lb_server.delete(0, END)
lb_account.delete(0, END)
result = db(action="get_user_roles", arg1=popup_id)
notempty = False
if len(result) > 0 and result[0] != "":
notempty = True
for i in result:
lb_account.insert(END, "["+i+"] "+db(action="get_roles_name", arg1=i)[0])
#
result2 = db(action="get_roles")
cont = False
for i in result2:
if notempty == True:
for j in result:
if i[1] == db(action="get_roles_name", arg1=j)[0]:
cont = True
if cont == True:
cont = False
continue
lb_server.insert(END, "["+str(i[0])+"] "+i[1])
def role_popup_exit(event=None):
global popup
popup.destroy()
if tab_button_names[active_tab] == "Mitarbeiter":
tab_open_mitarbeiter()
def role_popup_action(event=None):
global popup, lb_server, lb_account, popup_id
if event == None:
return
#
if event == "left":
if len(lb_account.curselection()) == 1:
result = db(action="get_user_roles", arg1=popup_id)
sel = lb_account.get(lb_account.curselection()).split(" ")[0].replace("[", "").replace("]", "")
try:
result.pop(result.index(sel))
except ValueError:
pass
db(action="set_user_roles", arg1=result, arg2=popup_id)
elif event == "right":
if len(lb_server.curselection()) == 1:
result = db(action="get_user_roles", arg1=popup_id)
sel = lb_server.get(lb_server.curselection()).split(" ")[0].replace("[", "").replace("]", "")
result.append(sel)
while True:
try:
result.pop(result.index(""))
except ValueError:
break
db(action="set_user_roles", arg1=result, arg2=popup_id)
elif event == "ok":
role_popup_exit()
if event != "ok":
role_popup_refresh_lb()
def role_popup_button_1(event):
global popup, lb_server, lb_account
if event.widget == lb_server:
role_popup_action(event="right")
elif event.widget == lb_account:
role_popup_action(event="left")
def role_popup(id):
global account, popup, listbox, settings, lb_server, lb_account, popup_id
popup_id = id
#Toplevel Window
popup = Tk()
popup.protocol("WM_DELETE_WINDOW", role_popup_exit)
popup.title("Rolleneditor")
fpopup = Frame(popup, width=popup.winfo_width(), height=popup.winfo_height(), bg=settings["bg_color"])
fpopup.pack()
#Content
lb_server = Listbox(fpopup, selectmode=SINGLE)
lb_account = Listbox(fpopup, selectmode=SINGLE)
left = Button(fpopup, text="<--", command=lambda: role_popup_action(event="left"))
right = Button(fpopup, text="-->", command=lambda: role_popup_action(event="right"))
ok = Button(fpopup, text="Ok", command=lambda: role_popup_action(event="ok"))
lab = Label(fpopup, bg=settings["bg_color"], text=db(action="get_user_username", arg1=popup_id))
sep = ttk.Separator(fpopup,orient=HORIZONTAL)
lab2 = Label(fpopup, bg=settings["bg_color"], text="Achtung! Änderungen werden sofort übernommen.", fg=settings["bg_color_list"])
#
lb_server.grid(row=3, column=1, padx=20, pady=5, sticky="NESW", rowspan=4)
lb_account.grid(row=3, column=3, padx=20, pady=5, sticky="NESW", rowspan=4)
left.grid(row=4, column=2, padx=20, pady=5, sticky="EW")
right.grid(row=3, column=2, padx=20, pady=5, sticky="EW")
ok.grid(row=8, column=3, padx=20, pady=5, sticky="EW")
lab.grid(row=2, column=3, padx=20, pady=5, sticky="NESW")
sep.grid(row=7, column=1, padx=20, pady=5, sticky="NS")
lab2.grid(row=1, column=1, padx=20, pady=5, sticky="NW", columnspan=3)
# LB Contents
role_popup_refresh_lb()
#Main
lb_server.bind("<Double-Button-1>", role_popup_button_1)
lb_server.bind("<Return>", role_popup_button_1)
lb_account.bind("<Double-Button-1>", role_popup_button_1)
lb_account.bind("<Return>", role_popup_button_1)
popup.bind("<F5>", lambda: role_popup_action(event="refresh"))
popup.mainloop()
def detail_frame(options=False):
global detail_frame_object, detail_frame_data, objects
if options == False:
detail_frame_object.destroy()
detail_frame_object = None
detail_frame_data = {}
return True
else:
if "detail_frame_data" in globals():
pass
else:
detail_frame_data = {}
if len(detail_frame_data) == 0:
detail_frame_data = {
"width":512,
"height":614,
"row":1,
"column":1
}
for i in options.keys():
detail_frame_data.update({i:options[i]})
dfd = detail_frame_data.copy()
# Frame
detail_frame_object = ttk.Labelframe(active_tab_widget, width=dfd["width"], height=dfd["height"], text=" Details ")
detail_frame_object.grid(column=dfd["column"], row=dfd["row"])
detail_frame_object.grid_propagate(False)
#Elements
row = 0
keys = sorted(dfd.keys())
for key in keys:
if key.split("_")[0] == "field":
if dfd[key][0] == "label":
dfd[key+"__title"] = Label(detail_frame_object, text=dfd[key][1]+":", font="Arial 14", background='#FFFFFF')
dfd[key+"__title"].grid(row=row+1, column=1, padx=10, pady=5, columnspan=2, sticky="NW")
dfd[key+"__content"] = Label(detail_frame_object, text=dfd[key][2], font="Arial 10", background='#FFFFFF')
dfd[key+"__content"].grid(row=row+2, column=1, padx=10, pady=5, columnspan=2, sticky="NW")
row = row + 2
elif dfd[key][0] == "title":
dfd[key+"__title"] = Label(detail_frame_object, text=dfd[key][1], font="Arial 14", background='#FFFFFF')
dfd[key+"__title"].grid(row=row+1, column=1, padx=10, pady=5, columnspan=2, sticky="NW")
row = row + 1
elif dfd[key][0] == "list":
if dfd.has_key(key+"__listcount") == False:
dfd[key+"__listcount"] = 0
item_key = key+"__item_"+str(dfd[key+"__listcount"])
dfd[item_key+"_0"] = Label(detail_frame_object, text=dfd[key][1]+":", font="Arial 10", background='#FFFFFF')
dfd[item_key+"_1"] = Label(detail_frame_object, text=dfd[key][2], font="Arial 10", background='#FFFFFF')
dfd[item_key+"_0"].grid(row=row+1, column=1, padx=10, pady=5, columnspan=1, sticky="NW")
dfd[item_key+"_1"].grid(row=row+1, column=2, padx=10, pady=5, columnspan=1, sticky="NW")
row = row + 1
else:
print "detail_frame_object(): Unknown fieldtype >{0}<".format(dfd[key][0])
objects.append(detail_frame_object)
def print_widget__grabwidget(widget):
# grabs widget and stores it as a file
x = widget.winfo_rootx()
y = widget.winfo_rooty()
w = widget.winfo_width()
h = widget.winfo_height()
return ImageGrab.grab((x, y, x+w, y+h))
def print_widget(widget):
widget.update()
widget.update_idletasks()
image = print_widget__grabwidget(widget)
image.save("./images/tmp.bmp")
# Creates a Dib instance from grabbed file
im = Img.open("./images./tmp.bmp")
dib = ImageWin.Dib('RGB',im.size)
dib.paste(im,None)
imagesize = (im.size[0]*10, im.size[1]*10)
# Sends the dib to the windows standard printer
printer = win32print.GetDefaultPrinter()
tkMessageBox.showinfo(title="Druckvorgang eingereiht!",
message="Der Auftrag wurde an den Drucker '{0}' gesendet!".format(printer))
phandle = win32print.OpenPrinter(printer)
dc = win32ui.CreateDC()
dc.CreatePrinterDC()
dc.StartDoc(im.filename)
dc.StartPage()
dib.draw(dc.GetHandleAttrib(), (0, 0) + imagesize) # output size can be changed
dc.EndPage() # by modifying the im.size tuple
dc.EndDoc()
win32print.ClosePrinter(phandle)
del dc
del im
os.unlink("./images/tmp.bmp")
def tfi(type=False, data=False):
if type == "M.roles":
roles = []
for i in data.split(","):
for j in i.split(" "):
if len(j) > 0:
roles.append(j[0])
text=""
for i in roles:
rolename = db(action="get_roles_name", arg1=i)
if rolename == None:
continue
text = text + rolename[0] + ", "
text = text[:-2]
elif type == "S.user":
text = db(action="get_user_username", arg1=str(data))
else:
return ""
return text
def button(event):
pass
def button_press(id=False, arg=""):
global objects, tag
#
if id == 1:
account_login()
elif id == 2:
account_logout()
elif id == "treeview_filter":
if tab_button_names[active_tab] == "Mitarbeiter":
text = tag["filter"].get()
tab_open_mitarbeiter(db_request="get_users|username name ID imagefiletype created created_by}{0}".format(text))
elif id == "action_add":
if tab_button_names[active_tab] == "Mitarbeiter":
dict = {
"username":"Benutzername*",
"name":"Name*",
"pw":"Passwort*",
"photo":"Foto",
"type_pw":"password",
"type_photo":"image",}
entry_popup(options=dict)
elif tab_button_names[active_tab] == "Aufträge":
dict = {
"name":"Name*",
"desc":"Beschreibung*",
"prio":"Priorität",
"for":"Für",
"type_desc":"big",
"type_for":"pick_group",
"type_prio":"slider",
"option_prio":"1-10"}
entry_popup(options=dict)
elif id == "action_rem":
if tab_button_names[active_tab] == "Mitarbeiter":
sel = treeview_get_selection_info()
if sel == False:
return
if sel["parent"] == "":
if tkMessageBox.askyesno(title="Bitte bestätigen", message="Wollen Sie sicher die ausgewählten Elemente unwiederruflich löschen?") == True:
db(action="delete_user", arg1=sel["id"])
if account[0] != 0:
tab_open_mitarbeiter()
else:
if sel["rowname"] == "bild":
db(action="delete_user_image", arg1=account[0])
tree.item(sel["id"], values=("Nein", ""))
elif tab_button_names[active_tab] == "Aufträge":
if job != False:
ask = tkMessageBox.askyesnocancel(title="Wirklich Löschen?",
message="Möchten Sie den Auftrag mit der id: '{0}' endgültig löschen?".format(job))
if ask == True: