-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotepad.py
75 lines (60 loc) · 2.11 KB
/
notepad.py
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
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""A notepad GUI.
@author Hank Adler
@version 0.1.0
@license MIT
"""
import sys
from PyQt5.QtWidgets import (
QApplication, QMainWindow, QStatusBar, QAction, QTextEdit, QToolBar, QDockWidget
)
from PyQt5.QtCore import Qt, QSize
from PyQt5.QtGui import QIcon
class Window(QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(100, 100, 350, 350)
self.setWindowTitle('Notepad')
self.setCentralWidget(QTextEdit())
self.add_menubar()
self.add_toolbar()
self.add_dock()
self.show()
def add_menubar(self):
# Add menubar and menus.
menubar = self.menuBar()
file_menu = menubar.addMenu('File')
view_menu = menubar.addMenu('View')
# Add Exit action to File menu.
exit_action = QAction(QIcon('resources/exit.png'), 'Exit', self)
exit_action.setShortcut('Ctrl+Q')
exit_action.setStatusTip('Quit Progam')
exit_action.triggered.connect(self.close)
file_menu.addAction(exit_action)
# Add Fullscreen action to View menu.
appearance_submenu = view_menu.addMenu('Appearance')
fullscreen_action = QAction('Fullscreen', self, checkable=True)
fullscreen_action.setStatusTip('Switch to fullscreen mode')
fullscreen_action.triggered.connect(self.on_fullscreen)
appearance_submenu.addAction(fullscreen_action)
# Add statusbar.
self.setStatusBar(QStatusBar(self))
def on_fullscreen(self, checked):
if checked:
self.showFullScreen()
else:
self.showNormal()
def add_toolbar(self):
toolbar = QToolBar('Main Toolbar', self)
toolbar.setIconSize(QSize(16, 16))
self.addToolBar(toolbar)
def add_dock(self):
dock = QDockWidget('Main Dock', self)
dock.setAllowedAreas(Qt.AllDockWidgetAreas)
dock.setWidget(QTextEdit())
self.addDockWidget(Qt.LeftDockWidgetArea, dock)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
sys.exit(app.exec_())