2
2
import argparse
3
3
4
4
from PyQt5 import QtNetwork
5
+ from PyQt5 .QtNetwork import QLocalSocket , QLocalServer
5
6
from PyQt5 .QtCore import QThread , pyqtSignal , QSettings
6
7
from PyQt5 .QtWidgets import QApplication , QMainWindow , QVBoxLayout , QWidget , QHBoxLayout , QFormLayout
7
8
from PyQt5 .QtWidgets import QPushButton , QFileDialog , QTreeWidget , QTreeWidgetItem , QAction , QSplitter , QTableWidgetItem
@@ -84,22 +85,20 @@ def parse_file(file_path):
84
85
# Připojení nulových sloupců k původnímu poli
85
86
np_spectrum = np .hstack ((np_spectrum , zero_columns ))
86
87
87
- print (np_spectrum )
88
-
89
88
time_column = np_spectrum [:, 1 ]
90
- print (time_column )
91
- np_spectrum = np_spectrum [:, 8 :]
92
- print (np_spectrum )
93
-
94
- #print("Unique events: ", unique_events)
89
+ #print(time_column)
90
+ np_spectrum = np_spectrum [:, 7 :]
91
+ #print(np_spectrum)
95
92
96
93
for i , event in enumerate (unique_events ):
97
94
time_index = np .searchsorted (time_column , event [0 ])
98
95
print (event [0 ], event [1 ], time_index )
99
96
np_spectrum [time_index , event [1 ]] += 1
100
- # np_spectrum[event[0], i] += event[1]
101
97
102
98
sums = np .sum (np_spectrum [:, 1 :], axis = 1 )
99
+
100
+ #print("Scitam tohle..")
101
+ #print(np_spectrum[:, 1:])
103
102
hist = np .sum (np_spectrum [:, 1 :], axis = 0 )
104
103
105
104
minimal_time = time_column .min ()
@@ -858,14 +857,12 @@ def get_airdos_status(self):
858
857
})
859
858
860
859
a ,b = self .sht_read_sensor_data (self .addr_sht , [0x24 , 0x0b ] )
861
-
862
860
data ['SHT' ] = {
863
861
'temperature' : a ,
864
862
'humidity' : b
865
863
}
866
864
867
865
a , b = self .sht_read_sensor_data (self .addr_an_sht , [0x24 , 0x0b ] )
868
-
869
866
data ['AIRDOS_SHT' ] = {
870
867
'temperature' : a ,
871
868
'humidity' : b
@@ -1136,18 +1133,14 @@ def plot_data(self, data):
1136
1133
self .imv .setPredefinedGradient ('thermal' )
1137
1134
self .imv .getView ().showGrid (True , True , 0.2 )
1138
1135
1139
-
1140
1136
# Invert the y-axis
1141
1137
self .imv .getView ().invertY (False )
1142
1138
#self.imv.getView().setLogMode(x=False, y=True)
1143
1139
1144
-
1145
1140
# Add axis labels
1146
1141
#self.imv.setLabel('left', 'Y Axis')
1147
1142
#self.imv.setLabel('bottom', 'X Axis')
1148
1143
1149
-
1150
-
1151
1144
class PlotTab (QWidget ):
1152
1145
def __init__ (self ):
1153
1146
super ().__init__ ()
@@ -1171,8 +1164,6 @@ def initUI(self):
1171
1164
self .upload_file_button .setMaximumHeight (20 )
1172
1165
self .upload_file_button .clicked .connect (lambda : UploadFileDialog ().exec_ ())
1173
1166
1174
-
1175
-
1176
1167
log_view_widget = QWidget ()
1177
1168
1178
1169
self .left_panel = QSplitter (Qt .Vertical )
@@ -1189,8 +1180,6 @@ def initUI(self):
1189
1180
self .logView_splitter .addWidget (self .left_panel )
1190
1181
#self.logView_splitter.addWidget(QWidget())
1191
1182
1192
-
1193
-
1194
1183
layout = QVBoxLayout ()
1195
1184
layout .addWidget (self .logView_splitter )
1196
1185
self .setLayout (layout )
@@ -1222,14 +1211,19 @@ def on_data_loaded(self, data):
1222
1211
self .properties_tree .clear ()
1223
1212
1224
1213
def add_properties_to_tree (item , properties ):
1225
- for key , value in properties .items ():
1226
- if isinstance (value , dict ):
1227
- parent_item = QTreeWidgetItem ([key ])
1228
- item .addChild (parent_item )
1229
- add_properties_to_tree (parent_item , value )
1230
- else :
1231
- child_item = QTreeWidgetItem ([key , str (value )])
1232
- item .addChild (child_item )
1214
+ for key , value in properties .items ():
1215
+ # Pokud je to uroven ve storomu
1216
+ if isinstance (value , dict ):
1217
+ parent_item = QTreeWidgetItem ([key ])
1218
+ item .addChild (parent_item )
1219
+ add_properties_to_tree (parent_item , value )
1220
+ # Zobraz samotne hodnoty
1221
+ else :
1222
+ if key in ['internal_time_min' , 'internal_time_max' , 'log_duration' ]:
1223
+ value_td = datetime .timedelta (seconds = value )
1224
+ value = f"{ value_td } , ({ value } seconds)"
1225
+ child_item = QTreeWidgetItem ([key , str (value )])
1226
+ item .addChild (child_item )
1233
1227
1234
1228
metadata = data [3 ]
1235
1229
for key , value in metadata .items ():
@@ -1590,6 +1584,7 @@ def main():
1590
1584
parser .add_argument ('--labdos' , action = 'store_true' , help = 'Enable labdos control tab' )
1591
1585
parser .add_argument ('--no_gui' , action = 'store_true' , help = 'Disable GUI and run in headless mode' )
1592
1586
parser .add_argument ('--version' , action = 'store_true' , help = 'Print version and exit' )
1587
+ parser .add_argument ('--new-window' , action = 'store_true' , help = "Open file in new window" )
1593
1588
1594
1589
args = parser .parse_args ()
1595
1590
@@ -1602,8 +1597,39 @@ def main():
1602
1597
pg .setConfigOption ('background' , 'w' )
1603
1598
pg .setConfigOption ('foreground' , 'gray' )
1604
1599
1605
-
1606
1600
app = QApplication (sys .argv )
1601
+
1602
+ # Create a local server for IPC
1603
+ server_name = 'dosview'
1604
+ socket = QLocalSocket ()
1605
+ socket .connectToServer (server_name )
1606
+
1607
+ if socket .waitForConnected (500 ):
1608
+ socket .write (args .file_path .encode ())
1609
+ socket .flush ()
1610
+ socket .waitForBytesWritten (1000 )
1611
+ socket .disconnectFromServer ()
1612
+ print ("dosview is already running. Sending file path to the running instance." )
1613
+ sys .exit (0 )
1614
+ else :
1615
+ server = QLocalServer ()
1616
+ server .listen (server_name )
1617
+
1618
+ def handle_connection ():
1619
+ socket = server .nextPendingConnection ()
1620
+ if socket .waitForReadyRead (1000 ):
1621
+ filename = socket .readAll ().data ().decode ()
1622
+ print ("Opening file from external instance startup ..." , filename )
1623
+ ex .openPlotTab (filename )
1624
+ ex .activateWindow ()
1625
+ ex .raise_ ()
1626
+ ex .setFocus ()
1627
+
1628
+
1629
+
1630
+ server .newConnection .connect (handle_connection )
1631
+
1632
+
1607
1633
ex = App (args )
1608
1634
sys .exit (app .exec_ ())
1609
1635
0 commit comments