-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathscreendatabase.py
2060 lines (1854 loc) · 84 KB
/
screendatabase.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
import os
try:
from os.path import sep
except:
from os import sep
from shutil import move
import threading
from kivy.app import App
from kivy.clock import Clock
from kivy.cache import Cache
from kivy.animation import Animation
from kivy.uix.screenmanager import Screen
from kivy.properties import ObjectProperty, StringProperty, ListProperty, BooleanProperty, NumericProperty, DictProperty
from kivy.uix.boxlayout import BoxLayout
from functools import partial
from generalcommands import to_bool, get_folder_info, local_path, verify_copy
from generalelements import NormalPopup, ConfirmPopup, MoveConfirmPopup, ScanningPopup, InputPopup, InputPopupTag, MenuButton, NormalDropDown, AlbumSortDropDown, AlbumExportDropDown
from generalconstants import *
from kivy.lang.builder import Builder
Builder.load_string("""
<DatabaseScreen>:
canvas.before:
Color:
rgba: app.theme.background
Rectangle:
pos: self.pos
size: self.size
id: databaseScreen
BoxLayout:
focus: True
orientation: 'vertical'
MainHeader:
NormalButton:
text: ' Import '
on_release: app.show_import()
disabled: app.database_scanning
NormalButton:
size_hint_x: None
width: 0 if self.disabled else self.texture_size[0] + 20
opacity: 0 if self.disabled else 1
text: ' Update Database '
on_release: app.database_rescan()
disabled: app.database_scanning
NormalButton:
size_hint_x: None
width: 0 if self.disabled else self.texture_size[0] + 20
opacity: 0 if self.disabled else 1
text: ' Cancel Database Scan '
on_release: app.cancel_database_import()
disabled: not app.database_scanning
warn: True
NormalButton:
size_hint_x: None
width: 0 if app.single_database else self.texture_size[0] + 20
text: ' Database Transfer '
on_release: app.show_transfer()
disabled: app.single_database or app.database_scanning
opacity: 0 if app.single_database else 1
NormalButton:
text: ' Video Editing '
on_release: app.show_video_converter(from_database=True)
size_hint_x: None
disabled: not app.ffmpeg
opacity: 0 if self.disabled else 1
width: 0 if self.disabled else self.texture_size[0] + 20
HeaderLabel:
text: 'Photo Database'
InfoLabel:
DatabaseLabel:
InfoButton:
SettingsButton:
BoxLayout:
orientation: 'horizontal'
SplitterPanelLeft:
id: leftpanel
#width: app.leftpanel_width
BoxLayout:
orientation: 'vertical'
Header:
size_hint_y: None
height: app.button_scale
ShortLabel:
text: 'Sort:'
MenuStarterButtonWide:
id: sortButton
text: root.sort_method
on_release: root.sort_dropdown.open(self)
ReverseToggle:
id: sortReverseButton
state: root.sort_reverse_button
on_press: root.resort_reverse(self.state)
PhotoListRecycleView:
id: database
viewclass: 'RecycleTreeViewButton'
scroll_distance: 10
scroll_timeout: 200
bar_width: int(app.button_scale * .5)
bar_color: app.theme.scroller_selected
bar_inactive_color: app.theme.scroller
scroll_type: ['bars', 'content']
SelectableRecycleBoxLayout:
id: databaseInterior
DatabaseOptions:
id: databaseOptionsArea
orientation: 'vertical'
height: app.button_scale * (1 + (5*self.height_scale)) if app.simple_interface else app.button_scale * 2
size_hint_y: None
BoxLayout:
canvas.before:
Color:
rgba: app.theme.menu_background if app.simple_interface else app.theme.header_background
Rectangle:
size: self.size
pos: self.pos
source: 'data/buttonflat.png' if app.simple_interface else 'data/headerbg.png'
orientation: 'vertical'
size_hint_y: 1
opacity: databaseOptionsArea.height_scale if app.simple_interface else 1
disabled: False if (databaseOptions.state == 'down' or not app.simple_interface) else True
BoxLayout:
orientation: 'vertical' if app.simple_interface else 'horizontal'
NormalLabel:
size_hint_y: 1
id: operationType
text: ''
NormalButton:
size_hint_y: 1
id: newFolder
size_hint_x: 1
text: 'New'
on_release: root.add_item()
disabled: not root.can_new_folder or app.database_scanning
NormalButton:
size_hint_y: 1
id: renameFolder
size_hint_x: 1
text: 'Rename'
on_release: root.rename_item()
disabled: not root.can_rename_folder or app.database_scanning
NormalButton:
size_hint_y: 1
id: deleteFolder
size_hint_x: 1
text: 'Delete'
warn: True
on_release: root.delete_item()
disabled: not root.can_delete_folder or app.database_scanning
BoxLayout:
size_hint_y: None
height: app.button_scale
NormalInput:
size_hint_y: 1
multiline: True
disable_lines: True
hint_text: 'Search...'
text: root.search_text
on_text: root.search(self.text)
NormalButton:
size_hint_y: 1
text: 'Clear'
on_release: root.clear_search()
NormalToggle:
id: databaseOptions
size_hint_x: 1
text: 'Database Options'
height: app.button_scale if app.simple_interface else 0
opacity: 1 if app.simple_interface else 0
disabled: False if app.simple_interface else True
on_press: databaseOptionsArea.set_hidden(self.state)
BoxLayout:
orientation: 'vertical'
Header:
ShortLabel:
id: folderType
text: ''
NormalLabel:
id: folderPath
text: ''
LargeBufferX:
ShortLabel:
text: 'Sort:'
MenuStarterButton:
size_hint_x: None
width: self.texture_size[0] + 80
id: albumSortButton
text: root.album_sort_method
on_release: root.album_sort_dropdown.open(self)
ReverseToggle:
id: albumSortReverseButton
state: root.album_sort_reverse_button
on_press: root.album_resort_reverse(self.state)
GridLayout:
id: folderDetails
cols: 1
size_hint_y: None
height: self.minimum_height
disabled: app.database_scanning
MainArea:
NormalRecycleView:
data: root.data
id: photosContainer
viewclass: 'PhotoRecycleThumb'
SelectableRecycleGrid:
scale: root.scale
id: photos
Header:
HalfSlider:
min: root.scale_min
max: root.scale_max
value: root.scale
on_value: root.scale = self.value
reset_value: root.reset_scale
NormalButton:
text: 'Open Folder'
disabled: not root.can_browse
opacity: 1 if root.can_browse else 0
width: (self.texture_size[0] + app.button_scale) if root.can_browse else 0
on_release: root.open_browser()
MenuStarterButton:
text: ' Export '
on_release: root.album_exports.open(self)
NormalButton:
text: 'Toggle Select'
on_release: root.toggle_select()
NormalButton:
id: deleteButton
text: 'Delete Selected'
disabled: not root.photos_selected or app.database_scanning
on_release: root.delete_selected_confirm()
warn: True
MenuStarterButton:
width: 0 if app.simple_interface else self.texture_size[0] + app.button_scale
opacity: 0 if app.simple_interface else 1
size_hint_x: None
id: tagButton
text: 'Add Tag To...'
disabled: not root.photos_selected or app.database_scanning
on_release: root.tag_menu.open(self)
<TransferScreen>:
canvas.before:
Color:
rgba: app.theme.background
Rectangle:
pos: self.pos
size: self.size
id: transferScreen
BoxLayout:
orientation: 'vertical'
MainHeader:
NormalButton:
text: 'Back To Library'
on_release: root.back()
NormalToggle:
text: ' Quick Move ' if self.state == 'normal' else ' Verify Move '
state: 'down' if app.config.get("Settings", "quicktransfer") == '0' else 'normal'
on_release: app.toggle_quicktransfer(self)
HeaderLabel:
text: 'Database Folder Transfer'
InfoLabel:
DatabaseLabel:
InfoButton:
SettingsButton:
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'vertical'
id: leftArea
Header:
MenuStarterButtonWide:
size_hint_x: 1
id: leftDatabaseMenu
text: root.left_database
on_release: root.database_dropdown_left.open(self)
MediumBufferX:
ShortLabel:
text: 'Sort:'
MenuStarterButton:
size_hint_x: 1
text: root.left_sort_method
on_release: root.left_sort_dropdown.open(self)
ReverseToggle:
state: 'down' if root.left_sort_reverse else 'normal'
on_press: root.left_resort_reverse(self.state)
NormalButton:
text: ' Toggle Select '
width: self.texture_size[0]
on_release: leftDatabaseArea.toggle_select()
MainArea:
PhotoListRecycleView:
id: leftDatabaseHolder
viewclass: 'RecycleTreeViewButton'
scroll_distance: 10
scroll_timeout: 200
bar_width: int(app.button_scale * .5)
bar_color: app.theme.scroller_selected
bar_inactive_color: app.theme.scroller
scroll_type: ['bars', 'content']
SelectableRecycleBoxLayout:
multiselect: True
id: leftDatabaseArea
MediumBufferX:
BoxLayout:
orientation: 'vertical'
id: rightArea
Header:
MenuStarterButtonWide:
size_hint_x: 1
id: rightDatabaseMenu
text: root.right_database
on_release: root.database_dropdown_right.open(self)
MediumBufferX:
ShortLabel:
text: 'Sort:'
MenuStarterButton:
size_hint_x: 1
text: root.right_sort_method
on_release: root.right_sort_dropdown.open(self)
ReverseToggle:
state: 'down' if root.right_sort_reverse else 'normal'
on_press: root.right_resort_reverse(self.state)
NormalButton:
text: ' Toggle Select '
width: self.texture_size[0]
on_release: rightDatabaseArea.toggle_select()
MainArea:
PhotoListRecycleView:
id: rightDatabaseHolder
viewclass: 'RecycleTreeViewButton'
scroll_distance: 10
scroll_timeout: 200
bar_width: int(app.button_scale * .5)
bar_color: app.theme.scroller_selected
bar_inactive_color: app.theme.scroller
scroll_type: ['bars', 'content']
SelectableRecycleBoxLayout:
multiselect: True
id: rightDatabaseArea
<DatabaseRestoreScreen>:
BoxLayout:
orientation: 'vertical'
MainHeader:
MainArea:
orientation: 'vertical'
Widget:
NormalLabel:
text: 'Restoring database backup, please wait...'
Widget:
<AlbumDetails>:
size_hint_y: None
height: app.button_scale if app.simple_interface else (app.button_scale * 2)
orientation: 'horizontal'
Header:
height: app.button_scale if app.simple_interface else (app.button_scale * 2)
ShortLabel:
text: 'Description:'
NormalInput:
id: albumDescription
height: app.button_scale if app.simple_interface else (app.button_scale * 2)
input_filter: app.test_description
multiline: True
text: ''
on_focus: app.new_description(self, root.owner, root.selected, root.type)
<FolderDetails>:
size_hint_y: None
height: app.button_scale
orientation: 'horizontal'
Header:
ShortLabel:
text: 'Title:'
NormalInput:
id: folderTitle
size_hint_x: 0.5
input_filter: app.test_album
multiline: True
disable_lines: True
text: ''
on_focus: app.new_title(self, root.owner, root.selected, root.type)
SmallBufferX:
ShortLabel:
text: 'Description:'
NormalInput:
id: folderDescription
input_filter: app.test_description
multiline: True
text: ''
on_focus: app.new_description(self, root.owner, root.selected, root.type)
<DatabaseSortDropDown>:
MenuButton:
text: 'Name'
on_release: root.select(self.text)
MenuButton:
text: 'Title'
on_release: root.select(self.text)
MenuButton:
text: 'Imported'
on_release: root.select(self.text)
MenuButton:
text: 'Modified'
on_release: root.select(self.text)
MenuButton:
text: 'Amount'
on_release: root.select(self.text)
""")
class DatabaseScreen(Screen):
"""Screen layout for the main photo database."""
#Display variables
type = StringProperty('folder') #Currently selected type: folder, tag
selected = StringProperty('') #Currently selected album in the database, may be blank
photos = [] #List of photo infos in the currently displayed album
folders = []
data = ListProperty()
displayable = BooleanProperty(False)
sort_dropdown = ObjectProperty() #Database sorting menu
sort_method = StringProperty('Name') #Currently selected database sort mode
sort_reverse = BooleanProperty(False) #Database sorting reversed or not
album_sort_dropdown = ObjectProperty() #Album sorting menu
album_sort_method = StringProperty('Name') #Currently selected album sort mode
album_sort_reverse = BooleanProperty(False) #Album sorting reversed or not
details = ObjectProperty() #Holder for the folder/album details widget
popup = None #Holder for the popup dialog widget
sort_reverse_button = StringProperty('normal')
album_sort_reverse_button = StringProperty('normal')
tag_menu = ObjectProperty()
album_menu = ObjectProperty()
album_exports = ObjectProperty()
expanded_tags = BooleanProperty(True)
expanded_folders = []
update_folders = True
search_text = StringProperty()
search_refresh = ObjectProperty()
photos_selected = BooleanProperty(False)
can_delete_folder = BooleanProperty(False)
can_rename_folder = BooleanProperty(False)
can_new_folder = BooleanProperty(False)
can_browse = BooleanProperty(False)
scale = NumericProperty(1) #Controls the scale of picture widgets
scale_min = .5
scale_max = 3
scrollto = StringProperty('')
def back(self, *_):
return False
def scroll_to(self, fullpath):
#Function that tries to scroll the photo list area to the given photo
if fullpath:
photos_container = self.ids['photosContainer']
for index, photodata in enumerate(self.data):
if photodata['fullpath'] == fullpath:
box = photos_container.children[0]
pos_index = (box.default_size[1] + box.spacing[1]) * (index / box.cols)
scroll = photos_container.convert_distance_to_scroll(0, pos_index - (photos_container.height * 0.5))[1]
if scroll > 1.0:
scroll = 1.0
elif scroll < 0.0:
scroll = 0.0
photos_container.scroll_y = 1.0 - scroll
photos_area = self.ids['photos']
photos_area.select_node(index)
break
def rescale_screen(self):
app = App.get_running_app()
self.ids['leftpanel'].width = app.left_panel_width()
self.update_treeview()
def open_browser(self):
if self.can_browse:
try:
import webbrowser
folders = []
for photo in self.photos:
path = os.path.join(photo[2], photo[1])
folders.append(path)
if folders:
folder = os.path.abspath(max(set(folders), key=folders.count))
webbrowser.open(folder)
except Exception as e:
pass
def update_can_browse(self):
if platform in ['win', 'linux', 'macosx'] and self.type.lower() == 'folder' and self.displayable:
self.can_browse = True
else:
self.can_browse = False
def clear_search(self, *_):
self.search_text = ''
def search(self, text):
self.search_text = text
if self.tag_menu:
Clock.unschedule(self.search_refresh)
self.search_refresh = Clock.schedule_once(self.update_treeview, 0.5)
def add_item(self, *_):
if self.type == 'Tag':
self.new_tag()
elif self.type == 'Folder':
self.add_folder()
else:
pass
def rename_item(self, *_):
if self.type == 'Tag':
pass
elif self.type == 'Folder':
self.rename_folder()
else:
pass
def delete_item(self, *_):
if self.type == 'Tag':
self.delete_folder()
elif self.type == 'Folder':
self.delete_folder()
else:
pass
def get_selected_photos(self, fullpath=False):
photos = self.ids['photos']
photos_container = self.ids['photosContainer']
selected_indexes = photos.selected_nodes
selected_photos = []
for selected in selected_indexes:
if fullpath:
selected_photos.append(photos_container.data[selected]['fullpath'])
else:
selected_photos.append(photos_container.data[selected]['photoinfo'])
return selected_photos
def on_sort_reverse(self, *_):
"""Updates the sort reverse button's state variable, since kivy doesnt just use True/False for button states."""
app = App.get_running_app()
self.sort_reverse_button = 'down' if to_bool(app.config.get('Sorting', 'database_sort_reverse')) else 'normal'
def on_album_sort_reverse(self, *_):
"""Updates the sort reverse button's state variable, since kivy doesnt just use True/False for button states."""
app = App.get_running_app()
sort_reverse = to_bool(app.config.get('Sorting', 'album_sort_reverse'))
self.album_sort_reverse_button = 'down' if sort_reverse else 'normal'
def export_screen(self):
"""Switches the app to export mode with the current selected album."""
if self.selected and self.type != 'None':
app = App.get_running_app()
app.export_target = self.selected
app.export_type = self.type
app.show_export(from_database=True)
def collage_screen(self):
"""Switches the app to collage mode with the current selected album."""
app = App.get_running_app()
app.export_type = self.type
app.export_target = self.selected
app.show_collage(from_database=True)
def text_input_active(self):
"""Checks if any 'NormalInput' or 'FloatInput' widgets are currently active (being typed in).
Returns: True or False
"""
input_active = False
for widget in self.walk(restrict=True):
if widget.__class__.__name__ == 'NormalInput' or widget.__class__.__name__ == 'FloatInput' or widget.__class__.__name__ == 'IntegerInput':
if widget.focus:
input_active = True
break
return input_active
def has_popup(self):
"""Checks if the popup window is open for this screen.
Returns: True or False
"""
if self.popup:
if self.popup.open:
return True
return False
def dismiss_extra(self):
"""Dummy function, not valid for this screen, but the app calls it when escape is pressed."""
return False
def dismiss_popup(self, *_):
"""If this screen has a popup, closes it and removes it."""
if self.popup:
self.popup.dismiss()
self.popup = None
def key(self, key):
"""Handles keyboard shortcuts, performs the actions needed.
Argument:
key: The name of the key command to perform.
"""
if self.text_input_active():
pass
else:
if not self.popup or (not self.popup.open):
if key == 'left' or key == 'up':
self.previous_album()
if key == 'right' or key == 'down':
self.next_album()
if key == 'enter':
self.go_to_photo()
if key == 'delete':
self.delete()
if key == 'a':
self.toggle_select()
if key == 'end':
self.database_index(-1)
if key == 'home':
self.database_index(0)
if key == 'pgup':
self.previous_album(page=True)
if key == 'pgdn':
self.next_album(page=True)
elif self.popup and self.popup.open:
if key == 'enter':
self.popup.content.dispatch('on_answer', 'yes')
def go_to_photo(self, *_):
if self.type != 'None':
if len(self.photos) > 0:
app = App.get_running_app()
app.target = self.selected
app.photo = ''
app.fullpath = ''
app.type = self.type
app.show_album(button=None)
def database_index(self, index, wrap=True):
database = self.ids['database']
database_interior = self.ids['databaseInterior']
data = database.data
database_length = len(data)
if index < 0:
if wrap:
index = database_length - 1
else:
index = 0
elif index >= database_length:
if wrap:
index = 0
else:
index = database_length - 1
new_folder = data[index]
self.displayable = new_folder['displayable']
self.type = new_folder['type']
self.selected = new_folder['target']
database_interior.selected = new_folder
database.scroll_to_selected()
self.show_selected()
def database_current_index(self):
database = self.ids['database']
selected = self.selected
data = database.data
current_index = 0
for i, node in enumerate(data):
if node['target'] == selected and node['type'] == self.type:
current_index = i
return current_index
def previous_album(self, page=False):
"""Selects the previous album in the database."""
current_index = self.database_current_index()
if page:
database_interior = self.ids['databaseInterior']
page_length = len(database_interior.children) - 1
self.database_index(current_index - page_length, wrap=False)
else:
self.database_index(current_index - 1)
def next_album(self, page=False):
"""Selects the next album in the database."""
current_index = self.database_current_index()
if page:
database_interior = self.ids['databaseInterior']
page_length = len(database_interior.children) - 1
self.database_index(current_index + page_length, wrap=False)
else:
self.database_index(current_index + 1)
def show_selected(self, *_):
"""Scrolls the treeview to the currently selected folder"""
database = self.ids['database']
selected = self.selected
data = database.data
selected_data = {}
for i, node in enumerate(data):
if node['target'] == selected and node['type'] == self.type:
selected_data = node
node['selected'] = True
else:
node['selected'] = False
database.refresh_from_data()
database_interior = self.ids['databaseInterior']
database_interior.selected = selected_data
database.scroll_to_selected()
def delete(self):
"""Begins the file delete process. Will call 'delete_selected_confirm' if an album is active."""
photos = self.ids['photos']
if photos.selected_nodes:
self.delete_selected_confirm()
def delete_selected_confirm(self):
"""Step two of file delete process. Opens a confirm popup dialog.
Dialog will call 'delete_selected_answer' on close.
"""
if self.type == 'Tag':
action_text = 'Remove The Tag "'+self.selected+'" From Selected Files?'
content = ConfirmPopup(text='The files will remain in the database and on the disk.', yes_text='Remove', no_text="Don't Remove", warn_yes=True)
else:
action_text = 'Delete The Selected Files?'
content = ConfirmPopup(text='Selected files will be removed from the database and deleted from the disk!', yes_text='Delete', no_text="Don't Delete", warn_yes=True)
app = App.get_running_app()
content.bind(on_answer=self.delete_selected_answer)
self.popup = NormalPopup(title=action_text, content=content, size_hint=(None, None), size=(app.popup_x, app.button_scale * 4), auto_dismiss=False)
self.popup.open()
def delete_selected_answer(self, instance, answer):
"""Final step of the file delete process, if the answer was 'yes' will delete the selected files.
Arguments:
instance: The widget that called this command.
answer: String, 'yes' if confirm, anything else on deny."""
del instance
if answer == 'yes':
app = App.get_running_app()
#get the selected photos
selected_photos = self.get_selected_photos()
selected_files = []
for photo in selected_photos:
full_filename = os.path.join(photo[2], photo[0])
selected_files.append([photo[0], full_filename])
#decide what to do with the photos
if self.type == 'Tag':
for photo in selected_files:
app.database_remove_tag(photo[0], self.selected, message=True)
app.message("Removed the tag '"+self.selected+"' from "+str(len(selected_files))+" Files.")
else:
folders = []
errors = []
deleted_files = 0
for photo in selected_files:
deleted = app.delete_photo(photo[0], photo[1])
if deleted is True:
deleted_files = deleted_files + 1
folders.append(photo[1])
else:
error = 'Unable to delete "'+photo[0]+'", '+str(deleted)
errors.append(error)
app.update_photoinfo(folders=folders)
if errors:
error_text = "\n".join(errors)
app.popup_message(text=error_text, title='Error')
if deleted_files:
app.message("Deleted "+str(deleted_files)+" Files.")
app.photos.commit()
self.on_selected('', '')
self.dismiss_popup()
self.update_treeview()
def drop_widget(self, fullpath, position, dropped_type='file', aspect=1):
"""Called when a widget is dropped after being dragged.
Determines what to do with the widget based on where it is dropped.
Arguments:
fullpath: String, file location of the object being dragged.
position: List of X,Y window coordinates that the widget is dropped on.
dropped_type: String, describes the object being dropped. May be: 'folder' or 'file'
"""
app = App.get_running_app()
folder_list = self.ids['databaseInterior']
folder_container = self.ids['database']
if folder_container.collide_point(position[0], position[1]): #check if dropped in the folders list
#Now, determine exactly what the widget was dropped on
offset_x, offset_y = folder_list.to_widget(position[0], position[1])
for widget in folder_list.children:
if widget.collide_point(position[0], offset_y):
if dropped_type == 'folder' and widget.type == 'Folder':
if not widget.displayable:
move_to = ''
else:
move_to = widget.fullpath
if move_to != fullpath:
if not move_to.startswith(fullpath):
if app.database_scanning:
app.popup_message("Scanning database, can't move folder.", title='Warning')
return
question = 'Move "'+fullpath+'" into "'+widget.fullpath+'"?'
content = ConfirmPopup(text=question, yes_text='Move', no_text="Don't Move", warn_yes=True)
app = App.get_running_app()
content.bind(on_answer=partial(self.move_folder_answer, fullpath, move_to))
self.popup = NormalPopup(title='Confirm Move', content=content, size_hint=(None, None), size=(app.popup_x, app.button_scale * 4), auto_dismiss=False)
self.popup.open()
return
elif dropped_type == 'file':
if widget.type != 'None':
selected_photos = self.get_selected_photos(fullpath=True)
if fullpath not in selected_photos:
selected_photos.append(fullpath)
if app.database_scanning:
app.popup_message("Scanning database, can't move photo(s).", title='Warning')
return
if widget.type == 'Tag':
self.add_to_tag(widget.target, selected_photos=selected_photos)
elif widget.type == 'Folder':
content = ConfirmPopup(text='Move These Files To "'+widget.target+'"?', yes_text="Move", no_text="Don't Move", warn_yes=True)
content.bind(on_answer=self.move_files)
self.popup = MoveConfirmPopup(photos=selected_photos, target=widget.target, title='Confirm Move', content=content, size_hint=(None, None), size=(app.popup_x, app.button_scale * 4), auto_dismiss=False)
self.popup.open()
pass
return
def move_files(self, instance, answer):
"""Calls the app's move_files command if the dialog was answered with a 'yes'.
Arguments:
instance: The button that called this function.
answer: String, if it is 'yes', the function will activate, if anything else, nothing will happen.
"""
del instance
if answer == 'yes':
app = App.get_running_app()
app.move_files(self.popup.photos, self.popup.target)
self.selected = self.popup.target
self.update_treeview()
self.dismiss_popup()
def toggle_select(self):
"""Toggles the selection of photos in the current album."""
photos = self.ids['photos']
photos.toggle_select()
self.update_selected()
def select_none(self):
"""Deselects all photos."""
photos = self.ids['photos']
photos.clear_selection()
self.update_selected()
def update_selected(self, *_):
"""Checks if any files are selected in the current album, and updates buttons that only work when files are selected."""
if not self.ids:
return
photos = self.ids['photos']
if photos.selected_nodes:
self.photos_selected = True
else:
self.photos_selected = False
def add_to_tag(self, tag_name, selected_photos=None):
"""Adds a tag to the currently selected photos.
Arguments:
tag_name: Tag to add to selected photos.
selected_photos: List of selected photo data.
"""
if not selected_photos:
selected_photos = self.get_selected_photos(fullpath=True)
tag_name = tag_name.strip(' ')
added_tag = 0
if tag_name:
app = App.get_running_app()
for photo in selected_photos:
added = app.database_add_tag(photo, tag_name)
if added:
added_tag = added_tag + 1
self.select_none()
if added_tag:
if tag_name == 'favorite':
self.on_selected()
app.photos.commit()
self.update_treeview()
app.message("Added tag '"+tag_name+"' to "+str(added_tag)+" files.")
def add_to_tag_menu(self, instance):
self.add_to_tag(instance.text)
self.tag_menu.dismiss()
def can_add_tag(self, tag_name):
"""Checks if a new tag can be created.
Argument:
tag_name: The tag name to check.
Returns: True or False.
"""
app = App.get_running_app()
tag_name = tag_name.lower().strip(' ')
tags = app.tags
if tag_name and (tag_name not in tags) and (tag_name.lower() != 'favorite'):
return True
else:
return False
def add_tag(self, instance=None, answer="yes"):
"""Adds the current input tag to the app tags."""
if answer == "yes":
if instance is not None:
tag_name = instance.ids['input'].text.strip(' ')
if not tag_name:
self.dismiss_popup()
return
else:
tag_input = self.ids['newTag']
tag_name = tag_input.text.strip(' ')
tag_input.text = ''
app = App.get_running_app()
app.tag_make(tag_name)
self.update_treeview()
self.dismiss_popup()
def toggle_expanded_folder(self, folder):
if folder in self.expanded_folders:
self.expanded_folders.remove(folder)
else:
self.expanded_folders.append(folder)
self.update_treeview()
def update_treeview(self, *_):
"""Updates the treeview's data"""
if not self.ids:
return
app = App.get_running_app()
database = self.ids['database']
database.data = []
data = []
#add the favorites item
total_favorites = len(app.database_get_tag('favorite'))
if total_favorites > 0:
total_photos = '('+str(total_favorites)+')'
else:
total_photos = ''
database_favorites = {
'fullpath': 'Favorites',
'target': 'favorite',
'owner': self,
'type': 'Tag',
'folder_name': 'Favorites',
'total_photos_numeric': total_favorites,
'total_photos': total_photos,
'expandable': False,
'displayable': True,
'indent': 0,
'subtext': '',
'height': app.button_scale + int(app.button_scale * 0.1),
'end': True,
'dragable': False,
'selected': False
}
data.append(database_favorites)
#add the tags tree item
sorted_tags = sorted(app.tags)
expandable_tags = True if len(sorted_tags) > 0 else False
tag_root = {
'fullpath': 'Tags',
'folder_name': 'Tags',