Side Project#/PEDU

Develop PEDU with pyqt4 - 2

ch4rli3kop 2018. 6. 27. 01:34
반응형

다음으로는 MainWindow에 Status bar, Menu bar, Tool bar를 만들어주겠습니다. 


붉은 색은 Menu bar에 대한 추가된 부분들이고, 주황 색은 Tool bar, 녹색은 Status bar에 대한 코드 영역들입니다.

파란 부분은 메뉴나 툴 바를 선택했을 때 수행하는 동작을 구현한 부분입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from PyQt4.QtGui import *
from PyQt4.QtCore import*
import sys
 
 
class MyWindow(QMainWindow):
   def __init__(self):
      QMainWindow.__init__(self)
 
      ### 윈도우 특성 설정 ###
      self.setWindowTitle('PEDU')
      self.setGeometry(400,200,1500,600)
      #self.setWindowIcon(QIcon(''))
      self.statusBar().showMessage('ready')
      self.creat_menubar_child()
      self.creat_menubar()
      self.show()
 
 
   def creat_menubar_child(self):
      ### 메뉴바 설정 ###
      #load file
      self.fileAction1 = QAction("load file",self)
      self.fileAction1.setShortcut("Ctrl+O")
      self.fileAction1.setStatusTip("Load the file in local place")# 밑에서 상태를 알려줌
      self.fileAction1.triggered.connect(self.open_file)
 
      #exit 
      self.fileAction2 = QAction("Exit",self)
      self.fileAction2.setShortcut("Ctrl+C")
      self.fileAction2.setStatusTip("Exit the App")
      self.fileAction2.triggered.connect(self.close_window)
 
      #change font
      self.fileAction3 = QAction("Change Font",self)
      self.fileAction3.setShortcut("Ctrl+T")
      self.fileAction3.setStatusTip("Change the string font in application")
      self.fileAction3.triggered.connect(self.change_font)
 
 
   def creat_menubar(self):
      ### MenuBar ###
      mainMenu = self.menuBar()
      
      #File      
      fileMenu1 = mainMenu.addMenu('File')
      fileMenu1.addAction(self.fileAction1)
      fileMenu1.addAction(self.fileAction2)
 
      #Option
      fileMenu2 = mainMenu.addMenu('Options')
      fileMenu2.addAction(self.fileAction3)
 
      #Tool
      fileMenu3 = mainMenu.addMenu('Tools')
 
 
      ### toolbar 설정 ###
      #open_file
      # openIcon = QIcon()
      # openIcon.addFile('openFileImage2.png', QSize(16,16))
      # openAction = QAction(toolIcon, 'open_file', self)
      openAction = QAction(QIcon('file_open.png'), 'Open', self)
      openAction.triggered.connect(self.open_file)
 
      #exit_file
      exitAction = QAction(QIcon('exit.png'), 'Exit', self)
      exitAction.triggered.connect(self.close_window)
 
      #change_font
      setFontAction = QAction(QIcon('option.png'), 'Setting', self)
      setFontAction.triggered.connect(self.change_font)
 
 
      #open_file2
      self.openToolBar = self.addToolBar("Open")
      self.openToolBar.addAction(openAction)
 
      #exit_file2
      self.exitToolBar = self.addToolBar("Exit")
      self.exitToolBar.addAction(exitAction) 
 
      #change_font2
      self.setToolBar = self.addToolBar("Setting")
      self.setToolBar.addAction(setFontAction)
 
 
   def open_file(self):
      global filename
      filename = QFileDialog.getOpenFileName(self, "Select file")
      global Pfile
      Pfile = pefile.PE(filename)
 
 
   def close_window(self):
      result = QMessageBox.question(self, 'Message',"Are you sure you leave?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
 
      if result == QMessageBox.Yes:
         sys.exit()
      else:
         pass
      
 
   def change_font(self):
      font, valid = QFontDialog.getFont()
      if valid:
         self.styleChoice.setFont(font)
 
 
if __name__ == '__main__':
   app = QApplication(sys.argv)
   ex = MyWindow()
   sys.exit(app.exec_())
cs



실행 화면은 다음과 같습니다.

[menu bar 및 status bar]


[tool bar 및 status bar]


툴 바에 사용한 아이콘들은 적당히 인터넷 서핑으로 찾으면 될 것 같습니다.


반응형

'Side Project# > PEDU' 카테고리의 다른 글

Develop PEDU with pyqt4 - 4  (0) 2018.06.27
Develop PEDU with pyqt4 - 3  (0) 2018.06.27
Develop PEDU with pyqt4 - 1  (0) 2018.06.27
Develop PEDU with pyqt4  (0) 2018.06.26