hkuadmin continue

This commit is contained in:
fasiondog 2021-04-23 01:40:51 +08:00
parent 9bd6f099a9
commit 617f812043
10 changed files with 195 additions and 87 deletions

View File

@ -24,14 +24,16 @@
import logging
import sys
sys.path.append('.')
from PyQt5 import QtCore, QtGui, QtWidgets
import qdarkstyle
from UiConfig import UiConfig
from admin.widget.HkuSessionViewWidget import HkuSessionViewWidget
from widget.HkuSessionViewWidget import HkuSessionViewWidget
from dialog import *
from widget import *
from data import *
_translate = QtCore.QCoreApplication.translate
@ -94,6 +96,8 @@ class MyMainWindow(QtWidgets.QMainWindow):
self.statusBar().showMessage(_translate('MainWindow', 'Running'))
QtCore.QMetaObject.connectSlotsByName(self)
self.db = LocalDatabase()
def closeEvent(self, event):
self.ui_config.save(self)
event.accept()
@ -185,6 +189,8 @@ class MyMainWindow(QtWidgets.QMainWindow):
self.ui_config.set('main_window', 'style', style_name)
def actionEditSession(self):
item = self.server_view_dock.tree.currentItem()
print(item.text(0) if item else 'None')
edit_session_dialog = HkuEditSessionDialog()
if edit_session_dialog.exec():
print("ok")

View File

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
from sqlalchemy.ext.declarative import declarative_base
BaseModel = declarative_base()

View File

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
import os
import sqlalchemy
from .BaseModel import BaseModel
from .model import SessionModel
class LocalDatabase:
def __init__(self):
self.db_name = "%s/.hikyuu/admin/hkuadmin.db" % os.path.expanduser('~')
self.engine = sqlalchemy.create_engine(
"sqlite:///%s?check_same_thread=false" % self.db_name, echo=False, future=True
)
BaseModel.metadata.create_all(self.engine)
self.session = sqlalchemy.orm.sessionmaker(bind=self.engine)()
def __del__(self):
self.session.close()
self.engine.dispose()

View File

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from .model import *
from .LocalDatabase import LocalDatabase

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
import os
from sqlalchemy import Column, Integer, String
from .BaseModel import BaseModel
class SessionModel(BaseModel):
__tablename__ = 'session'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(64))
host = Column(String(39))
port = Column(Integer)
user = Column(String(64))
password = Column(String(64))
remark = Column(String(256))

View File

@ -13,6 +13,7 @@ class HkuEditSessionDialog(QtWidgets.QDialog, Ui_HkuEditSessionDialog):
super(HkuEditSessionDialog, self).__init__(parent)
self.setWindowIcon(QtGui.QIcon(":/icon/server.png"))
self.setupUi(self)
self.remark_textEdit.textChanged.connect(self.limitRemarkMaxLength)
self.count = 1
def accept(self):
@ -27,6 +28,16 @@ class HkuEditSessionDialog(QtWidgets.QDialog, Ui_HkuEditSessionDialog):
def on_test_pushButton_clicked(self):
print("jjjj")
def limitRemarkMaxLength(self):
text = self.remark_textEdit.toPlainText()
print(len(text))
max_length = 3
if len(text) > max_length:
self.remark_textEdit.setText(text[:max_length])
cursor = self.remark_textEdit.textCursor()
cursor.movePosition(QtGui.QTextCursor.End)
self.remark_textEdit.setTextCursor(cursor)
if __name__ == "__main__":
import sys

View File

