Commits

Alexey Loshkarev committed b8525c4

one press less to result
center window on start

Comments (0)

Files changed (4)

         
         self.connect(self.ui.runButton, QtCore.SIGNAL("clicked()"), self.run)
         self.connect(self.ui.command, QtCore.SIGNAL("editTextChanged(QString)"), self.command_changed)
+        
         self.commands = []
         self.config_load()
 
 
 # Form implementation generated from reading ui file 'main.ui'
 #
-# Created: Fri Dec  7 12:18:12 2012
+# Created: Fri Dec  7 12:24:44 2012
 #      by: PyQt4 UI code generator 4.9.4
 #
 # WARNING! All changes made in this file will be lost!
         self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
         self.horizontalLayout_3 = QtGui.QHBoxLayout(self.centralwidget)
         self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3"))
-        self.command = QtGui.QComboBox(self.centralwidget)
+        self.command = MyComboBox(self.centralwidget)
         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
         sizePolicy.setHorizontalStretch(0)
         sizePolicy.setVerticalStretch(0)
         MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "AlfF2", None, QtGui.QApplication.UnicodeUTF8))
         self.runButton.setText(QtGui.QApplication.translate("MainWindow", "Run", None, QtGui.QApplication.UnicodeUTF8))
 
+from ui.mycombobox import MyComboBox
   <widget class="QWidget" name="centralwidget">
    <layout class="QHBoxLayout" name="horizontalLayout_3">
     <item>
-     <widget class="QComboBox" name="command">
+     <widget class="MyComboBox" name="command">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
         <horstretch>0</horstretch>
   </widget>
   <widget class="QStatusBar" name="statusbar"/>
  </widget>
+ <customwidgets>
+  <customwidget>
+   <class>MyComboBox</class>
+   <extends>QComboBox</extends>
+   <header>ui/mycombobox.h</header>
+  </customwidget>
+ </customwidgets>
  <resources/>
  <connections/>
 </ui>

altf2/ui/mycombobox.py

+
+from PyQt4 import QtCore, QtGui
+
+class MyComboBox(QtGui.QComboBox):
+    
+    def keyPressEvent(self, event):
+        
+        key = event.key()
+        event.setAccepted(False)
+        
+        if event.modifiers() == QtCore.Qt.NoModifier and key == QtCore.Qt.Key_Escape:
+            self.parent().parent().close()
+            event.accept()
+        
+        elif (event.modifiers() == QtCore.Qt.KeypadModifier and key == QtCore.Qt.Key_Enter) or \
+             (event.modifiers() == QtCore.Qt.NoModifier and key == QtCore.Qt.Key_Return):
+            self.parent().parent().run()
+            event.accept()
+
+        if not event.isAccepted():
+            super(MyComboBox, self).keyPressEvent(event)
+