Skip to content

Commit 4327369

Browse files
committed
Exclude id from displaying/hiding columns
1 parent 69fbc20 commit 4327369

File tree

6 files changed

+28
-21
lines changed

6 files changed

+28
-21
lines changed

pyqt_openai/chatNavWidget.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def __initUi(self):
147147
self.__model.setHeaderData(i, Qt.Orientation.Horizontal, self.__columns[i])
148148
self.__model.select()
149149
# descending order by insert date
150-
idx = self.__columns.index('insert_dt')
150+
idx = self.__columns.index(THREAD_ORDERBY)
151151
self.__model.sort(idx, Qt.SortOrder.DescendingOrder)
152152

153153
# init the proxy model
@@ -237,11 +237,15 @@ def refreshData(self, title=None):
237237
self.__proxyModel.setFilterRegularExpression(title)
238238

239239
def __clicked(self, idx):
240-
# get id of record
241-
id = self.__model.data(self.__proxyModel.mapToSource(idx.siblingAtColumn(0)), role=Qt.ItemDataRole.DisplayRole)
242-
title = self.__model.data(self.__proxyModel.mapToSource(idx.siblingAtColumn(1)), role=Qt.ItemDataRole.DisplayRole)
243-
244-
self.clicked.emit(id, title)
240+
# get the source index
241+
source_idx = self.__proxyModel.mapToSource(idx)
242+
# get the primary key value of the row
243+
cur_id = self.__model.record(source_idx.row()).value("id")
244+
clicked_thread = DB.selectThread(cur_id)
245+
# get the title
246+
title = clicked_thread['name']
247+
248+
self.clicked.emit(cur_id, title)
245249

246250
def __getSelectedIds(self):
247251
selected_idx_s = self.__tableView.selectedIndexes()

pyqt_openai/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# APP
22
IMAGE_FILE_EXT = 'Image file (*.jpg *.png)'
33
DEFAULT_ICON_SIZE = (24, 24)
4+
COLUMN_TO_EXCLUDE_FROM_SHOW_HIDE = ['id']
45

56
PAYPAL_URL = 'https://paypal.me/yjg30737'
67
BUYMEACOFFEE_URL = 'https://www.buymeacoffee.com/yjg30737'

pyqt_openai/models.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@ def __init__(self, **kwargs):
1717
setattr(self, key, value)
1818

1919
@classmethod
20-
def get_keys(cls):
21-
return [field.name for field in fields(cls)]
22-
23-
@classmethod
24-
def get_keys_for_insert(cls, excludes: list = None):
20+
def get_keys(cls, excludes: list = None):
2521
"""
2622
Function that returns the keys of the target data type as a list.
2723
Exclude the keys in the "excludes" list.
2824
"""
2925
if excludes is None:
3026
excludes = []
31-
arr = cls.get_keys()
27+
arr = [field.name for field in fields(cls)]
3228
for exclude in excludes:
3329
if exclude in arr:
3430
arr.remove(exclude)
@@ -40,7 +36,7 @@ def get_values_for_insert(self, excludes: list = None):
4036
"""
4137
if excludes is None:
4238
excludes = []
43-
arr = [getattr(self, key) for key in self.get_keys_for_insert(excludes)]
39+
arr = [getattr(self, key) for key in self.get_keys(excludes)]
4440
return arr
4541

4642
def get_items(self, excludes: list = None):
@@ -49,7 +45,7 @@ def get_items(self, excludes: list = None):
4945
"""
5046
if excludes is None:
5147
excludes = []
52-
return {key: getattr(self, key) for key in self.get_keys_for_insert(excludes)}.items()
48+
return {key: getattr(self, key) for key in self.get_keys(excludes)}.items()
5349

