개정판 eafaadaf
Add QConfigurationDialog
DTI_PID/DTI_PID/DTI_PID_UI.py | ||
---|---|---|
61 | 61 |
self.pushButtonCreateSymbol = QtWidgets.QPushButton(self.Symbol) |
62 | 62 |
self.pushButtonCreateSymbol.setObjectName("pushButtonCreateSymbol") |
63 | 63 |
self.verticalLayout_2.addWidget(self.pushButtonCreateSymbol) |
64 |
self.listView_2 = QtWidgets.QListView(self.Symbol) |
|
65 |
self.listView_2.setObjectName("listView_2") |
|
66 |
self.verticalLayout_2.addWidget(self.listView_2) |
|
64 | 67 |
self.listView = QtWidgets.QListView(self.Symbol) |
65 | 68 |
self.listView.setObjectName("listView") |
66 | 69 |
self.verticalLayout_2.addWidget(self.listView) |
DTI_PID/DTI_PID/QConfigurationDialog.py | ||
---|---|---|
1 |
# coding: utf-8 |
|
2 |
import os |
|
3 |
from PyQt5.QtCore import * |
|
4 |
from PyQt5.QtGui import * |
|
5 |
from PyQt5.QtWidgets import * |
|
6 |
import sqlite3 |
|
7 |
import Configuration_UI |
|
8 |
|
|
9 |
#DB_NAME = "db/DTI_PID_test.db" |
|
10 |
DB_NAME = os.path.dirname(os.path.realpath(__file__)) + "\\db\\DTI_PID.db" |
|
11 |
|
|
12 |
class QConfigurationDialog(QDialog): |
|
13 |
def __init__(self, parent): |
|
14 |
QDialog.__init__(self, parent) |
|
15 |
|
|
16 |
self.ui = Configuration_UI.Ui_ConfigurationDialog() |
|
17 |
self.ui.setupUi(self) |
|
18 |
self.isAccepted = False |
|
19 |
|
|
20 |
try: |
|
21 |
# Creates or opens a file called mydb with a SQLite3 DB |
|
22 |
db = sqlite3.connect(DB_NAME) |
|
23 |
# Get a cursor object |
|
24 |
cursor = db.cursor() |
|
25 |
|
|
26 |
sql = "select * from configuration where section='Sliding Window'" |
|
27 |
cursor.execute(sql) |
|
28 |
rows = cursor.fetchall() |
|
29 |
for row in rows: |
|
30 |
if row[1] == 'Width': |
|
31 |
self.ui.spinBoxWidth.setValue(int(row[2])) |
|
32 |
elif row[1] == 'Height': |
|
33 |
self.ui.spinBoxHeight.setValue(int(row[2])) |
|
34 |
# Catch the exception |
|
35 |
except Exception as e: |
|
36 |
# Roll back any change if something goes wrong |
|
37 |
db.rollback() |
|
38 |
raise e |
|
39 |
finally: |
|
40 |
# Close the db connection |
|
41 |
db.close() |
|
42 |
|
|
43 |
def accept(self): |
|
44 |
try: |
|
45 |
self.isAccepted = True |
|
46 |
|
|
47 |
# Creates or opens a file called mydb with a SQLite3 DB |
|
48 |
db = sqlite3.connect(DB_NAME) |
|
49 |
# Get a cursor object |
|
50 |
cursor = db.cursor() |
|
51 |
sql = "update configuration set value={} where section='Sliding Window' and key='Width'".format(self.ui.spinBoxWidth.value()) |
|
52 |
cursor.execute(sql) |
|
53 |
|
|
54 |
sql = "update configuration set value={} where section='Sliding Window' and key='Height'".format(self.ui.spinBoxHeight.value()) |
|
55 |
cursor.execute(sql) |
|
56 |
|
|
57 |
db.commit() |
|
58 |
except Exception as e: |
|
59 |
db.rollback() |
|
60 |
finally: |
|
61 |
db.close() |
|
62 |
|
|
63 |
QDialog.accept(self) |
DTI_PID/DTI_PID/UI/DTI__PID.ui | ||
---|---|---|
108 | 108 |
</widget> |
109 | 109 |
</item> |
110 | 110 |
<item> |
111 |
<widget class="QListView" name="listView_2"/> |
|
112 |
</item> |
|
113 |
<item> |
|
111 | 114 |
<widget class="QListView" name="listView"/> |
112 | 115 |
</item> |
113 | 116 |
</layout> |
내보내기 Unified diff