@@ -726,13 +726,15 @@ def get_icon_camera() -> QIcon:
726726 return read_QIcon (name )
727727
728728
729- def editor_contextMenuEvent (self , p : 'PayToEdit' , e : 'QContextMenuEvent' ) -> None :
730- m = self .createStandardContextMenu ()
731- m .addSeparator ()
732- m .addAction (get_icon_camera (), _ ("Read QR code with camera" ), p .on_qr_from_camera_input_btn )
733- m .addAction (read_QIcon ("picture_in_picture.png" ), _ ("Read QR code from screen" ), p .on_qr_from_screenshot_input_btn )
734- m .addAction (read_QIcon ("file.png" ), _ ("Read file" ), p .on_input_file )
735- m .exec (e .globalPos ())
729+ def add_input_actions_to_context_menu (gih : 'GenericInputHandler' , m : QMenu ) -> None :
730+ if gih .on_qr_from_camera_input_btn :
731+ m .addAction (get_icon_camera (), _ ("Read QR code with camera" ), gih .on_qr_from_camera_input_btn )
732+ if gih .on_qr_from_screenshot_input_btn :
733+ m .addAction (read_QIcon ("picture_in_picture.png" ), _ ("Read QR code from screen" ), gih .on_qr_from_screenshot_input_btn )
734+ if gih .on_qr_from_file_input_btn :
735+ m .addAction (read_QIcon ("qr_file.png" ), _ ("Read QR code from file" ), gih .on_qr_from_file_input_btn )
736+ if gih .on_input_file :
737+ m .addAction (read_QIcon ("file.png" ), _ ("Read text from file" ), gih .on_input_file )
736738
737739
738740def scan_qr_from_screenshot () -> QrCodeResult :
@@ -758,6 +760,11 @@ def scan_qr_from_screenshot() -> QrCodeResult:
758760
759761
760762class GenericInputHandler :
763+ on_qr_from_camera_input_btn : Callable [[], None ] = None
764+ on_qr_from_screenshot_input_btn : Callable [[], None ] = None
765+ on_qr_from_file_input_btn : Callable [[], None ] = None
766+ on_input_file : Callable [[], None ] = None
767+
761768 def input_qr_from_camera (
762769 self ,
763770 * ,
@@ -1019,39 +1026,6 @@ def qr_show():
10191026 # side-effect: we export this method:
10201027 self .on_qr_show_btn = qr_show
10211028
1022- def add_qr_input_combined_button (
1023- self ,
1024- * ,
1025- config : 'SimpleConfig' ,
1026- allow_multi : bool = False ,
1027- show_error : Callable [[str ], None ],
1028- setText : Callable [[str ], None ] = None ,
1029- ):
1030- input_qr_from_camera = partial (
1031- self .input_qr_from_camera ,
1032- config = config ,
1033- allow_multi = allow_multi ,
1034- show_error = show_error ,
1035- setText = setText ,
1036- )
1037- input_qr_from_screenshot = partial (
1038- self .input_qr_from_screenshot ,
1039- allow_multi = allow_multi ,
1040- show_error = show_error ,
1041- setText = setText ,
1042- )
1043- self .add_menu_button (
1044- icon = get_icon_camera (),
1045- tooltip = _ ("Read QR code" ),
1046- options = [
1047- (get_icon_camera (), _ ("Read QR code from camera" ), input_qr_from_camera ),
1048- ("picture_in_picture.png" , _ ("Read QR code from screen" ), input_qr_from_screenshot ),
1049- ],
1050- )
1051- # side-effect: we export these methods:
1052- self .on_qr_from_camera_input_btn = input_qr_from_camera
1053- self .on_qr_from_screenshot_input_btn = input_qr_from_screenshot
1054-
10551029 def add_qr_input_from_camera_button (
10561030 self ,
10571031 * ,
@@ -1067,7 +1041,7 @@ def add_qr_input_from_camera_button(
10671041 show_error = show_error ,
10681042 setText = setText ,
10691043 )
1070- self .addButton (get_icon_camera (), input_qr_from_camera , _ ("Read QR code from camera" ))
1044+ self .addButton (get_icon_camera (), input_qr_from_camera , _ ("Read QR code with camera" ))
10711045 # side-effect: we export these methods:
10721046 self .on_qr_from_camera_input_btn = input_qr_from_camera
10731047
0 commit comments