Skip to content
Snippets Groups Projects
  • Dilawar Singh's avatar
    Squashed 'moose-gui/' changes from 38da92b04..5d7f7633f · 0e72b330
    Dilawar Singh authored
    5d7f7633f Too many python3 incompatibility issues. For now on, gui is only compatible with python2.
    599dbd6d3 Testing with python3 as well. If python3 support is not intented, we can fallback this commit.
    83be02e60 changes made after addition of groups, some of action are implemented
    24cba7d6f  some more clean
    cdf16259d at file load dialog, a clean round trip is done
    08fc6cd0b at loading time, kkit model is checked for the atleast for 1 compartment and atleast 2 species
    373efaa6d check if moose object already exist, if yes use element, else create a object
    e37368553 in mousePressEvent further check made for group object along with compartment and other moose object
    ae6265ed8 travis is failing, while installing python-libsbml trying to fix providing -H
    c70f30098 some clean up with co-ordinates while saving into XML files
    dd177002c wrong comparsion with path and moose object was done corrected
    24ecdccac some clean up with groups
    84be91147 changes made related to group
    5a6c654c7 Merge branch 'master' of https://github.com/BhallaLab/moose-gui
    3fcc20a66 mgui in cleanup in dialog box, mload: sbml reader returns modelpath and errormsg, kkit: co-ordinates for sbml(auto co-ordinates) values are kept in annotation as its and while displayed as its, but for genesis default scenewidth and height is taken care and kkitOrdinatesUtil: sbml auto co-ordinates are kept as its
    d93fd2118 hover overcompartment shows name and some more cleaned up after the bad merger 320e525a and also wrong commit from 6fc726e
    ed79c3980 indentation correction and missing lib
    f4d880f53 Cleaned up, these 9 files after the bad merger 320e525a and also wrong commit from 6fc726e560556f7619e31fe022ef094793d6a13a
    2c594c457 in gui stoich.status along with warning, which Reac and Enz are dangling is also displayed in the QMessageBox
    
    git-subtree-dir: moose-gui
    git-subtree-split: 5d7f7633f5e20d48e4bfa0a2b38697c4d0d60d6a
    0e72b330
PlotWidgetContainer.py 5.67 KiB

# -*- coding: utf-8 -*-
from __future__ import print_function

"""
"""
__credits__     =   ["Upi Lab"]
__author__      =   "Aviral Goel"
__license__     =   "GPL3"
__version__     =   "1.0.0"
__maintainer__  =   "Aviral Goel", "HarshaRani"
__email__       =   "goel.aviral@gmail.com"
__status__      =   "Development"
__updated__     =   "Jul 26 2017"


import sys
import os
import PyQt4
from PyQt4 import QtGui, Qt
from PyQt4.QtGui import QWidget
from PyQt4.QtGui import QSizeGrip
from PyQt4.QtGui import QDockWidget
from PyQt4.QtGui import QLayout
from PyQt4.QtGui import QVBoxLayout
from PyQt4.QtGui import QGridLayout
from PyQt4.QtGui import QScrollArea
from PyQt4.QtGui import QToolBar
from PyQt4.QtGui import QSizeGrip
from PyQt4.QtGui import QSplitter

import moose
import default
import sidebar
# from default import PlotWidget

