1 """Components for the top level of the QUB Express.
2
3 Copyright 2008-2014 Research Foundation State University of New York
4 This file is part of QUB Express.
5
6 QUB Express is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 QUB Express is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License,
17 named LICENSE.txt, in the QUB Express program directory. If not, see
18 <http://www.gnu.org/licenses/>.
19
20
21 """
22
23
24 import os
25 import traceback
26
27 import gtk
28 import gobject
29 import numpy
30 import random
31 import urllib2
32
33 import qubx.faces
34 import qubx.GTK
35 import qubx.model
36 import qubx.modelGTK
37 import qubx.notebook
38 import qubx.notebookGTK
39 import qubx.pyenv
40 import qubx.pyenvGTK
41 import qubx.settings
42 import qubx.settingsGTK
43 import qubx.table
44 import qubx.tableGTK
45 import qubx.toolspace
46 import qubx.trials
47
48 from itertools import izip, count
49 from math import *
50 from gtk import gdk
51 from qubx.accept import *
52 from qubx.GTK import pack_item, pack_space, pack_hsep, pack_vsep, pack_label, pack_button, pack_check, pack_radio, pack_scrolled, build_menuitem
53 from qubx.toolspace import ColorInfo
54 from qubx.util_types import *
55
56
57 COLOR_MODEL_FILE_MENU = ('QubX.model.file.menu', (.05, .05, .75, 1))
58 ColorInfo[COLOR_MODEL_FILE_MENU[0]].label = 'Model file menu triangle'
59 COLOR_FILES = ('QubX.files', (0,0,0,.75))
60 ColorInfo[COLOR_FILES[0]].label = 'Model files menu background'
61
63 """Panel showing one of possibly many open model files.
64
65 @ivar views: list of L{qubx.modelGTK.QubModelView}
66 """
67
68 __explore_featured = ['nbPicturePrefs', 'mnuExt', 'subExtMenu', 'menubar', 'itemFile', 'itemNB', 'balance_all_loops']
69
70 - def __init__(self, tables, global_name=""):
71 qubx.faces.FilesFace.__init__(self, ' Models', qubx.model.QubModels(),
72 lambda table:qubx.modelGTK.QubModelView(table,qubx.faces.FILEMENU_WIDTH), qubx.faces.FILEMENU_WIDTH,
73 popup_color=COLOR_MODEL_FILE_MENU, global_name=global_name)
74 self.layFiles.cBG = COLOR_FILES
75 self.__ref = Reffer()
76 self.nbPicturePrefs = qubx.modelGTK.ModelNbPicturePrefs(parent=None, global_name='QubX.Models.nbPicturePrefs')
77 self.tables = tables
78 self.tables.add_table(self.table)
79 hdr = qubx.toolspace.Button_Popup_PNG(self.mnuFile, os.path.join(qubx.global_namespace.app_path, 'icons', 'folder.png'), "File menu")
80 hdr.show()
81 tables.find_view(' Models').set_index_widget(hdr, hdr.do_popup)
82 self.mnuFile.insert(build_menuitem('Open Trials...', self.__ref(lambda item: qubx.global_namespace.QubX.Trials.open())), 3)
83 self.OnSwitch += self.__ref(self.__onSwitch)
84 self.OnSave += self.__ref(self.__onSave)
85 self.OnClosing += self.__ref(self.__onClosing)
86 qubx.notebook.Notebook.register_auto('Model_Open.Picture', 'Model picture, on open/choose')
87 qubx.notebook.Notebook.register_auto('Model_Open.PictureNO', 'Model picture, no overlays, on open/choose')
88 qubx.notebook.Notebook.register_auto('Model_Save.Picture', 'Model picture, on save')
89 qubx.notebook.Notebook.register_auto('Model_Save.PictureNO', 'Model picture, no overlays, on save')
90 self.mnuExt = gtk.Menu()
91 self.subExtMenu = qubx.toolspace.SubLayer_MenuLines(self.mnuExt, 'Modeling Tools', self.__ref(self.__onPopupExt),
92 w=qubx.faces.TOOLTOGGLE_WIDTH_EM, h=qubx.faces.TOOLTOGGLE_WIDTH_EM)
93 self.menubar = gtk.MenuBar()
94 self.itemFile = gtk.MenuItem('File')
95 self.itemFile.connect('activate', bind(self.on_popup_file))
96 self.itemFile.show()
97 self.menubar.append(self.itemFile)
98 self.menubar.append(build_menuitem('Tools', self.__ref(bind(self.__onPopupExt)), submenu=self.mnuExt))
99 self.itemNB = gtk.MenuItem('Notebook')
100 self.itemNB.connect('activate', self.__onPopupNB)
101 self.itemNB.show()
102 self.menubar.append(self.itemNB)
103
104 self.table.insert(0, qubx.model.QubModel())
105 self.views[0].file.path = '<Trials>'
106 self.table[0, 'Group'] = 0
107 self.tab_sublayers.append(self.subExtMenu)
108
109 gobject.timeout_add(12000, self.__run_down)
110
132 - def open(self, path=None):
146 return (self._file and self._file.path and self._file.changed) or False
148 return (self.index and self._file and self._file.path and self._file.changed) or False
149 - def save(self, path=None):
153 """Overridden to keep Trials open"""
154 self._no_to_all = False
155 for i in reversed(xrange(1, self.table.size)):
156 self.index = i
157 if not self.close_one():
158 return False
159 return True
175 if view != self.page0:
176 self.tables.add_table(file.states, file.undoStack,
177 qubx.tableGTK.TableViewCtrls(file.states, file.undoStack, qubx.tableGTK.TableViewCtrls.PLOT))
178 self.tables.add_table(file.classes, file.undoStack)
179 self.tables.add_table(file.rates, file.undoStack,
180 qubx.tableGTK.TableViewCtrls(file.rates, file.undoStack, 'k = k0 * Ligand * e^(k1*Voltage + k2*Pressure)'))
181 self.tables.add_table(file.constraints_kin, file.undoStack,
182 qubx.tableGTK.TableViewCtrls(file.constraints_kin, file.undoStack, qubx.tableGTK.TableViewCtrls.ADD, qubx.tableGTK.TableViewCtrls.REMOVE, 'or right-click a rate to edit constraints interactively.', view.chkBalanceLoops, 'Balance all loops'))
183 view.chkBalanceLoops.show()
184 file.OnChangeChanged += self.__ref(self.__onChangeChanged)
185 file.OnChangePath += self.__ref(self.__onChangePath)
186 self.itemFile.set_submenu(view.mnuFile)
187 self.itemNB.set_submenu(view.subNotebook.popup)
188 if self.index:
189 self.itemClose.show()
190 self.itemCloseAll.show()
191 else:
192 self.itemClose.hide()
193 self.itemCloseAll.hide()
205 return [('QuB model files', '.qmf'),
206 ('QuB model JSON', '.qmj'),
207 ('QuB legacy mdl files', '.mdl')]
209 return [('QuB model files', '.qmf'),
210 ('QuB model JSON', '.qmj')]
229