コード例 #1
0
ファイル: emulator.py プロジェクト: 1Zarkos1/gui_repo
    def initUI(self):
        cenWidget = QWidget(self)
        mainVertLayout = QVBoxLayout(cenWidget)
        # widget and horizontal layout for functional buttons and address bar
        topNavWidg = QWidget()
        topNavLayout = QHBoxLayout(topNavWidg)
        actions = ['back', 'forward', 'home']
        for i in range(3):
            but = QPushButton()
            but.clicked.connect(partial(self.navigate, action=actions[i]))
            but.setIcon(QIcon(f'../img/{actions[i]}.png'))
            but.setIconSize(QSize(25, 25))
            topNavLayout.addWidget(but)
        # address bar
        self.curPathLine = QLineEdit()
        self.curPathLine.setText(self.currentDirectory)
        self.curPathLine.installEventFilter(self)
        topNavLayout.addWidget(self.curPathLine)
        mainVertLayout.addWidget(topNavWidg)
        # scroll area and vertical layout for viewing current directory files
        scroll = QScrollArea()
        scroll.setWidgetResizable(True)
        viewWidg = QWidget()
        viewVertLayout = QVBoxLayout(viewWidg)
        viewVertLayout.installEventFilter(self)
        viewVertLayout.setAlignment(Qt.AlignTop)
        viewVertLayout.setSpacing(0)
        viewVertLayout.setContentsMargins(3, 3, 3, 3)
        # make label for each directory and file directly in current folder
        self.files = [QLabel(filename) for filename in self.getDirList()]
        for f in self.files:
            f.installEventFilter(self)
            viewVertLayout.addWidget(f)

        scroll.setWidget(viewWidg)

        mainVertLayout.addWidget(scroll)
        mainVertLayout.setContentsMargins(0, 0, 0, 0)
        mainVertLayout.setSpacing(0)
        mainVertLayout.setAlignment(Qt.AlignLeft)

        self.setCentralWidget(cenWidget)