diff --git a/dosview.desktop b/dosview.desktop new file mode 100644 index 0000000..acc8769 --- /dev/null +++ b/dosview.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] +Version=1.0 +Type=Application +Name=DosView +Exec=dosview %f +Icon=/usr/local/share/icons/icon_ust.png +MimeType=text/plain;text/dos +Terminal=false +Categories=Utility;TextEditor; diff --git a/dosview/__init__.py b/dosview/__init__.py index 469844b..8fc8b4d 100644 --- a/dosview/__init__.py +++ b/dosview/__init__.py @@ -3,6 +3,7 @@ from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidget from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar +from PyQt5.QtWidgets import QFileDialog import random import csv from matplotlib.figure import Figure @@ -10,11 +11,19 @@ import matplotlib.pyplot as plt import pandas as pd +from PyQt5.QtGui import QIcon def parse_file(file_path): metadata = {} - df_log = pd.read_csv(file_path, sep = ',', header = None, names=range(505)) + max_size = 0 + + with open(file_path, 'r') as file: + for line in file: + parts_size = len(line.split(",")) + if parts_size > max_size: max_size = parts_size + + df_log = pd.read_csv(file_path, sep = ',', header = None, names=range(max_size), low_memory=False) data_types = df_log[0].unique().tolist() df_spectrum = df_log [df_log[0] == '$HIST'] @@ -75,7 +84,10 @@ def plot(self): self.axes2 = self.figure.add_subplot(212) # Add second subplot self.axes2.clear() # Clear previous plot - self.axes2.plot(self.data[2], 'b.', alpha=0.3) + self.axes2.plot(self.data[2], 'b.-', alpha=0.3) + + self.axes2.set_yscale('log') + self.axes2.set_xscale('log') self.axes2.set_xlabel('Channel') self.axes2.set_ylabel('Count') @@ -100,11 +112,14 @@ def __init__(self, file_path): self.height = 400 self.file_path = file_path self.initUI() - + def initUI(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) + # Set the window icon + self.setWindowIcon(QIcon('media/icon_ust.png')) + m = PlotCanvas(self, width=5, height=4, file_path=self.file_path) self.setCentralWidget(m) m.move(0,0) @@ -117,9 +132,19 @@ def initUI(self): def main(): parser = argparse.ArgumentParser(description='Process some integers.') - parser.add_argument('file_path', type=str, help='Path to the input file') + parser.add_argument('file_path', type=str, help='Path to the input file', default=None) args = parser.parse_args() + if not args.file_path: + print("Please provide a file path") + file_dialog = QFileDialog() + file_path, _ = file_dialog.getOpenFileName() + if not file_path: + print("No file selected") + sys.exit() + else: + args.file_path = file_path + app = QApplication(sys.argv) ex = App(args.file_path) sys.exit(app.exec_()) diff --git a/media/icon_ust.png b/media/icon_ust.png new file mode 100644 index 0000000..b93a01a Binary files /dev/null and b/media/icon_ust.png differ diff --git a/setup.py b/setup.py index cc56ae3..c5f8874 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,10 @@ 'dosview = dosview:main', ], }, + data_files=[ + ('/usr/local/share/applications', ['dosview.desktop']), + ('/usr/local/share/icons', ['media/icon_ust.png']) + ], install_requires=required, classifiers=[ 'Development Status :: 3 - Alpha',