def initializeMenu(self): self.menu_widget = DynamicMenu(self) self.menu_widget.setGeometry(QtCore.QRect(10, 10, 320, 190)) self.menu_widget.setVisible(True) self.connect(self.menu_widget, QtCore.SIGNAL('showWidget'), self.showWidgetCallback) self.menuButton = QSvgWidget("icons/three-bars.svg", self) self.menuButton.setGeometry(QtCore.QRect(10, 200, 30, 35)) pressableSender(self.menuButton).connect(self.menuButtonPressed) self.menuButton.setVisible(False) self.onButtonIndicator = ButtonIndicator(self, 30, "green") self.onButtonIndicator.setGeometry(QtCore.QRect(50, 202, 30, 30)) self.onButtonIndicator.setVisible(False) self.contextButtonIndicator = ButtonIndicator(self, 30, "blue") self.contextButtonIndicator.setGeometry(QtCore.QRect(80, 202, 30, 30)) self.contextButtonIndicator.setVisible(False) self.offButtonIndicator = ButtonIndicator(self, 30, "red") self.offButtonIndicator.setGeometry(QtCore.QRect(110, 202, 30, 30)) self.offButtonIndicator.setVisible(False) font = QtGui.QFont() font.setPointSize(15) self.statusDisplay = QtGui.QLabel(self) self.statusDisplay.setGeometry(QtCore.QRect(150, 200, 140, 35)) self.statusDisplay.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.statusDisplay.setStyleSheet('color: #eaf736') self.statusDisplay.setFont(font) pressableSender(self.statusDisplay).connect(self.audioStatusPressed)
def updateShape(self): ''' @if English @endif @if Slovak Aktualizácia zobrazenia komponentu. Uprava shape komponentu po jeho vytvoreni, zmene parametrov alebo vlastnosti. V derivovanych komponentoch moze obsahovat obnovenie farebnej schemy objektu napr. po odstraneni chyby, ktora bola opticky indikovana odlisnym (cervenym) sfarbenim objektu. @endif ''' # nacitanie grafickeho obrazku shapeImage shapeFile = self.path + '/img/' + self.shapeImage if os.path.isfile(shapeFile) is True: if shapeFile.endswith('.svg') is True: self.shapeSvg = QSvgWidget(shapeFile) self.shapeSvg.setAttribute(Qt.WA_NoSystemBackground) if shapeFile.endswith('.png') is True: self.shapePng = QPixmap(shapeFile)
def fill(self): # Vispa # icon # Version # Release date os.path.getmtime(filename) # website url # license self.setLayout(QVBoxLayout()) if "vispa" in self._application.windowTitle().lower(): self._logo = QSvgWidget(":/resources/vispa_logo.svg") sizeHint = self._logo.sizeHint() logo_width_height_ratio = 1.0 * sizeHint.width() / sizeHint.height() logo_width = 200 self._logo.setFixedSize(logo_width, logo_width/logo_width_height_ratio) self.layout().addWidget(self._logo) else: label=QLabel(self._application.windowTitle()) self.layout().addWidget(label) self.layout().addWidget(QLabel("Version "+ self._application.version())) self.layout().addWidget(QLabel("More information can be found on:")) websiteLink = QLabel("<a href='"+ websiteUrl +"'>"+ websiteUrl +"</a>") websiteLink.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.TextSelectableByMouse) websiteLink.setOpenExternalLinks(True) self.layout().addWidget(websiteLink) buttonBox=QDialogButtonBox() buttonBox.addButton(QDialogButtonBox.Close) self.connect(buttonBox,SIGNAL("rejected()"),self,SLOT("reject()")) self.layout().addWidget(buttonBox)
def paintEvent(self, event): painter = QPainter(self) painter.setBrush(QBrush(Qt.white)) painter.setPen(Qt.NoPen) painter.drawRect(0, 0, self.width() - 1, self.height() - 1) painter.end() QSvgWidget.paintEvent(self, event)
def __setupUi(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) top_layout = QHBoxLayout() top_layout.setContentsMargins(12, 12, 12, 12) # Top row with full text description and a large preview # image. self.__label = QLabel(self, objectName="description-label", wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft) self.__label.setWordWrap(True) self.__label.setFixedSize(220, PREVIEW_SIZE[1]) self.__image = QSvgWidget(self, objectName="preview-image") self.__image.setFixedSize(*PREVIEW_SIZE) self.__imageFrame = DropShadowFrame(self) self.__imageFrame.setWidget(self.__image) # Path text below the description and image path_layout = QHBoxLayout() path_layout.setContentsMargins(12, 0, 12, 0) path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self, objectName="path-label") self.__path = TextLabel(self, objectName="path-text") path_layout.addWidget(path_label) path_layout.addWidget(self.__path) self.__selectAction = \ QAction(self.tr("Select"), self, objectName="select-action", ) top_layout.addWidget(self.__label, 1, alignment=Qt.AlignTop | Qt.AlignLeft) top_layout.addWidget(self.__image, 1, alignment=Qt.AlignTop | Qt.AlignRight) vlayout.addLayout(top_layout) vlayout.addLayout(path_layout) # An list view with small preview icons. self.__previewList = LinearIconView(objectName="preview-list-view") self.__previewList.doubleClicked.connect(self.__onDoubleClicked) vlayout.addWidget(self.__previewList) self.setLayout(vlayout)
class AboutDialog(QDialog): def __init__(self, application): self._application = application QDialog.__init__(self, self._application.mainWindow()) self.setAttribute(Qt.WA_DeleteOnClose) self.setFocusPolicy(Qt.StrongFocus) self.setWindowFlags(Qt.Window) self.setAutoFillBackground(True) #self.setPalette(QPalette(Qt.white)) self.fill() self.setWindowTitle("About "+self._application.windowTitle()) self.resize(220, 200) def setApplication(self, app): self._application = app def fill(self): # Vispa # icon # Version # Release date os.path.getmtime(filename) # website url # license self.setLayout(QVBoxLayout()) if "vispa" in self._application.windowTitle().lower(): self._logo = QSvgWidget(":/resources/vispa_logo.svg") sizeHint = self._logo.sizeHint() logo_width_height_ratio = 1.0 * sizeHint.width() / sizeHint.height() logo_width = 200 self._logo.setFixedSize(logo_width, logo_width/logo_width_height_ratio) self.layout().addWidget(self._logo) else: label=QLabel(self._application.windowTitle()) self.layout().addWidget(label) self.layout().addWidget(QLabel("Version "+ self._application.version())) self.layout().addWidget(QLabel("More information can be found on:")) websiteLink = QLabel("<a href='"+ websiteUrl +"'>"+ websiteUrl +"</a>") websiteLink.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.TextSelectableByMouse) websiteLink.setOpenExternalLinks(True) self.layout().addWidget(websiteLink) buttonBox=QDialogButtonBox() buttonBox.addButton(QDialogButtonBox.Close) self.connect(buttonBox,SIGNAL("rejected()"),self,SLOT("reject()")) self.layout().addWidget(buttonBox) def onScreen(self): self.show() self.raise_() self.activateWindow() self.setFocus()
def __init__(self, symbol, color, parent=None): QFrame.__init__(self, parent) self._symbol = symbol self.backColor = color # define and set stylesheets self.setup_stylesheets() self.setStyleSheet(self._theStyleSheet) # layout layout = QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) self.setToolTip(symbol["description"]) # add the symbol's svg svgWidget = QSvgWidget(symbol["svgPath"]) svgWidth = int(symbol["width"]) self.setMinimumWidth(svgWidth * 25) self.setMaximumWidth(svgWidth * 25) self.setMinimumHeight(25) self.setMaximumHeight(25) layout.addWidget(svgWidget) self.setLayout(layout)
def setupUi(self, info_box): info_box.setObjectName(_fromUtf8("info_box")) info_box.resize(317, 174) info_box.setFlat(False) info_box.setCheckable(False) info_box.setChecked(False) self.weather_icon = QSvgWidget(info_box) self.weather_icon.setGeometry(QtCore.QRect(30, 50, 50, 50)) self.weather_icon.setObjectName(_fromUtf8("weather_icon")) self.temp_high = QtGui.QLabel(info_box) self.temp_high.setGeometry(QtCore.QRect(110, 50, 181, 17)) self.temp_high.setObjectName(_fromUtf8("temp_high")) self.condition = QtGui.QLabel(info_box) self.condition.setGeometry(QtCore.QRect(20, 110, 251, 17)) self.condition.setObjectName(_fromUtf8("condition")) self.temp_low = QtGui.QLabel(info_box) self.temp_low.setGeometry(QtCore.QRect(110, 80, 171, 17)) self.temp_low.setObjectName(_fromUtf8("temp_low")) self.weather_setter = QtGui.QPushButton(info_box) self.weather_setter.setGeometry(QtCore.QRect(170, 140, 114, 27)) self.weather_setter.setObjectName(_fromUtf8("weather_setter")) self.quitter = QtGui.QPushButton(info_box) self.quitter.setGeometry(QtCore.QRect(50, 140, 84, 22)) self.quitter.setObjectName(_fromUtf8("quitter")) self.retranslateUi(info_box) QtCore.QMetaObject.connectSlotsByName(info_box)
def __init__(self, parent): super(RadioWidget, self).__init__(parent) self.resize(320, 240) freqFont = QtGui.QFont() freqFont.setPointSize(35) self.frequencyDisplay = QtGui.QLCDNumber(self) self.frequencyDisplay.setGeometry(QtCore.QRect(90, 15, 131, 51)) self.frequencyDisplay.setFont(freqFont) self.frequencyDisplay.setStyleSheet('color: white') self.frequencyDisplay.setFrameShape(QtGui.QFrame.NoFrame) self.updateRadioFrequency() self.slideUpFrame = QFrame(self) self.slideUpFrame.setGeometry(QtCore.QRect(230, 15, 50, 50)) self.slideUpFrame.setFrameShape(QtGui.QFrame.Box) self.slideUpFrame.setFrameShadow(QtGui.QFrame.Plain) self.slideUpFrame.setStyleSheet(self.buttonDefaultStyle) self.slideUpButton = QSvgWidget("icons/forward3.svg", self.slideUpFrame) self.slideUpButton.setGeometry(QtCore.QRect(5, 5, 40, 40)) pressable(self.slideUpButton).connect(self.doFreqUpPressed) self.slideDownFrame = QFrame(self) self.slideDownFrame.setGeometry(QtCore.QRect(50, 15, 50, 50)) self.slideDownFrame.setFrameShape(QtGui.QFrame.Box) self.slideDownFrame.setFrameShadow(QtGui.QFrame.Plain) self.slideDownFrame.setStyleSheet(self.buttonDefaultStyle) self.slideDownButton = QSvgWidget("icons/backward2.svg", self.slideDownFrame) self.slideDownButton.setGeometry(QtCore.QRect(0, 5, 40, 40)) pressable(self.slideDownButton).connect(self.doFreqDownPressed) self.horizontalLayoutWidget = QtGui.QWidget(self) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 100, 300, 80)) self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout.setAlignment(self.horizontalLayoutWidget, QtCore.Qt.AlignCenter) self.horizontalLayout.setMargin(0) QtCore.QMetaObject.connectSlotsByName(self)
def display(sc, title="SVG scene"): """Display a scene in a Qdialog :Parameters: - `sc` (`SVGScene`) - `title` (str) - window title """ qapp = QApplication.instance() if qapp is None: qapp = QApplication([]) dial = QDialog() dial.setWindowTitle(title) dial.setPalette(QPalette(QColor(255, 255, 255))) lay = QVBoxLayout(dial) w = QSvgWidget(dial) data = QByteArray(str(to_xml(sc))) w.load(data) r = w.renderer() w.setMinimumSize(r.defaultSize()) lay.addWidget(w) dial.show() qapp.exec_()
def __init__(self, symbol, synchronizer, parent=None): super(SymbolDisplayItem, self).__init__(symbol, synchronizer, parent) # adjust the size according to the symbol's svg svgWidget = QSvgWidget(symbol["svgPath"]) svgWidth = int(symbol["width"]) self.setMinimumWidth(svgWidth * 25) self.setMaximumWidth(svgWidth * 25) self.setMinimumHeight(25) self.setMaximumHeight(25)
def display (sc, title = "SVG scene") : """Display a scene in a Qdialog :Parameters: - `sc` (`SVGScene`) - `title` (str) - window title """ qapp = QApplication.instance() if qapp is None : qapp = QApplication([]) dial = QDialog() dial.setWindowTitle(title) dial.setPalette(QPalette(QColor(255,255,255) ) ) lay = QVBoxLayout(dial) w = QSvgWidget(dial) data = QByteArray(str(to_xml(sc) ) ) w.load(data) r = w.renderer() w.setMinimumSize(r.defaultSize() ) lay.addWidget(w) dial.show() qapp.exec_()
def __init__(self, board_configuration=None): """ Initialize the chessboard. """ super().__init__() self.setWindowTitle("Chess GUI") self.setGeometry(300, 300, 800, 800) self.widgetSvg = QSvgWidget(parent=self) self.widgetSvg.setGeometry(10, 10, 600, 600) self.boardSize = min(self.widgetSvg.width(), self.widgetSvg.height()) self.coordinates = True self.margin = 0.05 * self.boardSize if self.coordinates else 0 self.squareSize = (self.boardSize - 2 * self.margin) / 8.0 self.pieceToMove = [None, None] self.pieceToInsert = [None, None] self.board = chess.Board() if(board_configuration): self.board.set_piece_map(board_configuration) self.drawBoard()
class Ui_info_box(object): def setupUi(self, info_box): info_box.setObjectName(_fromUtf8("info_box")) info_box.resize(317, 174) info_box.setFlat(False) info_box.setCheckable(False) info_box.setChecked(False) self.weather_icon = QSvgWidget(info_box) self.weather_icon.setGeometry(QtCore.QRect(30, 50, 50, 50)) self.weather_icon.setObjectName(_fromUtf8("weather_icon")) self.temp_high = QtGui.QLabel(info_box) self.temp_high.setGeometry(QtCore.QRect(110, 50, 181, 17)) self.temp_high.setObjectName(_fromUtf8("temp_high")) self.condition = QtGui.QLabel(info_box) self.condition.setGeometry(QtCore.QRect(20, 110, 251, 17)) self.condition.setObjectName(_fromUtf8("condition")) self.temp_low = QtGui.QLabel(info_box) self.temp_low.setGeometry(QtCore.QRect(110, 80, 171, 17)) self.temp_low.setObjectName(_fromUtf8("temp_low")) self.weather_setter = QtGui.QPushButton(info_box) self.weather_setter.setGeometry(QtCore.QRect(170, 140, 114, 27)) self.weather_setter.setObjectName(_fromUtf8("weather_setter")) self.quitter = QtGui.QPushButton(info_box) self.quitter.setGeometry(QtCore.QRect(50, 140, 84, 22)) self.quitter.setObjectName(_fromUtf8("quitter")) self.retranslateUi(info_box) QtCore.QMetaObject.connectSlotsByName(info_box) def retranslateUi(self, info_box): info_box.setWindowTitle(QtGui.QApplication.translate("info_box", "fail", None, QtGui.QApplication.UnicodeUTF8)) info_box.setTitle(QtGui.QApplication.translate("info_box", "forecast_date", None, QtGui.QApplication.UnicodeUTF8)) self.temp_high.setText(QtGui.QApplication.translate("info_box", "TextLabel", None, QtGui.QApplication.UnicodeUTF8)) self.condition.setText(QtGui.QApplication.translate("info_box", "TextLabel", None, QtGui.QApplication.UnicodeUTF8)) self.temp_low.setText(QtGui.QApplication.translate("info_box", "TextLabel", None, QtGui.QApplication.UnicodeUTF8)) self.weather_setter.setText(QtGui.QApplication.translate("info_box", "Set Weather", None, QtGui.QApplication.UnicodeUTF8)) self.quitter.setText(QtGui.QApplication.translate("info_box", "Quit", None, QtGui.QApplication.UnicodeUTF8))
def __init__(self, symbol, synchronizer, parent = None): super(SymbolSelectorItem, self).__init__(parent) self._synchronizer = synchronizer self._symbol = symbol # define and set stylesheets self.define_stylesheets() self.setStyleSheet(self._unselectedStyleSheet) self.setToolTip(symbol["description"]) # add the symbol's svg svgWidget = QSvgWidget(symbol["svgPath"]) svgWidth = int(symbol["width"]) #.toInt()[0] svgWidget.setMaximumSize(QSize(svgWidth * 30, 30)) self.setMinimumSize(svgWidth * 30, 30) self.setMaximumSize(svgWidth * 30, 30) # finalize the layout layout = QHBoxLayout() layout.setContentsMargins( 0, 0, 0, 0 ) layout.addWidget(svgWidget) self.setLayout(layout)
def wHistogram(ncolor, siDiferencias, x, y): colors = ("#348f00", "#780098", "#b300a0", "#0181b2", "#00b2f0", "#e8537a", "#e95355", "#e87653") estilo = pygal.style.Style(background='transparent', plot_background='transparent', foreground='#53E89B', foreground_light='#53A0E8', foreground_dark='#630C0D', opacity='0.8', opacity_hover='.9', transition='250ms ease-in', colors=(colors[ncolor], )) chart = pygal.Line( x_label_rotation=90, show_dots=False, interpolation_parameters={ 'type': 'kochanek_bartels', 'b': -1, 'c': 1, 't': 1 }, interpolate='hermite' if siDiferencias else 'cubic', style=estilo, fill=True, show_legend=False, css=['./IntFiles/PyGal/style.css', './IntFiles/PyGal/graph.css'], label_font_size=7) chart.x_labels = x chart.add("0", y) cr = chart.render() fich = VarGen.configuracion.ficheroTemporal("svg") f = open(fich, "wb") f.write(cr.replace('x="-5"', 'x="-25"')) f.close() return QSvgWidget(fich)
def setupUi(self, ManageKnittingSymbolDialog): ManageKnittingSymbolDialog.setObjectName(_fromUtf8("ManageKnittingSymbolDialog")) ManageKnittingSymbolDialog.resize(753, 660) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("../icons/sconcho_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) ManageKnittingSymbolDialog.setWindowIcon(icon) self.verticalLayout_5 = QtGui.QVBoxLayout(ManageKnittingSymbolDialog) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.frame = QtGui.QFrame(ManageKnittingSymbolDialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName(_fromUtf8("frame")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.frame) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.label_7 = QtGui.QLabel(self.frame) self.label_7.setObjectName(_fromUtf8("label_7")) self.verticalLayout.addWidget(self.label_7) self.availableSymbolsWidget = QtGui.QTreeWidget(self.frame) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.availableSymbolsWidget.sizePolicy().hasHeightForWidth()) self.availableSymbolsWidget.setSizePolicy(sizePolicy) self.availableSymbolsWidget.setColumnCount(1) self.availableSymbolsWidget.setObjectName(_fromUtf8("availableSymbolsWidget")) self.verticalLayout.addWidget(self.availableSymbolsWidget) self.addSymbolButton = QtGui.QPushButton(self.frame) self.addSymbolButton.setObjectName(_fromUtf8("addSymbolButton")) self.verticalLayout.addWidget(self.addSymbolButton) self.line = QtGui.QFrame(self.frame) self.line.setFrameShape(QtGui.QFrame.HLine) self.line.setFrameShadow(QtGui.QFrame.Sunken) self.line.setObjectName(_fromUtf8("line")) self.verticalLayout.addWidget(self.line) self.importSymbolsButton = QtGui.QPushButton(self.frame) self.importSymbolsButton.setObjectName(_fromUtf8("importSymbolsButton")) self.verticalLayout.addWidget(self.importSymbolsButton) self.exportSymbolsButton = QtGui.QPushButton(self.frame) self.exportSymbolsButton.setObjectName(_fromUtf8("exportSymbolsButton")) self.verticalLayout.addWidget(self.exportSymbolsButton) self.verticalLayout_4.addLayout(self.verticalLayout) self.horizontalLayout.addWidget(self.frame) self.symbolEntryFrame = QtGui.QFrame(ManageKnittingSymbolDialog) self.symbolEntryFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolEntryFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolEntryFrame.setObjectName(_fromUtf8("symbolEntryFrame")) self.verticalLayout_3 = QtGui.QVBoxLayout(self.symbolEntryFrame) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.label_4 = QtGui.QLabel(self.symbolEntryFrame) self.label_4.setObjectName(_fromUtf8("label_4")) self.verticalLayout_2.addWidget(self.label_4) self.horizontalLayout_8 = QtGui.QHBoxLayout() self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8")) self.symbolPreviewFrame = QtGui.QFrame(self.symbolEntryFrame) self.symbolPreviewFrame.setMinimumSize(QtCore.QSize(100, 60)) self.symbolPreviewFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolPreviewFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolPreviewFrame.setObjectName(_fromUtf8("symbolPreviewFrame")) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.symbolPreviewFrame) self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.svgWidget = QSvgWidget(self.symbolPreviewFrame) self.svgWidget.setObjectName(_fromUtf8("svgWidget")) self.horizontalLayout_2.addWidget(self.svgWidget) self.horizontalLayout_8.addWidget(self.symbolPreviewFrame) self.svgPathEdit = QtGui.QLineEdit(self.symbolEntryFrame) self.svgPathEdit.setReadOnly(False) self.svgPathEdit.setObjectName(_fromUtf8("svgPathEdit")) self.horizontalLayout_8.addWidget(self.svgPathEdit) self.browseSymbolButton = QtGui.QPushButton(self.symbolEntryFrame) self.browseSymbolButton.setEnabled(True) self.browseSymbolButton.setAutoDefault(False) self.browseSymbolButton.setObjectName(_fromUtf8("browseSymbolButton")) self.horizontalLayout_8.addWidget(self.browseSymbolButton) self.verticalLayout_2.addLayout(self.horizontalLayout_8) spacerItem = QtGui.QSpacerItem(20, 18, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem) self.label_12 = QtGui.QLabel(self.symbolEntryFrame) self.label_12.setObjectName(_fromUtf8("label_12")) self.verticalLayout_2.addWidget(self.label_12) self.gridLayout_3 = QtGui.QGridLayout() self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.symbolNameLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolNameLabel.setEnabled(True) self.symbolNameLabel.setObjectName(_fromUtf8("symbolNameLabel")) self.gridLayout_3.addWidget(self.symbolNameLabel, 0, 0, 1, 1) self.symbolNameEntry = QtGui.QLineEdit(self.symbolEntryFrame) self.symbolNameEntry.setReadOnly(False) self.symbolNameEntry.setObjectName(_fromUtf8("symbolNameEntry")) self.gridLayout_3.addWidget(self.symbolNameEntry, 0, 1, 1, 1) self.symbolCategoryLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolCategoryLabel.setEnabled(True) self.symbolCategoryLabel.setObjectName(_fromUtf8("symbolCategoryLabel")) self.gridLayout_3.addWidget(self.symbolCategoryLabel, 1, 0, 1, 1) self.symbolWidthLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolWidthLabel.setEnabled(True) self.symbolWidthLabel.setObjectName(_fromUtf8("symbolWidthLabel")) self.gridLayout_3.addWidget(self.symbolWidthLabel, 3, 0, 1, 1) self.symbolWidthSpinner = QtGui.QSpinBox(self.symbolEntryFrame) self.symbolWidthSpinner.setEnabled(True) self.symbolWidthSpinner.setReadOnly(False) self.symbolWidthSpinner.setMinimum(1) self.symbolWidthSpinner.setObjectName(_fromUtf8("symbolWidthSpinner")) self.gridLayout_3.addWidget(self.symbolWidthSpinner, 3, 1, 1, 1) self.symbolDescriptionLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolDescriptionLabel.setEnabled(True) self.symbolDescriptionLabel.setObjectName(_fromUtf8("symbolDescriptionLabel")) self.gridLayout_3.addWidget(self.symbolDescriptionLabel, 4, 0, 1, 1) self.symbolDescriptionEntry = QtGui.QTextEdit(self.symbolEntryFrame) self.symbolDescriptionEntry.setReadOnly(False) self.symbolDescriptionEntry.setObjectName(_fromUtf8("symbolDescriptionEntry")) self.gridLayout_3.addWidget(self.symbolDescriptionEntry, 4, 1, 1, 1) self.categoryChooser = QtGui.QComboBox(self.symbolEntryFrame) self.categoryChooser.setObjectName(_fromUtf8("categoryChooser")) self.gridLayout_3.addWidget(self.categoryChooser, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout_3) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem1) self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.cancelOrDeleteButton = QtGui.QPushButton(self.symbolEntryFrame) self.cancelOrDeleteButton.setObjectName(_fromUtf8("cancelOrDeleteButton")) self.horizontalLayout_3.addWidget(self.cancelOrDeleteButton) self.addOrUpdateButton = QtGui.QPushButton(self.symbolEntryFrame) self.addOrUpdateButton.setObjectName(_fromUtf8("addOrUpdateButton")) self.horizontalLayout_3.addWidget(self.addOrUpdateButton) self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.verticalLayout_3.addLayout(self.verticalLayout_2) self.horizontalLayout.addWidget(self.symbolEntryFrame) spacerItem3 = QtGui.QSpacerItem(13, 13, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem3) self.verticalLayout_5.addLayout(self.horizontalLayout) self.horizontalLayout_6 = QtGui.QHBoxLayout() self.horizontalLayout_6.setSpacing(6) self.horizontalLayout_6.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint) self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6")) spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_6.addItem(spacerItem4) self.pushButton_4 = QtGui.QPushButton(ManageKnittingSymbolDialog) self.pushButton_4.setAutoDefault(False) self.pushButton_4.setObjectName(_fromUtf8("pushButton_4")) self.horizontalLayout_6.addWidget(self.pushButton_4) self.verticalLayout_5.addLayout(self.horizontalLayout_6) self.symbolNameLabel.setBuddy(self.symbolNameEntry) self.symbolCategoryLabel.setBuddy(self.categoryChooser) self.symbolWidthLabel.setBuddy(self.symbolWidthSpinner) self.symbolDescriptionLabel.setBuddy(self.symbolDescriptionEntry) self.retranslateUi(ManageKnittingSymbolDialog) QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), ManageKnittingSymbolDialog.close) QtCore.QMetaObject.connectSlotsByName(ManageKnittingSymbolDialog)
class Ui_ManageKnittingSymbolDialog(object): def setupUi(self, ManageKnittingSymbolDialog): ManageKnittingSymbolDialog.setObjectName(_fromUtf8("ManageKnittingSymbolDialog")) ManageKnittingSymbolDialog.resize(753, 660) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("../icons/sconcho_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) ManageKnittingSymbolDialog.setWindowIcon(icon) self.verticalLayout_5 = QtGui.QVBoxLayout(ManageKnittingSymbolDialog) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.frame = QtGui.QFrame(ManageKnittingSymbolDialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName(_fromUtf8("frame")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.frame) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.label_7 = QtGui.QLabel(self.frame) self.label_7.setObjectName(_fromUtf8("label_7")) self.verticalLayout.addWidget(self.label_7) self.availableSymbolsWidget = QtGui.QTreeWidget(self.frame) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.availableSymbolsWidget.sizePolicy().hasHeightForWidth()) self.availableSymbolsWidget.setSizePolicy(sizePolicy) self.availableSymbolsWidget.setColumnCount(1) self.availableSymbolsWidget.setObjectName(_fromUtf8("availableSymbolsWidget")) self.verticalLayout.addWidget(self.availableSymbolsWidget) self.addSymbolButton = QtGui.QPushButton(self.frame) self.addSymbolButton.setObjectName(_fromUtf8("addSymbolButton")) self.verticalLayout.addWidget(self.addSymbolButton) self.line = QtGui.QFrame(self.frame) self.line.setFrameShape(QtGui.QFrame.HLine) self.line.setFrameShadow(QtGui.QFrame.Sunken) self.line.setObjectName(_fromUtf8("line")) self.verticalLayout.addWidget(self.line) self.importSymbolsButton = QtGui.QPushButton(self.frame) self.importSymbolsButton.setObjectName(_fromUtf8("importSymbolsButton")) self.verticalLayout.addWidget(self.importSymbolsButton) self.exportSymbolsButton = QtGui.QPushButton(self.frame) self.exportSymbolsButton.setObjectName(_fromUtf8("exportSymbolsButton")) self.verticalLayout.addWidget(self.exportSymbolsButton) self.verticalLayout_4.addLayout(self.verticalLayout) self.horizontalLayout.addWidget(self.frame) self.symbolEntryFrame = QtGui.QFrame(ManageKnittingSymbolDialog) self.symbolEntryFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolEntryFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolEntryFrame.setObjectName(_fromUtf8("symbolEntryFrame")) self.verticalLayout_3 = QtGui.QVBoxLayout(self.symbolEntryFrame) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.label_4 = QtGui.QLabel(self.symbolEntryFrame) self.label_4.setObjectName(_fromUtf8("label_4")) self.verticalLayout_2.addWidget(self.label_4) self.horizontalLayout_8 = QtGui.QHBoxLayout() self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8")) self.symbolPreviewFrame = QtGui.QFrame(self.symbolEntryFrame) self.symbolPreviewFrame.setMinimumSize(QtCore.QSize(100, 60)) self.symbolPreviewFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolPreviewFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolPreviewFrame.setObjectName(_fromUtf8("symbolPreviewFrame")) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.symbolPreviewFrame) self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.svgWidget = QSvgWidget(self.symbolPreviewFrame) self.svgWidget.setObjectName(_fromUtf8("svgWidget")) self.horizontalLayout_2.addWidget(self.svgWidget) self.horizontalLayout_8.addWidget(self.symbolPreviewFrame) self.svgPathEdit = QtGui.QLineEdit(self.symbolEntryFrame) self.svgPathEdit.setReadOnly(False) self.svgPathEdit.setObjectName(_fromUtf8("svgPathEdit")) self.horizontalLayout_8.addWidget(self.svgPathEdit) self.browseSymbolButton = QtGui.QPushButton(self.symbolEntryFrame) self.browseSymbolButton.setEnabled(True) self.browseSymbolButton.setAutoDefault(False) self.browseSymbolButton.setObjectName(_fromUtf8("browseSymbolButton")) self.horizontalLayout_8.addWidget(self.browseSymbolButton) self.verticalLayout_2.addLayout(self.horizontalLayout_8) spacerItem = QtGui.QSpacerItem(20, 18, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem) self.label_12 = QtGui.QLabel(self.symbolEntryFrame) self.label_12.setObjectName(_fromUtf8("label_12")) self.verticalLayout_2.addWidget(self.label_12) self.gridLayout_3 = QtGui.QGridLayout() self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.symbolNameLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolNameLabel.setEnabled(True) self.symbolNameLabel.setObjectName(_fromUtf8("symbolNameLabel")) self.gridLayout_3.addWidget(self.symbolNameLabel, 0, 0, 1, 1) self.symbolNameEntry = QtGui.QLineEdit(self.symbolEntryFrame) self.symbolNameEntry.setReadOnly(False) self.symbolNameEntry.setObjectName(_fromUtf8("symbolNameEntry")) self.gridLayout_3.addWidget(self.symbolNameEntry, 0, 1, 1, 1) self.symbolCategoryLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolCategoryLabel.setEnabled(True) self.symbolCategoryLabel.setObjectName(_fromUtf8("symbolCategoryLabel")) self.gridLayout_3.addWidget(self.symbolCategoryLabel, 1, 0, 1, 1) self.symbolWidthLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolWidthLabel.setEnabled(True) self.symbolWidthLabel.setObjectName(_fromUtf8("symbolWidthLabel")) self.gridLayout_3.addWidget(self.symbolWidthLabel, 3, 0, 1, 1) self.symbolWidthSpinner = QtGui.QSpinBox(self.symbolEntryFrame) self.symbolWidthSpinner.setEnabled(True) self.symbolWidthSpinner.setReadOnly(False) self.symbolWidthSpinner.setMinimum(1) self.symbolWidthSpinner.setObjectName(_fromUtf8("symbolWidthSpinner")) self.gridLayout_3.addWidget(self.symbolWidthSpinner, 3, 1, 1, 1) self.symbolDescriptionLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolDescriptionLabel.setEnabled(True) self.symbolDescriptionLabel.setObjectName(_fromUtf8("symbolDescriptionLabel")) self.gridLayout_3.addWidget(self.symbolDescriptionLabel, 4, 0, 1, 1) self.symbolDescriptionEntry = QtGui.QTextEdit(self.symbolEntryFrame) self.symbolDescriptionEntry.setReadOnly(False) self.symbolDescriptionEntry.setObjectName(_fromUtf8("symbolDescriptionEntry")) self.gridLayout_3.addWidget(self.symbolDescriptionEntry, 4, 1, 1, 1) self.categoryChooser = QtGui.QComboBox(self.symbolEntryFrame) self.categoryChooser.setObjectName(_fromUtf8("categoryChooser")) self.gridLayout_3.addWidget(self.categoryChooser, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout_3) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem1) self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.cancelOrDeleteButton = QtGui.QPushButton(self.symbolEntryFrame) self.cancelOrDeleteButton.setObjectName(_fromUtf8("cancelOrDeleteButton")) self.horizontalLayout_3.addWidget(self.cancelOrDeleteButton) self.addOrUpdateButton = QtGui.QPushButton(self.symbolEntryFrame) self.addOrUpdateButton.setObjectName(_fromUtf8("addOrUpdateButton")) self.horizontalLayout_3.addWidget(self.addOrUpdateButton) self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.verticalLayout_3.addLayout(self.verticalLayout_2) self.horizontalLayout.addWidget(self.symbolEntryFrame) spacerItem3 = QtGui.QSpacerItem(13, 13, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem3) self.verticalLayout_5.addLayout(self.horizontalLayout) self.horizontalLayout_6 = QtGui.QHBoxLayout() self.horizontalLayout_6.setSpacing(6) self.horizontalLayout_6.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint) self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6")) spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_6.addItem(spacerItem4) self.pushButton_4 = QtGui.QPushButton(ManageKnittingSymbolDialog) self.pushButton_4.setAutoDefault(False) self.pushButton_4.setObjectName(_fromUtf8("pushButton_4")) self.horizontalLayout_6.addWidget(self.pushButton_4) self.verticalLayout_5.addLayout(self.horizontalLayout_6) self.symbolNameLabel.setBuddy(self.symbolNameEntry) self.symbolCategoryLabel.setBuddy(self.categoryChooser) self.symbolWidthLabel.setBuddy(self.symbolWidthSpinner) self.symbolDescriptionLabel.setBuddy(self.symbolDescriptionEntry) self.retranslateUi(ManageKnittingSymbolDialog) QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), ManageKnittingSymbolDialog.close) QtCore.QMetaObject.connectSlotsByName(ManageKnittingSymbolDialog) def retranslateUi(self, ManageKnittingSymbolDialog): ManageKnittingSymbolDialog.setWindowTitle(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "sconcho: Manage Custom Knitting Symbols", None, QtGui.QApplication.UnicodeUTF8)) self.label_7.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Available Symbols</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.availableSymbolsWidget.headerItem().setText(0, QtGui.QApplication.translate("ManageKnittingSymbolDialog", "Category/Symbol", None, QtGui.QApplication.UnicodeUTF8)) self.addSymbolButton.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "&Add New Symbol", None, QtGui.QApplication.UnicodeUTF8)) self.importSymbolsButton.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "Import Symbols", None, QtGui.QApplication.UnicodeUTF8)) self.exportSymbolsButton.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "Export Symbols", None, QtGui.QApplication.UnicodeUTF8)) self.label_4.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">SVG Image</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.browseSymbolButton.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "&Browse", None, QtGui.QApplication.UnicodeUTF8)) self.label_12.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Description</span></p></body></html>", None, QtGui.QApplication.UnicodeUTF8)) self.symbolNameLabel.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "symbol &name", None, QtGui.QApplication.UnicodeUTF8)) self.symbolCategoryLabel.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "symbol &category", None, QtGui.QApplication.UnicodeUTF8)) self.symbolWidthLabel.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "symbol &width", None, QtGui.QApplication.UnicodeUTF8)) self.symbolDescriptionLabel.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "symbol &description", None, QtGui.QApplication.UnicodeUTF8)) self.cancelOrDeleteButton.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "Cancel", None, QtGui.QApplication.UnicodeUTF8)) self.addOrUpdateButton.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "Add", None, QtGui.QApplication.UnicodeUTF8)) self.pushButton_4.setText(QtGui.QApplication.translate("ManageKnittingSymbolDialog", "Close", None, QtGui.QApplication.UnicodeUTF8))
def __set_layout(self, surface_manager, character): """ Set layout of this widget """ main_layout = QHBoxLayout() left_layout = QVBoxLayout() right_layout = QVBoxLayout() left_top_layout = QHBoxLayout() left_bottom_layout = QVBoxLayout() icon_layout = QVBoxLayout() stat_layout = QGridLayout() self.body = QLabel() self.body.setText(str(character.body)) self.body.setObjectName('no_border') self.mind = QLabel() self.mind.setText(str(character.mind)) self.mind.setObjectName('no_border') self.finesse = QLabel() self.finesse.setText(str(character.finesse)) self.finesse.setObjectName('no_border') self.hp = QLabel() self.hp.setText('{0}/{1}'.format(character.hit_points, character.max_hp)) self.hp.setObjectName('no_border') self.mana = QLabel() self.mana.setText('0/0') self.mana.setObjectName('no_border') body_label = QLabel('Body:') body_label.setObjectName('no_border') mind_label = QLabel('Mind:') mind_label.setObjectName('no_border') finesse_label = QLabel('Finesse:') finesse_label.setObjectName('no_border') hp_label = QLabel('HP:') hp_label.setObjectName('no_border') mana_label = QLabel('Mana:') mana_label.setObjectName('no_border') stat_layout.addWidget(self.body, 0, 1) stat_layout.addWidget(body_label, 0, 0) stat_layout.addWidget(self.mind, 1, 1) stat_layout.addWidget(mind_label, 1, 0) stat_layout.addWidget(self.finesse, 2, 1) stat_layout.addWidget(finesse_label, 2, 0) stat_layout.addWidget(self.hp, 3, 1) stat_layout.addWidget(hp_label, 3, 0) stat_layout.addWidget(self.mana, 4, 1) stat_layout.addWidget(mana_label, 4, 0) self.character_icon = QSvgWidget(':strong.svg') self.character_icon.setMaximumSize(150, 150) self.character_icon.setMinimumSize(150, 150) icon_layout.addWidget(self.character_icon) skills_label = QLabel('Skills') skills_label.setObjectName('section_title') skills = ListView() right_layout.addWidget(skills_label) right_layout.addWidget(skills) effects_label = QLabel('Effects') effects_label.setObjectName('section_title') effects = ListView() for effect in character.get_effects(): effects.add_item(title=effect.title, description=effect.description, icon=surface_manager.get_icon(effect.icon)) left_bottom_layout.addWidget(effects_label) left_bottom_layout.addWidget(effects) left_top_layout.addLayout(icon_layout) left_top_layout.addLayout(stat_layout) left_layout.addLayout(left_top_layout) left_layout.addLayout(left_bottom_layout) main_layout.addLayout(left_layout) main_layout.addLayout(right_layout) self.setLayout(main_layout)
class BedbotWidget(QtGui.QWidget): loadedModules = None currentWidget = None currentWidgetIndex = 2 listenToButtons = True hasIOLibraries = False autoCloseTimer = None currentAudioModule = None pinConfig = {} pinCallbacks = [] disabledPins = [] currentButtonIndicators = [] pinStatusTimer = None def __init__(self, parent, modules): super(BedbotWidget, self).__init__(parent) self.resize(320, 240) self.loadPinConfig() self.loadedModules = modules self.connect(self, QtCore.SIGNAL('processPigpioEvent'), self.pinEventCallback) self.initializeMenu() menuWidgets = [] for m in self.loadedModules: self.connect(m, QtCore.SIGNAL('logEvent'), self.logEvent) """For a module to be used in the app, it must be located in the Modules folder and have an 'Enabled' attribute set to True. If it's not there, or it's false, the module is ignored """ if (hasattr(m, "Enabled") == True and m.Enabled == True): """Scans all active modules to see if they should be added to the menu. Module must have 'addMenuWidget' function """ if (self.moduleHasFunction(m, "addMenuWidget")): if (hasattr(m, "menuOrder") == True): menuWidgets.insert(m.menuOrder, m) else: menuWidgets.insert(len(menuWidgets), m) """Scans all active modules to see if they require the pin configuration.""" if (self.moduleHasFunction(m, "setPin")): m.setPin(self.pinConfig) """Allows a module to tell other modules to send output on a specific pin (for the audio relay)""" self.connect(m, QtCore.SIGNAL('pinRequested'), self.pinRequestedCallback) """Tells BedbotWidget to show a popup according to specifications provided""" self.connect(m, QtCore.SIGNAL('showPopup'), self.showPopupCallback) """Tells BedbotWidget which colored circle indicators to display""" self.connect(m, QtCore.SIGNAL('requestButtonPrompt'), self.buttonPromptRequestCallback) """Event that modules can call to invoke methods on other modules without knowing about them beforehand """ self.connect(m, QtCore.SIGNAL('broadcastModuleRequest'), self.broadcastModuleRequestCallback) """Allows active modules to send signals to all other modules to stop audio playback""" self.connect(m, QtCore.SIGNAL('stopAllAudio'), self.stopAllAudioCallback) """If a modules uses the audio output, it must have the attribute 'UsesAudio' and have it set to True If it does, than it can use the audio status display in BedbotWidget to display it's current status """ if (hasattr(m, "UsesAudio") == True and m.UsesAudio == True): self.connect(m, QtCore.SIGNAL('audioStarted'), self.audioStartedCallback) self.connect(m, QtCore.SIGNAL('audioStopped'), self.audioStoppedCallback) """ After all modules are loaded, use the attribute 'menuOrder' on active modules to organize the menu icons""" for i in range(0, len(menuWidgets)): menuWidgets[i].menuOrder = i self.addMainWidget(menuWidgets[i]) self.menu_widget.configureMenu() self.toggleMainMenu(True) QtCore.QMetaObject.connectSlotsByName(self) def broadcastModuleRequestCallback(self, caller, methodToCall, methodArgs=None, callbackMethod=None, targetModuleName=None): """Callback for the 'broadcastModuleRequest' event that modules can call to invoke methods on other modules without knowing about them beforehand """ results = [] for m in self.loadedModules: if (targetModuleName != None and type(m).__name__ != targetModuleName): continue if (hasattr(m, "Enabled") == True and m.Enabled == True): if (self.moduleHasFunction(m, methodToCall)): if (callbackMethod != None): if (methodArgs != None): results.append( getattr(m, methodToCall)(methodArgs)) else: results.append(getattr(m, methodToCall)()) else: getattr(m, methodToCall)(methodArgs) if (callbackMethod != None and hasattr(caller, "Enabled") == True and caller.Enabled == True): if (self.moduleHasFunction(caller, callbackMethod)): getattr(caller, callbackMethod)(results) def stopAllAudioCallback(self): self.stopAllAudio() def buttonPromptRequestCallback(self, buttonsToPrompt): self.clearButtonPrompts() for x in buttonsToPrompt: if (x == "ON"): self.onButtonIndicator.setVisible(True) elif (x == "CONTEXT"): self.contextButtonIndicator.setVisible(True) elif (x == "OFF"): self.offButtonIndicator.setVisible(True) def clearButtonPrompts(self): self.onButtonIndicator.setVisible(False) self.contextButtonIndicator.setVisible(False) self.offButtonIndicator.setVisible(False) def showPopupCallback(self, caller, msg=None, popupType=None, popupArgs=None): self.customPopup = Popup(self) self.connect(self.customPopup, QtCore.SIGNAL('popupResult'), self.popupCallback) if (popupType == None): self.customPopup.doWait(msg) else: if (popupType == "optionSelect" and popupArgs != None): self.customPopup.optionSelect(msg, popupArgs) elif (popupType == "numberSelect"): self.customPopup.numberSelect(msg, popupArgs) elif (popupType == "alarm"): self.customPopup.alarm(popupArgs) elif (popupType == "snooze"): self.customPopup.snooze(popupArgs) def popupCallback(self, result): for m in self.loadedModules: if (self.moduleHasFunction(m, "popupResult")): m.popupResult(result) def pinRequestedCallback(self, pin): self.pinEventCallback(pin) def audioStoppedCallback(self, sourceModule): self.currentAudioModule = None self.stopAllAudio(self.currentAudioModule) self.statusDisplay.setText("") def audioStartedCallback(self, sourceModule): self.currentAudioModule = sourceModule self.stopAllAudio(self.currentAudioModule) self.statusDisplay.setText("") if (self.moduleHasFunction(self.currentAudioModule, "getAudioStatusDisplay")): self.statusDisplay.setText( self.currentAudioModule.getAudioStatusDisplay()) def stopAllAudio(self, ignoredModule=None): for m in self.loadedModules: if (hasattr(m, "UsesAudio") == True and m.UsesAudio == True and (ignoredModule == None or (ignoredModule != None and m != ignoredModule))): if (self.moduleHasFunction(m, "stop")): m.stop() def logEvent(self, evtStr): print(evtStr) logging.info(str(evtStr)) def initializeMenu(self): self.menu_widget = DynamicMenu(self) self.menu_widget.setGeometry(QtCore.QRect(10, 10, 320, 190)) self.menu_widget.setVisible(True) self.connect(self.menu_widget, QtCore.SIGNAL('showWidget'), self.showWidgetCallback) self.menuButton = QSvgWidget("icons/three-bars.svg", self) self.menuButton.setGeometry(QtCore.QRect(10, 200, 30, 35)) pressableSender(self.menuButton).connect(self.menuButtonPressed) self.menuButton.setVisible(False) self.onButtonIndicator = ButtonIndicator(self, 30, "green") self.onButtonIndicator.setGeometry(QtCore.QRect(50, 202, 30, 30)) self.onButtonIndicator.setVisible(False) self.contextButtonIndicator = ButtonIndicator(self, 30, "blue") self.contextButtonIndicator.setGeometry(QtCore.QRect(80, 202, 30, 30)) self.contextButtonIndicator.setVisible(False) self.offButtonIndicator = ButtonIndicator(self, 30, "red") self.offButtonIndicator.setGeometry(QtCore.QRect(110, 202, 30, 30)) self.offButtonIndicator.setVisible(False) font = QtGui.QFont() font.setPointSize(15) self.statusDisplay = QtGui.QLabel(self) self.statusDisplay.setGeometry(QtCore.QRect(150, 200, 140, 35)) self.statusDisplay.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.statusDisplay.setStyleSheet('color: #eaf736') self.statusDisplay.setFont(font) pressableSender(self.statusDisplay).connect(self.audioStatusPressed) def audioStatusPressed(self, obj): if (self.currentAudioModule != None): self.menu_widget.setMenuItemSelected(self.currentAudioModule) self.showWidgetCallback(self.currentAudioModule) def toggleMainMenu(self, showMenu): if (showMenu): self.hideMainWidgets() self.autoCloseTimer = QTimer() self.autoCloseTimer.timeout.connect(self.autoCloseMainMenu) self.autoCloseTimer.start(5000) self.menuButton.setVisible(not showMenu) self.menu_widget.setVisible(showMenu) def autoCloseMainMenu(self): self.autoCloseTimer.stop() self.autoCloseTimer = None if (self.currentWidget != None): self.showWidgetCallback(self.currentWidget) def triggerMenuButton(self): self.menuButtonTimer.stop() self.menuButton.load("icons/three-bars.svg") self.toggleMainMenu(True) def menuButtonPressed(self, obj): self.menuButton.load("icons/three-barsSelected.svg") self.menuButtonTimer = QTimer() self.menuButtonTimer.timeout.connect(self.triggerMenuButton) self.menuButtonTimer.start(500) def showWidgetCallback(self, w): if (self.autoCloseTimer != None): self.autoCloseTimer.stop() self.autoCloseTimer = None self.hideMainWidgets() w.showWidget() self.currentWidget = w self.toggleMainMenu(False) def hideMainWidgets(self): self.clearButtonPrompts() for m in self.loadedModules: if (hasattr(m, "Enabled") == True and m.Enabled == True): if (self.moduleHasFunction(m, "hideWidget")): m.hideWidget() self.menu_widget.setVisible(False) def moduleHasFunction(self, m, functionName): """Helper to determine if a module has a specific function available""" funct = getattr(m, functionName, None) if (callable(funct)): return True return False def addMainWidget(self, w): """Adds a widget that has Enabled set to true, has a method called 'addMenuWidget' and has an optional menuOrder parameter""" w.addMenuWidget(self) self.menu_widget.addMenuItem(w) def simulateButton(self, buttonDesc): """Simulates a button call, usually for debug purposes""" self.pinEventCallback(self.pinConfig[buttonDesc]) def pinEventCallback(self, channel): self.logEvent("pin callback for channel: " + str(channel)) if (hasattr(self, "customPopup") == True): self.customPopup.processPin(self.pinConfig, channel) #else: for m in self.loadedModules: if (hasattr(m, "ListenForPinEvent") == True and m.ListenForPinEvent == True and self.moduleHasFunction(m, "processPinEvent")): m.processPinEvent(channel) def pigpioCallback(self, gpio, level, tick): currentlyDisabled = gpio in self.disabledPins if (currentlyDisabled == False): self.disabledPins.append(gpio) self.emit(QtCore.SIGNAL('processPigpioEvent'), gpio) t = Thread(target=self.reenablePin, args=( self, gpio, )) t.start() def reenablePin(self, parent, pin): """Renables a pin after it fires to prevent extra event from firing""" time.sleep(1) print("reenable pin: " + str(pin)) parent.disabledPins.remove(pin) def loadPinConfig(self): """Loads the pinConfig.json file that specifies the pins used and a name""" with open("pinConfig.json") as data_file: data = json.load(data_file) self.pinConfig = {} if (hasIOLibraries): self.pi = pigpio.pi() for x in range(0, len(data["pins"])): p = data["pins"][x] self.pinConfig[p["type"]] = p["pin"] if (hasIOLibraries and self.listenToButtons == True and p["listenForPress"] == True): self.logEvent("adding event to pin: " + str(p["pin"])) self.pi.set_pull_up_down(p["pin"], pigpio.PUD_DOWN) cb1 = self.pi.callback(p["pin"], pigpio.RISING_EDGE, self.pigpioCallback) def doClose(self): try: self.customPopup.closePopup() except Exception: print("problem disposing of popup") for m in self.loadedModules: try: m.dispose() except BaseException: print("problem disposing") print(m) try: self.pi.stop() except BaseException: print("problem cleaning up IO")
class PreviewBrowser(QWidget): """A Preview Browser for recent/premade scheme selection. """ # Emitted when the current previewed item changes currentIndexChanged = Signal(int) # Emitted when an item is double clicked in the preview list. activated = Signal(int) def __init__(self, *args): QWidget.__init__(self, *args) self.__model = None self.__currentIndex = -1 self.__template = DESCRIPTION_TEMPLATE self.__setupUi() def __setupUi(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) top_layout = QHBoxLayout() top_layout.setContentsMargins(12, 12, 12, 12) # Top row with full text description and a large preview # image. self.__label = QLabel(self, objectName="description-label", wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft) self.__label.setWordWrap(True) self.__label.setFixedSize(220, PREVIEW_SIZE[1]) self.__image = QSvgWidget(self, objectName="preview-image") self.__image.setFixedSize(*PREVIEW_SIZE) self.__imageFrame = DropShadowFrame(self) self.__imageFrame.setWidget(self.__image) # Path text below the description and image path_layout = QHBoxLayout() path_layout.setContentsMargins(12, 0, 12, 0) path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self, objectName="path-label") self.__path = TextLabel(self, objectName="path-text") path_layout.addWidget(path_label) path_layout.addWidget(self.__path) self.__selectAction = \ QAction(self.tr("Select"), self, objectName="select-action", ) top_layout.addWidget(self.__label, 1, alignment=Qt.AlignTop | Qt.AlignLeft) top_layout.addWidget(self.__image, 1, alignment=Qt.AlignTop | Qt.AlignRight) vlayout.addLayout(top_layout) vlayout.addLayout(path_layout) # An list view with small preview icons. self.__previewList = LinearIconView(objectName="preview-list-view") self.__previewList.doubleClicked.connect(self.__onDoubleClicked) vlayout.addWidget(self.__previewList) self.setLayout(vlayout) def setModel(self, model): """Set the item model for preview. """ if self.__model != model: if self.__model: s_model = self.__previewList.selectionModel() s_model.selectionChanged.disconnect(self.__onSelectionChanged) self.__model.dataChanged.disconnect(self.__onDataChanged) self.__model = model self.__previewList.setModel(model) if model: s_model = self.__previewList.selectionModel() s_model.selectionChanged.connect(self.__onSelectionChanged) self.__model.dataChanged.connect(self.__onDataChanged) if model and model.rowCount(): self.setCurrentIndex(0) def model(self): """Return the item model. """ return self.__model def setPreviewDelegate(self, delegate): """Set the delegate to render the preview images. """ raise NotImplementedError def setDescriptionTemplate(self, template): self.__template = template self.__update() def setCurrentIndex(self, index): """Set the selected preview item index. """ if self.__model is not None and self.__model.rowCount(): index = min(index, self.__model.rowCount() - 1) index = self.__model.index(index, 0) sel_model = self.__previewList.selectionModel() # This emits selectionChanged signal and triggers # __onSelectionChanged, currentIndex is updated there. sel_model.select(index, sel_model.ClearAndSelect) elif self.__currentIndex != -1: self.__currentIndex = -1 self.__update() self.currentIndexChanged.emit(-1) def currentIndex(self): """Return the current selected index. """ return self.__currentIndex def __onSelectionChanged(self, *args): """Selected item in the preview list has changed. Set the new description and large preview image. """ rows = self.__previewList.selectedIndexes() if rows: index = rows[0] self.__currentIndex = index.row() else: index = QModelIndex() self.__currentIndex = -1 self.__update() self.currentIndexChanged.emit(self.__currentIndex) def __onDataChanged(self, topleft, bottomRight): """Data changed, update the preview if current index in the changed range. """ if self.__currentIndex <= topleft.row() and \ self.__currentIndex >= bottomRight.row(): self.__update() def __onDoubleClicked(self, index): """Double click on an item in the preview item list. """ self.activated.emit(index.row()) def __update(self): """Update the current description. """ if self.__currentIndex != -1: index = self.model().index(self.__currentIndex, 0) else: index = QModelIndex() if not index.isValid(): description = "" name = "" path = "" svg = NO_PREVIEW_SVG else: description = str(index.data(Qt.WhatsThisRole)) if not description: description = "No description." description = escape(description) description = description.replace("\n", "<br/>") name = str(index.data(Qt.DisplayRole)) if not name: name = "Untitled" name = escape(name) path = str(index.data(Qt.StatusTipRole)) svg = str(index.data(previewmodel.ThumbnailSVGRole)) desc_text = self.__template.format(description=description, name=name) self.__label.setText(desc_text) self.__path.setText(path) if not svg: svg = NO_PREVIEW_SVG if svg: self.__image.load(QByteArray(svg.encode("utf-8")))
def __set_layout(self, surface_manager, character, parent): """ Set layout of this widget """ main_layout = QHBoxLayout() left_side = QVBoxLayout() self.ring_slot = ItemGlyph(None, surface_manager, self, QPixmap(':ring.png')) self.items.append(self.ring_slot) self.weapon_slot = ItemGlyph(None, surface_manager, self, QPixmap(':inventory_sword.png')) self.items.append(self.weapon_slot) self.gloves_slot = ItemGlyph(None, surface_manager, self, QPixmap(':mailed-fist.png')) self.items.append(self.gloves_slot) left_side.addStretch() left_side.addWidget(self.ring_slot) left_side.addWidget(self.weapon_slot) left_side.addWidget(self.gloves_slot) left_side.addStretch() middle = QVBoxLayout() middle_top = QHBoxLayout() self.head_slot = ItemGlyph(None, surface_manager, self, QPixmap(':helm.png')) self.items.append(self.head_slot) self.necklace_slot = ItemGlyph(None, surface_manager, self, QPixmap(':necklace.png')) self.items.append(self.necklace_slot) middle_top.addStretch() middle_top.addWidget(self.head_slot) middle_top.addWidget(self.necklace_slot) middle_top.addStretch() middle_middle = QHBoxLayout() self.character_icon = QSvgWidget(':strong.svg') self.character_icon.setMaximumSize(150, 150) self.character_icon.setMinimumSize(150, 150) middle_middle.addWidget(self.character_icon) middle_bottom = QHBoxLayout() self.boots_slot = ItemGlyph(None, surface_manager, self, QPixmap(':boots.png')) self.items.append(self.boots_slot) self.belt_slot = ItemGlyph(None, surface_manager, self, QPixmap(':belts.png')) self.items.append(self.belt_slot) middle_bottom.addStretch() middle_bottom.addWidget(self.boots_slot) middle_bottom.addWidget(self.belt_slot) middle_bottom.addStretch() middle.addLayout(middle_top) middle.addLayout(middle_middle) middle.addLayout(middle_bottom) right_side = QVBoxLayout() self.arrows_slot = ItemGlyph(None, surface_manager, self, QPixmap(':arrow-cluster.png')) self.items.append(self.arrows_slot) self.shield_slot = ItemGlyph(None, surface_manager, self, QPixmap(':shield.png')) self.items.append(self.shield_slot) self.armour_slot = ItemGlyph(None, surface_manager, self, QPixmap(':breastplate.png')) self.items.append(self.armour_slot) right_side.addStretch() right_side.addWidget(self.arrows_slot) right_side.addWidget(self.shield_slot) right_side.addWidget(self.armour_slot) right_side.addStretch() main_layout.addLayout(left_side) main_layout.addLayout(middle) main_layout.addLayout(right_side) self.setLayout(main_layout)
class Component(QGraphicsItem): """! @if English Superclass for visual components. @endif @if Slovak Supertrieda pre vizualne komponenty. @endif """ def __init__(self, className, position=QPoint(0, 0), parent=None): super(Component, self).__init__(parent) # self.isSelected=False # priznak vybraneho komponentu self.setPos(position) self.setFlag(QGraphicsItem.ItemIsSelectable) # cesta k umiestneniu suboru - treba pre urcenie umiestnenia # suboru s obrazkom k shape v adresaroch ./img file_path = sys.modules[self.__class__.__module__].__file__ self.path, file_name = os.path.split(file_path) self.shapeSvg = None # referencia na svg ikony v shape self.shapePng = None self.position = position # aktualna poloha objektu self.uid = 1 # identifikacne cislo objektu self.className = className # meno triedy objektu self.diagram = None # ref na diagram, na ktorom je umiestneny komponent self.compType = TYPE_DECORATION # typ objektu self.box = QRectF(0, 0, 10, 10) # ohranicenie objektu self.shapeImage = '' # obrazok komponentu (SVG,PNG ... - ak je pouzity) self.shapeColor = Color.red # farba komponentu vytvoreneho na graf. kontexte self.shapeFillColor = Color.cadetBlue # farba vyplne komponentu self.borderColor = Color.blue # farba ohranicenia objektu self.flippedVertical = False # priznak vertikalneho preklopenia self.flippedHorizontal = False # priznak horizontalneho preklopenia self.terminal = {} # zoznam terminalov komponentu self.parameter = {} # parametre komponentu self.paramList = [ ] # zoznam parametrov komponentu v poradi ich vytvaranie, # pouziva sa pri editovani vlastnosti komponentu # (nahrada usporiadaneho slovnika pre Python 2) self.addParameter( 'Ref', 'A') # default parameter - referencia alebo meno komponentu self.setZValue(10) def __str__(self): ''' ''' s = '\n' s = s + '<C> Comp. name :' + str(self.className) + '\n' s = s + ' uid :' + str(self.uid) + '\n' s = s + ' ref :' + self.parameter['Ref'].value + '\n' s = s + ' selected :' + str(self.isSelected()) + '\n' s = s + ' Terminal(s):' + '\n' for t in self.terminal.keys(): s = s + ' Number :' + str(self.terminal[t].num) + '\n' s = s + ' Name :' + str(self.terminal[t].name) + '\n' s = s + ' Value :' + str(self.terminal[t].value) + '\n' s = s + ' Type :' + \ str(self.terminal[t].termType) + '\n' if len(self.terminal[t].connect) == 0: s = s + ' Connect: []' + '\n' else: s = s + ' Connect:' + '\n' for n in self.terminal[t].connect: s = s + ' Net name: ' + str(n.name) + ' Start = ' \ + n.startComponent.parameter['Ref'].value + '[' + str(n.startTerminal) + '] \t' + \ ' End = ' + n.endComponent.parameter[ 'Ref'].value + '[' + str(n.endTerminal) + ']' + '\n' return s def drawShape(self, painter): """! @if English @endif @if Slovak Virtualna metoda implementovana v derivovanych komponentoch, neimplementovat v supertriede, spolocne vlastnosti su implementovane v metode paint. @endif """ pass def paint(self, painter, option, widget=None): painter.setRenderHint(QPainter.Antialiasing) # vykreslenie komponentu self.drawShape(painter) # vykreslenie terminalov na povrchu komponentu # TODO - volba vykreslenia terminalov for n in self.terminal: self.terminal[n].drawTerminal(painter) # vykreslenie borderu komponentu if self.isSelected() is True: painter.setPen(QPen(self.borderColor, 1, Qt.DashLine)) painter.setBrush(QBrush(Qt.NoBrush)) painter.drawRect(self.box) def boundingRect(self): ''' @if English @endif @if Slovak Ohraničenie komponentu. Štandardné ohraničenie komponentu, pre správnu identifikaciu terminalov je rozmer ohraničenia zvačšeny o 10px vzhladom na viditelny box. @endif ''' box = QRectF(self.box) # deep copy povodneho ohranicenia box.adjust(-5, -5, 10, 10) # temp. uprava rozmerov return box def updateShape(self): ''' @if English @endif @if Slovak Aktualizácia zobrazenia komponentu. Uprava shape komponentu po jeho vytvoreni, zmene parametrov alebo vlastnosti. V derivovanych komponentoch moze obsahovat obnovenie farebnej schemy objektu napr. po odstraneni chyby, ktora bola opticky indikovana odlisnym (cervenym) sfarbenim objektu. @endif ''' # nacitanie grafickeho obrazku shapeImage shapeFile = self.path + '/img/' + self.shapeImage if os.path.isfile(shapeFile) is True: if shapeFile.endswith('.svg') is True: self.shapeSvg = QSvgWidget(shapeFile) self.shapeSvg.setAttribute(Qt.WA_NoSystemBackground) if shapeFile.endswith('.png') is True: self.shapePng = QPixmap(shapeFile) def drawIcon(self, gc, x, y): ''' @if English @endif @if Slovak Vykreslenie ikony komponentu (SVG alebo PNG). Ikona komponentu sa nemení pri horizontálnom preklopení (flip horizontal) komponentu. @endif ''' # zrusenie preklopenia komponentu if self.flippedHorizontal is True: t = gc.transform() t.setMatrix(-t.m11(), t.m12(), t.m13(), t.m21(), t.m22(), t.m23(), t.m31(), t.m32(), t.m33()) gc.setTransform(t) #print(self.shapePng) if self.shapePng is not None: w = self.shapePng.width() h = self.shapePng.height() gc.drawPixmap(x, y, w, h, self.shapePng) if self.shapeSvg is not None: self.shapeSvg.render(gc, targetOffset=QPoint(x, y)) # obnovenie predchadzajuceho nastavenia if self.flippedHorizontal is True: t = gc.transform() t.setMatrix(-t.m11(), t.m12(), t.m13(), t.m21(), t.m22(), t.m23(), t.m31(), t.m32(), t.m33()) gc.setTransform(t) def deleteShape(self): """! @if English @endif @if Slovak Upratanie externych casti komponentu pri mazanie pocas editovania, ktore nie su zaradene do struktury grafickych komponentov. Metoda sa volá pri operacii delete komponentu z editora. Priklad použitia - interaktivny komponent (QPushButton) je vložený na plochu QGraphicsScene priamo metodou addWidget, pri delete komponentu nie je možné vložený button zmazať vyradením z kontainera itemov. @endif """ pass def addTerminal(self, name='', num=1, termtype=0, position=(0, 0), direction=0, connType=TERM.NONE, discType=TERM.CROSS): """! @if English Define new terminal. @endif @if Slovak Pridanie noveho terminálu komponentu. Vytvorenie noveho terminálu a zaradenie ho do slovnika terminalov, klúčom je číslo terminálu. Vrati referenciu terminalu pre dalsie upravy. @endif """ term = Terminal(self, name, num, termtype, position, direction) self.terminal[num] = term term.termDiscType = discType term.termConnType = connType return term def setPosition(self, position): ''' Nastavenie polohy komponentu. ''' self.setPos(position) self.position = position def addParameter(self, name, value, visible=False, position=QPoint(0, 0), color=Color.black, visibleName=False, paramType=PARAM.NONE): '''! @if English Add new component parameter. @endif @if Slovak Priradenie noveho parametra komponentu. @endif ''' # kontrola na existenciu parametra, zabranenie opakovanemu vytvaraniu rovnakych parametrov if name not in self.parameter: # vytvorenie noveho parameter param = Parameter(name, value, visible, position, color, visibleName, paramType, self) self.parameter[name] = param self.paramList.append(param) else: # update vlastnosti existujuceho parametra self.parameter[name].value = value self.parameter[name].visibleValue = visible self.parameter[name].position = position self.parameter[name].color = color self.parameter[name].visibleName = visibleName self.parameter[name].paramType = paramType def sim(self, flag, value, time, step): """! @if English @endif @if Slovak Implementácia algoritmu simulácie. Metóda je definovana v derivovaných objektoch. @endif """ pass def gen(self): """! @if English @endif @if Slovak @endif """ pass
def __init__(self, parent=None): QSvgWidget.__init__(self, parent) sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) sizePolicy.setHeightForWidth(True) self.setSizePolicy(sizePolicy)
def addMenuItem(self, obj): menuButton = QSvgWidget(obj.getMenuIcon(), self) menuButton.tag = obj self.menuItems.append(menuButton)
class Ui_ManageKnittingSymbolDialog(object): def setupUi(self, ManageKnittingSymbolDialog): ManageKnittingSymbolDialog.setObjectName( _fromUtf8("ManageKnittingSymbolDialog")) ManageKnittingSymbolDialog.resize(753, 660) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("../icons/sconcho_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) ManageKnittingSymbolDialog.setWindowIcon(icon) self.verticalLayout_5 = QtGui.QVBoxLayout(ManageKnittingSymbolDialog) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.frame = QtGui.QFrame(ManageKnittingSymbolDialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName(_fromUtf8("frame")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.frame) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.label_7 = QtGui.QLabel(self.frame) self.label_7.setObjectName(_fromUtf8("label_7")) self.verticalLayout.addWidget(self.label_7) self.availableSymbolsWidget = QtGui.QTreeWidget(self.frame) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.availableSymbolsWidget.sizePolicy().hasHeightForWidth()) self.availableSymbolsWidget.setSizePolicy(sizePolicy) self.availableSymbolsWidget.setColumnCount(1) self.availableSymbolsWidget.setObjectName( _fromUtf8("availableSymbolsWidget")) self.verticalLayout.addWidget(self.availableSymbolsWidget) self.addSymbolButton = QtGui.QPushButton(self.frame) self.addSymbolButton.setObjectName(_fromUtf8("addSymbolButton")) self.verticalLayout.addWidget(self.addSymbolButton) self.line = QtGui.QFrame(self.frame) self.line.setFrameShape(QtGui.QFrame.HLine) self.line.setFrameShadow(QtGui.QFrame.Sunken) self.line.setObjectName(_fromUtf8("line")) self.verticalLayout.addWidget(self.line) self.importSymbolsButton = QtGui.QPushButton(self.frame) self.importSymbolsButton.setObjectName( _fromUtf8("importSymbolsButton")) self.verticalLayout.addWidget(self.importSymbolsButton) self.exportSymbolsButton = QtGui.QPushButton(self.frame) self.exportSymbolsButton.setObjectName( _fromUtf8("exportSymbolsButton")) self.verticalLayout.addWidget(self.exportSymbolsButton) self.verticalLayout_4.addLayout(self.verticalLayout) self.horizontalLayout.addWidget(self.frame) self.symbolEntryFrame = QtGui.QFrame(ManageKnittingSymbolDialog) self.symbolEntryFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolEntryFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolEntryFrame.setObjectName(_fromUtf8("symbolEntryFrame")) self.verticalLayout_3 = QtGui.QVBoxLayout(self.symbolEntryFrame) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.label_4 = QtGui.QLabel(self.symbolEntryFrame) self.label_4.setObjectName(_fromUtf8("label_4")) self.verticalLayout_2.addWidget(self.label_4) self.horizontalLayout_8 = QtGui.QHBoxLayout() self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8")) self.symbolPreviewFrame = QtGui.QFrame(self.symbolEntryFrame) self.symbolPreviewFrame.setMinimumSize(QtCore.QSize(100, 60)) self.symbolPreviewFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolPreviewFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolPreviewFrame.setObjectName(_fromUtf8("symbolPreviewFrame")) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.symbolPreviewFrame) self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.svgWidget = QSvgWidget(self.symbolPreviewFrame) self.svgWidget.setObjectName(_fromUtf8("svgWidget")) self.horizontalLayout_2.addWidget(self.svgWidget) self.horizontalLayout_8.addWidget(self.symbolPreviewFrame) self.svgPathEdit = QtGui.QLineEdit(self.symbolEntryFrame) self.svgPathEdit.setReadOnly(False) self.svgPathEdit.setObjectName(_fromUtf8("svgPathEdit")) self.horizontalLayout_8.addWidget(self.svgPathEdit) self.browseSymbolButton = QtGui.QPushButton(self.symbolEntryFrame) self.browseSymbolButton.setEnabled(True) self.browseSymbolButton.setAutoDefault(False) self.browseSymbolButton.setObjectName(_fromUtf8("browseSymbolButton")) self.horizontalLayout_8.addWidget(self.browseSymbolButton) self.verticalLayout_2.addLayout(self.horizontalLayout_8) spacerItem = QtGui.QSpacerItem(20, 18, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem) self.label_12 = QtGui.QLabel(self.symbolEntryFrame) self.label_12.setObjectName(_fromUtf8("label_12")) self.verticalLayout_2.addWidget(self.label_12) self.gridLayout_3 = QtGui.QGridLayout() self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.symbolNameLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolNameLabel.setEnabled(True) self.symbolNameLabel.setObjectName(_fromUtf8("symbolNameLabel")) self.gridLayout_3.addWidget(self.symbolNameLabel, 0, 0, 1, 1) self.symbolNameEntry = QtGui.QLineEdit(self.symbolEntryFrame) self.symbolNameEntry.setReadOnly(False) self.symbolNameEntry.setObjectName(_fromUtf8("symbolNameEntry")) self.gridLayout_3.addWidget(self.symbolNameEntry, 0, 1, 1, 1) self.symbolCategoryLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolCategoryLabel.setEnabled(True) self.symbolCategoryLabel.setObjectName( _fromUtf8("symbolCategoryLabel")) self.gridLayout_3.addWidget(self.symbolCategoryLabel, 1, 0, 1, 1) self.symbolWidthLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolWidthLabel.setEnabled(True) self.symbolWidthLabel.setObjectName(_fromUtf8("symbolWidthLabel")) self.gridLayout_3.addWidget(self.symbolWidthLabel, 3, 0, 1, 1) self.symbolWidthSpinner = QtGui.QSpinBox(self.symbolEntryFrame) self.symbolWidthSpinner.setEnabled(True) self.symbolWidthSpinner.setReadOnly(False) self.symbolWidthSpinner.setMinimum(1) self.symbolWidthSpinner.setObjectName(_fromUtf8("symbolWidthSpinner")) self.gridLayout_3.addWidget(self.symbolWidthSpinner, 3, 1, 1, 1) self.symbolDescriptionLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolDescriptionLabel.setEnabled(True) self.symbolDescriptionLabel.setObjectName( _fromUtf8("symbolDescriptionLabel")) self.gridLayout_3.addWidget(self.symbolDescriptionLabel, 4, 0, 1, 1) self.symbolDescriptionEntry = QtGui.QTextEdit(self.symbolEntryFrame) self.symbolDescriptionEntry.setReadOnly(False) self.symbolDescriptionEntry.setObjectName( _fromUtf8("symbolDescriptionEntry")) self.gridLayout_3.addWidget(self.symbolDescriptionEntry, 4, 1, 1, 1) self.categoryChooser = QtGui.QComboBox(self.symbolEntryFrame) self.categoryChooser.setObjectName(_fromUtf8("categoryChooser")) self.gridLayout_3.addWidget(self.categoryChooser, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout_3) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem1) self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.cancelOrDeleteButton = QtGui.QPushButton(self.symbolEntryFrame) self.cancelOrDeleteButton.setObjectName( _fromUtf8("cancelOrDeleteButton")) self.horizontalLayout_3.addWidget(self.cancelOrDeleteButton) self.addOrUpdateButton = QtGui.QPushButton(self.symbolEntryFrame) self.addOrUpdateButton.setObjectName(_fromUtf8("addOrUpdateButton")) self.horizontalLayout_3.addWidget(self.addOrUpdateButton) self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.verticalLayout_3.addLayout(self.verticalLayout_2) self.horizontalLayout.addWidget(self.symbolEntryFrame) spacerItem3 = QtGui.QSpacerItem(13, 13, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem3) self.verticalLayout_5.addLayout(self.horizontalLayout) self.horizontalLayout_6 = QtGui.QHBoxLayout() self.horizontalLayout_6.setSpacing(6) self.horizontalLayout_6.setSizeConstraint( QtGui.QLayout.SetDefaultConstraint) self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6")) spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_6.addItem(spacerItem4) self.pushButton_4 = QtGui.QPushButton(ManageKnittingSymbolDialog) self.pushButton_4.setAutoDefault(False) self.pushButton_4.setObjectName(_fromUtf8("pushButton_4")) self.horizontalLayout_6.addWidget(self.pushButton_4) self.verticalLayout_5.addLayout(self.horizontalLayout_6) self.symbolNameLabel.setBuddy(self.symbolNameEntry) self.symbolCategoryLabel.setBuddy(self.categoryChooser) self.symbolWidthLabel.setBuddy(self.symbolWidthSpinner) self.symbolDescriptionLabel.setBuddy(self.symbolDescriptionEntry) self.retranslateUi(ManageKnittingSymbolDialog) QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), ManageKnittingSymbolDialog.close) QtCore.QMetaObject.connectSlotsByName(ManageKnittingSymbolDialog) def retranslateUi(self, ManageKnittingSymbolDialog): ManageKnittingSymbolDialog.setWindowTitle( _translate("ManageKnittingSymbolDialog", "sconcho: Manage Custom Knitting Symbols", None)) self.label_7.setText( _translate( "ManageKnittingSymbolDialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Available Symbols</span></p></body></html>", None)) self.availableSymbolsWidget.headerItem().setText( 0, _translate("ManageKnittingSymbolDialog", "Category/Symbol", None)) self.addSymbolButton.setText( _translate("ManageKnittingSymbolDialog", "&Add New Symbol", None)) self.importSymbolsButton.setText( _translate("ManageKnittingSymbolDialog", "Import Symbols", None)) self.exportSymbolsButton.setText( _translate("ManageKnittingSymbolDialog", "Export Symbols", None)) self.label_4.setText( _translate( "ManageKnittingSymbolDialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">SVG Image</span></p></body></html>", None)) self.browseSymbolButton.setText( _translate("ManageKnittingSymbolDialog", "&Browse", None)) self.label_12.setText( _translate( "ManageKnittingSymbolDialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n" "p, li { white-space: pre-wrap; }\n" "</style></head><body style=\" font-family:\'Sans Serif\'; font-size:9pt; font-weight:400; font-style:normal;\">\n" "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span style=\" font-weight:600;\">Description</span></p></body></html>", None)) self.symbolNameLabel.setText( _translate("ManageKnittingSymbolDialog", "symbol &name", None)) self.symbolCategoryLabel.setText( _translate("ManageKnittingSymbolDialog", "symbol &category", None)) self.symbolWidthLabel.setText( _translate("ManageKnittingSymbolDialog", "symbol &width", None)) self.symbolDescriptionLabel.setText( _translate("ManageKnittingSymbolDialog", "symbol &description", None)) self.cancelOrDeleteButton.setText( _translate("ManageKnittingSymbolDialog", "Cancel", None)) self.addOrUpdateButton.setText( _translate("ManageKnittingSymbolDialog", "Add", None)) self.pushButton_4.setText( _translate("ManageKnittingSymbolDialog", "Close", None))
def __set_layout(self, surface_manager, character): """ Set layout of this widget """ main_layout = QHBoxLayout() left_layout = QVBoxLayout() right_layout = QVBoxLayout() left_top_layout = QHBoxLayout() left_bottom_layout = QVBoxLayout() icon_layout = QVBoxLayout() stat_layout = QGridLayout() self.body = QLabel() self.body.setText(str(character.body)) self.body.setObjectName('no_border') self.mind = QLabel() self.mind.setText(str(character.mind)) self.mind.setObjectName('no_border') self.finesse = QLabel() self.finesse.setText(str(character.finesse)) self.finesse.setObjectName('no_border') self.hp = QLabel() self.hp.setText('{0}/{1}'.format(character.hit_points, character.max_hp)) self.hp.setObjectName('no_border') self.mana = QLabel() self.mana.setText('0/0') self.mana.setObjectName('no_border') body_label = QLabel('Body:') body_label.setObjectName('no_border') mind_label = QLabel('Mind:') mind_label.setObjectName('no_border') finesse_label = QLabel('Finesse:') finesse_label.setObjectName('no_border') hp_label = QLabel('HP:') hp_label.setObjectName('no_border') mana_label = QLabel('Mana:') mana_label.setObjectName('no_border') stat_layout.addWidget(self.body, 0, 1) stat_layout.addWidget(body_label, 0, 0) stat_layout.addWidget(self.mind, 1, 1) stat_layout.addWidget(mind_label, 1, 0) stat_layout.addWidget(self.finesse, 2, 1) stat_layout.addWidget(finesse_label, 2, 0) stat_layout.addWidget(self.hp, 3, 1) stat_layout.addWidget(hp_label, 3, 0) stat_layout.addWidget(self.mana, 4, 1) stat_layout.addWidget(mana_label, 4, 0) self.character_icon = QSvgWidget(':strong.svg') self.character_icon.setMaximumSize(150, 150) self.character_icon.setMinimumSize(150, 150) icon_layout.addWidget(self.character_icon) skills_label = QLabel('Skills') skills_label.setObjectName('section_title') skills = ListView() right_layout.addWidget(skills_label) right_layout.addWidget(skills) effects_label = QLabel('Effects') effects_label.setObjectName('section_title') effects = ListView() for effect in character.get_effects(): effects.add_item(title = effect.title, description = effect.description, icon = surface_manager.get_icon(effect.icon)) left_bottom_layout.addWidget(effects_label) left_bottom_layout.addWidget(effects) left_top_layout.addLayout(icon_layout) left_top_layout.addLayout(stat_layout) left_layout.addLayout(left_top_layout) left_layout.addLayout(left_bottom_layout) main_layout.addLayout(left_layout) main_layout.addLayout(right_layout) self.setLayout(main_layout)
class CharacterInventoryWidget(QWidget): """ Widget to show inventory of a character .. versionadded:: 0.6 """ def __init__(self, surface_manager, character, config, parent): """ Default constructor """ super(CharacterInventoryWidget, self).__init__(parent) self.surface_manager = surface_manager self.character = character self.config = config self.items = [] self.head_slot = None self.boots_slot = None self.shield_slot = None self.weapon_slot = None self.character_icon = None self.gloves_slot = None self.ring_slot = None self.arrows_slot = None self.necklace_slot = None self.belt_slot = None self.armour_slot = None self.__set_layout(surface_manager, character, parent) self.keymap, self.move_keys = self._construct_keymaps(config) ItemFocused = pyqtSignal(Item, name='ItemFocused') ItemActionA = pyqtSignal(Item, name='ItemActionA') ItemActionB = pyqtSignal(Item, name='ItemActionB') ItemActionX = pyqtSignal(Item, name='ItemActionX') ItemActionY = pyqtSignal(Item, name='ItemActionY') def _construct_keymaps(self, config): """ Construct keymaps from configuration :param config: controls configuration :type config: ControlsConfiguration :returns: keymap for widget and move keys :rtype: {}, {} .. versionadded:: 0.8 """ move_keys = {} keymap = {} for key in config.move_down_left: move_keys[key] = 1 keymap[key] = self._move for key in config.move_down: move_keys[key] = 1 keymap[key] = self._move for key in config.move_down_right: move_keys[key] = 1 keymap[key] = self._move for key in config.move_left: move_keys[key] = -1 keymap[key] = self._move for key in config.move_right: move_keys[key] = 1 keymap[key] = self._move for key in config.move_up_left: move_keys[key] = -1 keymap[key] = self._move for key in config.move_up: move_keys[key] = -1 keymap[key] = self._move for key in config.move_up_right: move_keys[key] = -1 keymap[key] = self._move for key in config.action_a: keymap[key] = self._action for key in config.action_b: keymap[key] = self._action return keymap, move_keys def __set_layout(self, surface_manager, character, parent): """ Set layout of this widget """ main_layout = QHBoxLayout() left_side = QVBoxLayout() self.ring_slot = ItemGlyph(None, surface_manager, self, QPixmap(':ring.png')) self.items.append(self.ring_slot) self.weapon_slot = ItemGlyph(None, surface_manager, self, QPixmap(':inventory_sword.png')) self.items.append(self.weapon_slot) self.gloves_slot = ItemGlyph(None, surface_manager, self, QPixmap(':mailed-fist.png')) self.items.append(self.gloves_slot) left_side.addStretch() left_side.addWidget(self.ring_slot) left_side.addWidget(self.weapon_slot) left_side.addWidget(self.gloves_slot) left_side.addStretch() middle = QVBoxLayout() middle_top = QHBoxLayout() self.head_slot = ItemGlyph(None, surface_manager, self, QPixmap(':helm.png')) self.items.append(self.head_slot) self.necklace_slot = ItemGlyph(None, surface_manager, self, QPixmap(':necklace.png')) self.items.append(self.necklace_slot) middle_top.addStretch() middle_top.addWidget(self.head_slot) middle_top.addWidget(self.necklace_slot) middle_top.addStretch() middle_middle = QHBoxLayout() self.character_icon = QSvgWidget(':strong.svg') self.character_icon.setMaximumSize(150, 150) self.character_icon.setMinimumSize(150, 150) middle_middle.addWidget(self.character_icon) middle_bottom = QHBoxLayout() self.boots_slot = ItemGlyph(None, surface_manager, self, QPixmap(':boots.png')) self.items.append(self.boots_slot) self.belt_slot = ItemGlyph(None, surface_manager, self, QPixmap(':belts.png')) self.items.append(self.belt_slot) middle_bottom.addStretch() middle_bottom.addWidget(self.boots_slot) middle_bottom.addWidget(self.belt_slot) middle_bottom.addStretch() middle.addLayout(middle_top) middle.addLayout(middle_middle) middle.addLayout(middle_bottom) right_side = QVBoxLayout() self.arrows_slot = ItemGlyph(None, surface_manager, self, QPixmap(':arrow-cluster.png')) self.items.append(self.arrows_slot) self.shield_slot = ItemGlyph(None, surface_manager, self, QPixmap(':shield.png')) self.items.append(self.shield_slot) self.armour_slot = ItemGlyph(None, surface_manager, self, QPixmap(':breastplate.png')) self.items.append(self.armour_slot) right_side.addStretch() right_side.addWidget(self.arrows_slot) right_side.addWidget(self.shield_slot) right_side.addWidget(self.armour_slot) right_side.addStretch() main_layout.addLayout(left_side) main_layout.addLayout(middle) main_layout.addLayout(right_side) self.setLayout(main_layout) def show_character(self): """ Show character """ self.weapon_slot.set_item(self.character.inventory.weapon) self.armour_slot.set_item(self.character.inventory.armour) self.arrows_slot.set_item(self.character.inventory.projectiles) self.head_slot.set_item(self.character.inventory.helm) self.boots_slot.set_item(self.character.inventory.boots) self.shield_slot.set_item(self.character.inventory.shield) self.gloves_slot.set_item(self.character.inventory.gloves) self.ring_slot.set_item(self.character.inventory.ring) self.necklace_slot.set_item(self.character.inventory.necklace) self.belt_slot.set_item(self.character.inventory.belt) def _move(self, key): """ Handle move keys .. versionadded:: 0.8 """ current = [x for x in self.items if x.display.objectName() == 'active_inventorybox'][0] index = self.items.index(current) new_index = index + self.move_keys[key] if new_index < len(self.items) and new_index >= 0: new = self.items[new_index] new.setFocus(Qt.OtherFocusReason) else: if new_index < 0: self.focusPreviousChild() else: self.focusNextChild() def _action(self, key): """ Handle action keys .. versionadded:: 0.8 """ item = [x for x in self.items if x.display.objectName() == 'active_inventorybox'][0].item if item is not None: if key in self.config.action_a: self.ItemActionA.emit(item) elif key in self.config.action_b: self.ItemActionB.emit(item) def keyPressEvent(self, event): #pylint: disable-msg=C0103 """ Handle keyboard events """ key = event.key() if key in self.keymap: self.keymap[key](key) else: super(CharacterInventoryWidget, self).keyPressEvent(event) def focus_on_first_item(self): """ Focus on the first item """ self.items[0].setFocus() def focus_on_last_item(self): """ Focus on the last item """ self.items[-1].setFocus()
class PreviewBrowser(QWidget): """A Preview Browser for recent/premade scheme selection. """ # Emitted when the current previewed item changes currentIndexChanged = Signal(int) # Emitted when an item is double clicked in the preview list. activated = Signal(int) def __init__(self, *args): QWidget.__init__(self, *args) self.__model = None self.__currentIndex = -1 self.__template = DESCRIPTION_TEMPLATE self.__setupUi() def __setupUi(self): vlayout = QVBoxLayout() vlayout.setContentsMargins(0, 0, 0, 0) top_layout = QHBoxLayout() top_layout.setContentsMargins(12, 12, 12, 12) # Top row with full text description and a large preview # image. self.__label = QLabel(self, objectName="description-label", wordWrap=True, alignment=Qt.AlignTop | Qt.AlignLeft) self.__label.setWordWrap(True) self.__label.setFixedSize(220, PREVIEW_SIZE[1]) self.__image = QSvgWidget(self, objectName="preview-image") self.__image.setFixedSize(*PREVIEW_SIZE) self.__imageFrame = DropShadowFrame(self) self.__imageFrame.setWidget(self.__image) # Path text below the description and image path_layout = QHBoxLayout() path_layout.setContentsMargins(12, 0, 12, 0) path_label = QLabel("<b>{0!s}</b>".format(self.tr("Path:")), self, objectName="path-label") self.__path = TextLabel(self, objectName="path-text") path_layout.addWidget(path_label) path_layout.addWidget(self.__path) self.__selectAction = \ QAction(self.tr("Select"), self, objectName="select-action", ) top_layout.addWidget(self.__label, 1, alignment=Qt.AlignTop | Qt.AlignLeft) top_layout.addWidget(self.__image, 1, alignment=Qt.AlignTop | Qt.AlignRight) vlayout.addLayout(top_layout) vlayout.addLayout(path_layout) # An list view with small preview icons. self.__previewList = LinearIconView(objectName="preview-list-view") self.__previewList.doubleClicked.connect(self.__onDoubleClicked) vlayout.addWidget(self.__previewList) self.setLayout(vlayout) def setModel(self, model): """Set the item model for preview. """ if self.__model != model: if self.__model: s_model = self.__previewList.selectionModel() s_model.selectionChanged.disconnect(self.__onSelectionChanged) self.__model.dataChanged.disconnect(self.__onDataChanged) self.__model = model self.__previewList.setModel(model) if model: s_model = self.__previewList.selectionModel() s_model.selectionChanged.connect(self.__onSelectionChanged) self.__model.dataChanged.connect(self.__onDataChanged) if model and model.rowCount(): self.setCurrentIndex(0) def model(self): """Return the item model. """ return self.__model def setPreviewDelegate(self, delegate): """Set the delegate to render the preview images. """ raise NotImplementedError def setDescriptionTemplate(self, template): self.__template = template self.__update() def setCurrentIndex(self, index): """Set the selected preview item index. """ if self.__model is not None and self.__model.rowCount(): index = min(index, self.__model.rowCount() - 1) index = self.__model.index(index, 0) sel_model = self.__previewList.selectionModel() # This emits selectionChanged signal and triggers # __onSelectionChanged, currentIndex is updated there. sel_model.select(index, sel_model.ClearAndSelect) elif self.__currentIndex != -1: self.__currentIndex = -1 self.__update() self.currentIndexChanged.emit(-1) def currentIndex(self): """Return the current selected index. """ return self.__currentIndex def __onSelectionChanged(self, *args): """Selected item in the preview list has changed. Set the new description and large preview image. """ rows = self.__previewList.selectedIndexes() if rows: index = rows[0] self.__currentIndex = index.row() else: index = QModelIndex() self.__currentIndex = -1 self.__update() self.currentIndexChanged.emit(self.__currentIndex) def __onDataChanged(self, topleft, bottomRight): """Data changed, update the preview if current index in the changed range. """ if self.__currentIndex <= topleft.row() and \ self.__currentIndex >= bottomRight.row(): self.__update() def __onDoubleClicked(self, index): """Double click on an item in the preview item list. """ self.activated.emit(index.row()) def __update(self): """Update the current description. """ if self.__currentIndex != -1: index = self.model().index(self.__currentIndex, 0) else: index = QModelIndex() if not index.isValid(): description = "" name = "" path = "" svg = NO_PREVIEW_SVG else: description = unicode(index.data(Qt.WhatsThisRole).toString()) if not description: description = "No description." description = escape(description) description = description.replace("\n", "<br/>") name = unicode(index.data(Qt.DisplayRole).toString()) if not name: name = "Untitled" name = escape(name) path = unicode(index.data(Qt.StatusTipRole).toString()) svg = unicode(index.data(previewmodel.ThumbnailSVGRole).toString()) desc_text = self.__template.format(description=description, name=name) self.__label.setText(desc_text) self.__path.setText(path) if not svg: svg = NO_PREVIEW_SVG if svg: self.__image.load(QByteArray(svg.encode("utf-8")))
class MainWindow(QWidget): """ Create a surface for the chessboard. """ def __init__(self, board_configuration=None): """ Initialize the chessboard. """ super().__init__() self.setWindowTitle("Chess GUI") self.setGeometry(300, 300, 800, 800) self.widgetSvg = QSvgWidget(parent=self) self.widgetSvg.setGeometry(10, 10, 600, 600) self.boardSize = min(self.widgetSvg.width(), self.widgetSvg.height()) self.coordinates = True self.margin = 0.05 * self.boardSize if self.coordinates else 0 self.squareSize = (self.boardSize - 2 * self.margin) / 8.0 self.pieceToMove = [None, None] self.pieceToInsert = [None, None] self.board = chess.Board() if(board_configuration): self.board.set_piece_map(board_configuration) self.drawBoard() @pyqtSlot(QWidget) def mousePressEvent(self, event): """ Handle left mouse clicks and enable moving chess pieces by clicking on a chess piece and then the target square. Moves must be made according to the rules of chess because illegal moves are suppressed. """ if event.x() <= self.boardSize and event.y() <= self.boardSize: # if event.buttons() == Qt.RightButton: if self.margin < event.x() < self.boardSize - self.margin and self.margin < event.y() < self.boardSize - self.margin: file = int((event.x() - self.margin) / self.squareSize) rank = 7 - int((event.y() - self.margin) / self.squareSize) square = chess.square(file, rank) piece = self.board.piece_at(square) coordinates = "{}{}".format(chr(file + 97), str(rank + 1)) if self.pieceToInsert[0] is not None and self.pieceToInsert[1] is not None: print("INSERTING.....") self.board.set_piece_at(square, chess.Piece(self.pieceToInsert[0], self.pieceToInsert[1])) self.pieceToInsert = [None, None] elif self.pieceToMove[0] is not None: #move = chess.Move.from_uci("{}{}".format(self.pieceToMove[1], coordinates)) # if move in self.board.legal_moves: self.board.set_piece_at(square, self.pieceToMove[0]) self.board.set_piece_at(self.pieceToMove[1], None) # self.board.push(move) piece = None coordinates = None self.pieceToMove = [piece, square] self.drawBoard() @pyqtSlot(QWidget) def keyPressEvent(self, event): """ Handle left mouse clicks and enable moving chess pieces by clicking on a chess piece and then the target square. Moves must be made according to the rules of chess because illegal moves are suppressed. """ pressed = event.key() print(pressed) if(pressed == 81): print("You want to insert a queen -- press q") self.pieceToInsert[0] = piece_name_index['queen'] elif(pressed == 75): print("You want to insert a king -- press k") self.pieceToInsert[0] = piece_name_index['king'] elif(pressed == 78): print("You want to insert a knight -- press n") self.pieceToInsert[0] = piece_name_index['knight'] elif(pressed == 80): print("You want to insert a pawn -- press p") self.pieceToInsert[0] = piece_name_index['pawn'] elif(pressed == 66): print("You want to insert a bishop -- press b") self.pieceToInsert[0] = piece_name_index['bishop'] elif(pressed == 82): print("You want to insert a rook -- press r") self.pieceToInsert[0] = piece_name_index['rook'] elif(pressed == 49): print("You want white") if(self.pieceToInsert[0]): self.pieceToInsert[1] = True elif(pressed == 48): print("You want black") if(self.pieceToInsert[0]): self.pieceToInsert[1] = False elif(pressed == 16777220): print("You are finished with the GUI") self.close() def drawBoard(self): global analyzed_board """ Draw a chessboard with the starting position and then redraw it for every new move. """ self.boardSvg = self.board._repr_svg_().encode("UTF-8") self.drawBoardSvg = self.widgetSvg.load(self.boardSvg) analyzed_board = self.board.copy() return self.drawBoardSvg def show(self): super().show() return self.board
class CharacterInventoryWidget(QWidget): """ Widget to show inventory of a character .. versionadded:: 0.6 """ def __init__(self, surface_manager, character, config, parent): """ Default constructor """ super(CharacterInventoryWidget, self).__init__(parent) self.surface_manager = surface_manager self.character = character self.config = config self.items = [] self.head_slot = None self.boots_slot = None self.shield_slot = None self.weapon_slot = None self.character_icon = None self.gloves_slot = None self.ring_slot = None self.arrows_slot = None self.necklace_slot = None self.belt_slot = None self.armour_slot = None self.__set_layout(surface_manager, character, parent) self.keymap, self.move_keys = self._construct_keymaps(config) ItemFocused = pyqtSignal(Item, name='ItemFocused') ItemActionA = pyqtSignal(Item, name='ItemActionA') ItemActionB = pyqtSignal(Item, name='ItemActionB') ItemActionX = pyqtSignal(Item, name='ItemActionX') ItemActionY = pyqtSignal(Item, name='ItemActionY') def _construct_keymaps(self, config): """ Construct keymaps from configuration :param config: controls configuration :type config: ControlsConfiguration :returns: keymap for widget and move keys :rtype: {}, {} .. versionadded:: 0.8 """ move_keys = {} keymap = {} for key in config.move_down_left: move_keys[key] = 1 keymap[key] = self._move for key in config.move_down: move_keys[key] = 1 keymap[key] = self._move for key in config.move_down_right: move_keys[key] = 1 keymap[key] = self._move for key in config.move_left: move_keys[key] = -1 keymap[key] = self._move for key in config.move_right: move_keys[key] = 1 keymap[key] = self._move for key in config.move_up_left: move_keys[key] = -1 keymap[key] = self._move for key in config.move_up: move_keys[key] = -1 keymap[key] = self._move for key in config.move_up_right: move_keys[key] = -1 keymap[key] = self._move for key in config.action_a: keymap[key] = self._action for key in config.action_b: keymap[key] = self._action return keymap, move_keys def __set_layout(self, surface_manager, character, parent): """ Set layout of this widget """ main_layout = QHBoxLayout() left_side = QVBoxLayout() self.ring_slot = ItemGlyph(None, surface_manager, self, QPixmap(':ring.png')) self.items.append(self.ring_slot) self.weapon_slot = ItemGlyph(None, surface_manager, self, QPixmap(':inventory_sword.png')) self.items.append(self.weapon_slot) self.gloves_slot = ItemGlyph(None, surface_manager, self, QPixmap(':mailed-fist.png')) self.items.append(self.gloves_slot) left_side.addStretch() left_side.addWidget(self.ring_slot) left_side.addWidget(self.weapon_slot) left_side.addWidget(self.gloves_slot) left_side.addStretch() middle = QVBoxLayout() middle_top = QHBoxLayout() self.head_slot = ItemGlyph(None, surface_manager, self, QPixmap(':helm.png')) self.items.append(self.head_slot) self.necklace_slot = ItemGlyph(None, surface_manager, self, QPixmap(':necklace.png')) self.items.append(self.necklace_slot) middle_top.addStretch() middle_top.addWidget(self.head_slot) middle_top.addWidget(self.necklace_slot) middle_top.addStretch() middle_middle = QHBoxLayout() self.character_icon = QSvgWidget(':strong.svg') self.character_icon.setMaximumSize(150, 150) self.character_icon.setMinimumSize(150, 150) middle_middle.addWidget(self.character_icon) middle_bottom = QHBoxLayout() self.boots_slot = ItemGlyph(None, surface_manager, self, QPixmap(':boots.png')) self.items.append(self.boots_slot) self.belt_slot = ItemGlyph(None, surface_manager, self, QPixmap(':belts.png')) self.items.append(self.belt_slot) middle_bottom.addStretch() middle_bottom.addWidget(self.boots_slot) middle_bottom.addWidget(self.belt_slot) middle_bottom.addStretch() middle.addLayout(middle_top) middle.addLayout(middle_middle) middle.addLayout(middle_bottom) right_side = QVBoxLayout() self.arrows_slot = ItemGlyph(None, surface_manager, self, QPixmap(':arrow-cluster.png')) self.items.append(self.arrows_slot) self.shield_slot = ItemGlyph(None, surface_manager, self, QPixmap(':shield.png')) self.items.append(self.shield_slot) self.armour_slot = ItemGlyph(None, surface_manager, self, QPixmap(':breastplate.png')) self.items.append(self.armour_slot) right_side.addStretch() right_side.addWidget(self.arrows_slot) right_side.addWidget(self.shield_slot) right_side.addWidget(self.armour_slot) right_side.addStretch() main_layout.addLayout(left_side) main_layout.addLayout(middle) main_layout.addLayout(right_side) self.setLayout(main_layout) def show_character(self): """ Show character """ self.weapon_slot.set_item(self.character.inventory.weapon) self.armour_slot.set_item(self.character.inventory.armour) self.arrows_slot.set_item(self.character.inventory.projectiles) self.head_slot.set_item(self.character.inventory.helm) self.boots_slot.set_item(self.character.inventory.boots) self.shield_slot.set_item(self.character.inventory.shield) self.gloves_slot.set_item(self.character.inventory.gloves) self.ring_slot.set_item(self.character.inventory.ring) self.necklace_slot.set_item(self.character.inventory.necklace) self.belt_slot.set_item(self.character.inventory.belt) def _move(self, key): """ Handle move keys .. versionadded:: 0.8 """ current = [ x for x in self.items if x.display.objectName() == 'active_inventorybox' ][0] index = self.items.index(current) new_index = index + self.move_keys[key] if new_index < len(self.items) and new_index >= 0: new = self.items[new_index] new.setFocus(Qt.OtherFocusReason) else: if new_index < 0: self.focusPreviousChild() else: self.focusNextChild() def _action(self, key): """ Handle action keys .. versionadded:: 0.8 """ item = [ x for x in self.items if x.display.objectName() == 'active_inventorybox' ][0].item if item is not None: if key in self.config.action_a: self.ItemActionA.emit(item) elif key in self.config.action_b: self.ItemActionB.emit(item) def keyPressEvent(self, event): #pylint: disable-msg=C0103 """ Handle keyboard events """ key = event.key() if key in self.keymap: self.keymap[key](key) else: super(CharacterInventoryWidget, self).keyPressEvent(event) def focus_on_first_item(self): """ Focus on the first item """ self.items[0].setFocus() def focus_on_last_item(self): """ Focus on the last item """ self.items[-1].setFocus()
def setupUi(self, ManageKnittingSymbolDialog): ManageKnittingSymbolDialog.setObjectName( _fromUtf8("ManageKnittingSymbolDialog")) ManageKnittingSymbolDialog.resize(753, 660) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(_fromUtf8("../icons/sconcho_icon.png")), QtGui.QIcon.Normal, QtGui.QIcon.Off) ManageKnittingSymbolDialog.setWindowIcon(icon) self.verticalLayout_5 = QtGui.QVBoxLayout(ManageKnittingSymbolDialog) self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5")) self.horizontalLayout = QtGui.QHBoxLayout() self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) self.frame = QtGui.QFrame(ManageKnittingSymbolDialog) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Preferred) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.frame.sizePolicy().hasHeightForWidth()) self.frame.setSizePolicy(sizePolicy) self.frame.setFrameShape(QtGui.QFrame.StyledPanel) self.frame.setFrameShadow(QtGui.QFrame.Raised) self.frame.setObjectName(_fromUtf8("frame")) self.verticalLayout_4 = QtGui.QVBoxLayout(self.frame) self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4")) self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setSizeConstraint(QtGui.QLayout.SetMinimumSize) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.label_7 = QtGui.QLabel(self.frame) self.label_7.setObjectName(_fromUtf8("label_7")) self.verticalLayout.addWidget(self.label_7) self.availableSymbolsWidget = QtGui.QTreeWidget(self.frame) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( self.availableSymbolsWidget.sizePolicy().hasHeightForWidth()) self.availableSymbolsWidget.setSizePolicy(sizePolicy) self.availableSymbolsWidget.setColumnCount(1) self.availableSymbolsWidget.setObjectName( _fromUtf8("availableSymbolsWidget")) self.verticalLayout.addWidget(self.availableSymbolsWidget) self.addSymbolButton = QtGui.QPushButton(self.frame) self.addSymbolButton.setObjectName(_fromUtf8("addSymbolButton")) self.verticalLayout.addWidget(self.addSymbolButton) self.line = QtGui.QFrame(self.frame) self.line.setFrameShape(QtGui.QFrame.HLine) self.line.setFrameShadow(QtGui.QFrame.Sunken) self.line.setObjectName(_fromUtf8("line")) self.verticalLayout.addWidget(self.line) self.importSymbolsButton = QtGui.QPushButton(self.frame) self.importSymbolsButton.setObjectName( _fromUtf8("importSymbolsButton")) self.verticalLayout.addWidget(self.importSymbolsButton) self.exportSymbolsButton = QtGui.QPushButton(self.frame) self.exportSymbolsButton.setObjectName( _fromUtf8("exportSymbolsButton")) self.verticalLayout.addWidget(self.exportSymbolsButton) self.verticalLayout_4.addLayout(self.verticalLayout) self.horizontalLayout.addWidget(self.frame) self.symbolEntryFrame = QtGui.QFrame(ManageKnittingSymbolDialog) self.symbolEntryFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolEntryFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolEntryFrame.setObjectName(_fromUtf8("symbolEntryFrame")) self.verticalLayout_3 = QtGui.QVBoxLayout(self.symbolEntryFrame) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.verticalLayout_2 = QtGui.QVBoxLayout() self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.label_4 = QtGui.QLabel(self.symbolEntryFrame) self.label_4.setObjectName(_fromUtf8("label_4")) self.verticalLayout_2.addWidget(self.label_4) self.horizontalLayout_8 = QtGui.QHBoxLayout() self.horizontalLayout_8.setObjectName(_fromUtf8("horizontalLayout_8")) self.symbolPreviewFrame = QtGui.QFrame(self.symbolEntryFrame) self.symbolPreviewFrame.setMinimumSize(QtCore.QSize(100, 60)) self.symbolPreviewFrame.setFrameShape(QtGui.QFrame.StyledPanel) self.symbolPreviewFrame.setFrameShadow(QtGui.QFrame.Raised) self.symbolPreviewFrame.setObjectName(_fromUtf8("symbolPreviewFrame")) self.horizontalLayout_2 = QtGui.QHBoxLayout(self.symbolPreviewFrame) self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2")) self.svgWidget = QSvgWidget(self.symbolPreviewFrame) self.svgWidget.setObjectName(_fromUtf8("svgWidget")) self.horizontalLayout_2.addWidget(self.svgWidget) self.horizontalLayout_8.addWidget(self.symbolPreviewFrame) self.svgPathEdit = QtGui.QLineEdit(self.symbolEntryFrame) self.svgPathEdit.setReadOnly(False) self.svgPathEdit.setObjectName(_fromUtf8("svgPathEdit")) self.horizontalLayout_8.addWidget(self.svgPathEdit) self.browseSymbolButton = QtGui.QPushButton(self.symbolEntryFrame) self.browseSymbolButton.setEnabled(True) self.browseSymbolButton.setAutoDefault(False) self.browseSymbolButton.setObjectName(_fromUtf8("browseSymbolButton")) self.horizontalLayout_8.addWidget(self.browseSymbolButton) self.verticalLayout_2.addLayout(self.horizontalLayout_8) spacerItem = QtGui.QSpacerItem(20, 18, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem) self.label_12 = QtGui.QLabel(self.symbolEntryFrame) self.label_12.setObjectName(_fromUtf8("label_12")) self.verticalLayout_2.addWidget(self.label_12) self.gridLayout_3 = QtGui.QGridLayout() self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3")) self.symbolNameLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolNameLabel.setEnabled(True) self.symbolNameLabel.setObjectName(_fromUtf8("symbolNameLabel")) self.gridLayout_3.addWidget(self.symbolNameLabel, 0, 0, 1, 1) self.symbolNameEntry = QtGui.QLineEdit(self.symbolEntryFrame) self.symbolNameEntry.setReadOnly(False) self.symbolNameEntry.setObjectName(_fromUtf8("symbolNameEntry")) self.gridLayout_3.addWidget(self.symbolNameEntry, 0, 1, 1, 1) self.symbolCategoryLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolCategoryLabel.setEnabled(True) self.symbolCategoryLabel.setObjectName( _fromUtf8("symbolCategoryLabel")) self.gridLayout_3.addWidget(self.symbolCategoryLabel, 1, 0, 1, 1) self.symbolWidthLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolWidthLabel.setEnabled(True) self.symbolWidthLabel.setObjectName(_fromUtf8("symbolWidthLabel")) self.gridLayout_3.addWidget(self.symbolWidthLabel, 3, 0, 1, 1) self.symbolWidthSpinner = QtGui.QSpinBox(self.symbolEntryFrame) self.symbolWidthSpinner.setEnabled(True) self.symbolWidthSpinner.setReadOnly(False) self.symbolWidthSpinner.setMinimum(1) self.symbolWidthSpinner.setObjectName(_fromUtf8("symbolWidthSpinner")) self.gridLayout_3.addWidget(self.symbolWidthSpinner, 3, 1, 1, 1) self.symbolDescriptionLabel = QtGui.QLabel(self.symbolEntryFrame) self.symbolDescriptionLabel.setEnabled(True) self.symbolDescriptionLabel.setObjectName( _fromUtf8("symbolDescriptionLabel")) self.gridLayout_3.addWidget(self.symbolDescriptionLabel, 4, 0, 1, 1) self.symbolDescriptionEntry = QtGui.QTextEdit(self.symbolEntryFrame) self.symbolDescriptionEntry.setReadOnly(False) self.symbolDescriptionEntry.setObjectName( _fromUtf8("symbolDescriptionEntry")) self.gridLayout_3.addWidget(self.symbolDescriptionEntry, 4, 1, 1, 1) self.categoryChooser = QtGui.QComboBox(self.symbolEntryFrame) self.categoryChooser.setObjectName(_fromUtf8("categoryChooser")) self.gridLayout_3.addWidget(self.categoryChooser, 1, 1, 1, 1) self.verticalLayout_2.addLayout(self.gridLayout_3) spacerItem1 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.verticalLayout_2.addItem(spacerItem1) self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName(_fromUtf8("horizontalLayout_3")) spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_3.addItem(spacerItem2) self.cancelOrDeleteButton = QtGui.QPushButton(self.symbolEntryFrame) self.cancelOrDeleteButton.setObjectName( _fromUtf8("cancelOrDeleteButton")) self.horizontalLayout_3.addWidget(self.cancelOrDeleteButton) self.addOrUpdateButton = QtGui.QPushButton(self.symbolEntryFrame) self.addOrUpdateButton.setObjectName(_fromUtf8("addOrUpdateButton")) self.horizontalLayout_3.addWidget(self.addOrUpdateButton) self.verticalLayout_2.addLayout(self.horizontalLayout_3) self.verticalLayout_3.addLayout(self.verticalLayout_2) self.horizontalLayout.addWidget(self.symbolEntryFrame) spacerItem3 = QtGui.QSpacerItem(13, 13, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout.addItem(spacerItem3) self.verticalLayout_5.addLayout(self.horizontalLayout) self.horizontalLayout_6 = QtGui.QHBoxLayout() self.horizontalLayout_6.setSpacing(6) self.horizontalLayout_6.setSizeConstraint( QtGui.QLayout.SetDefaultConstraint) self.horizontalLayout_6.setObjectName(_fromUtf8("horizontalLayout_6")) spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.horizontalLayout_6.addItem(spacerItem4) self.pushButton_4 = QtGui.QPushButton(ManageKnittingSymbolDialog) self.pushButton_4.setAutoDefault(False) self.pushButton_4.setObjectName(_fromUtf8("pushButton_4")) self.horizontalLayout_6.addWidget(self.pushButton_4) self.verticalLayout_5.addLayout(self.horizontalLayout_6) self.symbolNameLabel.setBuddy(self.symbolNameEntry) self.symbolCategoryLabel.setBuddy(self.categoryChooser) self.symbolWidthLabel.setBuddy(self.symbolWidthSpinner) self.symbolDescriptionLabel.setBuddy(self.symbolDescriptionEntry) self.retranslateUi(ManageKnittingSymbolDialog) QtCore.QObject.connect(self.pushButton_4, QtCore.SIGNAL(_fromUtf8("clicked()")), ManageKnittingSymbolDialog.close) QtCore.QMetaObject.connectSlotsByName(ManageKnittingSymbolDialog)
class RadioWidget(QtGui.QWidget): currentFrequency = 88.1 scanInterval = 0.5 scanDirection = "none" scanTimer = None playing = False radioManager = None buttonDefaultStyle = "border: 2px solid #000;" buttonPressedStyle = "border: 2px solid #fff;" presetFrameStyle = "border: 2px solid #7f7f7f; border-radius: 10px; margin:10px; " presetFrameSelectedStyle = "border: none; background-color: #fff200; border-radius: 10px; margin:10px; " presetContentsStyle = "border: none; color:#fff" presetContentsSelectedStyle = "border: none; color:#000" settingPreset = False def __init__(self, parent): super(RadioWidget, self).__init__(parent) self.resize(320, 240) freqFont = QtGui.QFont() freqFont.setPointSize(35) self.frequencyDisplay = QtGui.QLCDNumber(self) self.frequencyDisplay.setGeometry(QtCore.QRect(90, 15, 131, 51)) self.frequencyDisplay.setFont(freqFont) self.frequencyDisplay.setStyleSheet('color: white') self.frequencyDisplay.setFrameShape(QtGui.QFrame.NoFrame) self.updateRadioFrequency() self.slideUpFrame = QFrame(self) self.slideUpFrame.setGeometry(QtCore.QRect(230, 15, 50, 50)) self.slideUpFrame.setFrameShape(QtGui.QFrame.Box) self.slideUpFrame.setFrameShadow(QtGui.QFrame.Plain) self.slideUpFrame.setStyleSheet(self.buttonDefaultStyle) self.slideUpButton = QSvgWidget("icons/forward3.svg", self.slideUpFrame) self.slideUpButton.setGeometry(QtCore.QRect(5, 5, 40, 40)) pressable(self.slideUpButton).connect(self.doFreqUpPressed) self.slideDownFrame = QFrame(self) self.slideDownFrame.setGeometry(QtCore.QRect(50, 15, 50, 50)) self.slideDownFrame.setFrameShape(QtGui.QFrame.Box) self.slideDownFrame.setFrameShadow(QtGui.QFrame.Plain) self.slideDownFrame.setStyleSheet(self.buttonDefaultStyle) self.slideDownButton = QSvgWidget("icons/backward2.svg", self.slideDownFrame) self.slideDownButton.setGeometry(QtCore.QRect(0, 5, 40, 40)) pressable(self.slideDownButton).connect(self.doFreqDownPressed) self.horizontalLayoutWidget = QtGui.QWidget(self) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(10, 100, 300, 80)) self.horizontalLayout = QtGui.QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout.setAlignment(self.horizontalLayoutWidget, QtCore.Qt.AlignCenter) self.horizontalLayout.setMargin(0) QtCore.QMetaObject.connectSlotsByName(self) def fillPresets(self, presets, selected=False): self.settingPreset = selected print("Filling Radio presets") self.clearPresets() font = QtGui.QFont() font.setPointSize(18) self.changingPreset = None for x in range(0, len(presets)): pre = presets[x] presetButton = QFrame() presetButton.setFrameShape(QtGui.QFrame.Box) if (selected == True): presetButton.setStyleSheet(self.presetFrameSelectedStyle) else: presetButton.setStyleSheet(self.presetFrameStyle) presetButton.freq = pre.frequency presetButton.preID = pre.id releaseableSender(presetButton).connect(self.presetSelected) presetDisplay = QtGui.QLabel(presetButton) presetDisplay.setGeometry(QtCore.QRect(5, 0, 90, 80)) presetDisplay.setAlignment(QtCore.Qt.AlignCenter) if (selected == True): presetDisplay.setStyleSheet(self.presetContentsSelectedStyle) else: presetDisplay.setStyleSheet(self.presetContentsStyle) presetDisplay.setFont(font) presetDisplay.setText(str(pre.frequency)) self.horizontalLayout.addWidget(presetButton) def presetSelected(self, obj): if (self.settingPreset): self.emit(QtCore.SIGNAL('presetChanged'), [obj.preID, self.currentFrequency]) else: print("preset selected: " + str(obj.freq)) self.currentFrequency = float(obj.freq) self.updateRadioFrequency() self.emit(QtCore.SIGNAL('frequencyChanged'), self.currentFrequency) def clearPresets(self): for i in reversed(range(self.horizontalLayout.count())): self.horizontalLayout.itemAt(i).widget().deleteLater() def updateRadioFrequency(self): self.frequencyDisplay.display("{0:.1f}".format(self.currentFrequency)) newFreq = str(self.frequencyDisplay.value()) def isFreqValid(self, freq): if (freq >= 88.1 and freq <= 108.1): return True else: return False def doFreqDownPressed(self): self.scanDirection = "down" self.doChangeFrequency() def doFreqUpPressed(self): self.scanDirection = "up" self.doChangeFrequency() def doChangeFrequency(self): t = Thread(target=self.changeFrequency, args=(self, )) t.start() def changeFrequency(self, parent): freq = parent.currentFrequency if (self.scanDirection == "down"): freq = freq - 0.2 elif (self.scanDirection == "up"): freq = freq + 0.2 if (self.isFreqValid(freq)): parent.currentFrequency = freq parent.updateRadioFrequency()
import sys from PyQt4.QtGui import * from PyQt4 import QtCore, QtGui from PyQt4.QtSvg import QSvgWidget #from PyQt4.QtGui import QApplication, QGraphicsScene, QGraphicsView #from PyQt4.QtWebKit import QGraphicsWebView app_created = False app = QtCore.QCoreApplication.instance() if app is None: app = QtGui.QApplication(sys.argv) app_created = True app.references = set() widget = QSvgWidget("circle_star.svg") widget.resize(500, 500) widget.setWindowTitle("Hello SVG!") app.references.add(widget) widget.show() if app_created: app.exec_()