37
37
from classes import info
38
38
from classes .query import Clip , Effect , Transition
39
39
from windows .models .properties_model import PropertiesModel
40
- from windows .models .transition_model import TransitionsModel
41
- from windows .models .files_model import FilesModel
42
40
43
41
import openshot
44
42
@@ -380,45 +378,51 @@ def contextMenuEvent(self, event=None, release=False):
380
378
clip_id , item_type = selected_value .data ()
381
379
log .info ("Context menu shown for %s (%s) for clip %s on frame %s" % (property_name , property_key , clip_id , frame_number ))
382
380
log .info ("Points: %s" % points )
383
- log .info ("Property: %s" % str (cur_property ))
381
+
382
+ # Clear menu if models updated
383
+ if self .menu_reset :
384
+ self .choices = []
385
+ self .menu_reset = False
384
386
385
387
# Handle reader type values
386
388
if self .property_type == "reader" and not self .choices :
387
389
388
- # Refresh models
389
- self .transition_model .update_model ()
390
- self .files_model .update_model ()
391
-
392
390
# Add all files
393
391
file_choices = []
394
- for filesIndex in range (self .files_model .model .rowCount ()):
395
- modelIndex = self .files_model .model .index (filesIndex , 0 )
396
- fileItem = self .files_model .model .itemFromIndex (modelIndex )
397
- fileIcon = self .files_model .model .item (fileItem .row (), 0 ).icon ()
398
- fileName = self .files_model .model .item (fileItem .row (), 1 ).text ()
399
- fileParentPath = self .files_model .model .item (fileItem .row (), 4 ).text ()
392
+ for i in range (self .files_model .rowCount ()):
393
+ idx = self .files_model .index (i , 0 )
394
+ if not idx .isValid ():
395
+ continue
396
+ icon = idx .data (Qt .DecorationRole )
397
+ name = idx .sibling (idx .row (), 1 ).data ()
398
+ path = os .path .join (idx .sibling (idx .row (), 4 ).data (), name )
400
399
401
400
# Append file choice
402
- file_choices .append ({"name" : fileName ,
403
- "value" : os . path . join ( fileParentPath , fileName ) ,
401
+ file_choices .append ({"name" : name ,
402
+ "value" : path ,
404
403
"selected" : False ,
405
- "icon" : fileIcon
404
+ "icon" : icon
406
405
})
407
406
408
407
# Add root file choice
409
408
self .choices .append ({"name" : _ ("Files" ), "value" : file_choices , "selected" : False })
410
409
411
410
# Add all transitions
412
411
trans_choices = []
413
- for transIndex in range (self .transition_model .model .rowCount ()):
414
- modelIndex = self .transition_model .model .index (transIndex , 0 )
415
- transItem = self .transition_model .model .itemFromIndex (modelIndex )
416
- transIcon = self .transition_model .model .item (transItem .row (), 0 ).icon ()
417
- transName = self .transition_model .model .item (transItem .row (), 1 ).text ()
418
- transPath = self .transition_model .model .item (transItem .row (), 3 ).text ()
412
+ for i in range (self .transition_model .rowCount ()):
413
+ idx = self .transition_model .index (i , 0 )
414
+ if not idx .isValid ():
415
+ continue
416
+ icon = idx .data (Qt .DecorationRole )
417
+ name = idx .sibling (idx .row (), 1 ).data ()
418
+ path = idx .sibling (idx .row (), 3 ).data ()
419
419
420
420
# Append transition choice
421
- trans_choices .append ({"name" : transName , "value" : transPath , "selected" : False , "icon" : transIcon })
421
+ trans_choices .append ({"name" : name ,
422
+ "value" : path ,
423
+ "selected" : False ,
424
+ "icon" : icon
425
+ })
422
426
423
427
# Add root transitions choice
424
428
self .choices .append ({"name" : _ ("Transitions" ), "value" : trans_choices , "selected" : False })
@@ -476,7 +480,7 @@ def contextMenuEvent(self, event=None, release=False):
476
480
# Add menu options for keyframes
477
481
menu = QMenu (self )
478
482
if points > 1 :
479
- # Menu for more than 1 point
483
+ # Menu items only for multiple points
480
484
Bezier_Menu = QMenu (_ ("Bezier" ), self )
481
485
Bezier_Menu .setIcon (bezier_icon )
482
486
for bezier_preset in bezier_presets :
@@ -490,55 +494,51 @@ def contextMenuEvent(self, event=None, release=False):
490
494
Constant_Action .setIcon (constant_icon )
491
495
Constant_Action .triggered .connect (self .Constant_Action_Triggered )
492
496
menu .addSeparator ()
493
- Insert_Action = menu .addAction (_ ("Insert Keyframe" ))
494
- Insert_Action .triggered .connect (self .Insert_Action_Triggered )
495
- Remove_Action = menu .addAction (_ ("Remove Keyframe" ))
496
- Remove_Action .triggered .connect (self .Remove_Action_Triggered )
497
- menu .popup (QCursor .pos ())
498
- elif points == 1 :
499
- # Menu for a single point
497
+ if points >= 1 :
498
+ # Menu items for one or more points
500
499
Insert_Action = menu .addAction (_ ("Insert Keyframe" ))
501
500
Insert_Action .triggered .connect (self .Insert_Action_Triggered )
502
501
Remove_Action = menu .addAction (_ ("Remove Keyframe" ))
503
502
Remove_Action .triggered .connect (self .Remove_Action_Triggered )
504
503
menu .popup (QCursor .pos ())
505
504
506
- if self .choices :
507
- # Menu for choices
508
- for choice in self .choices :
509
- if type (choice ["value" ]) != list :
510
- # Add root choice items
511
- Choice_Action = menu .addAction (_ (choice ["name" ]))
512
- Choice_Action .setData (choice ["value" ])
513
- Choice_Action .triggered .connect (self .Choice_Action_Triggered )
505
+ # Menu for choices
506
+ if not self .choices :
507
+ return
508
+ for choice in self .choices :
509
+ if type (choice ["value" ]) != list :
510
+ # Just add root choice item
511
+ Choice_Action = menu .addAction (_ (choice ["name" ]))
512
+ Choice_Action .setData (choice ["value" ])
513
+ Choice_Action .triggered .connect (self .Choice_Action_Triggered )
514
+ continue
515
+
516
+ # Add sub-choice items (for nested choice lists)
517
+ # Divide into smaller QMenus (since large lists cover the entire screen)
518
+ # For example: Transitions -> 1 -> sub items
519
+ SubMenu = None
520
+ SubMenuRoot = QMenu (_ (choice ["name" ]), self )
521
+ SubMenuSize = 24
522
+ SubMenuNumber = 0
523
+ for sub_choice in choice ["value" ]:
524
+ if len (choice ["value" ]) > SubMenuSize :
525
+ if not SubMenu or len (SubMenu .children ()) == SubMenuSize or sub_choice == choice ["value" ][- 1 ]:
526
+ SubMenuNumber += 1
527
+ if SubMenu :
528
+ SubMenuRoot .addMenu (SubMenu )
529
+ SubMenu = QMenu (str (SubMenuNumber ), self )
530
+ Choice_Action = SubMenu .addAction (_ (sub_choice ["name" ]))
514
531
else :
515
- # Add sub-choice items (for nested choice lists)
516
- # Divide into smaller QMenus (since large lists cover the entire screen)
517
- # For example: Transitions -> 1 -> sub items
518
- SubMenu = None
519
- SubMenuRoot = QMenu (_ (choice ["name" ]), self )
520
- SubMenuSize = 24
521
- SubMenuNumber = 0
522
- for sub_choice in choice ["value" ]:
523
- if len (choice ["value" ]) > SubMenuSize :
524
- if not SubMenu or len (SubMenu .children ()) == SubMenuSize or sub_choice == choice ["value" ][- 1 ]:
525
- SubMenuNumber += 1
526
- if SubMenu :
527
- SubMenuRoot .addMenu (SubMenu )
528
- SubMenu = QMenu (str (SubMenuNumber ), self )
529
- Choice_Action = SubMenu .addAction (_ (sub_choice ["name" ]))
530
- else :
531
- Choice_Action = SubMenuRoot .addAction (_ (sub_choice ["name" ]))
532
- Choice_Action .setData (sub_choice ["value" ])
533
- subChoiceIcon = sub_choice .get ("icon" )
534
- if subChoiceIcon :
535
- Choice_Action .setIcon (subChoiceIcon )
536
- Choice_Action .triggered .connect (self .Choice_Action_Triggered )
537
- menu .addMenu (SubMenuRoot )
538
-
539
- # Show choice menu and release lock
540
- menu .popup (QCursor .pos ())
541
- self .contextMenuEvent (event , release = True )
532
+ Choice_Action = SubMenuRoot .addAction (_ (sub_choice ["name" ]))
533
+ Choice_Action .setData (sub_choice ["value" ])
534
+ if "icon" in sub_choice :
535
+ Choice_Action .setIcon (sub_choice ["icon" ])
536
+ Choice_Action .triggered .connect (self .Choice_Action_Triggered )
537
+ menu .addMenu (SubMenuRoot )
538
+
539
+ # Show choice menu and release lock
540
+ menu .popup (QCursor .pos ())
541
+ self .contextMenuEvent (event , release = True )
542
542
543
543
def Bezier_Action_Triggered (self , preset = []):
544
544
log .info ("Bezier_Action_Triggered: %s" % str (preset ))
@@ -584,17 +584,28 @@ def Choice_Action_Triggered(self, event):
584
584
# Update value of dropdown item
585
585
self .clip_properties_model .value_updated (self .selected_item , value = choice_value )
586
586
587
+ def refresh_menu (self ):
588
+ """ Ensure we update the meun when our source models change """
589
+ self .menu_reset = True
590
+
587
591
def __init__ (self , * args ):
588
592
# Invoke parent init
589
593
QTableView .__init__ (self , * args )
590
594
591
595
# Get a reference to the window object
592
596
self .win = get_app ().window
593
597
594
- # Get Model data
598
+ # Create properties model
595
599
self .clip_properties_model = PropertiesModel (self )
596
- self .transition_model = TransitionsModel (self )
597
- self .files_model = FilesModel (self )
600
+
601
+ # Get base models for files, transitions
602
+ self .transition_model = self .win .transition_model .model
603
+ self .files_model = self .win .files_model .model
604
+
605
+ # Connect to update signals, so our menus stay current
606
+ self .win .files_model .ModelRefreshed .connect (self .refresh_menu )
607
+ self .win .transition_model .ModelRefreshed .connect (self .refresh_menu )
608
+ self .menu_reset = False
598
609
599
610
# Keep track of mouse press start position to determine when to start drag
600
611
self .selected = []
@@ -627,8 +638,6 @@ def __init__(self, *args):
627
638
628
639
# Refresh view
629
640
self .clip_properties_model .update_model ()
630
- self .transition_model .update_model ()
631
- self .files_model .update_model ()
632
641
633
642
# Resize columns
634
643
self .resizeColumnToContents (0 )
0 commit comments