@ -14,55 +14,63 @@ from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_HkuEditSessionDialog(object):
def setupUi(self, HkuEditSessionDialog):
HkuEditSessionDialog.setObjectName("HkuEditSessionDialog")
HkuEditSessionDialog.resize(562, 390)
HkuEditSessionDialog.resize(562, 401)
self.layoutWidget = QtWidgets.QWidget(HkuEditSessionDialog)
self.layoutWidget.setGeometry(QtCore.QRect(30, 20, 501, 298))
self.layoutWidget.setGeometry(QtCore.QRect(30, 30, 501, 298))
self.layoutWidget.setObjectName("layoutWidget")
self.gridLayout = QtWidgets.QGridLayout(self.layoutWidget)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
self.password_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.password_lineEdit.setMaxLength(64)
self.password_lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
self.password_lineEdit.setPlaceholderText("")
self.password_lineEdit.setObjectName("password_lineEdit")
self.gridLayout.addWidget(self.password_lineEdit, 4, 1, 1, 2)
self.user_label = QtWidgets.QLabel(self.layoutWidget)
self.user_label.setObjectName("user_label")
self.gridLayout.addWidget(self.user_label, 3, 0, 1, 1)
self.host_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.host_lineEdit.setMaxLength(39)
self.host_lineEdit.setObjectName("host_lineEdit")
self.gridLayout.addWidget(self.host_lineEdit, 1, 1, 1, 2)
self.user_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.user_lineEdit.setMaxLength(64)
self.user_lineEdit.setObjectName("user_lineEdit")
self.gridLayout.addWidget(self.user_lineEdit, 3, 1, 1, 2)
self.password_label = QtWidgets.QLabel(self.layoutWidget)
self.password_label.setObjectName("password_label")
self.gridLayout.addWidget(self.password_label, 4, 0, 1, 1)
self.host_label = QtWidgets.QLabel(self.layoutWidget)
self.host_label.setObjectName("host_label")
self.gridLayout.addWidget(self.host_label, 0, 0, 1, 1)
self.ip_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.ip_lineEdit.setMaxLength(100)
self.ip_lineEdit.setObjectName("ip_lineEdit")
self.gridLayout.addWidget(self.ip_lineEdit, 0, 1, 1, 2)
self.gridLayout.addWidget(self.host_label, 1, 0, 1, 1)
self.port_label = QtWidgets.QLabel(self.layoutWidget)
self.port_label.setObjectName("port_label")
self.gridLayout.addWidget(self.port_label, 1, 0, 1, 1)
self.gridLayout.addWidget(self.port_label, 2, 0, 1, 1)
spacerItem = QtWidgets.QSpacerItem(218, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem, 2, 2, 1, 1)
self.label = QtWidgets.QLabel(self.layoutWidget)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.port_spinBox = QtWidgets.QSpinBox(self.layoutWidget)
self.port_spinBox.setMaximum(65535)
self.port_spinBox.setProperty("value", 9001)
self.port_spinBox.setObjectName("port_spinBox")
self.gridLayout.addWidget(self.port_spinBox, 1, 1, 1, 1)
spacerItem = QtWidgets.QSpacerItem(218, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem, 1, 2, 1, 1)
self.user_label = QtWidgets.QLabel(self.layoutWidget)
self.user_label.setObjectName("user_label")
self.gridLayout.addWidget(self.user_label, 2, 0, 1, 1)
self.user_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.user_lineEdit.setMaxLength(100)
self.user_lineEdit.setObjectName("user_lineEdit")
self.gridLayout.addWidget(self.user_lineEdit, 2, 1, 1, 2)
self.password_label = QtWidgets.QLabel(self.layoutWidget)
self.password_label.setObjectName("password_label")
self.gridLayout.addWidget(self.password_label, 3, 0, 1, 1)
self.password_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.password_lineEdit.setMaxLength(100)
self.password_lineEdit.setEchoMode(QtWidgets.QLineEdit.Password)
self.password_lineEdit.setPlaceholderText("")
self.password_lineEdit.setObjectName("password_lineEdit")
self.gridLayout.addWidget(self.password_lineEdit, 3, 1, 1, 2)
self.gridLayout.addWidget(self.port_spinBox, 2, 1, 1, 1)
self.remark_textEdit = QtWidgets.QTextEdit(self.layoutWidget)
self.remark_textEdit.setAcceptRichText(False)
self.remark_textEdit.setObjectName("remark_textEdit")
self.gridLayout.addWidget(self.remark_textEdit, 5, 1, 1, 2)
self.remark_label = QtWidgets.QLabel(self.layoutWidget)
self.remark_label.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignTop)
self.remark_label.setObjectName("remark_label")
self.gridLayout.addWidget(self.remark_label, 4, 0, 1, 1)
self.remark_textEdit = QtWidgets.QTextEdit(self.layoutWidget)
self.remark_textEdit.setObjectName("remark_textEdit")
self.gridLayout.addWidget(self.remark_textEdit, 4, 1, 1, 2)
self.gridLayout.addWidget(self.remark_label, 5, 0, 1, 1)
self.name_lineEdit = QtWidgets.QLineEdit(self.layoutWidget)
self.name_lineEdit.setMaxLength(64)
self.name_lineEdit.setObjectName("name_lineEdit")
self.gridLayout.addWidget(self.name_lineEdit, 0, 1, 1, 2)
self.layoutWidget1 = QtWidgets.QWidget(HkuEditSessionDialog)
self.layoutWidget1.setGeometry(QtCore.QRect(237, 340, 291, 25))
self.layoutWidget1.setGeometry(QtCore.QRect(237, 350, 291, 25))
self.layoutWidget1.setObjectName("layoutWidget1")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget1)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
@ -82,13 +90,20 @@ class Ui_HkuEditSessionDialog(object):
self.buttonBox.accepted.connect(HkuEditSessionDialog.accept)
self.buttonBox.rejected.connect(HkuEditSessionDialog.reject)
QtCore.QMetaObject.connectSlotsByName(HkuEditSessionDialog)
HkuEditSessionDialog.setTabOrder(self.name_lineEdit, self.host_lineEdit)
HkuEditSessionDialog.setTabOrder(self.host_lineEdit, self.port_spinBox)
HkuEditSessionDialog.setTabOrder(self.port_spinBox, self.user_lineEdit)
HkuEditSessionDialog.setTabOrder(self.user_lineEdit, self.password_lineEdit)
HkuEditSessionDialog.setTabOrder(self.password_lineEdit, self.remark_textEdit)
HkuEditSessionDialog.setTabOrder(self.remark_textEdit, self.test_pushButton)
def retranslateUi(self, HkuEditSessionDialog):
_translate = QtCore.QCoreApplication.translate
HkuEditSessionDialog.setWindowTitle(_translate("HkuEditSessionDialog", "Dialog"))
self.host_label.setText(_translate("HkuEditSessionDialog", "Host/ip:"))
self.port_label.setText(_translate("HkuEditSessionDialog", "Port:"))
self.user_label.setText(_translate("HkuEditSessionDialog", "User:"))
self.password_label.setText(_translate("HkuEditSessionDialog", "Password:"))
self.host_label.setText(_translate("HkuEditSessionDialog", "Host/ip:"))
self.port_label.setText(_translate("HkuEditSessionDialog", "Port:"))
self.label.setText(_translate("HkuEditSessionDialog", "Name:"))
self.remark_label.setText(_translate("HkuEditSessionDialog", "Remark:"))
self.test_pushButton.setText(_translate("HkuEditSessionDialog", "Test connect"))

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>562</width>
<height>390</height>
<height>401</height>
</rect>
</property>
<property name="windowTitle">
@ -17,44 +17,68 @@
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<y>30</y>
<width>501</width>
<height>298</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<item row="4" column="1" colspan="2">
<widget class="QLineEdit" name="password_lineEdit">
<property name="maxLength">
<number>64</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="user_label">
<property name="text">
<string>User:</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="host_lineEdit">
<property name="maxLength">
<number>39</number>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="user_lineEdit">
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="password_label">
<property name="text">
<string>Password:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="host_label">
<property name="text">
<string>Host/ip:</string>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="ip_lineEdit">
<property name="maxLength">
<number>100</number>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="port_label">
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="port_spinBox">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>9001</number>
</property>
</widget>
</item>
<item row="1" column="2">
<item row="2" column="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -67,41 +91,31 @@
</property>
</spacer>
</item>
<item row="2" column="0">
<widget class="QLabel" name="user_label">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>User:</string>
<string>Name:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="user_lineEdit">
<property name="maxLength">
<number>100</number>
<item row="2" column="1">
<widget class="QSpinBox" name="port_spinBox">
<property name="maximum">
<number>65535</number>
</property>
<property name="value">
<number>9001</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="password_label">
<property name="text">
<string>Password:</string>
<item row="5" column="1" colspan="2">
<widget class="QTextEdit" name="remark_textEdit">
<property name="acceptRichText">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QLineEdit" name="password_lineEdit">
<property name="maxLength">
<number>100</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
<property name="placeholderText">
<string/>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="remark_label">
<property name="text">
<string>Remark:</string>
@ -111,8 +125,12 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<widget class="QTextEdit" name="remark_textEdit"/>
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="name_lineEdit">
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
</layout>
</widget>
@ -120,7 +138,7 @@
<property name="geometry">
<rect>
<x>237</x>
<y>340</y>
<y>350</y>
<width>291</width>
<height>25</height>
</rect>
@ -159,6 +177,15 @@
</layout>
</widget>
</widget>
<tabstops>
<tabstop>name_lineEdit</tabstop>
<tabstop>host_lineEdit</tabstop>
<tabstop>port_spinBox</tabstop>
<tabstop>user_lineEdit</tabstop>
<tabstop>password_lineEdit</tabstop>
<tabstop>remark_textEdit</tabstop>
<tabstop>test_pushButton</tabstop>
</tabstops>
<resources/>
<connections>
<connection>

View File

@ -30,8 +30,10 @@ class HkuSessionViewWidget(QtWidgets.QDockWidget):
self.server_menu.addAction(self.parent().action_dict['action_file_session'])
self.tree.customContextMenuRequested.connect(self.on_tree_customContextMenuRequested)
def on_tree_customContextMenuRequested(self):
def on_tree_customContextMenuRequested(self, pos):
print("on_tree_customContextMenuRequested")
item = self.tree.itemAt(pos)
print(item.parent)
self.server_menu.exec(QtGui.QCursor.pos())
def addSession(self):

View File

@ -145,6 +145,7 @@ setup(
'qdarkstyle',
'flatbuffers',
'pynng',
'requests'
'requests',
'sqlalchemy'
],
)