2015-02-26 17:09:13 +01:00
# -*- coding: utf-8 -*-
import wx
from multiplatform_widgets import widgets
from wxUI . dialogs import baseDialog
class keystrokeEditorDialog ( baseDialog . BaseWXDialog ) :
2021-06-16 23:18:41 +02:00
def __init__ ( self ) :
super ( keystrokeEditorDialog , self ) . __init__ ( parent = None , id = - 1 , title = _ ( u " Keystroke editor " ) )
self . actions = [ ]
sizer = wx . BoxSizer ( wx . VERTICAL )
2022-11-18 00:37:44 +01:00
keysText = wx . StaticText ( self , - 1 , _ ( u " Select a keystroke to edit " ) )
2021-06-16 23:18:41 +02:00
self . keys = widgets . list ( self , _ ( u " Action " ) , _ ( u " Keystroke " ) , style = wx . LC_REPORT | wx . LC_SINGLE_SEL , size = ( 400 , 450 ) )
self . keys . list . SetFocus ( )
firstSizer = wx . BoxSizer ( wx . HORIZONTAL )
firstSizer . Add ( keysText , 0 , wx . ALL , 5 )
firstSizer . Add ( self . keys . list , 0 , wx . ALL , 5 )
2022-11-18 00:37:44 +01:00
self . edit = wx . Button ( self , - 1 , _ ( u " Edit " ) )
2021-06-16 23:18:41 +02:00
self . edit . SetDefault ( )
2022-11-18 00:37:44 +01:00
self . undefine = wx . Button ( self , - 1 , _ ( " Undefine keystroke " ) )
self . execute = wx . Button ( self , - 1 , _ ( u " Execute action " ) )
close = wx . Button ( self , wx . ID_CANCEL , _ ( u " Close " ) )
2021-06-16 23:18:41 +02:00
secondSizer = wx . BoxSizer ( wx . HORIZONTAL )
secondSizer . Add ( self . edit , 0 , wx . ALL , 5 )
secondSizer . Add ( self . execute , 0 , wx . ALL , 5 )
secondSizer . Add ( close , 0 , wx . ALL , 5 )
sizer . Add ( firstSizer , 0 , wx . ALL , 5 )
sizer . Add ( secondSizer , 0 , wx . ALL , 5 )
2022-11-18 00:37:44 +01:00
self . SetSizer ( sizer )
2021-06-16 23:18:41 +02:00
self . SetClientSize ( sizer . CalcMin ( ) )
2015-02-26 17:09:13 +01:00
2021-06-16 23:18:41 +02:00
def put_keystrokes ( self , actions , keystrokes ) :
selection = self . keys . get_selected ( )
self . keys . clear ( )
for i in keystrokes :
if ( i in actions ) == False :
continue
action = actions [ i ]
self . actions . append ( i )
2021-07-14 00:22:20 +02:00
keystroke = keystrokes . get ( i )
if keystroke == " " :
keystroke = _ ( " Undefined " )
2021-06-16 23:18:41 +02:00
self . keys . insert_item ( False , * [ action , keystroke ] )
self . keys . select_item ( selection )
2015-02-26 17:09:13 +01:00
2021-06-16 23:18:41 +02:00
def get_action ( self ) :
return self . keys . get_selected ( )
2015-02-26 17:09:13 +01:00
2021-07-14 00:22:20 +02:00
def undefine_keystroke_confirmation ( self ) :
return wx . MessageDialog ( self , _ ( " Are you sure you want to undefine this keystroke? " ) , _ ( " Undefine keystroke " ) , wx . YES_NO | wx . CANCEL | wx . ICON_QUESTION ) . ShowModal ( )
2015-02-26 17:09:13 +01:00
class editKeystrokeDialog ( baseDialog . BaseWXDialog ) :
2021-06-16 23:18:41 +02:00
def __init__ ( self ) :
super ( editKeystrokeDialog , self ) . __init__ ( parent = None , id = - 1 , title = _ ( u " Editing keystroke " ) )
panel = wx . Panel ( self )
sizer = wx . BoxSizer ( wx . VERTICAL )
self . control = wx . CheckBox ( panel , - 1 , _ ( u " Control " ) )
self . alt = wx . CheckBox ( panel , - 1 , _ ( u " Alt " ) )
self . shift = wx . CheckBox ( panel , - 1 , _ ( u " Shift " ) )
self . win = wx . CheckBox ( panel , - 1 , _ ( u " Windows " ) )
sizer1 = wx . BoxSizer ( wx . HORIZONTAL )
sizer1 . Add ( self . control )
sizer1 . Add ( self . alt )
sizer1 . Add ( self . shift )
sizer1 . Add ( self . win )
charLabel = wx . StaticText ( panel , - 1 , _ ( u " Key " ) )
self . key = wx . TextCtrl ( panel , - 1 )
sizer2 = wx . BoxSizer ( wx . HORIZONTAL )
sizer2 . Add ( charLabel )
sizer2 . Add ( self . key )
ok = wx . Button ( panel , wx . ID_OK , _ ( u " OK " ) )
ok . SetDefault ( )
cancel = wx . Button ( panel , wx . ID_CANCEL )
sizer3 = wx . BoxSizer ( wx . HORIZONTAL )
sizer3 . Add ( ok )
sizer3 . Add ( cancel )
sizer . Add ( sizer1 )
sizer . Add ( sizer2 )
sizer . Add ( sizer3 )
panel . SetSizerAndFit ( sizer )
2015-02-26 17:09:13 +01:00
def no_win_message ( ) :
2021-06-16 23:18:41 +02:00
return wx . MessageDialog ( None , _ ( u " You need to use the Windows key " ) , _ ( u " Invalid keystroke " ) , wx . OK | wx . ICON_ERROR ) . ShowModal ( )
2015-02-26 17:09:13 +01:00
def no_key ( ) :
2021-06-16 23:18:41 +02:00
return wx . MessageDialog ( None , _ ( u " You must provide a character for the keystroke " ) , _ ( u " Invalid keystroke " ) , wx . ICON_ERROR ) . ShowModal ( )