mirror of https://gitlab.com/pamhyr/pamhyr2
Debug: Add csv export method.
parent
1306977954
commit
ee95f0e89e
|
|
@ -19,7 +19,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from functools import reduce
|
from functools import reduce
|
||||||
from tools import trace, timer, _timers, _calls
|
from tools import trace, timer, _timers, _calls, reset_timers
|
||||||
|
|
||||||
from PyQt5.QtCore import (
|
from PyQt5.QtCore import (
|
||||||
Qt, QVariant, QAbstractTableModel,
|
Qt, QVariant, QAbstractTableModel,
|
||||||
|
|
@ -59,6 +59,10 @@ class TableModel(PamhyrTableModel):
|
||||||
self._setup_lst()
|
self._setup_lst()
|
||||||
self.layoutChanged.emit()
|
self.layoutChanged.emit()
|
||||||
|
|
||||||
|
def reset_timers(self):
|
||||||
|
reset_timers()
|
||||||
|
self.update_lst()
|
||||||
|
|
||||||
def data(self, index, role):
|
def data(self, index, role):
|
||||||
row = index.row()
|
row = index.row()
|
||||||
column = index.column()
|
column = index.column()
|
||||||
|
|
@ -72,3 +76,7 @@ class TableModel(PamhyrTableModel):
|
||||||
return self._lst[row][2]
|
return self._lst[row][2]
|
||||||
|
|
||||||
return QVariant()
|
return QVariant()
|
||||||
|
|
||||||
|
def to_csv(self):
|
||||||
|
data = "\n".join(map(lambda x: f"{x[0]},{x[1]},{x[2]}", self._lst))
|
||||||
|
return f"""name,time,calls\n{data}\n"""
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ class TimerWindow(PamhyrWindow):
|
||||||
self._alarm.start(2000)
|
self._alarm.start(2000)
|
||||||
|
|
||||||
def setup_connections(self):
|
def setup_connections(self):
|
||||||
self.find(QAction, "action_reset").triggered.connect(self.reset)
|
# self.find(QAction, "action_reset").triggered.connect(self.reset)
|
||||||
self.find(QAction, "action_export").triggered.connect(self.export)
|
self.find(QAction, "action_export").triggered.connect(self.export)
|
||||||
|
|
||||||
self._alarm.timeout.connect(self.update)
|
self._alarm.timeout.connect(self.update)
|
||||||
|
|
@ -148,8 +148,19 @@ class TimerWindow(PamhyrWindow):
|
||||||
def update(self):
|
def update(self):
|
||||||
self._table.update_lst()
|
self._table.update_lst()
|
||||||
|
|
||||||
def reset(self):
|
# def reset(self):
|
||||||
return
|
# self._table.reset_timers()
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
return
|
self.file_dialog(
|
||||||
|
select_file="AnyFile",
|
||||||
|
callback=lambda f: self.export_to(f[0]),
|
||||||
|
default_suffix=".csv",
|
||||||
|
file_filter=["CSV file (*.csv)"],
|
||||||
|
)
|
||||||
|
|
||||||
|
def export_to(self, filename):
|
||||||
|
csv = self._table.to_csv()
|
||||||
|
|
||||||
|
with open(filename, 'w', newline='') as csvfile:
|
||||||
|
csvfile.write(csv)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@
|
||||||
<attribute name="toolBarBreak">
|
<attribute name="toolBarBreak">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</attribute>
|
</attribute>
|
||||||
<addaction name="action_reset"/>
|
|
||||||
<addaction name="action_export"/>
|
<addaction name="action_export"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="action_export">
|
<action name="action_export">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue