-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_window.py
More file actions
executable file
·90 lines (71 loc) · 3.52 KB
/
app_window.py
File metadata and controls
executable file
·90 lines (71 loc) · 3.52 KB
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
#!/usr/bin/python3
# File: app_window.py
# Author: Dylan Lee
# Description:
# holds the class definition for our main widget
# import our widget class
from app_widget import App_Widget
# import any and all widgets from PyQt
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QToolBar
from PyQt5.QtWidgets import QAction
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QStatusBar
# this class inherits from QMainWindow and will be used to set up the applications GUI
class App_Window(QMainWindow):
def __init__(self):
super().__init__()
# give the main application window a name
self.setWindowTitle('Example GUI Application')
# create a central gui widget using our subclass of QWidget named App_Widget
self.central_widget = App_Widget()
self.setCentralWidget(self.central_widget)
# Time to create a status bar to show whatever info we need too at the bottom of the window
# this could be handy to display messages to confirm user actions
self.statusBar().showMessage('Important Status...')
# create the standard menubar toolbar displayed at the top of the window
menu_bar = self.menuBar()
# once the menu bar is created we add more menu options
file_menu = menu_bar.addMenu('File')
edit_menu = menu_bar.addMenu('Edit')
view_menu = menu_bar.addMenu('View')
tool_menu = menu_bar.addMenu('Tools')
# now to add some options for the menus
# first add a save and exit option in the file menu
# to make it look snazzier you can get icons for your buttons like this
save_icon = QIcon.fromTheme('document-save')
save_button = QAction(save_icon, 'Save', self)
save_button.setShortcut('Ctrl+S')
save_button.triggered.connect(self.show_Saved)
exit_icon = QIcon.fromTheme('application-exit')
exit_button = QAction(exit_icon, 'Quit', self)
# this binds the button to the macro you choose
exit_button.setShortcut('Ctrl+Q')
# this is what actually causes the app to close if exit is clicked
# this type of connection will be important for buttons with more complex actions
exit_button.triggered.connect(self.close)
# add the created save and exit button to the file_menu
file_menu.addAction(save_button)
file_menu.addAction(exit_button)
# now a copy and paste option for the edit menu
copy_icon = QIcon.fromTheme('edit-copy')
copy_button = QAction(copy_icon, 'Copy', self)
copy_button.setShortcut('Ctrl+C')
copy_button.triggered.connect(self.show_Copy)
paste_icon = QIcon.fromTheme('edit-paste')
paste_button = QAction(paste_icon, 'Paste', self)
paste_button.setShortcut('Ctrl+V')
paste_button.triggered.connect(self.show_Paste)
# add the newly made buttons to the edit menu
edit_menu.addAction(copy_button)
edit_menu.addAction(paste_button)
# hopefully this gives you an idea of how to design a toolbar
# an example of how to bind a function to a triggered action
# in this case all that happens is the status bar says copied, pasted, saved based on which button they click
def show_Saved(self):
self.statusBar().showMessage('Saved')
def show_Copy(self):
self.statusBar().showMessage('Copied')
def show_Paste(self):
self.statusBar().showMessage('Pasted')