def setCurrentFile(self, file): #print "=============== set current file ============" if file is self.current: return if file is None: self.clear() self.current = None return #if self.current is not None: #QtCore.QObject.disconnect(self.current, QtCore.SIGNAL('changed'), self.currentDirChanged) self.current = file self.clear() #QtCore.QObject.connect(self.current, QtCore.SIGNAL('changed'), self.currentDirChanged) ## Decide on the list of fields to display info = file.info() infoKeys = info.keys() #fields = OrderedDict() fields = self.manager.suggestedDirFields(file) ## Generate fields, populate if data exists #print "Add %d rows.." % len(fields) for f in fields: if f in infoKeys: infoKeys.remove(f) if type(fields[f]) is tuple: ft = fields[f][0] else: ft = fields[f] if ft == 'text': w = QtGui.QTextEdit() w.setTabChangesFocus(True) if f in info: w.setText(info[f]) elif ft == 'string': w = QtGui.QLineEdit() if f in info: w.setText(info[f]) elif ft == 'list': w = QtGui.QComboBox() w.addItems([''] + fields[f][1]) w.setEditable(True) if f in info: w.lineEdit().setText(info[f]) elif ft == 'bool': w = QtGui.QCheckBox() if f in info: w.setChecked(info[f]) else: raise Exception( "Don't understand info type '%s' (parameter %s)" % (fields[f][0], f)) self.addRow(f, w) #self.ui.fileInfoLayout.setMinAndMaxSize() ## Add fields for any other keys that happen to be present #print "Add %d rows.." % len(infoKeys) for f in infoKeys: if isinstance(info[f], dict): w = DictView(info[f]) #s = configfile.genString(info[f]) else: s = str(info[f]) if isinstance(f, basestring) and 'time' in f.lower( ) and info[f] > 1e9 and info[ f] < 2e9: ## probably this is a timestamp try: t0 = file.parent().info()['__timestamp__'] dt = " [elapsed = %0.3f s]" % (info[f] - t0) except: dt = "" #raise s = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(float(s))) + dt w = QtGui.QLabel(s) if type(f) is tuple: f = '.'.join(f) f = str(f).replace('__', '') self.addRow(f, w)
def setCurrentFile(self, file): #print "=============== set current file ============" if file is self.current: return ## What if we just want to update the data display? #self.clear() if file is None: self.current = None return if file.isDir(): ## Sequence or not? return else: typ = file.fileType() if typ is None: return else: image = False with pg.BusyCursor(): data = file.read() if typ == 'ImageFile': image = True elif typ == 'MetaArray': if data.ndim == 2 and not data.axisHasColumns( 0) and not data.axisHasColumns(1): image = True elif data.ndim > 2: image = True else: return with pg.BusyCursor(): if image: if self.currentType == 'image' and len(self.widgets) > 0: try: self.widgets[0].setImage(data, autoRange=False) except: print "widget types:", map(type, self.widgets) raise else: self.clear() w = pg.ImageView(self) #print "add image:", w.ui.roiPlot.plotItem #self.plots = [weakref.ref(w.ui.roiPlot.plotItem)] self.addWidget(w) w.setImage(data) self.widgets.append(w) self.currentType = 'image' else: self.clear() w = pg.MultiPlotWidget(self) self.addWidget(w) w.plot(data) self.currentType = 'plot' self.widgets.append(w) #print "add mplot:", w.mPlotItem.plots #self.plots = [weakref.ref(p[0]) for p in w.mPlotItem.plots] if (hasattr(data, 'implements') and data.implements('MetaArray')): if self.dictWidget is None: w = DictView(data._info) self.dictWidget = w #w.setText(str(data._info[-1])) self.addWidget(w) self.widgets.append(w) h = self.size().height() self.setSizes([h * 0.8, h * 0.2]) else: self.dictWidget.setData(data._info)
def setCurrentFile(self, file): #print "=============== set current file ============" if file is self.current: return if file is None: self.clear() self.current = None return self.current = file self.clear() ## Decide on the list of fields to display info = file.info() infoKeys = list(info.keys()) fields = self.manager.suggestedDirFields(file) ## Generate fields, populate if data exists #print "Add %d rows.." % len(fields) # each field has a number of options that can be set by providing # either a dict or a tuple (where the order of arguments determine their meaning). fieldTypeArgs = { 'text': ['numLines', 'default'], 'string': ['default'], 'list': ['values', 'default'], 'bool': ['default'], } for fieldName, fieldOpts in fields.items(): if fieldName in infoKeys: infoKeys.remove(fieldName) # a single value is interpreted as the first element of a tuple if not isinstance(fieldOpts, (dict, tuple)): fieldOpts = (fieldOpts, ) if isinstance(fieldOpts, tuple): fieldTyp = fieldOpts[0] # convert to dict based on order of args fieldOpts = { fieldTypeArgs[fieldTyp][i - 1]: fieldOpts[i] for i in range(1, len(fieldOpts)) } fieldOpts['type'] = fieldTyp fieldTyp = fieldOpts['type'] # now use args to create a widget for this field value = info.get(fieldName, fieldOpts.get('default', None)) if fieldTyp == 'text': w = Qt.QTextEdit() w.setTabChangesFocus(True) if value is not None: w.setText(value) elif fieldTyp == 'string': w = Qt.QLineEdit() if value is not None: w.setText(value) elif fieldTyp == 'list': w = Qt.QComboBox() w.addItems([''] + fieldOpts['values']) w.setEditable(True) if value is not None: w.lineEdit().setText(value) elif fieldTyp == 'bool': w = Qt.QCheckBox() if value is not None: w.setChecked(value) else: raise Exception( "Don't understand info type '%s' (parameter %s)" % (fieldTyp, fieldName)) self.addRow(fieldName, w) ## Add fields for any other keys that happen to be present #print "Add %d rows.." % len(infoKeys) for f in infoKeys: if isinstance(info[f], dict): w = DictView(info[f]) else: s = str(info[f]) if isinstance(f, six.string_types) and 'time' in f.lower( ) and info[f] > 1e9 and info[ f] < 2e9: ## probably this is a timestamp try: t0 = file.parent().info()['__timestamp__'] dt = " [elapsed = %0.3f s]" % (info[f] - t0) except: dt = "" s = time.strftime("%Y.%m.%d %H:%M:%S", time.localtime(float(s))) + dt w = Qt.QLabel(s) if type(f) is tuple: f = '.'.join(f) f = str(f).replace('__', '') self.addRow(f, w)