OpenStructure
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
remote.py
Go to the documentation of this file.
1 from PyQt4.QtCore import *
2 from PyQt4.QtGui import *
3 import threading
4 from ost import LogError
5 from ost import gui, gfx
6 from ost.io.remote import RemoteLoad, REMOTE_REPOSITORIES
7 import re
8 
9 class RemoteLoader(QWidget):
10  def __init__(self):
11  QWidget.__init__(self)
12  self._line = QLineEdit(self)
13  self._load = QToolButton(self)
14  self._load.setAttribute(Qt.WA_MacSmallSize)
15  QObject.connect(self._line, SIGNAL('returnPressed()'),
16  self._DoLoad)
17  QObject.connect(self._load, SIGNAL('clicked()'),
18  self._DoLoad)
19  hbox = QHBoxLayout(self)
20  hbox.addWidget(self._line,1)
21  hbox.addWidget(self._load,0)
22  self.setLayout(hbox)
23  hbox.setMargin(3)
24  hbox.setSpacing(3)
25  self._menu = self._RemoteMenu()
26  self._load.setMenu(self._menu)
27  self._current_repo = 'pdb'
29  self.setFixedHeight(self._load.height())
30  self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
31 
32  def _RemoteMenu(self):
33  menu = QMenu()
34  action_group = QActionGroup(menu)
35  for k,v in REMOTE_REPOSITORIES.iteritems():
36  action = menu.addAction(v.name)
37  action.setCheckable(True)
38  if k == 'pdb':
39  action.setChecked(True)
40  action.setData(QVariant(k))
41  action_group.addAction(action)
42  QObject.connect(menu, SIGNAL('triggered(QAction*)'),
43  self._ToggleRepo)
44  return menu
45  def _UpdateLoadButton(self, current):
46  name = REMOTE_REPOSITORIES[current].name
47  self._load.setText('load from %s ' % name)
48 
49  def _ToggleRepo(self, action):
50  self._current_repo = str(action.data().toString())
52 
53 
54  def _DoLoad(self):
55  split_ids = []
56  for p in str(self._line.text()).split(','):
57  for k in p.split():
58  if len(k.strip()):
59  split_ids.append(k.strip())
60  self._line.setText('')
61  for split_id in split_ids:
62  try:
63  ent = RemoteLoad(split_id, from_repo=self._current_repo)
64  except Exception, e:
65  LogError(str(e))
66  continue
67  g = gfx.Entity(split_id, ent)
68  try:
69  gfx.Scene().Add(g)
70  except Exception, e:
71  LogError(str(e))
72 
73 remote_loader=RemoteLoader()
74 remote_loader_for_panel=gui.Widget(remote_loader)
75 remote_loader_for_panel.qobject.setSizePolicy(QSizePolicy.Expanding,
76  QSizePolicy.Fixed)
77 panels=gui.GostyApp.Instance().perspective.panels
78 panels.AddWidgetToPool("Remote Loader",remote_loader_for_panel)
def RemoteLoad
Definition: remote.py:92
main class for organization and root for the graphical display
Definition: scene.hh:81
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:63
Base class for widgets.
Definition: widget.hh:40