OpenStructure
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_line = QtWidgets.QLineEdit(self)
12  self._load_load = QtWidgets.QToolButton(self)
13  self._line_line.returnPressed.connect(self._DoLoad_DoLoad)
14  self._load_load.clicked.connect(self._DoLoad_DoLoad)
15  hbox = QtWidgets.QHBoxLayout(self)
16  hbox.addWidget(self._line_line,1)
17  hbox.addWidget(self._load_load,0)
18  self.setLayout(hbox)
19  hbox.setContentsMargins(3,3,3,3)
20  hbox.setSpacing(3)
21  self._menu_menu = self._RemoteMenu_RemoteMenu()
22  self._load_load.setMenu(self._menu_menu)
23  self._current_repo_current_repo = 'pdb'
24  self._UpdateLoadButton_UpdateLoadButton(self._current_repo_current_repo)
25  self.setFixedHeight(self._load_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_ToggleRepo)
39  return menu
40  def _UpdateLoadButton(self, current):
41  name = REMOTE_REPOSITORIES[current].name
42  self._load_load.setText('load from %s ' % name)
43 
44  def _ToggleRepo(self, action):
45  self._current_repo_current_repo = str(action.data())
46  self._UpdateLoadButton_UpdateLoadButton(self._current_repo_current_repo)
47 
48 
49  def _DoLoad(self):
50  split_ids = []
51  for p in str(self._line_line.text()).split(','):
52  for k in p.split():
53  if len(k.strip()):
54  split_ids.append(k.strip())
55  self._line_line.setText('')
56  for split_id in split_ids:
57  try:
58  ent = RemoteLoad(split_id, from_repo=self._current_repo_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)
graphical rendering of mol::EntityHandle entites
Definition: entity.hh:60
main class for organization and root for the graphical display
Definition: scene.hh:80
Base class for widgets.
Definition: widget.hh:40
def _UpdateLoadButton(self, current)
Definition: remote.py:40
def _ToggleRepo(self, action)
Definition: remote.py:44
def RemoteLoad(id, from_repo='pdb')
Definition: remote.py:137