from __future__ import print_function import sys try : from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * print ("using PyQt5") except : from PyQt4.QtCore import * from PyQt4.QtGui import * print ("using PyQt4") # pip3 install PyQt5 # Debian, Ubuntu: apt-get install python3-pyqt5 # Fedora: dnf install python3-qt5 # ArchLinux: pacman -S python-pyqt5 class Window (QMainWindow) : def __init__ (self, parent = None) : super (Window, self).__init__ (parent) self.tree = QTreeWidget () self.tree.itemDoubleClicked.connect (self.itemClick) self.tab = QTabWidget () splitter = QSplitter (self) splitter.addWidget (self.tree) splitter.addWidget (self.tab) self.setCentralWidget (splitter) self.displayDir (self.tree, ".") def itemClick (self, item, column) : if sys.version_info >= (3, 0) : path = item.data (0, Qt.UserRole) else : path = item.data (0, Qt.UserRole).toString() info = QFileInfo (path) ext = "." + info.completeSuffix () widget = None if ext in [ ".h", ".cpp" ] : widget = QTextEdit () f = QFile (path) if f.open (QFile.ReadOnly) : data = f.readAll () if sys.version_info >= (3, 0) : data = str (data, "latin1") else: data = str (data) widget.setText (data) if widget == None : widget = QWidget () self.tab.addTab (widget, info.fileName ()) def displayDir (self, target, path) : localDir = QDir (path) dir = QDir (localDir.absolutePath ()) item = QTreeWidgetItem (target) item.setText (0, dir.dirName ()) item.setToolTip (0, dir.absolutePath ()) item.setData (0, Qt.UserRole, dir.absolutePath ()) item.setForeground (0, QColor ("red")) infoList = dir.entryInfoList (QDir.Files | QDir.Dirs | QDir.NoDotAndDotDot) for info in infoList : if info.isDir () : self.displayDir (item, info.filePath ()) else : node = QTreeWidgetItem (item) node.setText (0, info.fileName ()) node.setToolTip (0, info.filePath ()) node.setData (0, Qt.UserRole, info.filePath ()) node.setForeground (0, QColor ("blue")) app = QApplication (sys.argv) win = Window () win.show () app.exec_ () from __future__ import print_function import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * app = QApplication (sys.argv) win = QPushButton () win.setText ("knoflik") win.show () app.exec_ () from __future__ import print_function import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class Window (QPushButton) : def __init__ (self, parent = None) : super (Window, self).__init__ (parent) self.setText ("knoflik") self.clicked.connect (self.click) def click (self): self.setText ("click") app = QApplication (sys.argv) win = Window () win.show () app.exec_ () pip3 install PyQt5 Debian, Ubuntu: apt-get install python3-pyqt5 Fedora: dnf install python3-qt5 ArchLinux: pacman -S python-pyqt5