Source code for schrodinger.application.job_monitor.buttons

import os
import subprocess
import sys

from schrodinger.Qt import QtCore
from schrodinger.Qt import QtGui
from schrodinger.Qt import QtWidgets
from schrodinger.ui.qt.standard_widgets import flat_button

ICON_PATH = ":/job_monitor/icons/"
MENU_OFFSET_FROM_ICON = 25


[docs]class FileExplorerMenuButton(flat_button.FlatButton): """ A vertical three dots button which opens up a menu to copy the path specified to clipboard or open the file explorer of the platform to the path specified. :ivar fileExplorerError: a signal to notify that the file explorer couldn't be opened. The signal is emitted with the message corresponding to the specific error occured. :vartype fileExplorerError: QtCore.pyqtSignal """ fileExplorerError = QtCore.pyqtSignal(str)
[docs] def __init__(self, parent): super().__init__(parent) self.dir_path = None self.setIconPath(ICON_PATH + "menu_icon.png") self.setHoverIconPath(ICON_PATH + "menu_icon-h.png") self.setPressedIconPath(ICON_PATH + "menu_icon-p.png") self.setIconSize_(16, 12) self._createMenu() self.setPopupMode(QtWidgets.QToolButton.InstantPopup)
def _createMenu(self): """ Initialize the context menu with the options. """ menu = QtWidgets.QMenu(self) menu.addAction("Copy Text", self._copyToClipboard) menu.addSeparator() menu.addAction("View in File Browser...", self._openFileExplorer) self.setMenu(menu) def _copyToClipboard(self): """ Copy the directory path as a plaintext into the clipboard. """ clipboard = QtWidgets.QApplication.clipboard() clipboard.setText(self.dir_path) def _openFileExplorer(self): """ Open file explorer to the directory path. """ if not os.path.isdir(self.dir_path): self.fileExplorerError.emit("Directory doesn't exist") return emit_error = 0 if sys.platform.startswith("darwin"): emit_error = subprocess.call(['open', self.dir_path]) elif sys.platform.startswith("win"): try: os.startfile(self.dir_path) except (OSError, AttributeError, TypeError): emit_error = 1 elif sys.platform.startswith("linux"): emit_error = subprocess.call(['xdg-open', self.dir_path]) if emit_error: self.fileExplorerError.emit( "Couldn't find a file explorer to open the directory")
[docs]class BackButton(QtWidgets.QPushButton):
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.setCursor(QtCore.Qt.PointingHandCursor) sp = self.sizePolicy() sp.setHorizontalPolicy(QtWidgets.QSizePolicy.Maximum) self.setSizePolicy(sp) self.setIcon(QtGui.QIcon(ICON_PATH + "back-arrow.png"))