示例#1
0
def _InitRuleBasedProcessor():
    compound_lib_path = os.path.join(ost.GetSharedDataPath(),
                                     'compounds.chemlib')
    if os.path.exists(compound_lib_path):
        conop_inst = conop.Conopology.Instance()
        compound_lib = conop.CompoundLib.Load(compound_lib_path)
        conop_inst.SetDefaultLib(compound_lib)
        io.profiles['DEFAULT'].processor = conop.RuleBasedProcessor(
            compound_lib)
class InspectorWidget(ToolBarOptionsWidget):
    ICONS_PATH = os.path.join(ost.GetSharedDataPath(), "scene", "icons/")

    def __init__(self, parent=None):
        ToolBarOptionsWidget.__init__(self, parent)
        app = gui.GostyApp.Instance()
        options = [[
            InspectorWidget.ICONS_PATH + "render_icon.png",
            RenderOptionsWidget(self), None
        ],
                   [
                       InspectorWidget.ICONS_PATH + "color_icon.png",
                       ColorOptionsWidget(self), None
                   ],
                   [
                       InspectorWidget.ICONS_PATH + "preset_icon.png",
                       AdditionalSettingsWidget(self),
                       "Additional Node Settings"
                   ],
                   [
                       InspectorWidget.ICONS_PATH + "tool_icon.png",
                       app.tool_options_win.qobject, "Tool Options"
                   ]]
        for o in options:
            ToolBarOptionsWidget.AddWidget(self, o[0], o[1], o[2])

        self.obs = SceneObserverImpl()
        self.obs.AttachObserver(self)
        ost.scene.AttachObserver(self.obs)
        app.scene_win.qobject.ActiveNodesChanged.connect(
            self.ActiveNodesChanged)

        self.setMinimumSize(250, 215)

    #ToolBarOptionsWidget Method
    def OnComboChange(self, item):
        self.DoResize()

    #Observer Methods
    def NodeRemoved(self, node):
        SelHelper().Update()
        ToolBarOptionsWidget.Update(self)

    def RenderModeChanged(self, node):
        SelHelper().Update()
        ToolBarOptionsWidget.Update(self)

    def NodeChanged(self, node):
        SelHelper().Update()
        ToolBarOptionsWidget.Update(self)

    def ActiveNodesChanged(self):
        SelHelper().Update()
        ToolBarOptionsWidget.Update(self)
