6 from PyQt4
.QtCore
import *
7 from PyQt4
.QtGui
import *
9 reSimplify
= re
.compile(" +")
10 def simplifySpaces(txt
):
11 return reSimplify
.sub(" ", txt
)
18 sin
, sout
= os
.popen2(cmd
)
20 lines
= [simplifySpaces(x
.strip()) for x
in sout
.readlines()]
25 """0x032000e1 0 cpc6128 Qt Designer"""
26 lines
= runWmCtrl("-l")
29 tokens
= line
.split(" ")
31 text
= " ".join(tokens
[3:])
32 lst
.append( (text
, wid
) )
36 def switchToWindow(wid
):
40 class ListView(QListView
):
44 options
= self
.viewOptions()
45 for pos
in range(self
.model().rowCount()):
46 index
= self
.model().index(pos
, 0)
47 hint
= self
.itemDelegate().sizeHint(options
, index
)
48 width
= max(width
, hint
.width())
49 height
+= hint
.height()
50 return QSize(width
+ 10, height
+ 10)
53 class Window(QDialog
):
55 QDialog
.__init
__(self
)
56 flags
= self
.windowFlags()
57 self
.setWindowFlags(flags | Qt
.FramelessWindowHint
)
65 self
._model
= QStandardItemModel()
67 item
= QStandardItem(unicode(text
, "utf8"))
68 data
= QVariant(QString(wid
))
70 self
._model
.appendRow(item
)
73 def initProxyModel(self
):
74 self
._proxyModel
= QSortFilterProxyModel()
75 self
._proxyModel
.setFilterCaseSensitivity(Qt
.CaseInsensitive
)
76 self
._proxyModel
.setSourceModel(self
._model
)
81 frame
.setFrameStyle(QFrame
.Box | QFrame
.Plain
)
82 layout
= QVBoxLayout(self
)
84 layout
.addWidget(frame
)
87 self
._lineEdit
= QLineEdit(frame
)
88 QObject
.connect(self
._lineEdit
, SIGNAL("textEdited(const QString&)"),
90 QObject
.connect(self
._lineEdit
, SIGNAL("returnPressed()"),
91 self
.slotReturnPressed
)
93 self
._lineEdit
.installEventFilter(self
)
96 self
._view
= ListView(frame
)
97 self
._view
.setModel(self
._proxyModel
)
98 self
._view
.setEditTriggers(QAbstractItemView
.NoEditTriggers
)
99 QObject
.connect(self
._view
, SIGNAL("activated(const QModelIndex&)"),
103 layout
= QVBoxLayout(frame
)
105 layout
.addWidget(self
._lineEdit
)
106 layout
.addWidget(self
._view
)
109 def updateFilter(self
, text
):
110 self
._proxyModel
.setFilterFixedString(text
)
111 if not self
._view
.currentIndex().isValid():
112 firstIndex
= self
._proxyModel
.index(0, 0)
113 if firstIndex
.isValid():
114 self
._view
.setCurrentIndex(firstIndex
)
117 def eventFilter(self
, obj
, event
):
118 if event
.type() != QEvent
.KeyPress
:
121 if event
.key() in (Qt
.Key_Up
, Qt
.Key_Down
):
122 newEvent
= QKeyEvent(event
.type(), event
.key(), event
.modifiers(), event
.text())
123 QApplication
.postEvent(self
._view
, newEvent
)
129 def switchToWindow(self
, index
):
130 sourceIndex
= self
._proxyModel
.mapToSource(index
)
131 item
= self
._model
.itemFromIndex(sourceIndex
)
132 wid
= item
.data().toString()
133 switchToWindow(unicode(wid
))
137 def slotReturnPressed(self
):
138 index
= self
._view
.currentIndex()
140 self
.switchToWindow(index
)
142 cmd
= unicode(self
._lineEdit
.text())
143 os
.spawnlp(os
.P_NOWAIT
, 'sh', 'sh', '-c', cmd
)
148 app
= QApplication(sys
.argv
)
151 rect
= QApplication
.desktop().availableGeometry()
153 rect
.left() + (rect
.width() - window
.sizeHint().width()) / 2, \
154 rect
.top() + (rect
.height() - window
.sizeHint().height()) / 2 \
160 if __name__
=="__main__":