-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglpopulation.py
144 lines (137 loc) · 5.06 KB
/
glpopulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
##################################
#
# glpopulation.py
# Copyright (C) Louisiana State University, Health Sciences Center
# Written by 2011-2013 Ruben Tikidji-Hamburyan <[email protected]>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
# NON INFRINGEMENT. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###################################
from PyQt4 import QtGui, QtCore
import glneurons
import icons
class odpopulation:
def __init__(self):
self.name = ""
self.id = None
self.pid = -1
class glpopulation:
def __init__(self,parent = None, mainwnd = None, menubar = None, toolbar = None):
self.parent = parent
self.mainwnd = mainwnd
self.object = "population"
insertppl = QtGui.QAction(QtGui.QIcon(':/population.png'), 'Insert/Edit Population', mainwnd)
insertppl.setShortcut('Ctrl+L')
insertppl.setStatusTip('Insert Population')
mainwnd.connect(insertppl, QtCore.SIGNAL('triggered()'), self.insert)
menu = menubar.addMenu('&Population')
menu.addAction(insertppl)
toolbar.addAction(insertppl)
self.ischanged = False
self.poplst = []
self.tmppop = None
def clean(self):
del self.poplst
self.poplst = []
self.tmppop = None
self.ischanged = False
def insert(self):
if not self.parent.isactive : return
item = self.mainwnd.tree.currentItem()
ok = False
edit = QtGui.QInputDialog(self.mainwnd)
edit.setLabelText("Insert New name for population:")
if item.data(1,QtCore.Qt.UserRole) == self.object:
popid, ok = item.data(2,QtCore.Qt.UserRole).toInt()
if not ok:
print "Collapes POP item((("
else:
edit.setTextValue(self.poplst[popid].name)
if ok:
if edit.exec_():
if edit.textValue().length() < 1:
QtGui.QMessageBox.critical(self.mainwnd,"Critical ERROR!"," You should specify the name of population ",QtGui.QMessageBox.Ok,0)
return
self.poplst[popid].name = edit.textValue().toUtf8().data()
item.setText(2,self.poplst[popid].name)
else:
if not edit.exec_(): return
if edit.textValue().length() < 1:
QtGui.QMessageBox.critical(self.mainwnd,"Critical ERROR!"," You should specify the name of population ",QtGui.QMessageBox.Ok,0)
return
newpop = QtGui.QTreeWidgetItem(self.parent.root)
self.parent.root.addChild(newpop)
newpop.setIcon(0,QtGui.QIcon(':/population.png'))
newpop.setText(1,'Population:')
newpop.setText(2,edit.textValue())
newpop.setData(1,QtCore.Qt.UserRole,self.object)
newpop.setData(2,QtCore.Qt.UserRole,len(self.poplst))
pop = odpopulation()
pop.id = newpop
pop.name = edit.textValue().toUtf8().data()
pop.pid = len(self.poplst)
self.poplst.append(pop)
self.ischanged = True
def remove(self,item):
if item.data(1,QtCore.Qt.UserRole) != self.object: return
popid, ok = item.data(2,QtCore.Qt.UserRole).toInt()
if not ok: return
if len(self.poplst) <= popid : return
#del self.poplst[popid].nrn
self.poplst[popid].id = None
self.ischanged = True
def click(self):
self.insert()
def save(self):
result=[]
for pop in self.poplst:
if pop.id == None: continue
result.append("<population name=\"%s\">"%pop.name)
for prn in self.parent.glneurons.save(pid= pop.pid):
result.append("\t"+prn)
result.append("</population>")
self.ischanged = False
return result
def startpoint(self,name,attr={}):
if self.tmppop == None and name == self.object:
self.tmppop = odpopulation()
if attr.get("name",0):
self.tmppop.name=attr["name"]
self.tmppop.id = QtGui.QTreeWidgetItem(self.parent.root)
self.tmppop.id.setIcon(0,QtGui.QIcon(':/population.png'))
self.tmppop.id.setText(1,'Population:')
self.tmppop.id.setText(2,self.tmppop.name)
self.tmppop.id.setData(1,QtCore.Qt.UserRole,self.object)
self.tmppop.id.setData(2,QtCore.Qt.UserRole,len(self.poplst))
elif self.tmppop != None:
self.parent.glneurons.startpoint(name, attr=attr, pid=len(self.poplst) )
else :
QtGui.QMessageBox.critical(self.mainwnd,"Critical ERROR!","Bad or unexpected tag\n <%s> !"%name,QtGui.QMessageBox.Ok,0)
return
def stoppoint(self,name):
if self.tmppop != None and name == self.object:
self.parent.root.addChild(self.tmppop.id)
self.tmppop.pid = len(self.poplst)
self.poplst.append(self.tmppop)
self.tmppop = None
return
elif self.tmppop != None and name != self.object:
self.parent.glneurons.stoppoint(name)
return
QtGui.QMessageBox.critical(self.mainwnd,"Critical ERROR!","Bad or unexpected closed tag\n <%s> !"%name,QtGui.QMessageBox.Ok,0)
def getnames(self):
return [ x.name for x in self.poplst]