ELECTRICAL = 0
CHEMICAL = 1
class PlotWidgetContainer(QWidget):

    def __init__(self, modelRoot, *args, **kwargs):

        super(PlotWidgetContainer, self).__init__(*args)
        self.modelRoot = modelRoot
        if len(moose.wildcardFind(modelRoot + "/##[ISA=ChemCompt]")) == 0:
            self.modelType = ELECTRICAL
        else:
            self.modelType = CHEMICAL

        self.model          = moose.element(self.modelRoot)
        if self.modelRoot != "/":
            self.modelRoot = self.findModelPath(self.modelRoot)
            if moose.exists(modelRoot + "/data"):
                self.data   = moose.element(self.modelRoot + "/data")
            else:
                self.data   = moose.Neutral(self.modelRoot + "/data")

        else:
            self.data       = moose.element("/data")

        self._layout        = QVBoxLayout()
        self.graphs         = QSplitter()
        self.graphs.setOrientation(PyQt4.QtCore.Qt.Vertical)
        self.graphsArea     = QScrollArea()
        # self.graphsLayout   = QGridLayout()
        # self.menubar        = self.createMenuBar()
        self.rowIndex       = 0
            # self.setSizePolicy( QtGui.QSizePolicy.Expanding
        #                   , QtGui.QSizePolicy.Expanding
        #                   )

        self.graphs.setSizePolicy( QtGui.QSizePolicy.Expanding
                                 , QtGui.QSizePolicy.Expanding
                                 )
        self.setAcceptDrops(True)
        # self._layout.setSizeConstraint( QLayout.SetNoConstraint )
        # self.graphs.setLayout(self.graphsLayout)
        self.graphsArea.setWidget(self.graphs)
        self.graphsArea.setWidgetResizable(True)
        self.graphWidgets = []
        # self._layout.addWidget(self.menubar)
        self._layout.addWidget(self.graphsArea)
        self.setLayout(self._layout)

        for graph in self.data.children:
            self.addPlotWidget(graph = graph)

        if len(self.data.children) == 0:
            self.addPlotWidget()

    def mooseIsInstance(self,element, classNames):
        return moose.element(element).__class__.__name__ in classNames


    def findModelPath(self,element):
        child = element
        while not self.mooseIsInstance(element, "Shell"):
            child = moose.element(element).path
            element = moose.element(element).parent
        return child
        
    def deleteWidget(self, graphWidget):
        # print("Deleted => ", graphWidget)
        self.graphWidgets.remove(graphWidget)
        graphWidget.setParent(None)
        graphWidget.close()

    def createMenuBar(self):
        bar = sidebar.sidebar()
        bar.addAction(sidebar.add_graph_action(bar, lambda event: self.addPlotWidget() ))
        # bar.addAction(sidebar.delete_graph_action(bar, lambda event: self.addPlotWidget() ))
        # bar.addAction(sidebar.list_action(bar, self.showPlotView))
        return bar

    def addPlotWidget(self, row = None, col = 0, graph = None):
        if graph == None:
            graph = moose.Neutral(self.data.path + "/graph_" + str(self.rowIndex))
        widget = default.PlotWidget(self.model, graph, self.rowIndex, self)

        if self.modelType == ELECTRICAL:
            for axes in widget.canvas.axes.values():
            # axes.autoscale(False, axis='x', tight=True)
                axes.set_ylim(bottom = -0.07, top= 0.03)

        if row == None:
            row = self.rowIndex
        self.graphs.addWidget(widget)
        self.rowIndex += 1
        self.graphWidgets.append(widget)
        widget.widgetClosedSignal.connect(self.deleteWidget)
        widget.addGraph.connect(lambda event : self.addPlotWidget())
        # widget.resize(1, 1);
        return widget

    def showPlotView(self):
        pass

    def setModelRoot(self, *args):
        pass

    def getMenus(self, *args):
        return []

    def setDataRoot(self, *args):
        pass

    def updatePlots(self):
        for graphWidget in self.graphWidgets:
            graphWidget.updatePlots()

    def rescalePlots(self):
        for graphWidget in self.graphWidgets:
            graphWidget.rescalePlots()

    def extendXAxes(self, xlim):
        for graphWidget in self.graphWidgets:
            graphWidget.extendXAxes(xlim)

    def plotAllData(self):
        for graphWidget in self.graphWidgets:
            graphWidget.plotAllData()

    #print(graphWidget)
    # def plotAll(self):
    #     self.apply(lambda obj: obj.plotAll())

    # def plotAllData(self):
    #     selt.plotWidgetContainer.plotAllData()

    # def genColorMap(self,tableObject):
    #     pass

    # def onclick(self,event1):
    #     pass

    # def addTimeSeries(self, table, *args, **kwargs):
    #     pass

    # def addRasterPlot(self, eventtable, yoffset=0, *args, **kwargs):
    #     pass

    # def extendXAxes(self, xlim):
    #     pass

    # def saveCsv(self, line,directory):
    #     pass

    # def saveAllCsv(self):
    #     pass