#coding = utf-8
import sys
from PyQt5.QtWidgets
import QApplication, QMainWindow, QFileDialog
from Ui_login
import Ui_MainWindow
class
MyWin(
QMainWindow,
Ui_MainWindow):
'''
從QMainWindow, Ui_MainWindow繼承,實現界面設計和業務實現的解耦
'''
def
__init__(
self,
parent=
None):
super(MyWin,
self).
__init__(parent)
self.setupUi(
self)
self.__setting()
def
__setting(
self):
'''
增長自定義配置
'''
self.setWindowTitle(
"遠程維護工具")
self.resize(
800,
550)
self.splitter.setStretchFactor(
0,
1)
self.splitter.setStretchFactor(
1,
3)
self.splitter.setStretchFactor(
2,
2)
self.splitter.setMaximumWidth(
1500)
#增長信號處理
self.pushButton.clicked.connect(
self.slot1)
self.actionClose.triggered.connect(
self.close)
self.actionOpen.triggered.connect(
self.on_open)
self.actionSave.triggered.connect(
self.on_save)
#自定義信號處理函數
def
slot1(
self):
print(
"點擊。。。")
def
on_save(
self):
FullFileName, _ = QFileDialog.getSaveFileName(
self,
'文件另存爲',
r
'./',
'TXT (*.txt)')
set_text =
self.txt_view.toPlainText()
with
open(FullFileName,
'wt')
as f:
print(set_text,
file=f)
def
on_open(
self):
txtstr =
""
FullFileName, _ = QFileDialog.getOpenFileName(
self,
'打開',
r
'./',
'TXT (*.txt)')
with
open(FullFileName,
'rt')
as f:
lines = f.readlines()
for line
in lines:
txtstr = txtstr+line
self.txt_view.setText(txtstr)
if
__name__ ==
"__main__":
app = QApplication(sys.argv)
w = MyWin()
w.show()
sys.exit(app.exec_())