class SQNodeScriptLuaEditor(SQNodeEditor): def __init__(self): super(SQNodeScriptLuaEditor, self).__init__() layout = QtWidgets.QVBoxLayout(self) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) self.codeBox = CodeEditor(self) self.codeBox.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) layout.addWidget(self.codeBox) self.codeBox.textChanged.connect(self.onTextChanged) self.firstTouched = False def onTextChanged(self): self.targetNode.text = self.codeBox.toPlainText() self.notifyChanged() def onRefresh(self, node): self.codeBox.setPlainText(node.script or '', 'text/x-lua') def onLoad(self, node): self.firstTouched = False def setFocus(self): self.codeBox.setFocus() if self.firstTouched: return self.firstTouched = True self.codeBox.selectAll()
class SQNodeScriptLuaEditor( SQNodeEditor ): def __init__(self): super(SQNodeScriptLuaEditor, self).__init__() layout = QtGui.QVBoxLayout( self ) layout.setSpacing( 0 ) layout.setMargin( 0 ) self.codeBox = CodeEditor( self ) self.codeBox.setSizePolicy( QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding ) layout.addWidget( self.codeBox ) self.codeBox.textChanged.connect( self.onTextChanged ) self.firstTouched = False def onTextChanged( self ): self.targetNode.text = self.codeBox.toPlainText() self.notifyChanged() def onRefresh( self, node ): self.codeBox.setPlainText( node.script or '', 'text/x-lua' ) def onLoad( self, node ): self.firstTouched = False def setFocus( self ): self.codeBox.setFocus() if self.firstTouched: return self.firstTouched = True self.codeBox.selectAll()
class CodeBoxEditorWidget( QtGui.QWidget ): def __init__( self, *args ): super( CodeBoxEditorWidget, self ).__init__( *args ) self.setWindowFlags( Qt.Popup | Qt.Window ) self.ui = CodeBoxForm() self.ui.setupUi( self ) self.editor = None self.originalText = '' self.ui.buttonOK.clicked.connect( self.apply ) self.ui.buttonCancel.clicked.connect( self.cancel ) self.codeBox = CodeEditor( self.ui.containerContent ) layout = QtGui.QVBoxLayout( self.ui.containerContent ) layout.addWidget( self.codeBox ) layout.setSpacing( 0 ) layout.setMargin( 0 ) self.setFocusProxy( self.codeBox ) self.installEventFilter( self ) self.codeBox.installEventFilter( self ) def eventFilter( self, obj, ev ): e = ev.type() if obj == self: if e == QEvent.WindowDeactivate: obj.hide() elif obj == self.codeBox: if e == QEvent.KeyPress: if ( ev.key(), ev.modifiers() ) == ( Qt.Key_Return, Qt.ControlModifier ): self.apply() return True return QWidget.eventFilter( self, obj, ev ) def getText( self ): return self.codeBox.toPlainText() def startEdit( self, editor, text ): self.originalText = text or '' self.editor = editor self.codeBox.setPlainText( text, 'text/x-lua' ) def hideEvent( self, ev ): self.apply( True ) return super( CodeBoxEditorWidget, self ).hideEvent( ev ) def apply( self, noHide = False ): if self.editor: self.editor.changeText( self.getText() ) self.editor = None if not noHide: self.hide() def cancel( self, noHide = False ): if self.editor: self.editor.changeText( self.originalText ) self.editor = None if not noHide: self.hide()
class CodeBoxEditorWidget(QtWidgets.QWidget): def __init__(self, *args): super(CodeBoxEditorWidget, self).__init__(*args) self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint) self.setWindowModality(Qt.WindowModal) self.setWindowTitle('Code Edit') self.ui = CodeBoxForm() self.ui.setupUi(self) self.editor = None self.originalText = '' self.ui.buttonOK.clicked.connect(self.apply) self.ui.buttonCancel.clicked.connect(self.cancel) self.codeBox = CodeEditor(self.ui.containerContent) layout = QtWidgets.QVBoxLayout(self.ui.containerContent) layout.addWidget(self.codeBox) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) self.setFocusProxy(self.codeBox) self.installEventFilter(self) self.codeBox.installEventFilter(self) def eventFilter(self, obj, ev): e = ev.type() if obj == self: if e == QEvent.WindowDeactivate: obj.hide() elif obj == self.codeBox: if e == QEvent.KeyPress: if (ev.key(), ev.modifiers()) == (Qt.Key_Return, Qt.ControlModifier): self.apply() return True return QWidget.eventFilter(self, obj, ev) def getText(self): return self.codeBox.toPlainText() def startEdit(self, editor, text): self.originalText = text or '' self.editor = editor self.codeBox.setPlainText(text, 'text/x-lua') def hideEvent(self, ev): self.apply(True) return super(CodeBoxEditorWidget, self).hideEvent(ev) def apply(self, noHide=False): if self.editor: self.editor.changeText(self.getText()) self.editor = None if not noHide: self.hide() def cancel(self, noHide=False): if self.editor: self.editor.changeText(self.originalText) self.editor = None if not noHide: self.hide()
class CodeBoxEditorWidget( QtGui.QWidget ): def __init__( self, *args ): super( CodeBoxEditorWidget, self ).__init__( *args ) self.setWindowFlags( Qt.Popup | Qt.Window ) self.ui = CodeBoxForm() self.ui.setupUi( self ) self.installEventFilter( WindowAutoHideEventFilter( self ) ) self.editor = None self.originalText = '' self.ui.buttonOK.clicked.connect( self.apply ) self.ui.buttonCancel.clicked.connect( self.cancel ) self.codeBox = CodeEditor( self.ui.containerContent ) layout = QtGui.QVBoxLayout( self.ui.containerContent ) layout.addWidget( self.codeBox ) layout.setSpacing( 0 ) layout.setMargin( 0 ) # settingData = jsonHelper.tryLoadJSON( # app.findDataFile( 'script_settings.json' ) # ) # if settingData: # self.codeBox.applySetting( settingData ) self.setFocusProxy( self.codeBox ) def getText( self ): return self.codeBox.toPlainText() def startEdit( self, editor, text ): self.originalText = text or '' self.editor = editor self.codeBox.setPlainText( text, 'text/x-lua' ) def hideEvent( self, ev ): self.apply( True ) return super( CodeBoxEditorWidget, self ).hideEvent( ev ) def apply( self, noHide = False ): if self.editor: self.editor.changeText( self.getText() ) self.editor = None if not noHide: self.hide() def cancel( self, noHide = False ): if self.editor: self.editor.changeText( self.originalText ) self.editor = None if not noHide: self.hide() def keyPressEvent( self, ev ): key = ev.key() if ( key, ev.modifiers() ) == ( Qt.Key_Return, Qt.ControlModifier ): print("????" ) self.apply() return # if key == Qt.Key_Escape: # self.cancel() # return return super( CodeBoxEditorWidget, self ).keyPressEvent( ev )