-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·5117 lines (4106 loc) · 228 KB
/
main.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/python
# -*- coding: UTF-8 -*-
# Import general libraries.
import sys, os, uuid, shutil, time, math, tempfile, logging, datetime, gc, json
import xml.etree.cElementTree as ET
import geodaisy.converters as convert
import gphoto2 as gp
from os.path import expanduser
# Import PyQt5 libraries for generating the GUI application.
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtCore import QThread, pyqtSignal
#from PyQt5.QtWebKit import *
#from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWebEngine import *
from PyQt5.QtNetwork import *
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
# Import GIS libraries for showing geographic data.
import numpy as np
# Import DB libraries
import sqlite3 as sqlite
from sqlite3 import Error as dbError
# Import general operations.
import modules.camera as camera
import modules.general as general
import modules.features as features
import modules.media as sop_media
import modules.error as error
import modules.setupMainUi as setupMainUi
import modules.setupMainSkin as setupMainSkin
import modules.imageProcessing as imageProcessing
import modules.writeHtml as htmlWriter
import modules.geospatial as geospatial
import modules.flickr_upload as flickr
# Import GUI window.
import dialog.mainWindow as mainWindow
import dialog.configuration as configurationDialog
import dialog.consolidation as consolidationDialog
import dialog.material as materialDialog
import dialog.checkTetheredImage as checkTetheredImageDialog
import dialog.recordWithPhoto as recordWithPhotoDiaolog
import dialog.fileInformation as fileInformationDialog
import dialog.fileToObjects as fileToObjectsDialog
import dialog.textEditWithPhoto as textEditWithPhoto
import dialog.cameraSelect as cameraSelectDialog
import dialog.flickr as flickrDialog
# Import libraries for sound recording.
import queue
import sounddevice as sd
import soundfile as sf
# Labels for Consolidation and Material
LAB_CON = u"統合体"
LAB_MAT = u"資料"
# Connected devices.
CUR_CAM = None
class mainPanel(QMainWindow, mainWindow.Ui_MainWindow):
@property
def source_directory(self): return self._source_directory
@property
def config_file(self): return self._config_file
@property
def siggraph_directory(self): return self._siggraph_directory
@property
def map_directory(self): return self._map_directory
@property
def icon_directory(self): return self._icon_directory
@property
def temporal_directory(self): return self._temporal_directory
@property
def root_directory(self): return self._root_directory
@property
def lib_directory(self): return self._lib_directory
@property
def table_directory(self): return self._table_directory
@property
def consolidation_directory(self): return self._consolidation_directory
@property
def database(self): return self._database
@property
def label_consolidation(self): return self._label_consolidation
@property
def label_material(self): return self._label_material
@property
def qt_image(self): return self._qt_image
@property
def image_extensions(self): return self._image_extensions
@property
def raw_image_extensions(self): return self._raw_image_extensions
@property
def sound_extensions(self): return self._sound_extensions
@property
def current_consolidation(self): return self._current_consolidation
@property
def current_material(self): return self._current_material
@property
def current_file(self): return self._current_file
@property
def current_camera(self): return self._current_camera
@property
def gp_camera(self): return self._gp_camera
@property
def gp_context(self): return self._gp_context
@property
def awb_algo(self): return self._awb_algo
@property
def psp_algo(self): return self._psp_algo
@property
def ocr_lang_available(self): return self._ocr_lang_available
@property
def ocr_lang(self): return self._ocr_lang
@property
def ocr_psm(self): return self._ocr_psm
@property
def language(self): return self._language
@property
def skin(self): return self._skin
@property
def proxy(self): return self._proxy
@property
def flickr_apikey(self): return self._flickr_apikey
@property
def flickr_secret(self): return self._flickr_secret
@property
def map_tile(self): return self._map_tile
@property
def app_textEdit(self): return self._app_textEdit
@property
def image_file_operation(self): return self._image_file_operation
@property
def text_file_operation(self): return self._text_file_operation
@source_directory.setter
def source_directory(self, value): self._source_directory = value
@config_file.setter
def config_file(self, value): self._config_file = value
@siggraph_directory.setter
def siggraph_directory(self, value): self._siggraph_directory = value
@map_directory.setter
def map_directory(self, value): self._map_directory = value
@icon_directory.setter
def icon_directory(self, value): self._icon_directory = value
@temporal_directory.setter
def temporal_directory(self, value): self._temporal_directory = value
@root_directory.setter
def root_directory(self, value): self._root_directory = value
@lib_directory.setter
def lib_directory(self, value): self._lib_directory = value
@table_directory.setter
def table_directory(self, value): self._table_directory = value
@consolidation_directory.setter
def consolidation_directory(self, value): self._consolidation_directory = value
@database.setter
def database(self, value): self._database = value
@label_consolidation.setter
def label_consolidation(self, value): self._label_consolidation = value
@label_material.setter
def label_material(self, value): self._label_material = value
@qt_image.setter
def qt_image(self, value): self._qt_image = value
@image_extensions.setter
def image_extensions(self, value): self._image_extensions = value
@raw_image_extensions.setter
def raw_image_extensions(self, value): self._raw_image_extensions = value
@sound_extensions.setter
def sound_extensions(self, value): self._sound_extensions = value
@current_consolidation.setter
def current_consolidation(self, value): self._current_consolidation = value
@current_material.setter
def current_material(self, value): self._current_material = value
@current_file.setter
def current_file(self, value): self._current_file = value
@current_camera.setter
def current_camera(self, value): self._current_camera = value
@gp_camera.setter
def gp_camera(self, value): self._gp_camera = value
@gp_context.setter
def gp_context(self, value): self._gp_context = value
@awb_algo.setter
def awb_algo(self, value): self._awb_algo = value
@psp_algo.setter
def psp_algo(self, value): self._psp_algo = value
@ocr_lang_available.setter
def ocr_lang_available(self, value): self._ocr_lang_available = value
@ocr_lang.setter
def ocr_lang(self, value): self._ocr_lang = value
@ocr_psm.setter
def ocr_psm(self, value): self._ocr_psm = value
@language.setter
def language(self, value): self._language = value
@skin.setter
def skin(self, value): self._skin = value
@proxy.setter
def proxy(self, value): self._proxy = value
@flickr_apikey.setter
def flickr_apikey(self, value): self._flickr_apikey = value
@flickr_secret.setter
def flickr_secret(self, value): self._flickr_secret = value
@map_tile.setter
def map_tile(self, value): self._map_tile = value
@app_textEdit.setter
def app_textEdit(self, value): self._app_textEdit = value
@image_file_operation.setter
def image_file_operation(self, value): self._image_file_operation = value
@text_file_operation.setter
def text_file_operation(self, value): self._text_file_operation = value
def __init__(self, parent=None):
print("Start -> main::__init__(self, parent=None)")
try:
# Clear memory
gc.collect()
# Make this class as the super class and initialyze the class.
super(mainPanel, self).__init__(parent)
self.setupUi(self)
# Initialyze the window.
self.setWindowState(Qt.WindowMaximized) # Show as maximized.
# Hide uuid columns from tree widgets.
#self.tre_prj_item.hideColumn(0)
self.tre_fls.hideColumn(0)
# Activate modules.
print("## Initialize UI objects and functions.")
setupMainUi.activate(self)
# Initialyze the source paths.
print("## Initialize parameters.")
print("### Paths for souces...")
dir_src = os.path.dirname(os.path.abspath(__file__))
dir_lib = os.path.join(dir_src, "lib")
dir_sig = os.path.join(os.path.expanduser("~"),"siggraph")
dir_map = os.path.join(dir_src, "map")
dir_tmp = os.path.join(dir_src, "temp")
dir_icn = os.path.join(dir_src, "icon")
fil_cnf = os.path.join(dir_src, "config.xml")
# Initialyze properties.
print("### Parameters...")
general.initAll(self, dir_src, dir_lib, dir_sig, dir_map, dir_tmp, dir_icn, fil_cnf)
# Initialyze the proxy setting
print("### Proxy...")
self.setProxy()
# Initialyze the map viewer
print("### Map...")
self.setDefaultMap()
# Set the default skin.
print("### UI Skin...")
self.setSkin(lang=self._language, theme=self._skin)
# Detect the camera automatically
print("## Set Camera...")
self.detectCamera()
# Open the previous project.
print("## Now opening the project...")
if not self._database == None:
if os.path.exists(self._database):
self.openProject()
except Exception as e:
print("Error occured in main::__init__(self, parent=None)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
finally:
print("End -> main::__init__(self, parent=None)")
# ==========================
# General operation
# ==========================
def openProject(self):
print("Start -> main::openProject(self)")
try:
# Establish the connection to the self._database file.
conn = sqlite.connect(self._database)
if conn is not None:
# Check whether table exists or not.
general.checkExistenceOfTables(self._database)
# Check wether columns exists or not.
general.checkFieldsOfTables(self.database)
# Reconstruct the tree view for project items.
self.retriveProjectItems()
# Update the configuration file.
general.changeConfig(self)
# Set the top item.
if self.tre_prj_item.topLevelItemCount() > 0:
self.tre_prj_item.setCurrentItem(self.tre_prj_item.topLevelItem(0))
except sqlite.DatabaseError as e:
print("Error occured in main::openProject(self)")
print(str(e))
error.ErrorMessageDbConnection(details=str(e), language=self._language)
return(None)
finally:
# Finally set the root path to the text box.
if not self.root_directory == None:
self.lbl_prj_path.setText(self._root_directory)
print("End -> main::openProject(self)")
def retriveProjectItems(self):
print("Start -> main::retriveProjectItems(self)")
# Create a sqLite file if not exists.
try:
# Establish the connection to the self._database file.
conn = sqlite.connect(self._database)
# Exit if connection is not established.
if conn == None: return(None)
# Create the SQL query for selecting consolidation.
sql_con_sel = """SELECT uuid, name, description, id FROM consolidation ORDER BY id"""
# Create the SQL query for selecting the consolidation.
sql_mat_sel = """SELECT uuid, name, description, id FROM material WHERE con_id=? ORDER by id"""
# Instantiate the cursor for query.
cur_con = conn.cursor()
rows_con = cur_con.execute(sql_con_sel)
# Execute the query and get consolidation recursively
for row_con in rows_con:
# Get attributes from the row.
con_uuid = row_con[0]
con_name = row_con[1]
con_description = row_con[2]
print("# Get the consolidation:" + con_uuid)
# Convert the NULL value to the empty entry.
if con_uuid == None or con_uuid == "NULL": con_uuid = ""
if con_name == None or con_name == "NULL": con_name = ""
if con_description == None or con_description == "NULL": con_description = ""
# Update the tree view.
tre_prj_con_items = QTreeWidgetItem(self.tre_prj_item)
tre_prj_con_items.setText(0, con_uuid)
tre_prj_con_items.setText(1, con_name)
# Instantiate the cursor for query.
cur_mat = conn.cursor()
rows_mat = cur_mat.execute(sql_mat_sel, [con_uuid])
for row_mat in rows_mat:
# Get attributes from the row.
mat_uuid = row_mat[0]
mat_name = row_mat[1]
mat_description = row_mat[2]
print("# Get the material:" + mat_uuid)
# Convert the NULL value to the empty entry.
if mat_uuid == None or mat_uuid == "NULL": mat_uuid = ""
if mat_name == None or mat_name == "NULL": mat_name = ""
if mat_description == None or mat_description == "NULL": mat_description = ""
# Update the tree view.
tre_prj_mat_items = QTreeWidgetItem(tre_prj_con_items)
tre_prj_mat_items.setText(0, mat_uuid)
tre_prj_mat_items.setText(1, mat_name)
# Refresh the tree view.
self.tre_prj_item.show()
# Resize the column header by text length.
self.tre_prj_item.resizeColumnToContents(0)
self.tre_prj_item.resizeColumnToContents(1)
except sqlite.DatabaseError as e:
print("Error occured in main::retriveProjectItems(self)")
print(staticmethod(e))
error.ErrorMessageDbConnection(str(e.args[0]))
return(None)
finally:
print("End -> main::retriveProjectItems")
def openConfigDialog(self):
print("main::openConfigDialog(self)")
try:
# Exit if the root directory is not loaded.
if self._root_directory == None: error.ErrorMessageProjectOpen(language=self._language); return(None)
# Initialize the configuration dialog.
self.dialog_Config = configurationDialog.configurationDialog(parent=self)
# Open the configuration dialog.
if self.dialog_Config.exec_() == True:
# Apply language setting.
lang = self.dialog_Config.cbx_thm_lang.currentText()
if lang == u"日本語":
self._language = "ja"
elif lang == "English":
self._language = "en"
# Apply theme of the UI
self._skin = self.dialog_Config.cbx_skin.currentText().lower()
self.setSkin(lang=self._language, theme=self._skin)
# Apply auto white balance algorithm
self._awb_algo = self.dialog_Config.cbx_tool_awb.currentText()
# Apply pansharpening algorithm
self._psp_algo = self.dialog_Config.cbx_tool_psp.currentText()
# Apply default text editor.
self._app_textEdit = self.dialog_Config.tbx_exe_textedit.text()
# Apply proxy setting.
proxy_setting = self.dialog_Config.txt_proxy.text()
if proxy_setting == "No Proxy" or proxy_setting == "":
proxy_setting = "No Proxy"
self._proxy = proxy_setting
self.setProxy()
# Apply OCR page Segmentation Mode.
self._ocr_psm = str(int(self.dialog_Config.cbx_psm.currentText().split(":")[0])-1)
# Apply OCR languages.
if not self.dialog_Config.lst_lang_selected == None:
if self.dialog_Config.lst_lang_selected.count() > 0:
ocr_langs = [str(self.dialog_Config.lst_lang_selected.item(i).text()) for i in range(self.dialog_Config.lst_lang_selected.count())]
self._ocr_lang = "+".join(ocr_langs)
print(self._ocr_lang)
# Apply Flickr setting.
self._flickr_apikey = self.dialog_Config.txt_flc_api.text()
self._flickr_secret = self.dialog_Config.txt_flc_sec.text()
# Apply map tile source.
self._map_tile = self.dialog_Config.cbx_map_tile.currentText()
self.setDefaultMap()
# Save the current setting.
general.changeConfig(self)
except Exception as e:
print("Error occured in main::openConfigDialog(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def setProxy(self):
print("main::setProxy(self)")
try:
if not self._proxy == "No Proxy":
proxy_url = QUrl(self._proxy)
if unicode(proxy_url.scheme()).startswith('http'):
protocol = QNetworkProxy.HttpProxy
else:
protocol = QNetworkProxy.Socks5Proxy
QNetworkProxy.setApplicationProxy(
QNetworkProxy(
protocol,
proxy_url.host(),
proxy_url.port(),
proxy_url.userName(),
proxy_url.password())
)
except Exception as e:
self._proxy = "No Proxy"
print("Error occured in main::setProxy(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def setSkin(self, lang, theme):
print("main::setSkin(self, lang, theme)")
try:
# Reset values.
self._language = lang
self._skin = theme
# Apply the new skin.
setupMainSkin.applyMainWindowSkin(self, self._icon_directory, skin=self._skin)
setupMainSkin.setMainWindowButtonText(self)
# Set the tool tips with the specific language.
setupMainSkin.setMainWindowToolTips(self)
except Exception as e:
print("Error occured in main::setSkin(self, lang, theme)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def setLangEn(self):
print("main::setLangEn(self)")
try:
# Define language and skin theme.
self._language = "en"
# Set the default skin.
setupMainSkin.setMainWindowButtonText(self)
setupMainSkin.setMainWindowToolTips(self)
except Exception as e:
print("Error occured in main::setLangEn(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def setLangJa(self):
print("main::setLangJa(self)")
try:
# Define language and skin theme.
self._language = "ja"
# Set the default skin.
setupMainSkin.setMainWindowButtonText(self)
setupMainSkin.setMainWindowToolTips(self)
except Exception as e:
print("Error occured in main::setLangEn(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def importExternalData(self):
print("main::importExternalData(self)")
# Set the dialog tile message.
msg_title = ""
if self._language == "ja":
msg_title = "ファイルの選択"
elif self._language == "en":
msg_title = "Select files to import"
try:
# Exit if the root directory is not loaded.
if self._root_directory == None: error.ErrorMessageProjectOpen(language=self._language); return(None)
# Exit if the tree object is not selected.
selected = self.tre_prj_item.selectedItems()
if (selected == None or len(selected) == 0): error.ErrorMessageCurrentConsolidation(language=self._language); return(None)
if self.tab_target.currentIndex() == 0:
# Exit if the current consolidation is not selected.
if self._current_consolidation == None: error.ErrorMessageCurrentConsolidation(language=self._language); return(None)
elif self.tab_target.currentIndex()==1:
# Exit if the current consolidation is not selected.
if self._current_consolidation == None: error.ErrorMessageCurrentConsolidation(language=self._language); return(None)
# Exit if the current consolidation is not selected.
if self._current_material == None: error.ErrorMessageCurrentMaterial(language=self._language); return(None)
# Define directories for storing files.
in_dir = QFileDialog.getOpenFileNames(self, msg_title)
# Initialyze the uuid for the consolidation and the mateselfrial.
sop_object = None
# Initialyze the variables.
con_uuid = None
mat_uuid = None
item_path = None
# Get the current object from the selected tab index.
if self.tab_target.currentIndex() == 0:
# Instantiate the consolidation.
sop_object = self._current_consolidation
# Get the current consolidaiton uuid.
con_uuid = sop_object.uuid
# Get the item path of the selected consolidaiton.
item_path = os.path.join(self._consolidation_directory, con_uuid)
elif self.tab_target.currentIndex() == 1:
# Instantiate the material.
sop_object = self._current_material
# Instantiate the consolidation.
mat_uuid = sop_object.uuid
con_uuid = sop_object.consolidation
con_path = os.path.join(self._consolidation_directory, sop_object.consolidation)
item_path = os.path.join(os.path.join(con_path, "Materials"), mat_uuid)
else:
return(None)
# Exit if none of objecs are instantiated.
if sop_object == None: return(None)
# Import medias in selected path.
sop_media.mediaImporter(sop_object, item_path, in_dir[0], mat_uuid, con_uuid, self._database)
# Refresh the file list.
self.refreshFileList(sop_object)
except Exception as e:
print("Error occured in main::importExternalData(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def getTheRootDirectory(self):
print("main::getTheRootDirectory(self)")
# Set the dialog title message.
msg_dialog = ""
if self._language == "en":
msg_dialog = "Select the project directory"
elif self._language == "ja":
msg_dialog = "プロジェクトディレクトリの選択"
try:
# Initialyze the tree view.
self.tre_prj_item.clear()
# Reflesh the last selection.
self.refreshConsolidationInfo()
self.refreshMaterialInfo()
self.refreshImageInfo()
# Get the current directories and save as previous entries.
prev_root_directory = self._root_directory
prev_table_directory = self._table_directory
prev_consolidation_directory = self._consolidation_directory
prev_database = self._database
prev_consolidation = self._current_consolidation
prev_material = self._current_material
# Define directories for storing files.
self._root_directory = QFileDialog.getExistingDirectory(self, msg_dialog)
# Return nothing and exit this process if direcotry is not selected.
if not os.path.exists(self.root_directory):
self._root_directory = prev_root_directory
self._table_directory = prev_table_directory
self._consolidation_directory = prev_consolidation_directory
self._database = prev_database
self._current_consolidation = prev_consolidation
self._current_material = prev_material
# Exit this process.
return(None)
# Some essential directories are created under the root directory if they are not existed.
self._table_directory = os.path.join(self._root_directory, "Table")
self._consolidation_directory = os.path.join(self._root_directory, "Consolidation")
# Reset the current consolidation and the current material.
self._current_consolidation = None
self._current_material = None
# Define the DB file.
self._database = os.path.join(self._table_directory, "project.db")
# Check Flickr API Key File.
self.checkFlickrKey()
# Show the project creation dialog if the path is not existed.
if not os.path.exists(self._database):
createNewProject = general.askNewProject(self)
if createNewProject == None:
# Set initial settings by previously loaded.
self._root_directory = prev_root_directory
self._table_directory = prev_table_directory
self._consolidation_directory = prev_consolidation_directory
self._database = prev_database
self._current_consolidation = prev_consolidation
self._current_material = prev_material
# Exit this process.
return(None)
# Open the project.
self.openProject()
except Exception as e:
print("main::getTheRootDirectory(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def showImage(self, img_file_path):
print("Start -> main::showImage(self," + img_file_path + ")")
try:
# Check the image file can be displayed directry.
img_base, img_ext = os.path.splitext(img_file_path)
img_valid = False
for qt_ext in self._qt_image:
# Exit loop if extension is matched with Qt supported image.
if img_ext.lower() == qt_ext.lower():
img_valid = True
break
# Check whether the image is Raw image or not.
if not img_valid == True:
# Extract the thumbnail image from the RAW image by using "dcraw".
imageProcessing.getThumbnail(img_file_path)
# Get the extracted thumbnail image.
if not img_ext.lower() == "jpg":
img_file_path = img_base + ".thumb.jpg"
if os.path.exists(img_file_path):
# Check the exif rotation information.
imageProcessing.correctRotaion(img_file_path)
# Show the image on graphic view.
self.graphicsView.setFile(img_file_path)
else:
error.ErrorMessageImagePreview(details=str(e), language=self._language)
# Returns nothing.
return(None)
except Exception as e:
print("Error occured in main::showImage(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
finally:
print("End -> main::showImage")
def toggleCurrentObjectTab(self):
print("main::toggleCurrentObjectTab(self)")
try:
if self.tab_target.currentIndex() == 0:
if not self._current_consolidation == None:
# Set file information of material images.
self.refreshFileList(self._current_consolidation)
else:
self.refreshConsolidationInfo()
self.refreshMaterialInfo()
elif self.tab_target.currentIndex() == 1:
if not self._current_consolidation == None:
if not self._current_material == None:
# Set file information of material images.
self.refreshFileList(self._current_material)
else:
self.refreshMaterialInfo()
else:
self.refreshConsolidationInfo()
except Exception as e:
print("Error occured in main::toggleCurrentObjectTab(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def toggleCurrentTreeObject(self):
print("Start -> main::toggleCurrentTreeObject(self)")
# Exit if the root directory is not loaded.
if self._root_directory == None: error.ErrorMessageProjectOpen(language=self._language); return(None)
# Get the item of the material.
selected = self.tre_prj_item.selectedItems()
# Exit if selected item is 0.
if (selected == None or len(selected) == 0): return(None)
# Clear the information of the previously selected objects.
self._current_consolidation = None
self._current_material = None
# To clear current view of the material info...
self.refreshMaterialInfo()
try:
if selected[0].parent() == None:
# Get the Consolidation if the node have no parent.
selected_uuid = selected[0].text(0)
# Set current objects.
self._current_consolidation = features.Consolidation(is_new=False, uuid=selected_uuid, dbfile=self._database)
# Set attributes of the consolidation to input boxes.
self.setConsolidationInfo(self._current_consolidation)
# Set active control tab for consolidation.
self.tab_target.setCurrentIndex(0)
# Set file information of material images.
self.refreshFileList(self._current_consolidation)
self.toggleCurrentSourceTab()
elif selected[0].parent() != None:
self.tre_prj_item.setCurrentItem(selected[0])
# Get the Materil if the node have a parent.
selected_uuid = selected[0].text(0)
# Set current material.
self._current_material = features.Material(is_new=False, uuid=selected_uuid, dbfile=self._database)
self._current_consolidation = features.Consolidation(is_new=False, uuid=self._current_material.consolidation, dbfile=self._database)
# Set attributes of the consolidation and the material to the input boxes.
self.setConsolidationInfo(self._current_consolidation)
self.setMaterialInfo()
# Set active control tab for consolidation.
self.tab_target.setCurrentIndex(1)
# Set file information of material images.
self.refreshFileList(self._current_material)
self.toggleCurrentSourceTab()
except Exception as e:
print("Error occured in main::toggleCurrentTreeObject(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
finally:
print("End -> main::toggleCurrentTreeObject")
def toggleCurrentSourceTab(self):
print("main::toggleCurrentSource(self)")
# Exit if the root directory is not loaded.
if self._root_directory == None: return(None)
# Get the item of the material.
selected = self.tre_prj_item.selectedItems()
# Exit if selected item is 0.
if (selected == None or len(selected) == 0): return(None)
try:
if self.tab_src.currentIndex() == 3:
self.refreshMap()
except Exception as e:
print("Error occured in main::toggleCurrentSource(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def toggleShowFileMode(self):
print("main::toggleShowFileMode(self)")
try:
# Initialyze the uuid for the consolidation and the material.
sop_object = None
# Initialyze the variables.
con_uuid = None
mat_uuid = None
item_path = None
# Get the current object from the selected tab index.
if self.tab_target.currentIndex() == 0:
# Get the current consolidaiton uuid.
con_uuid = self.tbx_con_uuid.text()
# Instantiate the consolidation.
sop_object = features.Consolidation(is_new=False, uuid=con_uuid, dbfile=self._database)
elif self.tab_target.currentIndex() == 1:
# Get the current material uuid.
mat_uuid = self.tbx_mat_uuid.text()
# Instantiate the material.
sop_object = features.Material(is_new=False, uuid=mat_uuid, dbfile=self._database)
else:
return(None)
# Refresh the file list.
if not sop_object == None: self.refreshFileList(sop_object)
except Exception as e:
print("Error occured in main::toggleShowFileMode(self)")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def refreshFileList(self, sop_object):
print("main::refreshFileList(self, sop_object)")
try:
# "Clear the file list view"
self.tre_fls.clear()
# Clear current file.
self._current_file = None
# Get images from the given class.
images = sop_object.images
sounds = sop_object.sounds
movies = sop_object.movies
texts = sop_object.texts
geometries = sop_object.geometries
if not images == None and len(images) > 0:
for image in images: self.setFileInfo(image)
if not sounds == None and len(sounds) > 0:
for sound in sounds: self.setFileInfo(sound)
if not movies == None and len(movies) > 0:
for movie in movies: self.setFileInfo(movie)
if not texts == None and len(texts) > 0:
for text in texts: self.setFileInfo(text)
if not geometries == None and len(geometries) > 0:
for geometry in geometries: self.setFileInfo(geometry)
# Refresh the tree view.
self.tre_fls.resizeColumnToContents(0)
self.tre_fls.resizeColumnToContents(1)
self.tre_fls.resizeColumnToContents(2)
# Selct the top item as the default.
self.tre_fls.setCurrentItem(self.tre_fls.topLevelItem(0))
self.tre_fls.show()
except Exception as e:
print("Error occured in mainPanel::refreshFileList")
print(str(e))
error.ErrorMessageUnknown(details=str(e), show=True, language=self._language)
return(None)
def importFileToObjects(self):
print("Start -> main::importFileToObjects(self)")
try:
# Exit if the root directory is not loaded.
if self._root_directory == None: error.ErrorMessageProjectOpen(language=self._language); return(None)
self.dialogFileToObjects = fileToObjectsDialog.fileToObjectsDialog(parent=self)
if self.dialogFileToObjects.exec_():
dir_fls = self.dialogFileToObjects.tbx_fnam.text()
# Check whether import directory is empty or not.
if dir_fls == "" or dir_fls == None: return(False)
# Create a new consolidation.
con_uuid = str(uuid.uuid4())
sop_consolidation = features.Consolidation(is_new=True, uuid=None, dbfile=None)
sop_consolidation.uuid = con_uuid
sop_consolidation.name = os.path.basename(dir_fls)
# Insert the consolidation.
sop_consolidation.dbInsert(self._database)
# Create a directory to store consolidation.
con_dir = os.path.join(self._consolidation_directory, sop_consolidation.uuid)
general.createDirectories(con_dir, True)
bgn = self.dialogFileToObjects.spn_pos_bgn.value()
end = self.dialogFileToObjects.spn_pos_end.value()
fl_nams = self.dialogFileToObjects.importedFiles
obj_dict = dict()
for fl_nam in fl_nams:
obj_dict[fl_nam] = fl_nam[bgn:end]
for fl_nam in fl_nams:
find = fl_nam[bgn:end]
keys = [k for k, v in obj_dict.items() if v == find]
if len(keys) > 0:
# Create and insert Material.
sop_material = features.Material(is_new=True, uuid=None, dbfile=None)
sop_material.uuid = str(uuid.uuid4())
sop_material.consolidation = con_uuid
sop_material.name =find
sop_material.material_number = find
# Create a directory to store material
mat_dir = os.path.join(con_dir, "Materials")
itm_dir = os.path.join(mat_dir, sop_material.uuid)
if self.dialogFileToObjects.cbx_ftyp.currentText() == "Image":
# Define file type.
fl_typ = "image"
# Define the path for saving files.
img_path = os.path.join(itm_dir, "Images")
fl_path = os.path.join(img_path, "Main")
elif self.dialogFileToObjects.cbx_ftyp.currentText() == "Text":
# Define file type.
fl_typ = "text"