signature
stringlengths 8
3.44k
| body
stringlengths 0
1.41M
| docstring
stringlengths 1
122k
| id
stringlengths 5
17
|
|---|---|---|---|
def verify(self):
|
return self.model.verify()<EOL>
|
Wrapper for :meth:`verify<sparkle.stim.auto_parameter_model.AutoParameterModel.verify>`
|
f10634:c0:m20
|
def setDisplayTable(self, table):
|
self.displayTable = table<EOL>
|
Sets the table that determines what attributes to display
:param table: keys of stimulus names, and values of a list of attribute names to display
:type table: dict
|
f10635:c0:m1
|
def setDefaultAttributes(self, defaults):
|
self.defaultAttributes = defaults<EOL>
|
Sets the default attributes to display, if a stimulus type is not in
the display table
:param defaults: names of attributes to show
:type defaults: list<str>
|
f10635:c0:m2
|
def setDoc(self, docs):
|
<EOL>docs = sorted(docs, key=lambda k: k['<STR_LIT>'])<EOL>for doc in docs:<EOL><INDENT>stim_type = doc['<STR_LIT>']<EOL>if not stim_type in self.displayTable:<EOL><INDENT>continue<EOL><DEDENT>if not stim_type in self.displayTable[stim_type]:<EOL><INDENT>continue<EOL><DEDENT>display_attributes = self.displayTable.get(stim_type, self.defaultAttributes)<EOL>self.lyt.addWidget(ComponentDetailFrame(doc, display_attributes))<EOL><DEDENT>
|
Sets the documentation to display
:param docs: a list of the stimuli doc, which are dicts
:type docs: list<dict>
|
f10635:c0:m3
|
def clearDoc(self):
|
clearLayout(self.lyt)<EOL>
|
Clears the widget
|
f10635:c0:m4
|
def setComponents(self, components):
|
layout = self.layout()<EOL>for comp in components:<EOL><INDENT>attrWidget = ComponentAttributerChecker(comp)<EOL>layout.addWidget(attrWidget)<EOL><DEDENT>
|
Clears and sets the components contained in this widget
:param components: list of documentation for subclasses of AbStractStimulusComponents
:type Components: list<dict>
|
f10635:c2:m1
|
def setCheckedDetails(self, checked):
|
layout = self.layout()<EOL>for i in range(layout.count()):<EOL><INDENT>w = layout.itemAt(i).widget()<EOL>if w.stimType in checked:<EOL><INDENT>w.setChecked(checked[w.stimType])<EOL><DEDENT><DEDENT>
|
Sets which components are checked
:param checked: dictionary of stimtype:list<attribute names> for which components and their attributes should be checked
:type checked: dict
|
f10635:c2:m2
|
def getCheckedDetails(self):
|
attrs = {}<EOL>layout = self.layout()<EOL>for i in range(layout.count()):<EOL><INDENT>w = layout.itemAt(i).widget()<EOL>attrs[w.stimType] = w.getChecked()<EOL><DEDENT>return attrs<EOL>
|
Gets the currently checked components and checked attributes
:returns: dict -- of members with stimtype:list<attribute names>
|
f10635:c2:m3
|
def setChecked(self, tocheck):
|
layout = self.layout()<EOL>for i in range(layout.count()):<EOL><INDENT>w = layout.itemAt(i).widget()<EOL>if w.text() in tocheck:<EOL><INDENT>w.setChecked(True)<EOL><DEDENT><DEDENT>
|
Sets the attributes *tocheck* as checked
:param tocheck: attributes names to check
:type tocheck: list<str>
|
f10635:c3:m1
|
def getChecked(self):
|
attrs = []<EOL>layout = self.layout()<EOL>for i in range(layout.count()):<EOL><INDENT>w = layout.itemAt(i).widget()<EOL>if w.isChecked():<EOL><INDENT>attrs.append(str(w.text()))<EOL><DEDENT><DEDENT>return attrs<EOL>
|
Gets the checked attributes
:returns: list<str> -- checked attribute names
|
f10635:c3:m2
|
def trash(self):
|
return self.trashLbl<EOL>
|
Returns the trash widget for this container
:returns: :class:`TrashWidget<sparkle.gui.trashcan.TrashWidget>`
|
f10636:c0:m1
|
def getLabelByName(self, name):
|
name = name.lower()<EOL>if name in self.stimLabels:<EOL><INDENT>return self.stimLabels[name]<EOL><DEDENT>else:<EOL><INDENT>return None<EOL><DEDENT>
|
Gets a label widget by it component name
:param name: name of the AbstractStimulusComponent which this label is named after
:type name: str
:returns: :class:`DragLabel<sparkle.gui.drag_label.DragLabel>`
|
f10636:c0:m2
|
def addWidget(self, widget, name):
|
self.exploreStimTypeCmbbx.addItem(name)<EOL>self.componentStack.addWidget(widget)<EOL>widget.valueChanged.connect(self.valueChanged.emit)<EOL>
|
Add a component editor widget
|
f10638:c0:m1
|
def saveTemplate(self):
|
savedict = {}<EOL>for comp_editor in self.widgets():<EOL><INDENT>stim = comp_editor.component()<EOL>comp_editor.saveToObject()<EOL>savedict[stim.name] = stim.stateDict()<EOL><DEDENT>savedict['<STR_LIT>'] = self.delaySpnbx.value()<EOL>return savedict<EOL>
|
Get a json structure of the current inputs,
to be able to load later
|
f10638:c0:m5
|
def setModel(self, model):
|
self._model = model<EOL>self.ui.aofsSpnbx.setValue(model.samplerate())<EOL>
|
Sets the StimulusModel for this editor
|
f10639:c0:m1
|
def setStimIndex(self, row, stimIndex):
|
newcomp = self._allComponents[row][stimIndex]<EOL>self._model.removeComponent(row, <NUM_LIT:1>)<EOL>self._model.insertComponent(newcomp, row, <NUM_LIT:1>)<EOL>
|
Change out the component type in row to the one indexed by stimIndex
|
f10639:c0:m3
|
def addComponentEditor(self):
|
row = self._model.rowCount()<EOL>comp_stack_editor = ExploreComponentEditor()<EOL>self.ui.trackStack.addWidget(comp_stack_editor)<EOL>idx_button = IndexButton(row)<EOL>idx_button.pickMe.connect(self.ui.trackStack.setCurrentIndex)<EOL>self.trackBtnGroup.addButton(idx_button)<EOL>self.ui.trackBtnLayout.addWidget(idx_button)<EOL>self.ui.trackStack.setCurrentIndex(row)<EOL>comp_stack_editor.closePlease.connect(self.removeComponentEditor)<EOL>delay = Silence()<EOL>comp_stack_editor.delaySpnbx.setValue(delay.duration())<EOL>self._model.insertComponent(delay, row,<NUM_LIT:0>)<EOL>self._allComponents.append([x() for x in self.stimuli_types if x.explore])<EOL>for stim in self._allComponents[row]:<EOL><INDENT>editor = wrapComponent(stim).showEditor()<EOL>comp_stack_editor.addWidget(editor, stim.name)<EOL><DEDENT>exvocal = comp_stack_editor.widgetForName("<STR_LIT>")<EOL>if exvocal is not None:<EOL><INDENT>exvocal.filelistView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)<EOL><DEDENT>initcomp = self._allComponents[row][<NUM_LIT:0>]<EOL>self._model.insertComponent(initcomp, row, <NUM_LIT:1>)<EOL>self.buttons.append(idx_button)<EOL>comp_stack_editor.exploreStimTypeCmbbx.currentIndexChanged.connect(lambda x : self.setStimIndex(row, x))<EOL>comp_stack_editor.delaySpnbx.valueChanged.connect(lambda x : self.setDelay(row, x))<EOL>comp_stack_editor.valueChanged.connect(self.valueChanged.emit)<EOL>return comp_stack_editor<EOL>
|
Adds a new component to the model, and an editor for this component to this editor
|
f10639:c0:m7
|
def setTestNum(self, num):
|
self.ui.testNum.setNum(num+<NUM_LIT:1>)<EOL>
|
Sets the Test number to display
|
f10641:c0:m1
|
def setTraceNum(self, num):
|
self.ui.traceNum.setNum(num+<NUM_LIT:1>)<EOL>
|
Sets the Trace number to display
|
f10641:c0:m2
|
def setRepNum(self, num):
|
self.ui.repNum.setNum(num+<NUM_LIT:1>)<EOL>
|
Sets the Repetition number to display
|
f10641:c0:m3
|
def setDoc(self, doc):
|
self.ui.overAtten.setNum(doc['<STR_LIT>'])<EOL>self.ui.componentDetails.clearDoc()<EOL>self.ui.componentDetails.setDoc(doc['<STR_LIT>'])<EOL>
|
Presents the documentation
:param doc: documentation for StimulusModel. i.e. returned from
:meth:`componentDoc<sparkle.stim.stimulus_model.StimulusModel.componentDoc>`
or :meth:`templateDoc<sparkle.stim.stimulus_model.StimulusModel.templateDoc>`
|
f10641:c0:m4
|
def setDisplayAttributes(self, attrs):
|
self.ui.componentDetails.setDisplayTable(attrs)<EOL>
|
Sets which attributes to display
Actually just calls :meth:`setDisplayTable<sparkle.gui.stim.component_detail.ComponentsDetailWidget.setDisplayTable>`
|
f10641:c0:m5
|
def setModel(self, model):
|
self.stimModel = model<EOL>self.parameterModel = model.autoParams()<EOL>tone = self.stimModel.data(self.stimModel.index(<NUM_LIT:0>,<NUM_LIT:0>), QtCore.Qt.UserRole+<NUM_LIT:1>)<EOL>info = tone.auto_details()<EOL>fmax = info['<STR_LIT>']['<STR_LIT>']<EOL>self.ui.freqStartSpnbx.setMaximum(fmax)<EOL>self.ui.freqStopSpnbx.setMaximum(fmax)<EOL>self.ui.freqStepSpnbx.setMaximum(<NUM_LIT>)<EOL>dbmax = info['<STR_LIT>']['<STR_LIT>']<EOL>self.ui.dbStartSpnbx.setMaximum(dbmax)<EOL>self.ui.dbStopSpnbx.setMaximum(dbmax)<EOL>self.ui.dbStepSpnbx.setMaximum(<NUM_LIT>)<EOL>self.ui.durSpnbx.setMaximum(info['<STR_LIT>']['<STR_LIT>'])<EOL>self.ui.risefallSpnbx.setMaximum(info['<STR_LIT>']['<STR_LIT>'])<EOL>self.fmapper.setModel(self.parameterModel)<EOL>self.dbmapper.setModel(self.parameterModel)<EOL>self.fmapper.addMapping(self.ui.freqStartSpnbx, <NUM_LIT:1>)<EOL>self.fmapper.addMapping(self.ui.freqStopSpnbx, <NUM_LIT:2>)<EOL>self.fmapper.addMapping(self.ui.freqStepSpnbx, <NUM_LIT:3>)<EOL>self.fmapper.addMapping(self.ui.freqNstepsLbl, <NUM_LIT:4>, '<STR_LIT:text>')<EOL>self.dbmapper.addMapping(self.ui.dbStartSpnbx, <NUM_LIT:1>)<EOL>self.dbmapper.addMapping(self.ui.dbStopSpnbx, <NUM_LIT:2>)<EOL>self.dbmapper.addMapping(self.ui.dbStepSpnbx, <NUM_LIT:3>)<EOL>self.dbmapper.addMapping(self.ui.dbNstepsLbl, <NUM_LIT:4>, '<STR_LIT:text>')<EOL>self.fmapper.toFirst()<EOL>self.dbmapper.setCurrentIndex(<NUM_LIT:1>)<EOL>self.ui.durSpnbx.setValue(tone.duration())<EOL>self.ui.nrepsSpnbx.setValue(self.stimModel.repCount())<EOL>self.ui.risefallSpnbx.setValue(tone.risefall())<EOL>self.tone = tone<EOL>
|
Sets the QStimulusModel for this editor
|
f10642:c0:m1
|
def setStimDuration(self):
|
duration = self.ui.durSpnbx.value()<EOL>self.tone.setDuration(duration)<EOL>
|
Sets the duration of the StimulusModel from values pulled from
this widget
|
f10642:c0:m3
|
def setStimReps(self):
|
reps = self.ui.nrepsSpnbx.value()<EOL>self.stimModel.setRepCount(reps)<EOL>
|
Sets the reps of the StimulusModel from values pulled from
this widget
|
f10642:c0:m4
|
def setStimRisefall(self):
|
rf = self.ui.risefallSpnbx.value()<EOL>self.tone.setRisefall(rf)<EOL>
|
Sets the Risefall of the StimulusModel's tone from values pulled from
this widget
|
f10642:c0:m5
|
def model(self):
|
return self.stimModel<EOL>
|
Gets this editor's StimulusModel
|
f10642:c0:m6
|
def durationInputWidget(self):
|
return self.ui.durSpnbx<EOL>
|
Gets the input widget that handles duration
|
f10642:c0:m8
|
def rowReach(self):
|
return ROW_HEIGHT + ROW_SPACE<EOL>
|
Row span in pixels
:returns: int -- row height + space between rows
|
f10643:c0:m1
|
def setPixelScale(self, pxms):
|
pxms = float(pxms)/<NUM_LIT:2><EOL>self.pixelsPerms = pxms<EOL>if pxms*self.gridms < GRID_PIXEL_MIN:<EOL><INDENT>self.gridms = self.gridms*<NUM_LIT:2><EOL><DEDENT>elif pxms*self.gridms > GRID_PIXEL_MAX:<EOL><INDENT>self.gridms = self.gridms/<NUM_LIT:2><EOL><DEDENT>self._viewIsDirty = True<EOL>self.viewport().update()<EOL>return self.gridms<EOL>
|
Sets the zoom scale
:param pxms: number of pixels per ms
:type pxms: int
:returns: float -- the miliseconds between grid lines
|
f10643:c0:m2
|
def setModel(self, model):
|
super(StimulusView, self).setModel(model)<EOL>self.setSelectionModel(ComponentSelectionModel(model))<EOL>self._rects = [[None] * self.model().columnCountForRow(x) for x in range(self.model().rowCount())]<EOL>self._viewIsDirty = True<EOL>self._calculateRects()<EOL>
|
Sets the model this view represents. :qtdoc:`Re-implemented<QAbstractItemView.setModel>`
:param model: model to set
:type model: :class:`QStimulusModel<sparkle.gui.stim.stimulus_model.QStimulusModel>`
|
f10643:c0:m3
|
def indexXY(self, index):
|
rect = self.visualRect(index)<EOL>return rect.x(), rect.y()<EOL>
|
Returns the top left coordinates of the item for the given index
:param index: index for the item
:type index: :qtdoc:`QModelIndex`
:returns: (int, int) -- (x, y) view coordinates of item
|
f10643:c0:m4
|
def indexAt(self, point):
|
<EOL>wx = point.x() + self.horizontalScrollBar().value()<EOL>wy = point.y() + self.verticalScrollBar().value()<EOL>self._calculateRects()<EOL>for row in range(self.model().rowCount(self.rootIndex())):<EOL><INDENT>for col in range(self.model().columnCountForRow(row)):<EOL><INDENT>if self._rects[row][col].contains(wx, wy):<EOL><INDENT>return self.model().index(row, col, self.rootIndex())<EOL><DEDENT><DEDENT><DEDENT>return QtCore.QModelIndex()<EOL>
|
Returns the index of the component at *point* relative to view coordinates.
If there is None, and empty index is returned. :qtdoc:`Re-implemented<QAbstractItemView.indexAt>`
:param point: the point, in view coordinates, to find an index for
:type point: :qtdoc:`QPoint`
:returns: :qtdoc:`QModelIndex`
|
f10643:c0:m5
|
def splitAt(self, point):
|
wx = point.x() + self.horizontalScrollBar().value()<EOL>wy = point.y() + self.verticalScrollBar().value()<EOL>row = wy/(ROW_HEIGHT + ROW_SPACE)<EOL>if row > self.model().rowCount(self.rootIndex()) - <NUM_LIT:1>:<EOL><INDENT>row = self.model().rowCount(self.rootIndex())<EOL><DEDENT>for col in range(self.model().columnCountForRow(row)):<EOL><INDENT>if self._rects[row][col].contains(wx, wy):<EOL><INDENT>return (row, col)<EOL><DEDENT><DEDENT>return row, self.model().columnCountForRow(row)<EOL>
|
Gets the nearest index to *point*, *point* does not have to be over
an item. index can be +1 more in row and/or column than existing items
:param point: any point within the view, in view coordinates
:type point: :qtdoc:`QPoint`
:returns: (int, int) -- (row, column) of the nearest index
|
f10643:c0:m7
|
def isIndexHidden(self, index):
|
return False<EOL>
|
Items are never hidden. :qtdoc:`Re-implemented<QAbstractItemView.isIndexHidden>`
:returns: bool -- False
|
f10643:c0:m8
|
def visualRect(self, index):
|
if len(self._rects[index.row()]) -<NUM_LIT:1> < index.column() or index.row() == -<NUM_LIT:1>:<EOL><INDENT>return QtCore.QRect()<EOL><DEDENT>return self.visualRectRC(index.row(),index.column())<EOL>
|
The rectangle for the bounds of the item at *index*. :qtdoc:`Re-implemented<QAbstractItemView.visualRect>`
:param index: index for the rect you want
:type index: :qtdoc:`QModelIndex`
:returns: :qtdoc:`QRect` -- rectangle of the borders of the item
|
f10643:c0:m9
|
def visualRectRC(self, row, column):
|
rect = self._rects[row][column]<EOL>if rect.isValid():<EOL><INDENT>return QtCore.QRect(rect.x() - self.horizontalScrollBar().value(),<EOL>rect.y() - self.verticalScrollBar().value(),<EOL>rect.width(), rect.height())<EOL><DEDENT>else:<EOL><INDENT>return rect<EOL><DEDENT>
|
The rectangle for the bounds of the item at *row*, *column*
:param row: row of the item
:type row: int
:param column: column of the item
:type column: int
:returns: :qtdoc:`QRect` -- rectangle of the borders of the item
|
f10643:c0:m10
|
def dataChanged(self, topleft, bottomright):
|
self._viewIsDirty = True<EOL>super(StimulusView, self).dataChanged(topleft, bottomright)<EOL>
|
Marks view for repaint. :qtdoc:`Re-implemented<QAbstractItemView.dataChanged>`
|
f10643:c0:m11
|
def rowsInserted(self, parent, start, end):
|
self._viewIsDirty = True<EOL>super(StimulusView, self).rowsInserted(parent, start, end)<EOL>
|
Marks view for repaint. :qtdoc:`Re-implemented<QAbstractItemView.rowsInserted>`
|
f10643:c0:m12
|
def rowsAboutToBeRemoved(self, parent, start, end):
|
self._viewIsDirty = True<EOL>super(StimulusView, self).rowsAboutToBeRemoved(parent, start, end)<EOL>
|
Marks view for repaint. :qtdoc:`Re-implemented<QAbstractItemView.rowsAboutToBeRemoved>`
|
f10643:c0:m13
|
def somethingChanged(self):
|
self._viewIsDirty = True<EOL>
|
Marks view for repaint
|
f10643:c0:m14
|
def verticalOffset(self):
|
return self.verticalScrollBar().value()<EOL>
|
Offset caused by vertical scrollbar. :qtdoc:`Re-implemented<QAbstractItemView.verticalOffset>`
:returns: int -- number of increments (pixels) down in scroll bar
|
f10643:c0:m15
|
def horizontalOffset(self):
|
return self.horizontalScrollBar().value()<EOL>
|
Offset caused by horizontal scrollbar. :qtdoc:`Re-implemented<QAbstractItemView.horizontalOffset>`
:returns: int -- number of increments (pixels) over in scroll bar
|
f10643:c0:m16
|
def scrollTo(self, index, ScrollHint):
|
<EOL>area = self.viewport().rect()<EOL>rect = self.visualRect(index)<EOL>if rect.left() < area.left():<EOL><INDENT>self.horizontalScrollBar().setValue(<EOL>self.horizontalScrollBar().value() + rect.left() - area.left())<EOL><DEDENT>elif rect.right() > area.right():<EOL><INDENT>self.horizontalScrollBar().setValue(<EOL>self.horizontalScrollBar().value() + min(<EOL>rect.right() - area.right(), rect.left() - area.left()))<EOL><DEDENT>if rect.top() < area.top():<EOL><INDENT>self.verticalScrollBar().setValue(<EOL>self.verticalScrollBar().value() + rect.top() - area.top())<EOL><DEDENT>elif rect.bottom() > area.bottom():<EOL><INDENT>self.verticalScrollBar().setValue(<EOL>self.verticalScrollBar().value() + min(<EOL>rect.bottom() - area.bottom(), rect.top() - area.top()))<EOL><DEDENT>self.viewport().update()<EOL>
|
:qtdoc:`Re-implemented<QAbstractItemView.scrollTo>`
|
f10643:c0:m17
|
def scrollContentsBy(self, dx, dy):
|
<EOL>self.viewport().scroll(dx, dy)<EOL>
|
Scrolls the viewport. :qtdoc:`Re-implemented<QAbstractScrollArea.scrollContentsBy>`
|
f10643:c0:m18
|
def paintEvent(self, event):
|
selections = self.selectionModel()<EOL>option = self.viewOptions()<EOL>state = option.state<EOL>if self.parentWidget() is not None:<EOL><INDENT>background = self.parentWidget().palette().color(<NUM_LIT:1>)<EOL><DEDENT>else:<EOL><INDENT>background = option.palette.base()<EOL><DEDENT>foreground = QtGui.QPen(option.palette.color(QtGui.QPalette.WindowText))<EOL>textPen = QtGui.QPen(option.palette.color(QtGui.QPalette.Text))<EOL>highlightedPen = QtGui.QPen(option.palette.color(QtGui.QPalette.HighlightedText))<EOL>painter = QtGui.QPainter(self.viewport())<EOL>painter.setRenderHint(QtGui.QPainter.Antialiasing)<EOL>self._calculateRects()<EOL>viewrect = event.rect()<EOL>painter.fillRect(viewrect, background)<EOL>painter.setPen(foreground)<EOL>fontsz = self.font().pointSize() <EOL>wid = int(max(viewrect.width(), self._width))<EOL>nlines = int((wid/self.pixelsPerms)/self.gridms)<EOL>y0 = viewrect.y()<EOL>y1 = viewrect.y() + viewrect.height()<EOL>for iline in range(<NUM_LIT:1>, nlines + <NUM_LIT:1>):<EOL><INDENT>x = (iline * self.gridms * self.pixelsPerms) - self.horizontalScrollBar().value()<EOL>painter.drawLine(x, y0+fontsz+<NUM_LIT:2>, x, y1)<EOL>painter.drawText(x-<NUM_LIT:5>, y0+fontsz+<NUM_LIT:1>, str(iline*self.gridms))<EOL><DEDENT>for row in range(self.model().rowCount(self.rootIndex())):<EOL><INDENT>for col in range(self.model().columnCountForRow(row)):<EOL><INDENT>index = self.model().index(row, col, self.rootIndex())<EOL>component = self.model().data(index, QtCore.Qt.UserRole)<EOL>if component is not None:<EOL><INDENT>option = self.viewOptions()<EOL>option.rect = self.visualRectRC(row, col)<EOL>self.itemDelegate().paint(painter, option, index)<EOL><DEDENT><DEDENT><DEDENT>region = self.visualRegionForSelection(self.selectionModel().selection())<EOL>painter.save()<EOL>painter.setClipRegion(region)<EOL>painter.setOpacity(<NUM_LIT:0.5>)<EOL>painter.fillRect(viewrect, QtCore.Qt.blue)<EOL>painter.restore()<EOL>if self.dragline is not None:<EOL><INDENT>pen = QtGui.QPen(QtCore.Qt.blue)<EOL>pen.setWidth(<NUM_LIT:3>)<EOL>painter.setPen(pen)<EOL>painter.drawLine(self.dragline)<EOL><DEDENT>
|
All custom painting, draws the entire view. :qtdoc:`Re-implemented<qabstractscrollarea.paintEvent>`
|
f10643:c0:m19
|
def moveCursor(self, cursorAction, modifiers):
|
return QtCore.QModelIndex()<EOL>
|
Returns an empty index. :qtdoc:`Re-implemented<QAbstractItemView.moveCursor>`
|
f10643:c0:m20
|
def mouseDoubleClickEvent(self, event):
|
if self.mode == BuildMode:<EOL><INDENT>if event.button() == QtCore.Qt.LeftButton:<EOL><INDENT>index = self.indexAt(event.pos())<EOL>self.edit(index)<EOL><DEDENT><DEDENT>
|
Launches an editor for the component, if the mouse cursor is over an item
|
f10643:c0:m21
|
def grabImage(self, index):
|
<EOL>rect = self.visualRect(index)<EOL>pixmap = QtGui.QPixmap()<EOL>pixmap = pixmap.grabWidget(self, rect) <EOL>return pixmap<EOL>
|
Gets an image of the item at *index*
:param index: index of an item in the view
:type index: :qtdoc:`QModelIndex`
:returns: :qtdoc:`QPixmap`
|
f10643:c0:m23
|
def mousePressEvent(self, event):
|
if self.mode == BuildMode:<EOL><INDENT>super(StimulusView, self).mousePressEvent(event)<EOL><DEDENT>else:<EOL><INDENT>index = self.indexAt(event.pos())<EOL>if index.isValid():<EOL><INDENT>self.selectionModel().select(index, QtGui.QItemSelectionModel.Toggle)<EOL>comp = self.model().data(index, AbstractDragView.DragRole)<EOL>self.componentSelected.emit(comp)<EOL>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT><DEDENT>
|
In Auto-parameter selection mode, mouse press over an item emits
`componentSelected`
|
f10643:c0:m24
|
def emptySelection(self, empty):
|
self.setEnabled(not empty)<EOL>if empty:<EOL><INDENT>m = self.selectionModel()<EOL>for index in m.selectedIndexes():<EOL><INDENT>m.select(index, QtGui.QItemSelectionModel.Deselect)<EOL><DEDENT>self.hintRequested.emit('<STR_LIT>')<EOL><DEDENT>
|
Enables the view if not *empty*, clears the current selection and
disables view if is *emtpy*
:param emtpy: whether there are any components in the view
:type emtpy: bool
|
f10643:c0:m25
|
def updateSelectionModel(self, components):
|
<EOL>selmodel = ComponentSelectionModel(self.model())<EOL>self.setSelectionModel(selmodel)<EOL>for comp in components:<EOL><INDENT>selmodel.selectComponent(comp)<EOL><DEDENT>self.viewport().update()<EOL>
|
Creates a new selection model and adds *components* to it
:param components: components in this view to add to the selection
:type components: list<:class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`
|
f10643:c0:m26
|
def cursor(self, pos):
|
index = self.splitAt(pos)<EOL>if len(self._rects[index[<NUM_LIT:0>]])-<NUM_LIT:1> < index[<NUM_LIT:1>]:<EOL><INDENT>if index[<NUM_LIT:1>] == <NUM_LIT:0>:<EOL><INDENT>x = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>rect = self._rects[index[<NUM_LIT:0>]][index[<NUM_LIT:1>]-<NUM_LIT:1>]<EOL>x = rect.x() + rect.width()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>rect = self._rects[index[<NUM_LIT:0>]][index[<NUM_LIT:1>]]<EOL>x = rect.x()<EOL><DEDENT>y0 = index[<NUM_LIT:0>]*(ROW_HEIGHT + ROW_SPACE) + ROW_SPACE<EOL>y1 = y0 + ROW_HEIGHT<EOL>x -= self.horizontalScrollBar().value()<EOL>y0 -= self.verticalScrollBar().value()<EOL>y1 -= self.verticalScrollBar().value()<EOL>return QtCore.QLine(x,y0,x,y1)<EOL>
|
Returns a line for the cursor as position *pos*
:param pos: mouse cursor position
:type pos: :qtdoc:`QPoint`
:returns: :qtdoc:`QLine` -- position between items (indicates where drops will go)
|
f10643:c0:m27
|
def dropped(self, component, event):
|
if isinstance(component, AbstractStimulusComponent):<EOL><INDENT>row, col = self.splitAt(event.pos())<EOL>index = self.model().createIndex(row, col, component)<EOL>self.model().insertComponent(index, component)<EOL>if isinstance(event.source(), DragLabel):<EOL><INDENT>if component.__class__.__name__ in self._componentDefaults:<EOL><INDENT>component.loadState(self._componentDefaults[component.__class__.__name__])<EOL><DEDENT>self.edit(index)<EOL><DEDENT>self._viewIsDirty = True<EOL>self.viewport().update()<EOL><DEDENT>
|
Adds the dropped *component* into the model.
:meth:`Re-implemented<sparkle.gui.abstract_drag_view.AbstractDragView.dropped>`
|
f10643:c0:m28
|
def setMode(self, mode):
|
self.mode = mode<EOL>if mode == BuildMode:<EOL><INDENT>self.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)<EOL>self.setSelectionModel(QtGui.QItemSelectionModel(self.model()))<EOL>self.setEnabled(True)<EOL>self.model().updateComponentStartVals()<EOL><DEDENT>else:<EOL><INDENT>self.model().purgeAutoSelected()<EOL>self.setSelectionModel(ComponentSelectionModel(self.model()))<EOL>self.setSelectionMode(QtGui.QAbstractItemView.MultiSelection)<EOL><DEDENT>
|
Sets the "mode" for this view:
BuildMode 0: Allowing adding, moving and editing of component items
AutoParamMode 1: For adding components to a selection of an
auto-parameter. clicks toggle membership in selection. Moving and
editing of components disabled.
:param mode: which mode to set
:type mode: int
|
f10643:c0:m30
|
def visualRegionForSelection(self, selection):
|
region = QtGui.QRegion()<EOL>for index in selection.indexes():<EOL><INDENT>region = region.united(self._rects[index.row()][index.column()])<EOL><DEDENT>return region<EOL>
|
Gets the region of all of the components in selection
:param selection: a selection model for this view
:type selection: :qtdoc:`QItemSelectionModel`
:returns: :qtdoc:`QRegion` -- union of rects of the selected components
|
f10643:c0:m32
|
@staticmethod<EOL><INDENT>def updateDefaults(sender, state):<DEDENT>
|
<EOL>StimulusView._componentDefaults[str(sender)] = state<EOL>
|
Updates the input defaults for the component fields
:param sender: Component (:class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`) class name to set the defaults for
:type sender: str
:param state: the return value from that component's :meth:`stateDict<sparkle.stim.abstract_component.AbstractStimulusComponent.stateDict>` method
:type state: dict
|
f10643:c0:m33
|
@staticmethod<EOL><INDENT>def getDefaults():<DEDENT>
|
return StimulusView._componentDefaults<EOL>
|
Returns a dict of all the latest default settings that have been set in all views
|
f10643:c0:m34
|
def resizeEvent(self, event):
|
self._viewIsDirty = True<EOL>super(StimulusView, self).resizeEvent(event)<EOL>
|
Mark repaint needed. :qtdoc:`Re-implemented<QWidget.resizeEvent>`
|
f10643:c0:m36
|
def updateVocalAuto(self, component, files):
|
auto_model = self.model().autoParams()<EOL>row = auto_model.fileParameter(component)<EOL>if len(files) > <NUM_LIT:1>:<EOL><INDENT>clean_component = self.model().data(self.model().indexByComponent(component), AbstractDragView.DragRole)<EOL>p = {'<STR_LIT>' : '<STR_LIT:filename>',<EOL>'<STR_LIT>' : files,<EOL>'<STR_LIT>' : [clean_component]<EOL>}<EOL>if row is None:<EOL><INDENT>auto_model.insertItem(auto_model.index(<NUM_LIT:0>,<NUM_LIT:0>), p)<EOL><DEDENT>else:<EOL><INDENT>auto_model.setData(auto_model.index(row,<NUM_LIT:0>),p)<EOL><DEDENT><DEDENT>elif row is not None:<EOL><INDENT>auto_model.removeRow(row)<EOL><DEDENT>self.countChanged.emit()<EOL>
|
Updates the auto-parameter with selected *component* to have
*files*. Adds auto-parameter if not already present. The auto-parameter is expected to have only one selected
component (the one given). If length of files < 1, removes the
auto-parameter from the model.
:param component: Component that the auto-parameter is modifying
:type component: :class:`AbstractStimulusComponent<sparkle.stim.abstract_component.AbstractStimulusComponent>`
:param files: list of file names to act as the auto-parameter list
:type files: list<str>
|
f10643:c0:m37
|
def paint(self, painter, option, index):
|
component = index.model().data(index, role=QtCore.Qt.UserRole)<EOL>painter.drawRect(option.rect)<EOL>component.paint(painter, option.rect, option.palette)<EOL>
|
Uses the :meth:`paint<sparkle.gui.stim.components.qcomponents.QStimulusComponent.paint>`
method of the component it represents to fill in an appropriately
sized rectange. :qtdoc:`Re-implemented<QStyledItemDelegate.paint>`
|
f10643:c1:m0
|
def sizeHint(self, option, index):
|
<EOL>component = index.internalPointer()<EOL>width = self.component.duration() * self.pixelsPerms*<NUM_LIT:1000><EOL>return QtCore.QSize(width, <NUM_LIT:50>)<EOL>
|
Size based on component duration and a fixed height
|
f10643:c1:m1
|
def createEditor(self, parent, option, index):
|
<EOL>view = parent.parentWidget()<EOL>component = view.model().data(index)<EOL>if component is not None:<EOL><INDENT>editor = component.showEditor()<EOL><DEDENT>else:<EOL><INDENT>print('<STR_LIT>', type(component))<EOL>raise Exception('<STR_LIT>')<EOL><DEDENT>editor.attributesSaved.connect(view.updateDefaults)<EOL>editor.attributesSaved.connect(view.somethingChanged)<EOL>if component.name == '<STR_LIT>':<EOL><INDENT>files = view.model().autoParams().findFileParam(component)<EOL>if files is not None:<EOL><INDENT>editor.selectMany(files)<EOL><DEDENT>editor.vocalFilesChanged.connect(view.updateVocalAuto)<EOL><DEDENT>return editor<EOL>
|
Creates an editor in a separate window, specific for the component
type this delegate represents. :qtdoc:`Re-implemented<QStyledItemDelegate.createEditor>`
|
f10643:c1:m2
|
def setModelData(self, editor, model, index):
|
editor.saveToObject()<EOL>model.dataEdited()<EOL>editor.attributesSaved.disconnect()<EOL>if hasattr(editor, '<STR_LIT>'):<EOL><INDENT>editor.vocalFilesChanged.disconnect()<EOL><DEDENT>editor.close()<EOL>
|
Saves the input from the editor widget to the model component.
:qtdoc:`Re-implemented<QStyledItemDelegate.setModelData>`
|
f10643:c1:m3
|
def updateEditorGeometry(self, editor, option, index):
|
qr = editor.frameGeometry()<EOL>cp = QtGui.QDesktopWidget().availableGeometry().center()<EOL>qr.moveCenter(cp)<EOL>editor.move(qr.topLeft())<EOL>
|
centers the editor widget. :qtdoc:`Re-implemented<QStyledItemDelegate.updateEditorGeometry>`
|
f10643:c1:m4
|
def eventFilter(self, editor, event):
|
if event.type() == QtCore.QEvent.FocusIn:<EOL><INDENT>editor.setContentFocus()<EOL>return True<EOL><DEDENT>return super(ComponentDelegate, self).eventFilter(editor, event)<EOL>
|
Sets focus to the editor. :qtdoc:`Re-implemented<QStyledItemDelegate.eventFilter>`
|
f10643:c1:m5
|
def setAutoParams(self, params):
|
self._autoParams = params<EOL>
|
Sets the QAutoParameterModel for this stimulus
|
f10644:c0:m1
|
def autoParams(self):
|
return self._autoParams<EOL>
|
Gets the QAutoParameterModel for this stimulus
|
f10644:c0:m2
|
def headerData(self, section, orientation, role):
|
return '<STR_LIT>'<EOL>
|
Returns empty string. Required by view see :qtdoc:`subclassing<qabstractitemmodel.subclassing>`
|
f10644:c0:m3
|
def rowCount(self, parent=QtCore.QModelIndex()):
|
return self._stim.rowCount()<EOL>
|
Determines the numbers of rows the view will draw
Required by view, see :qtdoc:`subclassing<qabstractitemmodel.subclassing>`
|
f10644:c0:m4
|
def columnCount(self, parent=QtCore.QModelIndex()):
|
if parent.isValid():<EOL><INDENT>return self._stim.columnCount(parent.row())<EOL><DEDENT>else:<EOL><INDENT>return self._stim.columnCount()<EOL><DEDENT>
|
Determines the numbers of columns the view will draw
Required by view, see :qtdoc:`subclassing<qabstractitemmodel.subclassing>`
|
f10644:c0:m5
|
def columnCountForRow(self, row):
|
return self._stim.columnCountForRow(row)<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.columnCountForRow>`
|
f10644:c0:m6
|
def componentCount(self):
|
return self._stim.componentCount()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.componentCount>`
|
f10644:c0:m7
|
def repCount(self):
|
return self._stim.repCount()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.repCount>`
|
f10644:c0:m8
|
def setRepCount(self, count):
|
self._stim.setRepCount(count)<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.setRepCount>`
|
f10644:c0:m9
|
def traceCount(self):
|
return self._stim.traceCount()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.traceCount>`
|
f10644:c0:m10
|
def data(self, index, role=QtCore.Qt.UserRole, mode=BuildMode):
|
if role == CursorRole:<EOL><INDENT>if index.isValid():<EOL><INDENT>if mode == BuildMode:<EOL><INDENT>return cursors.openHand()<EOL><DEDENT>elif mode == AutoParamMode:<EOL><INDENT>return cursors.pointyHand()<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return QtGui.QCursor(QtCore.Qt.ArrowCursor)<EOL><DEDENT><DEDENT>if not index.isValid():<EOL><INDENT>return None<EOL><DEDENT>if role == QtCore.Qt.DisplayRole:<EOL><INDENT>component = self._stim.component(index.row(),index.column())<EOL>return component.__class__.__name__<EOL><DEDENT>elif role == QtCore.Qt.SizeHintRole:<EOL><INDENT>component = self._stim.component(index.row(),index.column())<EOL>return component.duration() <EOL><DEDENT>elif role == QtCore.Qt.UserRole or role == QtCore.Qt.UserRole+<NUM_LIT:1>: <EOL><INDENT>if self._stim.columnCountForRow(index.row()) > index.column():<EOL><INDENT>component = self._stim.component(index.row(),index.column())<EOL>if role == QtCore.Qt.UserRole:<EOL><INDENT>component = wrapComponent(component)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>component = None<EOL><DEDENT>return component<EOL><DEDENT>
|
Used by the view to determine data to present
See :qtdoc:`QAbstractItemModel<QAbstractItemModel.data>`,
and :qtdoc:`subclassing<qabstractitemmodel.subclassing>`
|
f10644:c0:m11
|
def index(self, row, col, parent=QtCore.QModelIndex()):
|
if row < self._stim.rowCount() and col < self._stim.columnCountForRow(row):<EOL><INDENT>component = self._stim.component(row, col)<EOL>return self.createIndex(row, col, component)<EOL><DEDENT>else:<EOL><INDENT>return QtCore.QModelIndex()<EOL><DEDENT>
|
Creates an index. An item must exist for the given *row*
and *col*
:returns: :qtdoc:`QModelIndex`
|
f10644:c0:m12
|
def insertComponent(self, index, comp):
|
<EOL>if self.columnCountForRow(index.row()) == <NUM_LIT:0>:<EOL><INDENT>self.beginInsertRows(QtCore.QModelIndex(), index.row(), index.row())<EOL>self._stim.insertComponent(comp, index.row(), index.column())<EOL>self.endInsertRows()<EOL><DEDENT>else:<EOL><INDENT>self._stim.insertComponent(comp, index.row(), index.column())<EOL><DEDENT>self.samplerateChanged.emit(self._stim.samplerate())<EOL>
|
Inserts new component *comp* at index
|
f10644:c0:m14
|
def insertItem(self, index, comp):
|
self.insertComponent(index, comp)<EOL>
|
Alias for `insertComponent`, as required by AbstractDragView
|
f10644:c0:m15
|
def removeComponent(self, index):
|
if index.row() == self.rowCount() -<NUM_LIT:1> and self.columnCountForRow(index.row()) == <NUM_LIT:1>:<EOL><INDENT>self.beginRemoveRows(QtCore.QModelIndex(), self._stim.rowCount()-<NUM_LIT:1>, <EOL>self._stim.rowCount()-<NUM_LIT:1>)<EOL>self._stim.removeComponent(index.row(), index.column())<EOL>self.endRemoveRows()<EOL><DEDENT>else:<EOL><INDENT>self._stim.removeComponent(index.row(), index.column())<EOL><DEDENT>self.samplerateChanged.emit(self._stim.samplerate())<EOL>
|
Removes the component at *index* from the model. If the two last
rows are now empty, trims the last row.
|
f10644:c0:m16
|
def removeItem(self, index):
|
self._stim.removeComponent(index.row(), index.column())<EOL>
|
Alias for removeComponent
|
f10644:c0:m17
|
def indexByComponent(self, component):
|
return self.index(*self._stim.indexByComponent(component))<EOL>
|
return a QModelIndex for the given *component*, or None if
it is not in the model
|
f10644:c0:m18
|
def setData(self, index, value, role=QtCore.Qt.UserRole):
|
<EOL>self._stim.overwriteComponent(value, index.row(), index.column())<EOL>self.samplerateChanged.emit(self.samplerate())<EOL>
|
Sets the component at *index* to *value*
|
f10644:c0:m19
|
def flags(self, index):
|
return QtCore.Qt.ItemIsEditable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable<EOL>
|
Determines interaction allowed with table cells.
See :qtdoc:`QAbstractItemModel<QAbstractItemModel.flags>`,
and :qtdoc:`subclassing<qabstractitemmodel.subclassing>`
|
f10644:c0:m21
|
def setEditor(self, name):
|
editor = get_stimulus_editor(name)<EOL>self.editor = editor<EOL>self._stim.setStimType(name)<EOL>
|
Sets the editor class for this Stimulus
|
f10644:c0:m22
|
def showEditor(self):
|
if self.editor is not None:<EOL><INDENT>editor = self.editor()<EOL>editor.setModel(self)<EOL>factory = get_stimulus_factory(self._stim.stimType())<EOL>editor.editingFinished.connect(factory.update)<EOL>return editor<EOL><DEDENT>else:<EOL><INDENT>logger = logging.getLogger('<STR_LIT>')<EOL>logger.warning('<STR_LIT>')<EOL><DEDENT>
|
Creates and shows an editor for this Stimulus
|
f10644:c0:m23
|
def signal(self):
|
return self._stim.signal()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.signal>`
|
f10644:c0:m24
|
def samplerate(self):
|
return self._stim.samplerate()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.samplerate>`
|
f10644:c0:m25
|
def duration(self):
|
return self._stim.duration()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.duration>`
|
f10644:c0:m26
|
def randomToggle(self, randomize):
|
if randomize:<EOL><INDENT>self._stim.setReorderFunc(order_function('<STR_LIT>'), '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>self._stim.reorder = None<EOL><DEDENT>
|
Sets the reorder function on this StimulusModel to a randomizer
or none, alternately
|
f10644:c0:m27
|
def reorder(self):
|
return self._stim.reorder<EOL>
|
Returns the reorder fucntion for this stimulus
|
f10644:c0:m28
|
def updateComponentStartVals(self):
|
self._stim.updateComponentStartVals()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.updateComponentStartVals>`
|
f10644:c0:m29
|
@staticmethod<EOL><INDENT>def loadFromTemplate(template, stim=None):<DEDENT>
|
stim = StimulusModel.loadFromTemplate(template, stim=stim)<EOL>qstim = QStimulusModel(stim)<EOL>qstim.setEditor(template['<STR_LIT>'])<EOL>return qstim<EOL>
|
Initialized this stimulus from a saved *template*
:param template: doc from a previously stored stimulus via :class:`templateDoc`
:type template: dict
|
f10644:c0:m30
|
def templateDoc(self):
|
doc = self._stim.templateDoc()<EOL>return doc<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.templateDoc>`
|
f10644:c0:m31
|
def warning(self):
|
return self._stim.warning()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.warning>`
|
f10644:c0:m32
|
def verify(self):
|
return self._stim.verify()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.verify>`
|
f10644:c0:m33
|
def purgeAutoSelected(self):
|
self._stim.purgeAutoSelected()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.purgeAutoSelected>`
|
f10644:c0:m34
|
def cleanComponents(self):
|
<EOL>self._stim.cleanComponents()<EOL>
|
Wrapper for :meth:`StimulusModel<sparkle.stim.stimulus_model.StimulusModel.cleanComponents>`
|
f10644:c0:m35
|
def trash(self):
|
return self.trashLbl<EOL>
|
Returns the trash widget
|
f10645:c0:m1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.