feat: more reasonable

This commit is contained in:
iridiumR 2023-05-22 11:35:19 +08:00
parent ce1c8c6df8
commit d87b0d6d87
No known key found for this signature in database
GPG key ID: 49735733EB1A32C8
2 changed files with 13 additions and 3 deletions

View file

@ -2,6 +2,7 @@ from PyQt6.QtWidgets import *
from ._pg import PostgresTab from ._pg import PostgresTab
from ._category import CategoryTab from ._category import CategoryTab
from ._pg import PostgresTab from ._pg import PostgresTab
from ._account import AccountTab
def initUI(self): def initUI(self):
@ -10,11 +11,13 @@ def initUI(self):
self.pg = PostgresTab() self.pg = PostgresTab()
self.categoryTab = CategoryTab(self) self.categoryTab = CategoryTab(self)
self.accountTab = AccountTab(self)
# 创建主窗口tab布局 # 创建主窗口tab布局
mainWidget = QTabWidget() mainWidget = QTabWidget()
mainWidget.addTab(self.pg, 'Connect') mainWidget.addTab(self.pg, 'Connect')
mainWidget.addTab(self.categoryTab, 'Category') mainWidget.addTab(self.categoryTab, 'Category')
mainWidget.addTab(self.accountTab, 'Account')
mainWidget.currentChanged.connect(self.onTabChanged) mainWidget.currentChanged.connect(self.onTabChanged)
@ -23,5 +26,5 @@ def initUI(self):
self.pg.onConnectClicked() self.pg.onConnectClicked()
def onTabChanged(self, index): def onTabChanged(self, index):
if (index == 1):
self.centralWidget().widget(index).selected() self.centralWidget().widget(index).selected()

View file

@ -3,12 +3,19 @@ import psycopg2
from ._tab import TabPage from ._tab import TabPage
class PostgresTab(TabPage): class PostgresTab(TabPage):
cur = None
conn = None
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.initUI() self.initUI()
cur = None # 退出时断开数据库连接
conn = None def __del__(self):
if(self.connected()):
self.disconnectFromDatabase()
def connected(self): def connected(self):
return self.cur is not None return self.cur is not None