batoolset 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batoolset/GUI/__init__.py +0 -0
- batoolset/GUI/list_gui.py +513 -0
- batoolset/GUI/multi_image_display.py +989 -0
- batoolset/GUI/open.py +325 -0
- batoolset/GUI/overlay_hints.py +45 -0
- batoolset/GUI/paint2.py +1345 -0
- batoolset/GUI/scrollablepaint.py +1152 -0
- batoolset/IJ_ROIs/__init__.py +0 -0
- batoolset/IJ_ROIs/tools.py +40 -0
- batoolset/PATH/__init__.py +0 -0
- batoolset/PATH/tools.py +79 -0
- batoolset/SQLite_tools/__init__.py +0 -0
- batoolset/SQLite_tools/tools.py +840 -0
- batoolset/__init__.py +0 -0
- batoolset/binary/__init__.py +0 -0
- batoolset/binary/tools.py +123 -0
- batoolset/binarytools/__init__.py +0 -0
- batoolset/binarytools/cell_center_detector.py +290 -0
- batoolset/clipboard_tools/__init__.py +0 -0
- batoolset/clipboard_tools/tools.py +7 -0
- batoolset/colors/__init__.py +0 -0
- batoolset/colors/colorgen.py +193 -0
- batoolset/colors/tools.py +22 -0
- batoolset/command_line/__init__.py +0 -0
- batoolset/command_line/tools.py +18 -0
- batoolset/dialogs/__init__.py +0 -0
- batoolset/dialogs/opensave.py +228 -0
- batoolset/dicts/__init__.py +0 -0
- batoolset/dicts/tools.py +299 -0
- batoolset/dims/__init__.py +0 -0
- batoolset/dims/tools.py +83 -0
- batoolset/draw/__init__.py +0 -0
- batoolset/draw/shapes/Position.py +183 -0
- batoolset/draw/shapes/__init__.py +0 -0
- batoolset/draw/shapes/automated_alignment_drawing_refactored.py +346 -0
- batoolset/draw/shapes/circle2d.py +99 -0
- batoolset/draw/shapes/compute_optimal_size_all_merged.py +317 -0
- batoolset/draw/shapes/ellipse2d.py +336 -0
- batoolset/draw/shapes/freehand2d.py +235 -0
- batoolset/draw/shapes/group.py +1830 -0
- batoolset/draw/shapes/image2d.py +2469 -0
- batoolset/draw/shapes/line2d.py +575 -0
- batoolset/draw/shapes/point2d.py +257 -0
- batoolset/draw/shapes/polygon2d.py +357 -0
- batoolset/draw/shapes/polyline2d.py +235 -0
- batoolset/draw/shapes/rect2d.py +388 -0
- batoolset/draw/shapes/rectangle2d.py +601 -0
- batoolset/draw/shapes/scalebar.py +304 -0
- batoolset/draw/shapes/serializablefont.py +126 -0
- batoolset/draw/shapes/serializableguiparams.py +10 -0
- batoolset/draw/shapes/square2d.py +103 -0
- batoolset/draw/shapes/textorientation.py +45 -0
- batoolset/draw/shapes/tools.py +467 -0
- batoolset/draw/shapes/transform2D.py +350 -0
- batoolset/draw/shapes/txt2d.py +550 -0
- batoolset/draw/widgets/__init__.py +0 -0
- batoolset/draw/widgets/col.py +343 -0
- batoolset/draw/widgets/image_group.py +248 -0
- batoolset/draw/widgets/image_organizer.py +96 -0
- batoolset/draw/widgets/paint.py +184 -0
- batoolset/draw/widgets/vectorial.py +257 -0
- batoolset/figure/__init__.py +0 -0
- batoolset/figure/alignment.py +814 -0
- batoolset/figure/column.py +1117 -0
- batoolset/figure/fig_tools.py +285 -0
- batoolset/figure/minimal_debugger_scale_etc.py +139 -0
- batoolset/figure/panel.py +697 -0
- batoolset/figure/row.py +852 -0
- batoolset/figure/user_selection.py +287 -0
- batoolset/files/__init__.py +0 -0
- batoolset/files/tools.py +1321 -0
- batoolset/images/__init__.py +0 -0
- batoolset/images/tools.py +81 -0
- batoolset/img.py +5216 -0
- batoolset/linux/__init__.py +0 -0
- batoolset/linux/tools.py +72 -0
- batoolset/lists/__init__.py +0 -0
- batoolset/lists/tools.py +436 -0
- batoolset/luts/__init__.py +0 -0
- batoolset/luts/lut_minimal_test.py +1207 -0
- batoolset/matplolib/__init__.py +0 -0
- batoolset/matplolib/tools.py +44 -0
- batoolset/np_tools/__init__.py +0 -0
- batoolset/np_tools/tools.py +252 -0
- batoolset/np_tools/trash.py +15 -0
- batoolset/pandas_tools/__init__.py +0 -0
- batoolset/pandas_tools/tools.py +880 -0
- batoolset/partials/__init__.py +0 -0
- batoolset/partials/tools.py +83 -0
- batoolset/plot_tools/__init__.py +0 -0
- batoolset/plot_tools/tools.py +70 -0
- batoolset/pyqt/__init__.py +0 -0
- batoolset/pyqt/tools.py +691 -0
- batoolset/re_tools/__init__.py +0 -0
- batoolset/re_tools/tools.py +35 -0
- batoolset/serialization/__init__.py +0 -0
- batoolset/serialization/tools.py +1192 -0
- batoolset/sets/__init__.py +0 -0
- batoolset/sets/tools.py +109 -0
- batoolset/settings/__init__.py +0 -0
- batoolset/settings/global_settings.py +134 -0
- batoolset/strings/__init__.py +0 -0
- batoolset/strings/tools.py +225 -0
- batoolset/ta/__init__.py +0 -0
- batoolset/ta/database/__init__.py +0 -0
- batoolset/ta/database/advanced_sql_plotter.py +1170 -0
- batoolset/ta/database/my_qt_table.py +79 -0
- batoolset/ta/database/preview_and_edit_sqlite_db.py +405 -0
- batoolset/ta/database/sql.py +2141 -0
- batoolset/ta/database/sql_column_name_dialog.py +122 -0
- batoolset/ta/measurements/TAmeasures.py +2226 -0
- batoolset/ta/measurements/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/__init__.py +0 -0
- batoolset/ta/measurements/measurements3D/get_point_on_surface_if_centroid_is_bad.py +175 -0
- batoolset/ta/measurements/measurements3D/height_map_to_projection.py +82 -0
- batoolset/ta/measurements/measurements3D/measures3D.py +208 -0
- batoolset/ta/measurements/measurements3D/triangulate.py +331 -0
- batoolset/ta/measurements/nematic.py +562 -0
- batoolset/ta/measurements/nematic_measurements.py +107 -0
- batoolset/ta/segmentation/__init__.py +0 -0
- batoolset/ta/segmentation/neo_wshed.py +314 -0
- batoolset/ta/selections/__init__.py +0 -0
- batoolset/ta/selections/selection.py +329 -0
- batoolset/ta/tracking/__init__.py +0 -0
- batoolset/ta/tracking/last_tracking_based_on_matching_or_on_translation_from_mermaid_warp.py +653 -0
- batoolset/ta/tracking/local_to_track_correspondance.py +138 -0
- batoolset/ta/tracking/rapid_detection_of_vertices.py +517 -0
- batoolset/ta/tracking/registration.py +108 -0
- batoolset/ta/tracking/swap_detector_and_fixer.py +296 -0
- batoolset/ta/tracking/track_correction.py +238 -0
- batoolset/ta/tracking/tracking_error_detector_and_fixer.py +3099 -0
- batoolset/ta/tracking/tracking_yet_another_approach_pyramidal_registration_n_neo_swapping_correction.py +725 -0
- batoolset/ta/utils/TA_tools.py +43 -0
- batoolset/ta/utils/__init__.py +0 -0
- batoolset/ta/utils/rps_tools.py +1783 -0
- batoolset/tests/__init__.py +0 -0
- batoolset/tests/rps_tools.py +51 -0
- batoolset/tests/tools.py +10 -0
- batoolset/tools/__init__.py +0 -0
- batoolset/tools/early_stopper_class.py +9 -0
- batoolset/tools/guided_data_recoverer.py +110 -0
- batoolset/tools/logger.py +100 -0
- batoolset/tools/mytimer.py +31 -0
- batoolset/tools/prompt_color.py +160 -0
- batoolset/tools/qthandler.py +118 -0
- batoolset/uitools/__init__.py +0 -0
- batoolset/uitools/blinker.py +56 -0
- batoolset/unsafe/__init__.py +0 -0
- batoolset/unsafe/tools.py +115 -0
- batoolset/utils/__init__.py +0 -0
- batoolset/utils/commontools.py +158 -0
- batoolset/utils/loadlist.py +728 -0
- batoolset/version.py +10 -0
- batoolset/xml/__init__.py +0 -0
- batoolset/xml/tools.py +65 -0
- batoolset/zip_tools/__init__.py +0 -0
- batoolset/zip_tools/tools.py +76 -0
- batoolset-0.1.0.dist-info/LICENSE +24 -0
- batoolset-0.1.0.dist-info/METADATA +45 -0
- batoolset-0.1.0.dist-info/RECORD +162 -0
- batoolset-0.1.0.dist-info/WHEEL +5 -0
- batoolset-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from batoolset.settings.global_settings import set_UI # set the UI to be used by qtpy
|
|
5
|
+
set_UI()
|
|
6
|
+
from batoolset.pyqt.tools import getCtrlModifier
|
|
7
|
+
from qtpy import QtGui, QtWidgets
|
|
8
|
+
from qtpy.QtCore import Qt, QMimeData
|
|
9
|
+
from qtpy.QtWidgets import QTableWidget, QApplication, QAbstractItemView
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class MyTableWidget(QTableWidget):
|
|
13
|
+
def __init__(self, parent=None):
|
|
14
|
+
super(MyTableWidget, self).__init__(parent)
|
|
15
|
+
self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectItems) # Set the selection behavior to select individual items
|
|
16
|
+
self.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection) # Set the selection mode to select a single item at a time
|
|
17
|
+
self.copy = None
|
|
18
|
+
|
|
19
|
+
def keyPressEvent(self, event):
|
|
20
|
+
"""
|
|
21
|
+
Handle key press events.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
event (QKeyEvent): The key event.
|
|
25
|
+
|
|
26
|
+
"""
|
|
27
|
+
key = event.key()
|
|
28
|
+
|
|
29
|
+
if key == Qt.Key_Delete:
|
|
30
|
+
# Delete key pressed, clear the text of the selected item
|
|
31
|
+
item = self.get_selected_item()
|
|
32
|
+
if item is not None:
|
|
33
|
+
item.setText('')
|
|
34
|
+
elif key == Qt.Key_C and (event.modifiers() & getCtrlModifier()):
|
|
35
|
+
# Ctrl+C pressed, copy the selected item(s) text
|
|
36
|
+
self.copy = self.get_selection()
|
|
37
|
+
elif key == Qt.Key_V and (event.modifiers() & getCtrlModifier()):
|
|
38
|
+
# Ctrl+V pressed, paste the copied text to the selected item
|
|
39
|
+
if self.copy is not None:
|
|
40
|
+
item = self.get_selected_item()
|
|
41
|
+
if item is not None:
|
|
42
|
+
item.setText(self.copy)
|
|
43
|
+
else:
|
|
44
|
+
super(MyTableWidget, self).keyPressEvent(event)
|
|
45
|
+
|
|
46
|
+
def get_selection(self):
|
|
47
|
+
"""
|
|
48
|
+
Get the selected item(s) text.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
str or list: The selected item(s) text.
|
|
52
|
+
|
|
53
|
+
"""
|
|
54
|
+
selection = []
|
|
55
|
+
items = self.selectedItems()
|
|
56
|
+
for item in items:
|
|
57
|
+
print('selected', item.text())
|
|
58
|
+
selection.append(item.text())
|
|
59
|
+
if len(selection) == 0:
|
|
60
|
+
return None
|
|
61
|
+
if len(selection) == 1:
|
|
62
|
+
return selection[0]
|
|
63
|
+
return selection
|
|
64
|
+
|
|
65
|
+
def get_selected_item(self):
|
|
66
|
+
"""
|
|
67
|
+
Get the selected item.
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
QTableWidgetItem or None: The selected item.
|
|
71
|
+
|
|
72
|
+
"""
|
|
73
|
+
items = self.selectedItems()
|
|
74
|
+
for item in items:
|
|
75
|
+
return item
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
pass
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
# faire deux modes --> un in mem
|
|
2
|
+
# faire une table 'properties' si elle existe
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# TODO lui faire aussi charger une liste d'images et tt un tas de fichiers db --> à faire
|
|
6
|
+
# peut etre faire une table style image properties
|
|
7
|
+
# je pourrais reinjecter
|
|
8
|
+
|
|
9
|
+
# cols to have --> time and d/x ratio and maybe also the xyz px sizes and the unit of size
|
|
10
|
+
# see how and where I can have that done
|
|
11
|
+
# maybe also set it as a parameter
|
|
12
|
+
# can I allow copy below if 1 or None
|
|
13
|
+
# maybe if not known set it to none then it is ignored
|
|
14
|
+
# then allow plots
|
|
15
|
+
# ce truc pourrait etre genere avant meme de rentrer la dedans à l'etape du preprocess --> good idea and no need to modify the file which is a bit painful
|
|
16
|
+
|
|
17
|
+
# ça marche mais faut le rendre un peu plus smart
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
from batoolset.settings.global_settings import set_UI # set the UI to qtpy
|
|
22
|
+
set_UI()
|
|
23
|
+
import os
|
|
24
|
+
import traceback
|
|
25
|
+
import numpy as np
|
|
26
|
+
import sqlite3
|
|
27
|
+
# import pandas as pd
|
|
28
|
+
# from qtpy import QtSql
|
|
29
|
+
# from qtpy.QtCore import Qt
|
|
30
|
+
from qtpy.QtCore import Qt
|
|
31
|
+
from qtpy.QtWidgets import QWidget, QApplication, QTableWidgetItem, QPushButton, QVBoxLayout
|
|
32
|
+
|
|
33
|
+
from batoolset.ta.database.sql_column_name_dialog import SQL_column_name_and_type
|
|
34
|
+
from batoolset.utils.loadlist import loadlist, smart_TA_list
|
|
35
|
+
from batoolset.ta.database.my_qt_table import MyTableWidget
|
|
36
|
+
from batoolset.ta.database.sql import TAsql, get_properties_master_db, \
|
|
37
|
+
reinject_properties_to_TA_files
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Example(QWidget):
|
|
41
|
+
def __init__(self, table_name='properties', lst=None, db_to_connect_to=None, non_editable_columns=[0,1]):
|
|
42
|
+
super().__init__()
|
|
43
|
+
self.db_connect = None
|
|
44
|
+
self.non_editable_columns = non_editable_columns
|
|
45
|
+
self.lst = lst
|
|
46
|
+
self.table_name = table_name
|
|
47
|
+
self.initUI()
|
|
48
|
+
self.set_db(db_to_connect_to)
|
|
49
|
+
# self.update_required = False
|
|
50
|
+
self.rows_to_update = []
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def initUI(self):
|
|
54
|
+
hbox = QVBoxLayout(self)
|
|
55
|
+
|
|
56
|
+
self.table_widget = MyTableWidget()
|
|
57
|
+
self.table_widget.itemChanged.connect(self.item_changed)
|
|
58
|
+
|
|
59
|
+
# db_connect = QtSql.QSqlDatabase.addDatabase("QSQLITE")
|
|
60
|
+
# db_connect.setDatabaseName("exemple.db")
|
|
61
|
+
# db_connect.open()
|
|
62
|
+
# model = QtSql.QSqlQueryModel(parent=self)
|
|
63
|
+
# model.setQuery("SELECT * FROM stocks")
|
|
64
|
+
# tableView.setModel(model)
|
|
65
|
+
#
|
|
66
|
+
# db_connect.close()
|
|
67
|
+
|
|
68
|
+
# model = QtGui.QStandardItemModel()
|
|
69
|
+
|
|
70
|
+
# print(len(cursor_obj.fetchall()))
|
|
71
|
+
|
|
72
|
+
# if self.db_connect is not None:
|
|
73
|
+
|
|
74
|
+
# faudrait creer une hbox où je sauve le reste --> TODO but ok for now
|
|
75
|
+
|
|
76
|
+
hbox.addWidget(self.table_widget)
|
|
77
|
+
|
|
78
|
+
save_button = QPushButton('Save')
|
|
79
|
+
save_button.clicked.connect(self.reinject_modified_properties)
|
|
80
|
+
hbox.addWidget(save_button)
|
|
81
|
+
|
|
82
|
+
# self.tab1c.layout = QVBoxLayout()
|
|
83
|
+
self.add_column_to_properties_table_button = QPushButton("Add column")
|
|
84
|
+
self.add_column_to_properties_table_button.clicked.connect(self.add_column_to_properties_table)
|
|
85
|
+
# self.tab1c.layout.addWidget(self.add_column_to_properties_table_button)
|
|
86
|
+
# self.tab1c.setLayout(self.tab1c.layout)
|
|
87
|
+
hbox.addWidget(self.add_column_to_properties_table_button)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
self.setLayout(hbox)
|
|
92
|
+
|
|
93
|
+
self.show()
|
|
94
|
+
|
|
95
|
+
def get_column_names(self):
|
|
96
|
+
col_names = []
|
|
97
|
+
for i in range(self.table_widget.columnCount()):
|
|
98
|
+
header_item = self.table_widget.horizontalHeaderItem(i)
|
|
99
|
+
col_names.append(header_item.text())
|
|
100
|
+
return col_names
|
|
101
|
+
|
|
102
|
+
def add_column_to_properties_table(self):
|
|
103
|
+
# ask the user for new col name and type
|
|
104
|
+
colnmame_n_type, ok = SQL_column_name_and_type.get_value(parent=self,title="New Column Name", existing_column_name=self.get_column_names())
|
|
105
|
+
if ok:
|
|
106
|
+
db = TAsql(filename_or_connection=self.db_connect)
|
|
107
|
+
# We add a column with the given type to the current table
|
|
108
|
+
db.add_column(self.table_name,colnmame_n_type[0],col_type=colnmame_n_type[1]) # maybe format string so that it is nice looking # shall i also specify type of column such as number or string or ignore ???
|
|
109
|
+
self.update_db()
|
|
110
|
+
# Force update all rows! because we have added a new column
|
|
111
|
+
for rrr in range(self.table_widget.rowCount()):
|
|
112
|
+
self.rows_to_update.append(rrr)
|
|
113
|
+
|
|
114
|
+
def reinject_modified_properties(self):
|
|
115
|
+
self.reinject_updated_props()
|
|
116
|
+
|
|
117
|
+
def set_db(self, db):
|
|
118
|
+
# if a db was already opened before then close it
|
|
119
|
+
self.close()
|
|
120
|
+
# if self.db_connect is not None:
|
|
121
|
+
# self.db_connect.close()
|
|
122
|
+
|
|
123
|
+
if isinstance(db, list):
|
|
124
|
+
self.lst = db
|
|
125
|
+
if db is None or not db:
|
|
126
|
+
db = None
|
|
127
|
+
else:
|
|
128
|
+
db = get_properties_master_db(db)
|
|
129
|
+
|
|
130
|
+
if db is None:
|
|
131
|
+
self.db_connect = None
|
|
132
|
+
self.cursor = None
|
|
133
|
+
self.table_widget.clear()
|
|
134
|
+
return
|
|
135
|
+
|
|
136
|
+
if isinstance(db, str):
|
|
137
|
+
self.db_connect = sqlite3.connect(db)
|
|
138
|
+
self.cursor = self.db_connect.cursor()
|
|
139
|
+
else:
|
|
140
|
+
self.db_connect =db.con
|
|
141
|
+
self.cursor = db.cur
|
|
142
|
+
|
|
143
|
+
self.update_db()
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def update_db(self):
|
|
147
|
+
if self.db_connect is None:
|
|
148
|
+
return
|
|
149
|
+
|
|
150
|
+
# print('self.table_name', self.table_name)
|
|
151
|
+
# self.db_connect = db
|
|
152
|
+
|
|
153
|
+
# rowcount = cursor.execute('''SELECT COUNT(*) FROM '''+table_name).fetchone()[0]
|
|
154
|
+
|
|
155
|
+
# pb table may not exist BUT WHY NOT CREATED YET DID I BREAK SMTHG ???
|
|
156
|
+
|
|
157
|
+
# print(rowcount)
|
|
158
|
+
try:
|
|
159
|
+
self.cursor.execute('''SELECT * FROM ''' + self.table_name)
|
|
160
|
+
except:
|
|
161
|
+
# if table does not exist --> skip
|
|
162
|
+
# traceback.print_exc()
|
|
163
|
+
return
|
|
164
|
+
content = self.cursor.fetchall()
|
|
165
|
+
|
|
166
|
+
self.table_widget.setRowCount(len(content))
|
|
167
|
+
self.table_widget.setColumnCount(len((content[0])))
|
|
168
|
+
|
|
169
|
+
column_names = [description[0] for description in self.cursor.description]
|
|
170
|
+
|
|
171
|
+
# print(cursor.rowcount)
|
|
172
|
+
|
|
173
|
+
# print(cursor.c)
|
|
174
|
+
# tableView.setColumnCount(cursor.) # --> ok --> needs be set too
|
|
175
|
+
# tableView.setColumnCount(2) # --> ok --> needs be set too
|
|
176
|
+
|
|
177
|
+
# for row, form in enumerate(cursor):
|
|
178
|
+
# for column, item in enumerate(form):
|
|
179
|
+
# self.tblTable.setItem(row, column, QtGui.QTableWidgetItem(str(item)))
|
|
180
|
+
# first = True
|
|
181
|
+
|
|
182
|
+
self.table_widget.itemChanged.disconnect()
|
|
183
|
+
|
|
184
|
+
for row, form in enumerate(content):
|
|
185
|
+
# tableView.insertRow(row)
|
|
186
|
+
|
|
187
|
+
# print(len(form))
|
|
188
|
+
# if first:
|
|
189
|
+
# first = False
|
|
190
|
+
# tableView.setColumnCount(len(form))
|
|
191
|
+
# tableView.setRowCount(len(cursor))
|
|
192
|
+
|
|
193
|
+
for column, item in enumerate(form):
|
|
194
|
+
# print(row, column, str(item))# this is ok
|
|
195
|
+
itm = QTableWidgetItem(str(item))
|
|
196
|
+
# we make unsaved TA only columns not editable to avoid issues
|
|
197
|
+
if self.non_editable_columns is not None and self.non_editable_columns:
|
|
198
|
+
if column in self.non_editable_columns:
|
|
199
|
+
itm.setFlags(itm.flags() ^ Qt.ItemIsEditable)
|
|
200
|
+
self.table_widget.setItem(row, column,itm)
|
|
201
|
+
|
|
202
|
+
# db_connect.close()
|
|
203
|
+
# tableView.update()
|
|
204
|
+
|
|
205
|
+
# need set all column names and headers
|
|
206
|
+
self.table_widget.setHorizontalHeaderLabels(column_names)
|
|
207
|
+
|
|
208
|
+
self.table_widget.itemChanged.connect(self.item_changed)
|
|
209
|
+
# self.update_required = False # reset update required
|
|
210
|
+
self.rows_to_update=[]
|
|
211
|
+
# print('oubsi', column_names)
|
|
212
|
+
|
|
213
|
+
def item_changed(self, item):
|
|
214
|
+
# self.update_required = True
|
|
215
|
+
# print('something changed --> update required')
|
|
216
|
+
row = item.row()
|
|
217
|
+
# col = item.column()
|
|
218
|
+
self.rows_to_update.append(row)
|
|
219
|
+
# print(self.rows_to_update) # rather use this because it also allows me to save just the necessary stuff --> no need to update all in fact
|
|
220
|
+
|
|
221
|
+
# TODO --> do that more properly some day
|
|
222
|
+
def saveToDb(self, tablename):
|
|
223
|
+
table_data = {}
|
|
224
|
+
for i in range(self.table_widget.columnCount()):
|
|
225
|
+
items = []
|
|
226
|
+
for j in range(self.table_widget.rowCount()):
|
|
227
|
+
item = self.table_widget.item(j, i)
|
|
228
|
+
items.append(item.text())
|
|
229
|
+
header_item = self.table_widget.horizontalHeaderItem(i)
|
|
230
|
+
# n_column = str(i) if h_item is None else h_item.text()
|
|
231
|
+
# print(h_item.text())
|
|
232
|
+
table_data[header_item.text()] = items
|
|
233
|
+
|
|
234
|
+
# df = pd.DataFrame(data=d)
|
|
235
|
+
# engine = sqlite3.connect(db_filename)
|
|
236
|
+
# df.to_sql(tablename, con=self.db_connect,if_exists='replace')# pas top car ajoute une colonne et fait une conversion de type
|
|
237
|
+
|
|
238
|
+
# print(d)
|
|
239
|
+
self.dict_to_sql(table_data, tablename)
|
|
240
|
+
|
|
241
|
+
def dict_to_sql(self, values, tablename):
|
|
242
|
+
# columns = ', '.join(values.keys())
|
|
243
|
+
# placeholders = ', '.join('?' * len(values))
|
|
244
|
+
|
|
245
|
+
# print(columns, placeholders)
|
|
246
|
+
|
|
247
|
+
# what I want is not insert but update all
|
|
248
|
+
# sql = 'INSERT INTO stocks ({}) VALUES ({})'.format(columns, placeholders)
|
|
249
|
+
# sql = 'UPDATE stocks ({}) VALUES ({})'.format(columns, placeholders)
|
|
250
|
+
# sql = ''' UPDATE stocks
|
|
251
|
+
# SET ({}) VALUES ({})
|
|
252
|
+
# WHERE id = ?'''.format(columns, placeholders)
|
|
253
|
+
|
|
254
|
+
# sql = 'UPDATE table_name SET column1 = value1, column2 = value2...., columnN = valueN WHERE [condition];'
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# values = [int(x) if isinstance(x, bool) else x for x in values.values()]
|
|
258
|
+
|
|
259
|
+
# print(values)
|
|
260
|
+
# print(sql)
|
|
261
|
+
|
|
262
|
+
# bug because of too many entries
|
|
263
|
+
|
|
264
|
+
# for iii in range(len(values[0])):
|
|
265
|
+
# row = [x[iii] for x in values]
|
|
266
|
+
# self.cursor.execute(sql, row)
|
|
267
|
+
|
|
268
|
+
# keys = values.keys()
|
|
269
|
+
# for value in values.values():
|
|
270
|
+
|
|
271
|
+
columns =' = ? ,\n\t'.join(values.keys())+' = ? '
|
|
272
|
+
# print(columns)
|
|
273
|
+
|
|
274
|
+
# in fact need update row by row --> see how
|
|
275
|
+
|
|
276
|
+
# purchases = [('2006-03-28', 'BUY', 'IBM', 1000, 45.00),
|
|
277
|
+
# ('2006-04-05', 'BUY', 'MSFT', 1000, 72.00),
|
|
278
|
+
# ('2006-04-06', 'SELL', 'IBM', 500, 53.00),
|
|
279
|
+
# ]
|
|
280
|
+
# c.executemany('INSERT INTO stocks VALUES (?,?,?,?,?)', purchases)
|
|
281
|
+
|
|
282
|
+
datas = list(values.values())
|
|
283
|
+
# print(datas)
|
|
284
|
+
# print(datas)
|
|
285
|
+
|
|
286
|
+
rowid = [iii+1 for iii in range(len(datas[0]))]
|
|
287
|
+
# datas = np.asarray(datas)
|
|
288
|
+
# print(datas.shape)
|
|
289
|
+
# print(rowid)
|
|
290
|
+
# datas = np.vstack([datas, rowid])
|
|
291
|
+
# datas = np.append(datas, rowid)
|
|
292
|
+
datas.append(rowid)
|
|
293
|
+
# print(np.array(datas))
|
|
294
|
+
# ok but needs be reordered into a format that is more friendly --> that takes
|
|
295
|
+
datas = np.asarray(datas).T.tolist()
|
|
296
|
+
# print('-->',datas)
|
|
297
|
+
# update all at once maybe
|
|
298
|
+
# for iii, data in enumerate(datas):
|
|
299
|
+
# data.append(iii+1)
|
|
300
|
+
|
|
301
|
+
# for iii,val in enumerate(datas):
|
|
302
|
+
|
|
303
|
+
sql = "UPDATE "+tablename+" \nSET " +columns +"\nWHERE ROWID = ?"
|
|
304
|
+
# sql ='''UPDATE Database_Name.Table_Name
|
|
305
|
+
# SET Column1_Name = value1, Column2_Name = value2,...
|
|
306
|
+
# WHERE condition'''
|
|
307
|
+
# val = #("Valley 345", "Canyon 123")
|
|
308
|
+
|
|
309
|
+
# print(sql)
|
|
310
|
+
# print(val)
|
|
311
|
+
|
|
312
|
+
# self.cursor.execute(sql, val)
|
|
313
|
+
self.cursor.executemany(sql, datas)
|
|
314
|
+
|
|
315
|
+
self.db_connect.commit()
|
|
316
|
+
# self.cursor.executemany(sql, values)
|
|
317
|
+
|
|
318
|
+
def close(self):
|
|
319
|
+
try:
|
|
320
|
+
if self.db_connect is not None:
|
|
321
|
+
self.db_connect.close()
|
|
322
|
+
self.db_connect = None
|
|
323
|
+
except:
|
|
324
|
+
pass
|
|
325
|
+
|
|
326
|
+
def reinject_updated_props(self):
|
|
327
|
+
if self.rows_to_update:
|
|
328
|
+
# lst = self.get_full_list(warn_on_empty_list=False)
|
|
329
|
+
if self.lst is not None and self.lst:
|
|
330
|
+
self.saveToDb('properties')
|
|
331
|
+
# self.properties_table.update_required = False
|
|
332
|
+
# I need get its db and reinject it
|
|
333
|
+
reinject_properties_to_TA_files(self.lst, TAsql(filename_or_connection=self.db_connect), indices_to_update=self.rows_to_update) # TODO rinject just the necessary lines
|
|
334
|
+
# else maybe ask where to save ???
|
|
335
|
+
self.rows_to_update = []
|
|
336
|
+
# self.properties_table.close()
|
|
337
|
+
|
|
338
|
+
#
|
|
339
|
+
# db_connect = sqlite3.connect("database.db")
|
|
340
|
+
# cur = db_connect.cursor()
|
|
341
|
+
# cur.execute("SELECT id, num, data FROM table")
|
|
342
|
+
# content = cur.fetchall()
|
|
343
|
+
# row_count = len(content)
|
|
344
|
+
# db_connect.commit()
|
|
345
|
+
# cur.close()
|
|
346
|
+
# db_connect.close()
|
|
347
|
+
# model = QtGui.QStandardItemModel()
|
|
348
|
+
#
|
|
349
|
+
# lst1 = []
|
|
350
|
+
# lst2 = []
|
|
351
|
+
# lst3 = []
|
|
352
|
+
#
|
|
353
|
+
# for i in content:
|
|
354
|
+
# lst1.append(i[0])
|
|
355
|
+
# lst2.append(i[1])
|
|
356
|
+
# lst3.append(i[2])
|
|
357
|
+
#
|
|
358
|
+
# for i in range(0, row_count):
|
|
359
|
+
# item1 = QtGui.QStandardItem(lst1[i])
|
|
360
|
+
# item2 = QtGui.QStandardItem(lst2[i])
|
|
361
|
+
# item3 = QtGui.QStandardItem(lst3[i])
|
|
362
|
+
#
|
|
363
|
+
# model.appendRow([item1, item2, item3])
|
|
364
|
+
# item1.setEditable(False)
|
|
365
|
+
# window.tableView.setModel(model)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
def _tmp_remove_props(lst):
|
|
369
|
+
database_list = smart_TA_list(lst, 'pyTA.db')
|
|
370
|
+
for db_file in database_list:
|
|
371
|
+
db = TAsql(db_file)
|
|
372
|
+
db.drop_table('properties2')
|
|
373
|
+
db.close()
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
# TODO connect this to the main db et creer le truc
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
if __name__ == "__main__":
|
|
380
|
+
# if True:
|
|
381
|
+
# db_connect = sqlite3.connect('test.db')
|
|
382
|
+
# print(type(db_connect))
|
|
383
|
+
# import sys
|
|
384
|
+
# sys.exit(0)
|
|
385
|
+
|
|
386
|
+
app = QApplication([])
|
|
387
|
+
|
|
388
|
+
lst = loadlist('/E/Sample_images/sample_images_PA/mini_different_nb_of_channels/list.lst')
|
|
389
|
+
# _tmp_remove_props(lst)
|
|
390
|
+
|
|
391
|
+
# db = get_properties_master_db(lst)
|
|
392
|
+
|
|
393
|
+
ex = Example(table_name = 'properties')
|
|
394
|
+
ex.set_db(lst)
|
|
395
|
+
ex.show()
|
|
396
|
+
app.exec_()
|
|
397
|
+
|
|
398
|
+
# TODO do some code to reinject all the lines into each file of the list --> quite easy
|
|
399
|
+
# just copy row per row and get all but the two first columns
|
|
400
|
+
|
|
401
|
+
# in fact I need upate the master db first but ok for a test
|
|
402
|
+
# ex.saveToDb('properties')
|
|
403
|
+
# reinject_properties_to_TA_files(lst, db)
|
|
404
|
+
|
|
405
|
+
ex.close()
|