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 PyQt5 import QtCore, QtWidgets
2 import threading
3 from ost import LogError
4 from ost import gui, gfx
5 from ost.io.remote import RemoteLoad, REMOTE_REPOSITORIES
6 import re
7 
8 class RemoteLoader(QtWidgets.QWidget):
9  def __init__(self):
10  QtWidgets.QWidget.__init__(self)
11  self._line = QtWidgets.QLineEdit(self)
12  self._load = QtWidgets.QToolButton(self)
13  self._line.returnPressed.connect(self._DoLoad)
14  self._load.clicked.connect(self._DoLoad)
15  hbox = QtWidgets.QHBoxLayout(self)
16  hbox.addWidget(self._line,1)
17  hbox.addWidget(self._load,0)
18  self.setLayout(hbox)
19  hbox.setContentsMargins(3,3,3,3)
20  hbox.setSpacing(3)
21  self._menu = self._RemoteMenu()
22  self._load.setMenu(self._menu)
23  self._current_repo = 'pdb'
25  self.setFixedHeight(self._load.height())
26  self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
27 
28  def _RemoteMenu(self):
29  menu = QtWidgets.QMenu()
30  action_group = QtWidgets.QActionGroup(menu)
31  for k,v in REMOTE_REPOSITORIES.items():
32  action = menu.addAction(v.name)
33  action.setCheckable(True)
34  if k == 'pdb':
35  action.setChecked(True)
36  action.setData(QtCore.QVariant(k))
37  action_group.addAction(action)
38  menu.triggered.connect(self._ToggleRepo)
39  return menu
40  def _UpdateLoadButton(self, current):
41  name = REMOTE_REPOSITORIES[current].name
42  self._load.setText('load from %s ' % name)
43 
44  def _ToggleRepo(self, action):
45  self._current_repo = str(action.data())
47 
48 
49  def _DoLoad(self):
50  split_ids = []
51  for p in str(self._line.text()).split(','):
52  for k in p.split():
53  if len(k.strip()):
54  split_ids.append(k.strip())
55  self._line.setText('')
56  for split_id in split_ids:
57  try:
58  ent = RemoteLoad(split_id, from_repo=self._current_repo)
59  except Exception as e:
60  LogError(str(e))
61  continue
62  g = gfx.Entity(split_id, ent)
63  try:
64  gfx.Scene().Add(g)
65  except Exception as e:
66  LogError(str(e))
67 
68 remote_loader=RemoteLoader()
69 remote_loader_for_panel=gui.Widget(remote_loader)
70 remote_loader_for_panel.qobject.setSizePolicy(QtWidgets.QSizePolicy.Expanding,
71  QtWidgets.QSizePolicy.Fixed)
72 panels=gui.GostyApp.Instance().perspective.panels
73 panels.AddWidgetToPool("Remote Loader",remote_loader_for_panel)
def RemoteLoad
Definition: remote.py:137
main class for organization and root for the graphical display
Definition: scene.hh:80
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:60
Base class for widgets.
Definition: widget.hh:40