PyQt5을 이용한 Python 코딩 ‘분석툴개발'(04)

오늘은 Dock의 기본 창 GUI을 완성해보겠다.

파일명 : TelAnalyzer_mGUI.py

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

import platform


class RTreeView(QTreeView):
    def __init__(self, parent=None):
        super(RTreeView, self).__init__(parent)


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()

        # Window 속성을 MDI로 맞춘다
        self.mdiArea = QMdiArea()                                           
        # 수평스크롤 사용        
       self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
       # 수직스크롤 사용
       self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
       # Window 중앙에 위치시킴
       self.setCentralWidget(self.mdiArea)                                 
        # OS를 구분하기 위한 변수 정의
        self.platform_type = platform.system()

        # GUI 설정함수
        self.createAction()
        self.createMenu()
        self.createToolBar()


        self.createStatusBar()
        self.createDockWindows()

        # MDI 기본적인 설정을 하는 부분
        self.setWindowTitle("Tel Analyzer Tool")
        root = QFileInfo(__file__).absolutePath()
        self.setWindowIcon(QIcon(root + '/image/mainicon.png'))
        self.resize(1200, 800)

    def createAction(self):
        root = QFileInfo(__file__).absolutePath()

        self.new_c_act = QAction(QIcon(root + '/image/new_case.png'), 
                                "&New Case...", self,
                                shortcut=QKeySequence.New,
                                statusTip="Create New Case",
                                triggered=self.NewCase)
        self.close_c_act = QAction(QIcon(root + '/image/close.png'), 
                                 "&Close Case...", self,
                                 statusTip="Close Case",
                                 triggered=self.CloseCase)

    def createMenu(self):
        # File Windows 사용자에게만 확인이 가능함
        self.fileMenu = self.menuBar().addMenu("&File")
        self.fileMenu.addAction(self.new_c_act)
        self.fileMenu.addAction(self.close_c_act)
        self.fileMenu.addSeparator()


    def createToolBar(self):
        self.fileToolBar = self.addToolBar("File")
        self.fileToolBar.addAction(self.new_c_act)
        self.fileToolBar.addAction(self.close_c_act)

    def NewCase(self):
        print("NewCase Test")

    def CloseCase(self):
        print("CloseCase Test")


    def createStatusBar(self):
        self.statusBar().showMessage("Ready")


    def createDockWindows(self):

        # Table View 를 이용하여 기본정보를 표시하는 부분을 만들어준다 
        dock = QDockWidget("Information & File Path", self)
        dock.setAllowedAreas(Qt.LeftDockWidgetArea | 
                             Qt.RightDockWidgetArea)
        self.fileInfoTable = QTableView(dock)

        # Table 정의부분
        if self.platform_type == "Windows":
            self.tableFont = QFont("Verdana", 8)
        elif self.platform_type == "Darwin":
            self.tableFont = QFont("Verdana", 10)
        self.fileInfoTable.setFont(self.tableFont)
        self.fileInfoTable.setAlternatingRowColors(True)
        self.fileInfoTable.setShowGrid(True)

        dock.setWidget(self.fileInfoTable)
        self.addDockWidget(Qt.LeftDockWidgetArea, dock)
        #self.viewMenu.addAction(dock.toggleViewAction())



        # Row Table View 
        dock = QDockWidget("Row Information", self)
        dock.setAllowedAreas(Qt.RightDockWidgetArea)
        self.rowInfoTable = QTableView(dock)
        # Table 정의부분
        self.rowInfoTable.setFont(self.tableFont)
        self.rowInfoTable.setAlternatingRowColors(True)
        self.rowInfoTable.setShowGrid(True)

        dock.setWidget(self.rowInfoTable)
        self.addDockWidget(Qt.RightDockWidgetArea, dock)
        #self.viewMenu.addAction(dock.toggleViewAction())


        # Tree View 를 이용하여 엑셀 원본 및 변환 파일 등을 계층으로 표시하는 부분
        dock = QDockWidget("Case Structure", self)
        dock.setAllowedAreas(Qt.LeftDockWidgetArea | 
                                Qt.RightDockWidgetArea)
        self.treefolder = RTreeView(dock)    # 사용자 정의 RTreeView
        self.treefolder.setAlternatingRowColors(True)
        self.treefolder.setContextMenuPolicy(Qt.CustomContextMenu)
        self.treefolder.customContextMenuRequested.connect(self.showCustomContextMenu)
        self.treefolder.setSortingEnabled(False)
        dock.setWidget(self.treefolder)
        self.addDockWidget(Qt.LeftDockWidgetArea, dock)
        #self.viewMenu.addAction(dock.toggleViewAction())


        # List View 를 이용하여 디버그 창을 만들어준다
        dock = QDockWidget("Debug & Processing Log...", self)
        dock.setAllowedAreas(Qt.LeftDockWidgetArea | 
                            Qt.RightDockWidgetArea | 
                            Qt.BottomDockWidgetArea)
        self.logInfo = QListWidget(dock)
        dock.setWidget(self.logInfo)
        self.addDockWidget(Qt.BottomDockWidgetArea, dock)
        #self.viewMenu.addAction(dock.toggleViewAction)

    def showCustomContextMenu(self, pos):
        index = self.treefolder.indexAt(pos)

if __name__ == '__main__':

    import sys

    app = QApplication(sys.argv)

    # main 폼을 정의하는 부분
    mainWin = MainWindow()

    mainWin.show()

    sys.exit(app.exec())

이제 실행해보자

Dock을 완성하고 나서 이제 다음시간에 컨트롤 실행들을 붙여보겠다

댓글 남기기