def __parseConfigTuple(self, pluginIndicator): """Checks what plugin provided""" if len(pluginIndicator) != 5: raise Exception("Unexpected format of an indicator " "description. Expected 5 values.") # ID field self.identifier = int(pluginIndicator[0]) # Pixmap/text field try: if isinstance(pluginIndicator[1], QPixmap): self.pixmap = QPixmap(pluginIndicator[1]) elif os.path.exists(pluginIndicator[1]): self.pixmap = QPixmap(pluginIndicator[1]) elif getPixmapLocation(pluginIndicator[1]) is not None: self.pixmap = getPixmap(pluginIndicator[1]) else: self.__setText(pluginIndicator[1]) except: self.__setBrokenIndicator("Failed to get plugin indicator " "pixmap. Indicator id: " + str(self.identifier)) return # Foreground color if pluginIndicator[2] is None: self.foregroundColor = None else: if type(pluginIndicator[2]) == str: self.foregroundColor = buildColor(pluginIndicator[2]) else: self.foregroundColor = QColor(pluginIndicator[2]) # Background color if pluginIndicator[3] is None: self.backgroundColor = None else: if type(pluginIndicator[3]) == str: self.backgroundColor = buildColor(pluginIndicator[3]) else: self.backgroundColor = QColor(pluginIndicator[3]) # Default tooltip if pluginIndicator[4] is None: self.defaultTooltip = "" else: self.defaultTooltip = str(pluginIndicator[4]).strip()
def getPixmap(self, name): """Provides the required pixmap""" try: return self.__cache[name] except KeyError: path = self.__getPath(name) if path is None: pixmap = QPixmap() self.__cache[name] = pixmap return pixmap try: pixmap = QPixmap(path) except: pixmap = QPixmap() self.__cache[name] = pixmap return pixmap
def loadResource(self, resourceType, resourceURL): """Overloaded; by default the remote pixmaps are not loaded""" if resourceType == QTextDocument.ImageResource: url = resourceURL.toString() currentFileName = self._parentWidget.getFileName() if currentFileName: currentDir = os.path.dirname(currentFileName) + os.path.sep if url.startswith(currentDir): url = url.replace(currentDir, '', 1) lowerUrl = url.lower() if url.startswith('plantuml:'): fName = url[9:] if os.path.exists(fName): return QPixmap(fName) # I cannot return my picture. If I do that then the resource # will not be reloaded when the generated diagram is ready return None if url.startswith('cdm-image:'): try: return getPixmap(url[10:]) except Exception as exc: logging.error('Unknown Codimension cache image: ' + url[10:]) return None if lowerUrl.startswith('http:/') or lowerUrl.startswith('https:/'): if not lowerUrl.startswith('http://') and \ not lowerUrl.startswith('https://'): url = url.replace(':/', '://', 1) fName = Settings().webResourceCache.getResource( url, self._parentWidget.getUUID()) if fName is not None: try: return QPixmap(fName) except Exception as exc: logging.error('Cannot use the image from ' + fName + ': ' + str(exc)) return None return TextViewer.loadResource(self, resourceType, resourceURL)
def __createLayout(self): """Creates the dialog layout""" self.resize(320, 120) self.setSizeGripEnabled(True) pluginVersion = getPluginVersionAndPath(self.__pluginHomeDir) pylintVersion, pylintPath = getPylintVersionAndPath() vboxLayout = QVBoxLayout(self) hboxLayout = QHBoxLayout() iconLabel = QLabel() iconLabel.setPixmap(QPixmap(self.__pluginHomeDir + 'pylint.png')) iconLabel.setScaledContents(True) iconLabel.setFixedSize(48, 48) hboxLayout.addWidget(iconLabel) titleLabel = QLabel('<b>Codimension pylint plugin</b>') titleLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) titleLabel.setFixedHeight(48) titleLabel.setAlignment(Qt.AlignCenter) infoLabel = QLabel('<hr><br>More info:' '<ul>' '<li>Plugin<br>' 'Version: ' + pluginVersion + '<br>' 'Location: ' + self.__pluginHomeDir + '</li>' '<li>Pylint<br>' 'Version: ' + pylintVersion + '<br>' + 'Location: ' + pylintPath + '</li>' '</ul><br>') hboxLayout.addWidget(titleLabel) vboxLayout.addLayout(hboxLayout) vboxLayout.addWidget(infoLabel) self.__buttonBox = QDialogButtonBox(self) self.__buttonBox.setOrientation(Qt.Horizontal) self.__buttonBox.setStandardButtons(QDialogButtonBox.Ok) self.__buttonBox.accepted.connect(self.close) self.__buttonBox.rejected.connect(self.close) vboxLayout.addWidget(self.__buttonBox)
def __createLayout(self): """Creates the dialog layout""" self.resize(640, 420) self.setSizeGripEnabled(True) vboxLayout = QVBoxLayout(self) hboxLayout = QHBoxLayout() iconLabel = QLabel() logoPath = os.path.dirname(os.path.abspath(__file__)) + \ os.path.sep + "svn-logo.png" iconLabel.setPixmap(QPixmap(logoPath)) iconLabel.setScaledContents(True) iconLabel.setFixedSize(48, 48) hboxLayout.addWidget(iconLabel) titleLabel = QLabel("Codimension SVN plugin settings") titleLabel.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) titleLabel.setFixedHeight(48) titleLabel.setAlignment(Qt.AlignCenter) hboxLayout.addWidget(titleLabel) vboxLayout.addLayout(hboxLayout) self.__tabWidget = QTabWidget(self) self.__tabWidget.setFocusPolicy(Qt.NoFocus) ideWide = self.__createIDEWide() self.__tabWidget.addTab(ideWide, "IDE Wide") projectSpecific = self.__createProjectSpecific() self.__tabWidget.addTab(projectSpecific, "Project Specific") version = self.__createVersionWidget() self.__tabWidget.addTab(version, "Versions") vboxLayout.addWidget(self.__tabWidget) # Buttons at the bottom self.__buttonBox = QDialogButtonBox(self) self.__buttonBox.setOrientation(Qt.Horizontal) self.__buttonBox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.__buttonBox.accepted.connect(self.userAccept) self.__buttonBox.rejected.connect(self.close) vboxLayout.addWidget(self.__buttonBox)
IND_INCOMPLETE = 11 IND_MISSING = 12 IND_OBSTRUCTED = 13 IND_UNKNOWN = 14 IND_ERROR = 100 pluginHomeDir = os.path.dirname(os.path.abspath(__file__)) + os.path.sep # Integer ID, icon, foreground color or None, # background color or None, default tooltip IND_DESCRIPTION = ( (IND_ADDED, QPixmap(pluginHomeDir + "status-added.png"), None, QColor(255, 255, 160, 255), "Added to SVN repository"), (IND_DELETED, QPixmap(pluginHomeDir + "status-deleted.png"), None, QColor(255, 255, 160, 255), "Deleted from SVN repository"), (IND_IGNORED, QPixmap(pluginHomeDir + "status-ignored.png"), None, QColor(255, 160, 255, 255), "Ignored"), (IND_MERGED, QPixmap(pluginHomeDir + "status-merged.png"), None, QColor(220, 255, 220, 255), "Local modifications received SVN repository modifications"), (IND_MODIFIED_LR,
class VCSIndicator: """Holds an indicator properties""" def __init__(self, configLine): """Config line looks as follows: id:::pathOrString:::ForegroundColor:::BackgroundColor:::Tooltip It comes from a config file or from a plugin""" self.identifier = None self.pixmap = None self.text = None self.backgroundColor = None self.foregroundColor = None self.defaultTooltip = "" self.__parseConfigLine(configLine) def __parseConfigLine(self, configLine): """Fills the members""" self.__parseConfigTuple(configLine) self.__scalePixmap() def __setBrokenIndicator(self, msg): """Sets the indicator to the broken state""" self.text = BROKEN_INDICATOR self.backgroundColor = QColor(0, 255, 255) self.foregroundColor = QColor(255, 0, 0) self.defaultTooltip = msg def __parseConfigTuple(self, pluginIndicator): """Checks what plugin provided""" if len(pluginIndicator) != 5: raise Exception("Unexpected format of an indicator " "description. Expected 5 values.") # ID field self.identifier = int(pluginIndicator[0]) # Pixmap/text field try: if isinstance(pluginIndicator[1], QPixmap): self.pixmap = QPixmap(pluginIndicator[1]) elif os.path.exists(pluginIndicator[1]): self.pixmap = QPixmap(pluginIndicator[1]) elif os.path.exists(getPixmapPath() + pluginIndicator[1]): self.pixmap = QPixmap(getPixmapPath() + pluginIndicator[1]) else: self.__setText(pluginIndicator[1]) except: self.__setBrokenIndicator("Failed to get plugin indicator " "pixmap. Indicator id: " + str(self.identifier)) return # Foreground color if pluginIndicator[2] is None: self.foregroundColor = None else: if type(pluginIndicator[2]) == str: self.foregroundColor = buildColor(pluginIndicator[2]) else: self.foregroundColor = QColor(pluginIndicator[2]) # Background color if pluginIndicator[3] is None: self.backgroundColor = None else: if type(pluginIndicator[3]) == str: self.backgroundColor = buildColor(pluginIndicator[3]) else: self.backgroundColor = QColor(pluginIndicator[3]) # Default tooltip if pluginIndicator[4] is None: self.defaultTooltip = "" else: self.defaultTooltip = str(pluginIndicator[4]).strip() def __setText(self, value): """Sets the indicator text""" if len(value) > MAX_TEXT_INDICATOR_LENGTH: self.text = value[:MAX_TEXT_INDICATOR_LENGTH] else: self.text = value self.text = self.text.strip() def __scalePixmap(self): """Scales the pixmap if necessary""" if self.pixmap is None: return if self.pixmap.width() > MAX_PIXMAP_INDICATOR_WIDTH or \ self.pixmap.height() > MAX_PIXMAP_INDICATOR_HEIGHT: maxSize = QSize(MAX_PIXMAP_INDICATOR_WIDTH, MAX_PIXMAP_INDICATOR_HEIGHT) self.pixmap = self.pixmap.scaled(maxSize, Qt.KeepAspectRatio) def isPixmap(self): """True if it is a pixmap label""" return self.pixmap is not None def draw(self, label): """Draws the indicator as members tell. label is QLabel""" label.setPalette(QLabel().palette()) if self.isPixmap(): label.setAutoFillBackground(False) label.setFrameStyle(QLabel().frameStyle()) label.setPixmap(self.pixmap) else: label.setFrameStyle(QFrame.StyledPanel) label.setAutoFillBackground(True) palette = label.palette() if self.backgroundColor is not None: palette.setColor(QPalette.Background, self.backgroundColor) if self.foregroundColor is not None: palette.setColor(QPalette.Foreground, self.foregroundColor) label.setPalette(palette) label.setText(self.text)