-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.py
2512 lines (2326 loc) · 85.2 KB
/
manager.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
27 May 2019
@autor: Daniel Carrasco
"""
from logging import getLogger, FileHandler, Formatter, DEBUG
from os import path
from modules_local.startfile import open_file as startfile
from io import BytesIO
from tempfile import _get_candidate_names, _get_default_tempdir
from hashlib import sha256, sha512
import base64
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
from cryptography.fernet import Fernet
import sys
import wx
import wx.lib.agw.ribbon as RB
from wx.grid import Grid
from widgets import ShapedButton
from modules import getResourcePath, compressionTools, crypto
from modules_local import (
addComponentWindow,
manageAttachments,
CTreeCtrl,
setDefaultTemplate,
options,
manageTemplates
)
import globals
from plugins.database.sqlite import dbase
from plugins.database.mysql import dbase as MySQL
global rootPath
if getattr(sys, 'frozen', False):
# The application is frozen
rootPath = path.dirname(path.realpath(sys.executable))
else:
# The application is not frozen
# Change this bit to match where you store your data files:
rootPath = path.dirname(path.realpath(__file__))
# Load main data
app = wx.App()
globals.init()
# ID de los botones
ID_CAT_ADD = wx.ID_HIGHEST + 1
ID_CAT_ADDSUB = ID_CAT_ADD + 1
ID_CAT_RENAME = ID_CAT_ADDSUB + 1
ID_CAT_DELETE = ID_CAT_RENAME + 1
ID_CAT_TEM_SET = ID_CAT_DELETE + 1
ID_COM_ADD = ID_CAT_TEM_SET + 1
ID_COM_DEL = ID_COM_ADD + 1
ID_COM_ED = ID_COM_DEL + 1
ID_STOCK_ADD = ID_COM_ED + 1
ID_STOCK_REM = ID_STOCK_ADD + 1
ID_DS_ADD = ID_STOCK_REM + 1
ID_DS_VIEW = ID_DS_ADD + 1
ID_TOOLS_OPTIONS = ID_DS_VIEW + 1
ID_TOOLS_MANAGE_TEMPLATES = ID_TOOLS_OPTIONS + 1
ID_TOOLS_VACUUM = ID_TOOLS_MANAGE_TEMPLATES + 1
########################################################################
########################################################################
########################################################################
class mainWindow(wx.Frame):
# ##=== Exit Function ===## #
def exitGUI(self, event):
if self.IsMaximized():
globals.config["main_window"]["maximized"] = 1
else:
globals.config["main_window"]["maximized"] = 0
if not options.options(self)._save('config.ini', globals.config):
dlg = wx.MessageDialog(
None,
"Ocurrió un error al guardar la configuración.",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
# Avoid slow close by deleting tree items
self.tree.Freeze()
self.Destroy()
def _category_create(self, event):
dlg = wx.TextEntryDialog(
self,
'Nombre de la catergoría',
'Añadir categoría'
)
dlg.SetValue("")
if dlg.ShowModal() == wx.ID_OK:
try:
category_id = self.database_comp.category_add(dlg.GetValue())
if category_id and len(category_id) > 0:
newID = category_id[0]
self.tree.AppendItem(
self.tree_root,
dlg.GetValue(),
image=0,
selImage=1,
data={
"id": newID,
"cat": True,
}
)
self.tree.SortChildren(self.tree_root)
self.log.debug(
"Category {} added correctly".format(dlg.GetValue())
)
return newID
else:
dlg = wx.MessageDialog(
None,
"Error creando la categoría",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return
except Exception as e:
dlg = wx.MessageDialog(
None,
"Error creando la categoría: {}".format(e),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return
dlg.Destroy()
def _subcat_create(self, event):
item = self.tree.GetSelection()
if not item.IsOk():
dlg = wx.MessageDialog(
None,
"Debe seleccionar una categoria",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return
itemName = self.tree.GetItemText(item)
itemData = self.tree.GetItemData(self.tree.GetSelection())
dlg = wx.TextEntryDialog(
self,
'Nombre de la subcatergoría a añadir en "{}"'.format(itemName),
'Añadir subcategoría'
)
if dlg.ShowModal() == wx.ID_OK:
try:
category_id = self.database_comp.category_add(
dlg.GetValue(),
itemData["id"]
)
if category_id:
newID = category_id[0]
self.tree.AppendItem(
self.tree.GetSelection(),
dlg.GetValue(),
image=0,
selImage=1,
data={
"id": newID,
"cat": True,
}
)
self.tree.SortChildren(self.tree.GetSelection())
if not self.tree.IsExpanded(self.tree.GetSelection()):
self.tree.Expand(self.tree.GetSelection())
self.log.debug(
"Subcategory {} added correctly".format(dlg.GetValue())
)
# self._tree_filter()
else:
dlg = wx.MessageDialog(
None,
"Error creando la subcategoría",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return
except Exception as e:
self.log.error(
"There was an error creating the subcategory: {}".format(e)
)
dlg = wx.MessageDialog(
None,
"Error creando la subcategoría: {}".format(e),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return
dlg.Destroy()
def _category_rename(self, event):
itemName = self.tree.GetItemText(self.tree.GetSelection())
itemData = self.tree.GetItemData(self.tree.GetSelection())
dlg = wx.TextEntryDialog(
self,
'Nuevo nombre de la categoría',
'Renombrar categoría'
)
dlg.SetValue(itemName)
if dlg.ShowModal() == wx.ID_OK:
try:
self.database_comp.category_rename(
dlg.GetValue(),
itemData["id"]
)
self.tree.SetItemText(self.tree.GetSelection(), dlg.GetValue())
self.log.debug(
"Category {} renamed to {} correctly".format(
itemName,
dlg.GetValue()
)
)
except Exception as e:
self.log.error(
"Error renaming {} to {}: {}.".format(
itemName,
dlg.GetValue(),
e
)
)
dlg.Destroy()
# self._tree_filter()
def _category_delete(self, event):
itemName = self.tree.GetItemText(self.tree.GetSelection())
itemData = self.tree.GetItemData(self.tree.GetSelection())
if not itemData:
dlg = wx.MessageDialog(
None,
"Debe seleccionar una categoría",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return False
dlg = wx.MessageDialog(
None,
"¿Seguro que desea eliminar la categoría {}?.".format(itemName) +
"\n\nAVISO: Se borrarán todas las subcategorías y componentes" +
" que contiene.",
'Eliminar',
wx.YES_NO | wx.ICON_QUESTION
)
if dlg.ShowModal() == wx.ID_YES:
if self.database_comp.category_delete(itemData["id"]):
self.tree.Delete(self.tree.GetSelection())
self._tree_selection(None)
self.log.debug(
"Category {} deleted correctly".format(itemName)
)
else:
print("There was an error deleting the category")
return
dlg.Destroy()
def _component_add(self, event):
parent = self.tree.GetSelection()
itemData = self.tree.GetItemData(parent)
# If selected is a componente, we use the parent
if not itemData['cat']:
parent = self.tree.GetItemParent(self.tree.GetSelection())
itemData = self.tree.GetItemData(parent)
template = self.database_comp._select(
"Categories",
["Template"],
where=[
{'key': 'ID', 'value': itemData['id']},
]
)
component_frame = addComponentWindow.addComponentWindow(
self,
default_template=template[0][0]
)
component_frame._parentCat = itemData
# component_frame.MakeModal(true);
component_frame.ShowModal()
if component_frame.component_id:
self.tree.AppendItem(
parent,
self.database_comp.component_data(
component_frame.component_id
)['name'],
image=2,
selImage=3,
data={
"id": component_frame.component_id,
"cat": False,
}
)
self.tree.SortChildren(parent)
if not self.tree.IsExpanded(parent):
self.tree.Expand(parent)
elif not component_frame.closed:
self.log.error(
"There was an error creating the component"
)
dlg = wx.MessageDialog(
None,
"Error creando el componente",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return
component_frame.Destroy()
def _component_edit(self, event):
itemData = self.tree.GetItemData(self.tree.GetSelection())
component_frame = addComponentWindow.addComponentWindow(
self,
itemData["id"]
)
component_frame.ShowModal()
if not component_frame.closed:
itemNewName = self.database_comp.component_data(itemData["id"])
self.tree.SetItemText(
self.tree.GetSelection(),
itemNewName['name']
)
if int(itemNewName.get("stock") > 0):
self.tree.SetItemTextColour(self.tree.GetSelection(), wx.Colour(0, 0, 0))
else:
self.tree.SetItemTextColour(self.tree.GetSelection(), wx.Colour(255, 0, 0))
self.tree.SortChildren(self.tree.GetSelection())
if not self.tree.IsExpanded(self.tree.GetSelection()):
self.tree.Expand(self.tree.GetSelection())
self._tree_selection(None)
component_frame.Destroy()
def _component_delete(self, event):
itemName = self.tree.GetItemText(self.tree.GetSelection())
itemData = self.tree.GetItemData(self.tree.GetSelection())
if not itemData:
dlg = wx.MessageDialog(
None,
"Debe seleccionar un componente",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return False
dlg = wx.MessageDialog(
None,
"¿Seguro que desea eliminar el componente {}?.\n\n".format(
itemName
),
'Eliminar',
wx.YES_NO | wx.ICON_QUESTION
)
if dlg.ShowModal() == wx.ID_YES:
try:
if self.database_comp._delete(
"Components",
[
{'key': 'ID', 'value': itemData["id"]}
]
) is not None:
self.log.debug("Commiting changes...")
self.database_comp.conn.commit()
self.tree.Delete(self.tree.GetSelection())
self.log.debug(
"Component id {} deleted correctly".format(
itemData["id"]
)
)
self._tree_selection(None)
else:
self.log.error("There was an error deleting the component")
return
except Exception as e:
self.log.error(
"There was an error deleting the component: {}".format(e)
)
dlg = wx.MessageDialog(
None,
"There was an error deleting the component: {}".format(
itemName
),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
def _set_default_template(self, event):
component_frame = setDefaultTemplate.setDefaultTemplate(self)
component_frame.ShowModal()
def _stock_add(self, event):
item = self.tree.GetSelection()
if not item.IsOk():
self.log.warning("Tree item is not OK")
return
itemData = self.tree.GetItemData(item)
stock = self.database_comp._select(
"Components",
["Stock"],
where=[
{
'key': 'ID',
'value': itemData['id']
},
]
)
while True:
dlg = wx.TextEntryDialog(
self,
'Añadir componentes a añadir',
'Añadir componentes'
)
if dlg.ShowModal() == wx.ID_OK:
try:
added = int(dlg.GetValue())
except Exception as e:
dlg = wx.MessageDialog(
None,
"La entrada indicada no es un número: {}".format(e),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
continue
try:
new_stock = stock[0][0] + added
self.database_comp._update(
"Components",
updates=[
{
'key': 'Stock',
'value': new_stock,
},
],
where=[
{
'key': 'ID',
'value': itemData['id']
},
],
auto_commit=True
)
self.update_data_grid(itemData['id'])
if new_stock > 0:
self.stock_bbar.EnableButton(ID_STOCK_REM, True)
self.tree.SetItemTextColour(item, wx.Colour(0, 0, 0))
dlg = wx.MessageDialog(
None,
"Stock añadido correctamente",
'Correcto',
wx.OK | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
break
except Exception as e:
self.log.error("There was an error addind the stock: {}".format(e))
dlg = wx.MessageDialog(
None,
"Ocurrió un error al añadir el stock: {}".format(e),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
break
else:
break
def _stock_remove(self, event):
item = self.tree.GetSelection()
if not item.IsOk():
self.log.warning("Tree item is not OK")
return
itemData = self.tree.GetItemData(item)
stock = self.database_comp._select(
"Components",
["Stock"],
where=[
{
'key': 'ID',
'value': itemData['id']
},
]
)
while True:
dlg = wx.TextEntryDialog(
self,
'Componentes usados (stock {})'.format(stock[0][0]),
'Quitar componentes'
)
if dlg.ShowModal() == wx.ID_OK:
try:
removed = int(dlg.GetValue())
except Exception as e:
dlg = wx.MessageDialog(
None,
"La entrada indicada no es un número: {}".format(e),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
continue
if removed <= stock[0][0]:
try:
new_stock = stock[0][0] - removed
self.database_comp._update(
"Components",
updates=[
{
'key': 'Stock',
'value': new_stock,
},
],
where=[
{
'key': 'ID',
'value': itemData['id']
},
],
auto_commit=True
)
self.update_data_grid(itemData['id'])
if new_stock == 0:
self.stock_bbar.EnableButton(ID_STOCK_REM, False)
self.tree.SetItemTextColour(item, wx.Colour(255, 0, 0))
dlg = wx.MessageDialog(
None,
"Stock quitado correctamente",
'Correcto',
wx.OK | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
break
except Exception as e:
self.log.error("There was an error removing the stock: {}".format(e))
dlg = wx.MessageDialog(
None,
"Ocurrió un error al quitar el stock: {}".format(e),
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
break
else:
self.log.warning(
"The stock {} is lower than used components {}".format(
stock[0][0],
removed
)
)
dlg = wx.MessageDialog(
None,
"No hay stock suficiente",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
else:
break
def _attachments_manage(self, event):
itemData = self.tree.GetItemData(self.tree.GetSelection())
component_frame = manageAttachments.manageAttachments(
self.database_comp,
self, itemData.get('id')
)
component_frame.ShowModal()
component_frame.Destroy()
self._tree_selection(None)
def _datasheet_view(self, event):
itemData = self.tree.GetItemData(self.tree.GetSelection())
tempFile = self.database_comp.datasheet_view(itemData.get('id'))
if tempFile:
startfile(tempFile)
else:
dlg = wx.MessageDialog(
None,
"Ocurrió un error al abrir el datasheet",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
def _image_add(self, event):
itemData = self.tree.GetItemData(self.tree.GetSelection())
# otherwise ask the user what new file to open
with wx.FileDialog(
self,
"Abrir fichero de imagen",
wildcard="Imágenes (*.jpg, *.jpeg, *.png, *.gif, *.bmp)|" +
"*.jpg;*.jpeg;*.png;*.gif;*.bmp|Todos los ficheros (*.*)|*.*",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST
) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
# Proceed loading the file chosen by the user
size = (
(globals.config["images"]["size"] + 1) * 100,
(globals.config["images"]["size"] + 1) * 100
)
format = wx.BITMAP_TYPE_PNG
if globals.config["images"]["format"] == 0:
format = wx.BITMAP_TYPE_JPEG
elif globals.config["images"]["format"] == 1:
format = wx.BITMAP_TYPE_PNG
elif globals.config["images"]["format"] == 1:
format = wx.BITMAP_TYPE_BMP
elif globals.config["images"]["format"] == 1:
format = wx.BITMAP_TYPE_TIFF
quality = None
if globals.config["images"]["format"] == 0:
quality = globals.config["images"]["jpeg_quality"]
elif globals.config["images"]["format"] == 1:
quality = globals.config["images"]["png_compression"]
image = self.database_comp.image_add(
fileDialog.GetPath(),
size,
itemData.get('id'),
itemData.get('cat'),
format,
quality,
globals.config["images"]["compression"]
)
if image:
self._tree_selection(None)
dlg = wx.MessageDialog(
None,
"Imagen añadida correctamente",
'Añadida',
wx.OK | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
else:
dlg = wx.MessageDialog(
None,
"Ocurrió un error al añadir la imagen",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
def _image_del(self, event):
itemName = self.tree.GetItemText(self.tree.GetSelection())
itemData = self.tree.GetItemData(self.tree.GetSelection())
imageID = self.loaded_images_id[self.actual_image]
if not imageID:
dlg = wx.MessageDialog(
None,
"El item no tiene imagen",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return False
if not itemData:
dlg = wx.MessageDialog(
None,
"Debe seleccionar un item",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
return False
dlg = wx.MessageDialog(
None,
"¿Seguro que desea eliminar la imagen de {}?.\n\n".format(
itemName
),
'Eliminar',
wx.YES_NO | wx.ICON_QUESTION
)
if dlg.ShowModal() == wx.ID_YES:
try:
if self.database_comp.image_del(imageID):
self.log.error("Image deleted sucessfully.")
self._tree_selection(None)
dlg = wx.MessageDialog(
None,
"Imagen eliminada correctamente",
'Borrada',
wx.OK | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
else:
self.log.error("There was an error deleting the image.")
dlg = wx.MessageDialog(
None,
"Ocurrió un error al borrar la imagen",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
except Exception as e:
self.log.error(
"There was an error deleting the image: {}.".format(e)
)
def _image_export(self, event):
with wx.FileDialog(
self,
"Guardar fichero de imagen",
wildcard="Imágenes PNG (*.png)|*.png",
style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT
) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
try:
bitmap = self.image.GetBitmap()
bitmap.SaveFile(fileDialog.GetPath(), wx.BITMAP_TYPE_PNG)
dlg = wx.MessageDialog(
None,
"Imagen guardada correctamente",
'Borrada',
wx.OK | wx.ICON_INFORMATION
)
dlg.ShowModal()
dlg.Destroy()
except Exception as e:
self.log.error(
"There was an error saving the image: {}.".format(e)
)
dlg = wx.MessageDialog(
None,
"Ocurrió un error al exportar la imagen",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
def _image_view(self, event):
bitmap = wx.Bitmap(self.loaded_images[self.actual_image])
tempName = next(_get_candidate_names())
tempFolder = _get_default_tempdir()
fName = path.join(
tempFolder,
tempName +
".png"
)
try:
bitmap.SaveFile(fName, wx.BITMAP_TYPE_PNG)
startfile(fName)
print("done")
except Exception as e:
self.log.error(
"There was an error saving the image: {}.".format(e)
)
dlg = wx.MessageDialog(
None,
"Ocurrió un error al exportar la imagen",
'Error',
wx.OK | wx.ICON_ERROR
)
dlg.ShowModal()
dlg.Destroy()
def _change_image_next(self, event):
self.actual_image += 1
if self.actual_image == 0:
self.button_back.Disable()
else:
self.button_back.Enable()
if self.actual_image == (len(self.loaded_images)-1):
self.button_next.Disable()
else:
self.button_next.Enable()
self._onImageResize(None)
if event:
event.Skip()
def _change_image_back(self, event):
self.actual_image -= 1
if self.actual_image == 0:
self.button_back.Disable()
else:
self.button_back.Enable()
if self.actual_image == (len(self.loaded_images)-1):
self.button_next.Disable()
else:
self.button_next.Enable()
self._onImageResize(None)
if event:
event.Skip()
def update_data_grid(self, id, category=False):
Name = None
Data = {}
# Is a category
if category:
# Getting data
category = self.database_comp._select(
"Categories",
["Name"],
where=[
{
'key': 'ID',
'value': id
},
]
)
parentOfCats = self.database_comp._select(
"Categories",
["COUNT(*)"],
where=[
{
'key': 'Parent',
'value': id
},
]
)
parentOfComp = self.database_comp._select(
"Components",
["COUNT(*)"],
where=[
{
'key': 'Category',
'value': id
},
]
)
# Generating Name and Data
Name = category[0][0]
Data = {
"Subcategorías": parentOfCats[0][0],
"Componentes": parentOfComp[0][0]
}
else:
component_data = self.database_comp.component_data(id)
if not component_data:
self.log.warning(
"There is no component data"
)
Name = (
"Tipo de componente no encontrado. Por favor, "
"verifica si se borró la plantilla."
)
else:
Name = component_data['name']
first = True
Key = ""
Value = ""
for item in component_data['template_data']['fields']:
item_value = component_data['data_real'].get(item['id'], {}).get('value', '--')
if item_value == "":
item_value = '--'
if first:
Key = item['label']
first = False
elif item['field_data'].get('join_previous', 'false').lower() == 'false':
Data.update({
Key: Value
})
Value = ""
Key = item['label']
first = False
else:
if item['field_data']['no_space'].lower() == 'false' and not first:
Value += " "
if item['field_data']['in_name_label'].lower() == 'true':
if item['field_data'].get(
'in_name_label_separator',
'true'
).lower() == 'true':
Value += "{}:".format(item['label'])
else:
Value += "{}".format(item['label'])
if item['field_data'].get(
'no_space',
'false'
).lower() == 'false' and not first:
Value += " "
Value += item_value
Data.update({
Key: Value
})
Data.update({
"Stock": component_data['stock']
})
# No Name
if Name is None:
self.log.warning("There's no name for component id {}".format(id))
return
# Cleanup GRID
if self.textFrame.GetNumberRows() > 1:
self.textFrame.DeleteRows(
1,
self.textFrame.GetNumberRows()-1
)
# Setting data
self.textFrame.SetCellValue(0, 0, Name)
current = 1
for key, value in Data.items():
self.textFrame.InsertRows(-1, 1)
inserted = self.textFrame.GetNumberRows()-1
self.textFrame.SetReadOnly(inserted, 0, True)
self.textFrame.SetReadOnly(inserted, 1, True)
self.textFrame.SetCellValue(inserted, 0, str(key))
self.textFrame.SetCellValue(inserted, 1, str(value))
self.textFrame.SetCellFont(current, 0, self.grid_left_row_font)
self.textFrame.SetCellFont(current, 1, self.grid_right_row_font)
current += 1
self.textFrame.AutoSizeRows(True)
self.OnGridSize(None)
def _toggleHasStock(self, event):
button = event.GetEventObject()
globals.config['general']['only_show_stock'] = str(button.GetValue())
self.tree.Freeze()
self._tree_filter(
filter=self.last_filter
)