00001 from PyQt4.QtCore import * 00002 from PyQt4.QtGui import * 00003 import threading 00004 from ost import LogError 00005 from ost import gui, gfx 00006 from ost.io.remote import RemoteLoad, REMOTE_REPOSITORIES 00007 import re 00008 00009 class RemoteLoader(QWidget): 00010 def __init__(self): 00011 QWidget.__init__(self) 00012 self._line = QLineEdit(self) 00013 self._load = QToolButton(self) 00014 self._load.setAttribute(Qt.WA_MacSmallSize) 00015 QObject.connect(self._line, SIGNAL('returnPressed()'), 00016 self._DoLoad) 00017 QObject.connect(self._load, SIGNAL('clicked()'), 00018 self._DoLoad) 00019 hbox = QHBoxLayout(self) 00020 hbox.addWidget(self._line,1) 00021 hbox.addWidget(self._load,0) 00022 self.setLayout(hbox) 00023 hbox.setMargin(3) 00024 hbox.setSpacing(3) 00025 self._menu = self._RemoteMenu() 00026 self._load.setMenu(self._menu) 00027 self._current_repo = 'pdb' 00028 self._UpdateLoadButton(self._current_repo) 00029 self.setFixedHeight(self._load.height()) 00030 self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) 00031 00032 def _RemoteMenu(self): 00033 menu = QMenu() 00034 action_group = QActionGroup(menu) 00035 for k,v in REMOTE_REPOSITORIES.iteritems(): 00036 action = menu.addAction(v.name) 00037 action.setCheckable(True) 00038 if k == 'pdb': 00039 action.setChecked(True) 00040 action.setData(QVariant(k)) 00041 action_group.addAction(action) 00042 QObject.connect(menu, SIGNAL('triggered(QAction*)'), 00043 self._ToggleRepo) 00044 return menu 00045 def _UpdateLoadButton(self, current): 00046 name = REMOTE_REPOSITORIES[current].name 00047 self._load.setText('load from %s ' % name) 00048 00049 def _ToggleRepo(self, action): 00050 self._current_repo = str(action.data().toString()) 00051 self._UpdateLoadButton(self._current_repo) 00052 00053 00054 def _DoLoad(self): 00055 split_ids = [] 00056 for p in str(self._line.text()).split(','): 00057 for k in p.split(): 00058 if len(k.strip()): 00059 split_ids.append(k.strip()) 00060 self._line.setText('') 00061 for split_id in split_ids: 00062 try: 00063 ent = RemoteLoad(split_id, from_repo=self._current_repo) 00064 except Exception, e: 00065 LogError(str(e)) 00066 continue 00067 g = gfx.Entity(split_id, ent) 00068 try: 00069 gfx.Scene().Add(g) 00070 except Exception, e: 00071 LogError(str(e)) 00072 00073 remote_loader=RemoteLoader() 00074 remote_loader_for_panel=gui.Widget(remote_loader) 00075 remote_loader_for_panel.qobject.setSizePolicy(QSizePolicy.Expanding, 00076 QSizePolicy.Fixed) 00077 panels=gui.GostyApp.Instance().perspective.panels 00078 panels.AddWidgetToPool("Remote Loader",remote_loader_for_panel)