Skip to content

Commit c8e9980

Browse files
author
Dilawar Singh
committed
Squashed 'moose-gui/' changes from a3d3a06..bc510df
bc510df removal of whitespace in target Name 9eb3039 colormap check 6884e38 Files with no model will not open pyqt widget, atleast one empty compartment should exist c830fa0 Merge pull request #9 from dilawar/master e1efc3d Merge branch 'master' of https://github.com/BhallaLab/moose-gui 9603662 Added suds to the source code, removing a dependency. git-subtree-dir: moose-gui git-subtree-split: bc510df870a692283993da17d0fb5bef67edab25
1 parent 0cda31e commit c8e9980

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+14482
-27
lines changed

__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
all = [ "plugins" ]
1+
all = [ "plugins", 'suds' ]

biomodelsclient.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545

4646
# Code:
4747

48-
4948
from suds.client import Client
5049
from suds.transport.http import HttpTransport as SudsHttpTransport
5150
import os

mgui.py

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,27 +1101,25 @@ def loadModelDialogSlot(self):
11011101
self.tr('Load model from file'))
11021102

11031103
if dialog.exec_():
1104-
fileNames = dialog.selectedFiles()
1105-
for fileName in fileNames:
1106-
modelName = dialog.getTargetPath()
1107-
if '/' in modelName:
1108-
raise mexception.ElementNameError('Model name cannot contain `/`')
1109-
ret = loadFile(str(fileName),'%s' %(modelName),merge=False)
1110-
#ret = loadFile(str(fileName), '/model/%s' % (modelName), merge=False)
1111-
#Harsha: This will clear out object editor's objectpath and make it invisible
1112-
self.objectEditSlot('/',False)
1113-
1114-
# Harsha: if subtype is None, in case of cspace then pluginLookup = /cspace/None
1115-
# which will not call kkit plugin so cleaning to /cspace
1116-
pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype'])
1117-
try:
1118-
pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])]
1119-
except KeyError:
1120-
pluginName = 'default'
1121-
print 'Loaded model', ret['model'].path
1122-
# if not moose.exists(ret['model'].path+'/info'):
1123-
# moose.Annotator(ret['model'].path+'/info')
1124-
1104+
valid = False
1105+
ret = []
1106+
ret,pluginName = self.checkPlugin(dialog)
1107+
if pluginName == 'kkit':
1108+
compt = moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')
1109+
if not len(compt):
1110+
reply = QtGui.QMessageBox.question(self, "Model is empty","Model has no compartment, atleast one compartment should exist to display the widget\n Do you want another file",
1111+
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
1112+
if reply == QtGui.QMessageBox.Yes:
1113+
dialog = LoaderDialog(self,self.tr('Load model from file'))
1114+
if dialog.exec_():
1115+
ret,pluginName = self.checkPlugin(dialog)
1116+
ret,valid = self.dialog_check(ret)
1117+
else:
1118+
QtGui.QApplication.restoreOverrideCursor()
1119+
return
1120+
else:
1121+
valid = True
1122+
if valid == True:
11251123
modelAnno = moose.Annotator(ret['model'].path+'/info')
11261124
if ret['subtype']:
11271125
modelAnno.modeltype = ret['subtype']
@@ -1133,6 +1131,46 @@ def loadModelDialogSlot(self):
11331131
if pluginName == 'kkit':
11341132
QtCore.QCoreApplication.sendEvent(self.plugin.getEditorView().getCentralWidget().view, QtGui.QKeyEvent(QtCore.QEvent.KeyPress, Qt.Qt.Key_A, Qt.Qt.NoModifier))
11351133

1134+
def checkPlugin(self,dialog):
1135+
fileNames = dialog.selectedFiles()
1136+
for fileName in fileNames:
1137+
modelName = dialog.getTargetPath()
1138+
if '/' in modelName:
1139+
raise mexception.ElementNameError('Model name cannot contain `/`')
1140+
ret = loadFile(str(fileName),'%s' %(modelName),merge=False)
1141+
#ret = loadFile(str(fileName), '/model/%s' % (modelName), merge=False)
1142+
#This will clear out object editor's objectpath and make it invisible
1143+
self.objectEditSlot('/',False)
1144+
#if subtype is None, in case of cspace then pluginLookup = /cspace/None
1145+
# which will not call kkit plugin so cleaning to /cspace
1146+
pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype'])
1147+
try:
1148+
pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])]
1149+
except KeyError:
1150+
pluginName = 'default'
1151+
print 'Loaded model', ret['model'].path
1152+
return ret,pluginName
1153+
1154+
def dialog_check(self,ret):
1155+
pluginLookup = '%s/%s' % (ret['modeltype'], ret['subtype'])
1156+
try:
1157+
pluginName = subtype_plugin_map['%s/%s' % (ret['modeltype'], ret['subtype'])]
1158+
except KeyError:
1159+
pluginName = 'default'
1160+
if pluginName == 'kkit':
1161+
compt = moose.wildcardFind(ret['model'].path+'/##[ISA=ChemCompt]')
1162+
if not len(compt):
1163+
reply = QtGui.QMessageBox.question(self, "Model is empty","Model has no compartment, atleast one compartment should exist to display the widget\n Do you want another file",
1164+
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
1165+
if reply == QtGui.QMessageBox.Yes:
1166+
dialog = LoaderDialog(self,self.tr('Load model from file'))
1167+
if dialog.exec_():
1168+
ret,pluginName = self.checkPlugin(dialog)
1169+
else:
1170+
QtGui.QApplication.restoreOverrideCursor()
1171+
return
1172+
else:
1173+
return ret,True
11361174
def newModelDialogSlot(self):
11371175
#Harsha: Create a new dialog widget for model building
11381176
self.popup.close()

mload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656
from plugins.setsolver import *
5757

5858
def loadGenCsp(target,filename,solver="gsl"):
59+
target = target.replace(" ", "")
5960
path = '/'+target
60-
#Harsha: Moving the model under /modelname/model and graphs under /model/graphs.
61+
#Moving the model under /modelname/model and graphs under /model/graphs.
6162
#This is passed while loading-time which will be easy for setting the stoich path
6263
mpath = '/'+target+'/'+"model"
6364
if moose.exists(mpath):
6465
moose.delete(mpath)
65-
6666
modelpath1 = moose.Neutral('%s' %(target))
6767
modelpath = moose.Neutral('%s/%s' %(modelpath1.path,"model"))
6868
model = moose.loadModel(filename, modelpath.path,solver)

plugins/kkitUtil.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ def colorCheck(fc_bgcolor,fcbg):
6262
elif fc_bgcolor.isdigit():
6363
""" color is int a map from int to r,g,b triplets from pickled color map file """
6464
tc = int(fc_bgcolor)
65-
tc = 2*tc
66-
pickledColor = colorMap[tc]
65+
tc = tc*2
66+
if tc < len(colorMap):
67+
pickledColor = colorMap[tc]
68+
else:
69+
pickledColor = (255, 0, 0)
6770
fc_bgcolor = QColor(*pickledColor)
6871

6972
elif fc_bgcolor.isalpha() or fc_bgcolor.isalnum():

suds/__init__.py

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
# This program is free software; you can redistribute it and/or modify
2+
# it under the terms of the (LGPL) GNU Lesser General Public License as
3+
# published by the Free Software Foundation; either version 3 of the
4+
# License, or (at your option) any later version.
5+
#
6+
# This program is distributed in the hope that it will be useful,
7+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9+
# GNU Library Lesser General Public License for more details at
10+
# ( http://www.gnu.org/licenses/lgpl.html ).
11+
#
12+
# You should have received a copy of the GNU Lesser General Public License
13+
# along with this program; if not, write to the Free Software
14+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15+
# written by: Jeff Ortel ( [email protected] )
16+
17+
"""
18+
Suds is a lightweight SOAP Python client providing a Web Service proxy.
19+
"""
20+
21+
import sys
22+
23+
24+
#
25+
# Project properties
26+
#
27+
28+
from version import __build__, __version__
29+
30+
31+
#
32+
# Exceptions
33+
#
34+
35+
class MethodNotFound(Exception):
36+
def __init__(self, name):
37+
Exception.__init__(self, u"Method not found: '%s'" % name)
38+
39+
class PortNotFound(Exception):
40+
def __init__(self, name):
41+
Exception.__init__(self, u"Port not found: '%s'" % name)
42+
43+
class ServiceNotFound(Exception):
44+
def __init__(self, name):
45+
Exception.__init__(self, u"Service not found: '%s'" % name)
46+
47+
class TypeNotFound(Exception):
48+
def __init__(self, name):
49+
Exception.__init__(self, u"Type not found: '%s'" % tostr(name))
50+
51+
class BuildError(Exception):
52+
msg = """
53+
An error occurred while building an instance of (%s). As a result the
54+
object you requested could not be constructed. It is recommended that
55+
you construct the type manually using a Suds object. Please open a
56+
ticket with a description of this error.
57+
Reason: %s
58+
"""
59+
def __init__(self, name, exception):
60+
Exception.__init__(self, BuildError.msg % (name, exception))
61+
62+
class SoapHeadersNotPermitted(Exception):
63+
msg = """
64+
Method (%s) was invoked with SOAP headers. The WSDL does not define
65+
SOAP headers for this method. Retry without the soapheaders keyword
66+
argument.
67+
"""
68+
def __init__(self, name):
69+
Exception.__init__(self, self.msg % name)
70+
71+
class WebFault(Exception):
72+
def __init__(self, fault, document):
73+
if hasattr(fault, 'faultstring'):
74+
Exception.__init__(self, u"Server raised fault: '%s'" %
75+
fault.faultstring)
76+
self.fault = fault
77+
self.document = document
78+
79+
80+
#
81+
# Logging
82+
#
83+
84+
class Repr:
85+
def __init__(self, x):
86+
self.x = x
87+
def __str__(self):
88+
return repr(self.x)
89+
90+
91+
#
92+
# Utility
93+
#
94+
95+
class null:
96+
"""
97+
The I{null} object.
98+
Used to pass NULL for optional XML nodes.
99+
"""
100+
pass
101+
102+
def objid(obj):
103+
return obj.__class__.__name__ + ':' + hex(id(obj))
104+
105+
def tostr(object, encoding=None):
106+
""" get a unicode safe string representation of an object """
107+
if isinstance(object, basestring):
108+
if encoding is None:
109+
return object
110+
else:
111+
return object.encode(encoding)
112+
if isinstance(object, tuple):
113+
s = ['(']
114+
for item in object:
115+
if isinstance(item, basestring):
116+
s.append(item)
117+
else:
118+
s.append(tostr(item))
119+
s.append(', ')
120+
s.append(')')
121+
return ''.join(s)
122+
if isinstance(object, list):
123+
s = ['[']
124+
for item in object:
125+
if isinstance(item, basestring):
126+
s.append(item)
127+
else:
128+
s.append(tostr(item))
129+
s.append(', ')
130+
s.append(']')
131+
return ''.join(s)
132+
if isinstance(object, dict):
133+
s = ['{']
134+
for item in object.items():
135+
if isinstance(item[0], basestring):
136+
s.append(item[0])
137+
else:
138+
s.append(tostr(item[0]))
139+
s.append(' = ')
140+
if isinstance(item[1], basestring):
141+
s.append(item[1])
142+
else:
143+
s.append(tostr(item[1]))
144+
s.append(', ')
145+
s.append('}')
146+
return ''.join(s)
147+
try:
148+
return unicode(object)
149+
except:
150+
return str(object)
151+
152+
153+
#
154+
# Python 3 compatibility
155+
#
156+
157+
if sys.version_info < (3, 0):
158+
from cStringIO import StringIO as BytesIO
159+
else:
160+
from io import BytesIO
161+
162+
# Idea from 'http://lucumr.pocoo.org/2011/1/22/forwards-compatible-python'.
163+
class UnicodeMixin(object):
164+
if sys.version_info >= (3, 0):
165+
# For Python 3, __str__() and __unicode__() should be identical.
166+
__str__ = lambda x: x.__unicode__()
167+
else:
168+
__str__ = lambda x: unicode(x).encode('utf-8')
169+
170+
# Used instead of byte literals because they are not supported on Python
171+
# versions prior to 2.6.
172+
def byte_str(s='', encoding='utf-8', input_encoding='utf-8', errors='strict'):
173+
"""
174+
Returns a bytestring version of 's', encoded as specified in 'encoding'.
175+
176+
Accepts str & unicode objects, interpreting non-unicode strings as byte
177+
strings encoded using the given input encoding.
178+
179+
"""
180+
assert isinstance(s, basestring)
181+
if isinstance(s, unicode):
182+
return s.encode(encoding, errors)
183+
if s and encoding != input_encoding:
184+
return s.decode(input_encoding, errors).encode(encoding, errors)
185+
return s
186+
187+
# Class used to represent a byte string. Useful for asserting that correct
188+
# string types are being passed around where needed.
189+
if sys.version_info >= (3, 0):
190+
byte_str_class = bytes
191+
else:
192+
byte_str_class = str

0 commit comments

Comments
 (0)