示例#3
0
class GradientPresetWidget(QtWidgets.QWidget):
    ICONS_DIR = os.path.join(ost.GetSharedDataPath(), "gui", "icons/")

    gradientSelected = QtCore.pyqtSignal(object, name="gradientSelected")

    def __init__(self, gradient_edit, parent=None):
        QtWidgets.QWidget.__init__(self, parent)

        #Title
        self.text_ = "Gradient Presets"

        #Refrences
        self.gradient_edit_ = gradient_edit

        #Create Ui elements
        self.list_view_ = QtWidgets.QListView()

        #Create Model
        self.list_model_ = GradientListModel(self)
        self.list_view_.setModel(self.list_model_)
        self.list_view_.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)

        preset_label = QtWidgets.QLabel(self.text_)
        font = preset_label.font()
        font.setBold(True)

        self.add_action = QtWidgets.QAction("+", self)
        self.add_action.setIcon(
            QtGui.QIcon(GradientPresetWidget.ICONS_DIR + "add_icon.png"))

        self.add_action.triggered.connect(self.Add)

        self.add_button_ = QtWidgets.QToolButton(self)
        self.add_button_.setIconSize(QtCore.QSize(20, 20))
        self.add_button_.setDefaultAction(self.add_action)

        grid = QtWidgets.QGridLayout()
        grid.setContentsMargins(0, 5, 0, 0)
        grid.addWidget(preset_label, 0, 0, 1, 1)
        qhbox = QtWidgets.QHBoxLayout()
        grid.addWidget(self.list_view_, 1, 0, 3, 3)
        grid.addWidget(self.add_button_, 4, 0, 1, 1)
        self.setLayout(grid)

        self.list_view_.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.list_view_.customContextMenuRequested.connect(
            self.contextMenuEvent)
        self.CreateImmutableContextMenu()
        self.CreateContextMenu()

        self.list_view_.doubleClicked.connect(self.Load)

    def CreateImmutableContextMenu(self):
        self.immucontextMenu_ = QtWidgets.QMenu("Context menu", self)
        self.load_ = QtWidgets.QAction("Load", self.list_view_)
        self.immucontextMenu_.addAction(self.load_)
        #Connect Signal with Slot
        self.load_.triggered.connect(self.LoadCurrentIndex)

    def CreateContextMenu(self):
        self.contextMenu_ = QtWidgets.QMenu("Context menu", self)
        self.remove_ = QtWidgets.QAction("Remove", self.list_view_)
        self.rename_ = QtWidgets.QAction("Rename", self.list_view_)
        self.contextMenu_.addAction(self.load_)
        self.contextMenu_.addAction(self.remove_)
        self.contextMenu_.addAction(self.rename_)
        #Connect Signals with Slots
        self.remove_.triggered.connect(self.Remove)
        self.rename_.triggered.connect(self.Rename)

    def contextMenuEvent(self, pos):
        #ContextMenu
        index = self.list_view_.indexAt(pos)
        if index.isValid():
            if self.list_model_.IsEditable(index.row()):
                self.contextMenu_.popup(QtWidgets.QCursor.pos())
            else:
                self.immucontextMenu_.popup(QtWidgets.QCursor.pos())

    def Add(self):
        if (self.list_view_.currentIndex().isValid()):
            self.list_view_.closePersistentEditor(
                self.list_view_.currentIndex())
        row = self.list_model_.GetLastRow()
        if self.list_model_.AddItem(datetime.now().isoformat(' '),
                                    self.gradient_edit_.GetGradient(), row,
                                    True, True):
            index = self.list_model_.index(row)
            self.list_view_.setCurrentIndex(index)
            self.Rename()
        else:
            QtWidgets.QMessageBox.information(
                self, "Gradient not added", "The gradient could not be added!")

    def Remove(self):
        if (self.list_view_.currentIndex().isValid()):
            ret = QtWidgets.QMessageBox.warning(
                self, "Delete Gradient", "Delete Gradient?",
                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
            if ret == QtWidgets.QMessageBox.Yes:
                self.list_model_.RemoveItem(
                    self.list_view_.currentIndex().row())

    def LoadCurrentIndex(self):
        if (self.list_view_.currentIndex().isValid()):
            self.Load(self.list_view_.currentIndex())

    def Load(self, index):
        if (index.isValid()):
            self.gradientSelected.emit(self.list_model_.GetGradient(index))

    def Rename(self):
        if (self.list_view_.currentIndex().isValid()):
            self.list_view_.edit(self.list_view_.currentIndex())

    def GetText(self):
        return self.text_
class PresetListModel(QtCore.QAbstractListModel):

    IMMUTABLE_PRESET_PATH = os.path.join(ost.GetSharedDataPath(), "scene",
                                         "presets.xml")
    MUTABLE_PRESET_PATH = "user_presets.xml"

    dataChanged = QtCore.pyqtSignal(int, int, name="dataChanged")

    def __init__(self, parent=None, *args):
        QtCore.QAbstractListModel.__init__(self, parent, *args)

        self.data_ = list()

        #Info Handler

        self.immutable_infoh_ = ImmutablePresetInfoHandler(
            PresetListModel.IMMUTABLE_PRESET_PATH)
        data_loc = str(
            QtCore.QStandardPaths.writableLocation(
                QtCore.QStandardPaths.DataLocation))

        mutable_path = os.path.join(str(data_loc), 'config',
                                    PresetListModel.MUTABLE_PRESET_PATH)
        qdir = QtCore.QDir(data_loc)
        if not qdir.exists():
            qdir.mkpath("config")
        self.infoh_ = PresetInfoHandler(mutable_path)
        self.LoadPresetsFromInfo()

    def AddItem(self, preset, row, editable, save):
        if self.NameIsValid(preset.GetName()):
            icon = self.GetIcon(preset)
            self.insertRow(row, QtCore.QModelIndex())
            self.data_[row] = [preset, icon, editable]
            model_index = self.createIndex(row, 0)
            index = self.index(row)
            end_index = self.createIndex(self.rowCount(), 0)
            if save:
                self.AddPresetToInfo(preset)
            self.dataChanged.emit(model_index, end_index)
            return True
        return False

    def IsEditable(self, row):
        return self.data_[row][2]

    def RemoveItem(self, row):
        if self.IsEditable(row):
            name = self.data_[row][0].GetName()
            self.removeRow(row, QtCore.QModelIndex())
            model_index = self.createIndex(row, 0)
            self.infoh_.RemovePreset(name)
            self.dataChanged.emit(model_index, model_index)
            return True
        return False

    def AddPresetToInfo(self, preset):
        self.infoh_.StorePreset(preset)

    def LoadPresetsFromInfo(self):
        if self.immutable_infoh_:
            presets = self.immutable_infoh_.GetPresets()
            for k, v in presets.items():
                self.AddItem(v, self.GetLastRow(), False, False)

        presets = self.infoh_.GetPresets()
        for k, v in presets.items():
            self.AddItem(v, self.GetLastRow(), True, False)

    def GetPreset(self, model_index):
        if model_index.isValid():
            return self.data_[model_index.row()][0]

    def GetLastRow(self):
        return self.rowCount()

    #Helper
    def GetIcon(self, preset):
        pixmap = QtGui.QPixmap(64, 64)
        pixmap.fill(QtCore.Qt.transparent)
        return QtGui.QIcon(pixmap)

    def NameIsValid(self, string):
        if len(string) == 0:
            return False
        for values in self.data_:
            if string == values[0].GetName():
                return False
        return True

    #Overwritten Methods
    def rowCount(self, parent=QtCore.QModelIndex()):
        return len(self.data_)

    def data(self, index, role):
        if index.isValid() and index.row() < self.rowCount():
            data = self.data_[index.row()]
            if role == QtCore.Qt.DisplayRole:
                return QtCore.QVariant(data[0].GetName())
            elif role == QtCore.Qt.DecorationRole:
                return QtCore.QVariant(data[1])
        return QtCore.QVariant()

    def setData(self, index, value, role):
        if index.isValid():
            row = index.row()
            if not self.data_[row]:
                self.data_[row] = list()
            if role == QtCore.Qt.EditRole and self.NameIsValid(
                    value.toString()):
                old_name = str(self.data_[row][0].GetName())
                new_name = value.toString()
                self.data_[row][0].SetName(str(new_name))
                self.infoh_.RenamePreset(old_name, str(new_name))
                self.dataChanged.emit(index, index)
                return True
            elif role == QtCore.Qt.DisplayRole:
                self.data_[row][0].SetName(value.toString())
            elif role == QtCore.Qt.DecorationRole:
                self.dat_[row][1] = value.toPyObject()
        return False

    def flags(self, index):
        if index.isValid():
            flags = QtCore.QAbstractItemModel.flags(self, index)
            if self.IsEditable(index.row()):
                return flags | QtCore.Qt.ItemIsEditable
            else:
                return flags
        return QtCore.Qt.ItemIsEnabled

    def insertRow(self, position, index):
        self.beginInsertRows(index, position, position)
        self.data_.insert(position, list())
        self.endInsertRows()
        return True

    def removeRow(self, position, index):
        self.beginRemoveRows(index, position, position)
        del self.data_[position]
        self.endRemoveRows()
        return True
示例#5
0
def LoadCHARMMForcefield():
    return Forcefield.Load(
        os.path.join(ost.GetSharedDataPath(), 'forcefields', 'CHARMM27.dat'))
示例#6
0
def LoadAMBERForcefield():
    return Forcefield.Load(
        os.path.join(ost.GetSharedDataPath(), 'forcefields', 'AMBER03.dat'))
示例#7
0
from PyQt5 import QtCore, QtGui, QtWidgets

import os
import ost
from ost import gui

LOGO_PATH = os.path.join(ost.GetSharedDataPath(), "gui", "images",
                         "logo-small.png")

SPLASH_TEXT = """"Welcome to <b>Openstructure</b>!<br/><br/>
You are running version %s<br /><br />If you are new to OpenStructure, we 
invite you to run the demos from the examples directory. Scripts can be 
displayed by right clicking on the file and selecting 'Show source'.<br/><br/>
Feel free visit our website at:<br /> 
<a href='https://www.openstructure.org'>https://www.openstructure.org</a>
""" % ost.VERSION


class SplashDialog(QtWidgets.QDialog):
    def __init__(self, parent=None):
        QtWidgets.QDialog.__init__(self, parent)
        layout = QtWidgets.QHBoxLayout(self)
        self.setLayout(layout)
        imageLabel = QtWidgets.QLabel()
        self.pix_map = QtGui.QPixmap(LOGO_PATH)
        imageLabel.setPixmap(self.pix_map)
        layout.addWidget(imageLabel)
        self.label = QtWidgets.QTextBrowser()
        self.label.setReadOnly(True)
        self.label.setOpenExternalLinks(True)
        self.label.setHtml(SPLASH_TEXT)
示例#8
0
class PresetWidget(QtWidgets.QWidget):
    PRESET_XML_FILE = os.path.join(ost.GetSharedDataPath(), "scene",
                                   "presets.xml")
    ICONS_DIR = os.path.join(ost.GetSharedDataPath(), "gui", "icons/")

    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)

        self.text_ = "Presets"

        #Create Ui elements
        self.list_view_ = QtWidgets.QListView()

        #Create Model
        self.list_model_ = PresetListModel(self)
        self.list_view_.setModel(self.list_model_)
        self.list_view_.setEditTriggers(
            QtWidgets.QAbstractItemView.NoEditTriggers)

        self.add_action = QtWidgets.QAction("+", self)
        self.add_action.setIcon(
            QtGui.QIcon(PresetWidget.ICONS_DIR + "add_icon.png"))

        self.add_action.triggered.connect(self.Add)

        self.add_button_ = QtWidgets.QToolButton(self)
        self.add_button_.setIconSize(QtCore.QSize(20, 20))
        self.add_button_.setDefaultAction(self.add_action)

        self.preset_editor_ = PresetEditor(self)

        grid = QtWidgets.QGridLayout()
        grid.setContentsMargins(0, 5, 0, 0)
        grid.addWidget(self.list_view_, 0, 0, 3, 3)
        grid.addWidget(self.add_button_, 3, 0, 1, 1)
        self.setLayout(grid)

        self.list_view_.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.list_view_.customContextMenuRequested.connect(
            self.contextMenuEvent)
        self.CreateImmutableContextMenu()
        self.CreateContextMenu()

        self.list_view_.doubleClicked.connect(self.Load)

        self.setMinimumSize(250, 200)

    def CreateImmutableContextMenu(self):
        self.immucontext_menu_ = QtWidgets.QMenu("Context menu", self)
        self.load_ = QtWidgets.QAction("Load", self.list_view_)
        self.immucontext_menu_.addAction(self.load_)
        #Connect Signal with Slot
        self.load_.triggered.connect(self.LoadCurrentIndex)

    def CreateContextMenu(self):
        self.context_menu_ = QtWidgets.QMenu("Context menu", self)
        self.remove_ = QtWidgets.QAction("Remove", self.list_view_)
        self.rename_ = QtWidgets.QAction("Rename", self.list_view_)
        self.edit_ = QtWidgets.QAction("Edit", self.list_view_)
        self.context_menu_.addAction(self.load_)
        self.context_menu_.addAction(self.remove_)
        self.context_menu_.addAction(self.rename_)
        self.context_menu_.addAction(self.edit_)
        #Connect Signals with Slots
        self.remove_.triggered.connect(self.Remove)
        self.rename_.triggered.connect(self.Rename)
        self.edit_.triggered.connect(self.Edit)

    def contextMenuEvent(self, pos):
        #ContextMenu
        index = self.list_view_.indexAt(pos)
        if index.isValid():
            if self.list_model_.IsEditable(index.row()):
                self.context_menu_.popup(QtWidgets.QCursor.pos())
            else:
                self.immucontext_menu_.popup(QtWidgets.QCursor.pos())

    def Add(self):
        row = self.list_model_.GetLastRow()
        preset = Preset(datetime.now().isoformat(' '))
        self.preset_editor_.SetPreset(preset)
        if (self.preset_editor_.exec_()):
            if self.list_model_.AddItem(preset, row, True, True):
                index = self.list_model_.index(row)
                self.list_view_.setCurrentIndex(index)
                self.Rename()

    def Remove(self):
        if (self.list_view_.currentIndex().isValid()):
            ret = QtWidgets.QMessageBox.warning(
                self, "Delete Preset", "Delete Preset?",
                QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
            if ret == QtWidgets.QMessageBox.Yes:
                self.list_model_.RemoveItem(
                    self.list_view_.currentIndex().row())

    def Edit(self):
        if (self.list_view_.currentIndex().isValid()):
            preset = self.list_model_.GetPreset(self.list_view_.currentIndex())
            self.preset_editor_.SetPreset(preset)
            if (self.preset_editor_.exec_()):
                row = self.list_view_.currentIndex().row()
                self.list_model_.RemoveItem(row)
                self.list_model_.AddItem(preset, row, True, True)

    def LoadCurrentIndex(self):
        if (self.list_view_.currentIndex().isValid()):
            self.Load(self.list_view_.currentIndex())

    def Load(self, index):
        if (index.isValid()):
            scene_selection = gui.SceneSelection.Instance()
            preset = self.list_model_.GetPreset(index)
            for i in range(0, scene_selection.GetActiveNodeCount()):
                node = scene_selection.GetActiveNode(i)
                if isinstance(node, gfx.Entity):
                    node.CleanColorOps()
                    preset.ApplyOn(node)

    def ChangeColor(self, node):
        self.LoadCurrentIndex()

    def Update(self):
        self.setEnabled(True)
        if SelHelper().CheckAllFlags(SelHelper.NO_SELECTION):
            self.setEnabled(False)
            return

        if SelHelper().CheckNotFlags(SelHelper.HAS_ENTITY
                                     | SelHelper.IS_ONE_TYPE):
            self.setEnabled(False)
            return

    def Rename(self):
        if (self.list_view_.currentIndex().isValid()):
            self.list_view_.edit(self.list_view_.currentIndex())

    def GetText(self):
        return self.text_
class GradientListModel(QtCore.QAbstractListModel):
  
  IMMUTABLE_GRADIENTS_PATH = os.path.join(ost.GetSharedDataPath(),"scene", 
                                          "gradients.xml")
  MUTABLE_GRADIENTS_PATH = "user_gradients.xml"

  dataChanged = QtCore.pyqtSignal(int, int, name="dataChanged")
  
  def __init__(self, parent=None, *args): 
    QtCore.QAbstractListModel.__init__(self, parent, *args)
    
    self.data_ = list()
    
    #Info Handler
    self.immutable_infoh_ = ImmutableGradientInfoHandler(GradientListModel.IMMUTABLE_GRADIENTS_PATH)
    self.infoh_ = GradientInfoHandler(GradientListModel.MUTABLE_GRADIENTS_PATH)
    self.LoadGradientFromInfo()
    
  def AddItem(self, name, gradient, row, editable, save):
    if self.NameIsValid(name):
      icon = self.GetIcon(gradient)
      self.insertRow(row, QtCore.QModelIndex())
      self.data_[row] = [name, gradient, icon, editable]
      model_index = self.createIndex(row,0)
      index = self.index(row)
      end_index = self.createIndex(self.rowCount(),0)
      if save:
        self.AddGradientToInfo(gradient,name)
      self.dataChanged.emit(model_index, end_index)
      return True
    return False
  
  def IsEditable(self, row):
    return self.data_[row][3]
  
  def RemoveItem(self, row):
    if self.IsEditable(row):
      name = self.data_[row][0]
      self.removeRow(row, QtCore.QModelIndex())
      model_index = self.createIndex(row,0)
      self.infoh_.RemoveGradient(name)
      self.dataChanged.emit(model_index, model_index)
      return True
    return False

  def AddGradientToInfo(self,gradient,name):
    self.infoh_.StoreQGradient(gradient,str(name))
    
  def LoadGradientFromInfo(self):
    if self.immutable_infoh_:
      qgradients = self.immutable_infoh_.GetQGradients()
      for k, v in qgradients.items():
        self.AddItem(k, v, self.GetLastRow(), False, False)
    
    qgradients = self.infoh_.GetQGradients()
    for k, v in qgradients.items():
      self.AddItem(k, v, self.GetLastRow(), True, False)

  def GetGradient(self, model_index):
    if model_index.isValid():
      return self.data_[model_index.row()][1]
  
  def GetLastRow(self):
    return self.rowCount()
  
  #Helper
  def GetIcon(self, gradient):
    pixmap = QtGui.QPixmap(64, 64)
    pixmap.fill(QtCore.Qt.transparent)
    painter = QtGui.QPainter()
    if painter.begin(pixmap):
      gradient.setStart(QtCore.QPointF(0, 0))
      gradient.setFinalStop(QtCore.QPointF(64, 0))
      brush = QtGui.QBrush(gradient)
      painter.setBrush(brush)
      painter.drawRect(0, 0, 64, 64)
      painter.end()
    
    return QtGui.QIcon(pixmap)
  
  def NameIsValid(self, string):
    if len(string)==0:
      return False
    for values in self.data_:
      if string == values[0]:
        return False
    return True
  
  #Overwritten Methods  
  def rowCount(self, parent=QtCore.QModelIndex()): 
    return len(self.data_) 
 
  def data(self, index, role):
    if index.isValid() and index.row()< self.rowCount():
      data = self.data_[index.row()]
      if role == QtCore.Qt.DisplayRole:
        return QtCore.QVariant(data[0])
      elif role == QtCore.Qt.DecorationRole:
        return QtCore.QVariant(data[2])
    return QtCore.QVariant()

  def setData(self, index, value, role):
    if index.isValid():
      row = index.row()
      if not self.data_[row]:
        self.data_[row] = list()
      if role == QtCore.Qt.EditRole and self.NameIsValid(value.toString()):
        old_name = str(self.data_[row][0])
        new_name = value.toString()
        self.data_[row][0] = new_name
        self.infoh_.RenameGradient(old_name,str(new_name))
        self.dataChanged.emit(index, index)
        return True
      elif role == QtCore.Qt.DisplayRole:
        self.data_[row][0] = value.toString()
      elif role == QtCore.Qt.DecorationRole:
        self.data_[row][2] = value.toPyObject()
    return False

  def flags(self, index):
    if index.isValid():
      flags = QtCore.QAbstractItemModel.flags(self,index)
      if self.IsEditable(index.row()):
        return flags | QtCore.Qt.ItemIsEditable
      else:
        return flags
    return QtCore.Qt.ItemIsEnabled
  
  def insertRow(self, position, index):
    self.beginInsertRows(index, position, position)
    self.data_.insert(position,list())
    self.endInsertRows()
    return True
  
  def removeRow(self, position, index):
    self.beginRemoveRows(index, position, position)
    del self.data_[position]
    self.endRemoveRows()
    return True