5450
def create_insert_query(self, table_name: str, excludes: list = None):
5551
if excludes is None:
@@ -58,7 +54,7 @@ def create_insert_query(self, table_name: str, excludes: list = None):
5854
Function to dynamically generate an SQLite insert statement.
5955
Takes the table name as a parameter.
6056
"""
61-
field_names = self.get_keys_for_insert(excludes)
57+
field_names = self.get_keys(excludes)
6258
columns = ', '.join(field_names)
6359
placeholders = ', '.join(['?' for _ in field_names])
6460
query = f'INSERT INTO {table_name} ({columns}) VALUES ({placeholders})'

pyqt_openai/settingsDialog.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import sys
33

4+
from pyqt_openai.constants import COLUMN_TO_EXCLUDE_FROM_SHOW_HIDE
45
from pyqt_openai.widgets.checkBoxListWidget import CheckBoxListWidget
56

67
# Get the absolute path of the current script file
@@ -104,7 +105,7 @@ def __initUi(self):
104105

105106
chatColAllCheckBox = QCheckBox('Check all')
106107
self.__chatColCheckBoxListWidget = CheckBoxListWidget()
107-
for k in ChatThreadContainer.get_keys():
108+
for k in ChatThreadContainer.get_keys(excludes=COLUMN_TO_EXCLUDE_FROM_SHOW_HIDE):
108109
self.__chatColCheckBoxListWidget.addItem(k, checked=k in self.__chat_column_to_show)
109110

110111
chatColAllCheckBox.stateChanged.connect(self.__chatColCheckBoxListWidget.toggleState)
@@ -119,7 +120,7 @@ def __initUi(self):
119120

120121
imageColAllCheckBox = QCheckBox('Check all')
121122
self.__imageColCheckBoxListWidget = CheckBoxListWidget()
122-
for k in ImagePromptContainer.get_keys():
123+
for k in ImagePromptContainer.get_keys(excludes=COLUMN_TO_EXCLUDE_FROM_SHOW_HIDE):
123124
self.__imageColCheckBoxListWidget.addItem(k, checked=k in self.__image_column_to_show)
124125

125126
imageColAllCheckBox.stateChanged.connect(self.__imageColCheckBoxListWidget.toggleState)
@@ -171,6 +172,6 @@ def getSettingsParam(self):
171172
show_toolbar=self.__showToolbarCheckBox.isChecked(),
172173
show_secondary_toolbar=self.__showSecondaryToolBarChkBox.isChecked(),
173174
thread_tool_widget=self.__showThreadToolWidgetChkBox.isChecked(),
174-
chat_column_to_show=self.__chatColCheckBoxListWidget.getCheckedItemsText(),
175-
image_column_to_show=self.__imageColCheckBoxListWidget.getCheckedItemsText()
175+
chat_column_to_show=COLUMN_TO_EXCLUDE_FROM_SHOW_HIDE+self.__chatColCheckBoxListWidget.getCheckedItemsText(),
176+
image_column_to_show=COLUMN_TO_EXCLUDE_FROM_SHOW_HIDE+self.__imageColCheckBoxListWidget.getCheckedItemsText()
176177
)

pyqt_openai/sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ def __createImage(self):
710710
# To not make table every time to change column's name and type
711711
self.__c.execute(f'PRAGMA table_info({self.__image_tb_nm})')
712712
existing_columns = set([column[1] for column in self.__c.fetchall()])
713-
required_columns = set(ImagePromptContainer.get_keys_for_insert(['id', 'update_dt', 'insert_dt']))
713+
required_columns = set(ImagePromptContainer.get_keys(['id', 'update_dt', 'insert_dt']))
714714

715715
# Find missing columns
716716
missing_columns = required_columns - existing_columns

pyqt_openai/widgets/imageNavWidget.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ def refresh(self):
142142
self.__model.select()
143143

144144
def __clicked(self, idx):
145-
cur_id = self.__proxyModel.data(self.__proxyModel.index(idx.row(), self.__columns.index('id')))
145+
# get the source index
146+
source_idx = self.__proxyModel.mapToSource(idx)
147+
148+
# get the primary key value of the row
149+
cur_id = self.__model.record(source_idx.row()).value("id")
150+
146151
# Get data from DB id
147152
data = DB.selectCertainImage(cur_id)['data']
148153
if data:

0 commit comments

Comments
 (0)