Commit e5a02ec8 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

First try toward opening data

parent 571a8d31
......@@ -21,12 +21,16 @@ QLabel = QtGui.QLabel
QLineEdit = QtGui.QLineEdit
QTextEdit = QtGui.QTextEdit
QPlainTextEdit = QtGui.QPlainTextEdit
QAction = QtGui.QAction
QIcon = QtGui.QIcon
QComboBox = QtGui.QComboBox
QFileDialog = QtGui.QFileDialog
# MatPlotLib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as QCanvas
# MyPlotLib
from myplotlib import MyAxes, MyFig, MyData
from myplotlib import MyAxes, MyFig, MyData, np
from myplotlib.test import FigTest1, readStupidData, readStupidData2
from .mplDesign import MyDesign, AxDesign, FigDesign
......@@ -37,5 +41,10 @@ from .qTabMyAxes import QTabMyAxes
from .qTabMyFig import QTabMyFig
from .qMyDesignTabs import QMyDesignTabs
from .qMyDesignWidget import QMyDesignWidget
from .qOpenFileWidget import QOpenFileWidget
from .qMyDesignGui import QMyDesignGui
# Import IOs
import myIOs
......@@ -2,6 +2,11 @@ from . import sys
from . import QApplication
from . import QMyDesignGui
from . import myIOs
for key in myIOs.__dict__.keys():
if key not in myIOs.__builtins__.keys() and not key.startswith('__'):
print(key)
app = QApplication(sys.argv)
......
from readSerie import readSerie
from .. import np
def readOrgFile(path2data, filename='runParam.org'):
# THROUGH THE POSSIBLE lAST / AWAY
if path2data[-1] == '/': path2data = path2data[:-1]
# TRY TO READ
try:
# INIT
firstLine = True # bool for testing first line
runs = None # future np.recarray to output
# OPENING
f = open(str(path2data)+'/'+str(filename), 'r')
# READING
for line in f.readlines():
# IF THE LINE LOOK LIKE AN ORG ARRAY (EXCLUDING |---+--...)
if(line[0] == '|' and line[1] != '-'):
# IF FIRST LINE -> DETECT NAMES
if(firstLine):
names = line.split('|')[1:-1]
# THROUGH AWAY THE WHITESPACES
for i in np.arange(0, len(names)):
names[i] = names[i].replace(" ", "")
# CREATE THE CORRESPONDING DTYPE
dtype = []
for name in names:
# NAMES ENDING IN _S are STRINGS
if name[-2:] == '_s':
dtype_tmp = (str(name[:-2]), '|S14')
dtype.append(dtype_tmp)
# OTHER FLOATS
else:
dtype_tmp = (str(name), float)
dtype.append(dtype_tmp)
firstLine = False
# IF WE ARE READING DATA
else:
run = line.split('|')[1:-1]
tmp = []
# CREATE THE RECARRAY CORRESPONDING TO THE LINE
for (dtp, data) in zip(dtype, run):
# IF DTYPE SAYS STRING MAKE A STRING WITHOUT WHITE SPACE
if dtp[1] == '|S14':
tmp.append(str(data.replace(' ', '')))
# IF DTYPE SAYS FLOAT MAKE A FLOAT
else:
# IF EMPTY MAKE 0.0
if(str(data).replace(' ', '') != ''):
tmp.append(float(data))
else:
tmp.append(0.0)
# CREATE THE RECARRAY FROM DATA and DTYPE
sglrun = np.array([tuple(tmp)], dtype=dtype)
tmp = None
# APPEND THE CURRENT LINE TO RUNS
if(runs is None):
runs = sglrun
else:
runs = np.append(runs, sglrun)
sglrun = None
# IF IOERROR TELLS THE USER AND RETURN NONE.
except IOError:
return(None)
# MAKE THE NDARRAY TO BECOME A RECARRAY
runs = runs.view(np.recarray)
return(runs)
from .. import MyData # CLASSES
from .readOrgFile import readOrgFile # FUNCTIONS
_D_DTNAME = None
_D_FILENAME = 'serieParam.org'
def readSerie(path2data, filename=_D_FILENAME, dtName=_D_DTNAME):
if(str(path2data)[-1] == '/'): path2data = path2data[:-1]
# CREATE LOCAL RAW DATA CONTAINER ------------------------------------
lrawdata = MyData()
# Give a name to the data set
if(dtName is not None):
lrawdata.name = str(dtName)
else:
lrawdata.name = str(path2data).split('/')[-1]
# READ SERIEPARAM.ORG
lrawdata.data = readOrgFile(path2data, filename=filename)
return(lrawdata)
from . import QMyDesignWidget
from . import QMainWindow
from . import QAction
from . import QIcon
from . import QWidget
from . import QOpenFileWidget
class QMyDesignGui(QMainWindow):
......@@ -10,7 +14,35 @@ class QMyDesignGui(QMainWindow):
self.statusBar() # an ugly wrapper to create the statusBar
self.initMenu()
self.setCentralWidget(QMyDesignWidget(self))
self.setWindowTitle('My Design Gui')
self.show()
def initMenu(self):
self.menuBar()
self.actionOfTheMenuBar = {'open': QAction(QIcon('open.png'), '&Open', self),
'save': QAction(QIcon('save.png'), '&Save', self),
'close': QAction(QIcon('exit.png'), '&Exit', self)}
self.actionOfTheMenuBar['open'].setStatusTip('Open some data')
self.actionOfTheMenuBar['save'].setStatusTip('Not yet implemented')
self.actionOfTheMenuBar['close'].setStatusTip('Not yet implemented')
self.actionOfTheMenuBar['open'].triggered.connect(self.openData)
self.menusOfTheMenuBar = {'File': self.menuBar().addMenu('&File'),
'Edit': self.menuBar().addMenu('&Edit'),
'Help': self.menuBar().addMenu('&Help')}
self.menusOfTheMenuBar['File'].addAction(self.actionOfTheMenuBar['open'])
def openData(self):
self.openFilePopup = QOpenFileWidget()
self.openFilePopup.resize(200, 200)
self.openFilePopup.show()
from . import QWidget
from . import QComboBox
from . import QVBoxLayout
from . import myIOs
from . import QFileDialog
from . import QLineEdit
AVAIL_FUNCTIONS = []
for key in myIOs.__dict__.keys():
if key not in myIOs.__builtins__.keys() and not key.startswith('__'):
AVAIL_FUNCTIONS.append(key)
class QOpenFileWidget(QWidget):
def __init__(self, parent=None):
super(QOpenFileWidget, self).__init__(parent)
self.functionsCombo = QComboBox(self)
for function in AVAIL_FUNCTIONS:
self.functionsCombo.addItem(function)
self.filename = QFileDialog.getOpenFileName(self)
self.fileNameLabel = QLineEdit(self)
self.fileNameLabel.setText(self.filename)
self.argLabels = []
for i in range(0, myIOs.__dict__[AVAIL_FUNCTIONS[0]].func_code.co_argcount):
self.argLabels.append(myIOs.__dict__[AVAIL_FUNCTIONS[0]].func_code.co_varnames[i])
self.fileNameLabel.setText(str(self.argLabels))
self.layout = QVBoxLayout(self)
self.layout.addWidget(self.functionsCombo)
self.layout.addWidget(self.fileNameLabel)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment