Python PyQt5.QtGui 模块,Qpixmap() 实例源码
我们从Python开源项目中,提取了以下48个代码示例,用于说明如何使用PyQt5.QtGui.Qpixmap()。
def __init__(self, ebeveyn=None):
super(Son, self).__init__(ebeveyn)
self.e = ebeveyn
self.kapanacak_mi =False
kutu = qgridLayout()
self.setLayout(kutu)
milis_logo = QLabel()
milis_logo.setAlignment(Qt.AlignCenter)
milis_logo.setpixmap(Qpixmap("./resimler/milis-logo.svg"))
kutu.addWidget(milis_logo,0,1,2)
self.veda_label = QLabel()
self.veda_label.setAlignment(Qt.AlignCenter)
self.veda_label.setWordWrap(True)
kutu.addWidget(self.veda_label,2)
self.denemeye_devam = qradiobutton()
self.denemeye_devam.setIcon(QIcon("./resimler/cik.svg"))
self.denemeye_devam.setIconSize(QSize(50,50))
self.denemeye_devam.toggled.connect(self.degisti)
kutu.addWidget(self.denemeye_devam,2,1)
self.kapat = qradiobutton()
self.kapat.setIcon(QIcon("./resimler/yeniden-baslat.svg"))
self.kapat.setIconSize(QSize(50,50))
self.kapat.toggled.connect(self.degisti)
kutu.addWidget(self.kapat,1)
self.denemeye_devam.setChecked(True)
def setupUi(self, FileInfoDialog):
FileInfoDialog.setobjectName("FileInfoDialog")
FileInfoDialog.resize(579, 472)
icon = QtGui.QIcon()
icon.addpixmap(QtGui.Qpixmap("icons/157-stats-bars.png"), QtGui.QIcon.normal, QtGui.QIcon.Off)
FileInfoDialog.setwindowIcon(icon)
self.gridLayout = QtWidgets.qgridLayout(FileInfoDialog)
self.gridLayout.setobjectName("gridLayout")
self.gridLayout_2 = QtWidgets.qgridLayout()
self.gridLayout_2.setobjectName("gridLayout_2")
self.tabWidget = QtWidgets.QTabWidget(FileInfoDialog)
self.tabWidget.setobjectName("tabWidget")
self.gridLayout_2.addWidget(self.tabWidget, 0, 1, 1)
self.buttonBox = QtWidgets.QDialogButtonBox(FileInfoDialog)
self.buttonBox.setorientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close)
self.buttonBox.setobjectName("buttonBox")
self.gridLayout_2.addWidget(self.buttonBox, 1)
self.gridLayout.addLayout(self.gridLayout_2, 1)
self.retranslateUi(FileInfoDialog)
self.tabWidget.setCurrentIndex(-1)
self.buttonBox.accepted.connect(FileInfoDialog.accept)
self.buttonBox.rejected.connect(FileInfoDialog.reject)
QtCore.QMetaObject.connectSlotsByName(FileInfoDialog)
def set_mainwindow_palette(fanart, first_time=None):
logger.info('\n{0}: mainwindow background\n'.format(fanart))
if fanart.endswith('default.jpg'):
default_dir, default_img = os.path.split(fanart)
default_fit = os.path.join(default_dir, 'default_fit.jpg')
if not os.path.exists(default_fit):
ui.image_fit_option(fanart, default_fit, fit_size=1)
fanart = default_fit
if not os.path.isfile(fanart) or ui.keep_background_constant:
fanart = ui.default_background
if os.path.isfile(fanart):
if not ui.keep_background_constant or first_time:
palette = QtGui.QPalette()
palette.setBrush(QtGui.QPalette.Background,
QtGui.QBrush(QtGui.Qpixmap(fanart)))
MainWindow.setPalette(palette)
ui.current_background = fanart
def __init__(self, data, parent=None):
super(UpdateDialog, self).__init__(parent)
self.setupUi(self)
self.setModal(True)
self.data = data
self.label.setpixmap(QtGui.Qpixmap(data['logo']))
self.settings = QtCore.QSettings('fume', 'Match-Explorer')
self.wouldYouLiketoDownloadLabel.setText(
"FuME {latest} ist verfügbar (Du verwendest Version {current}). "
"Möchtest du die neue Version jetzt herunterladen?".format(current=data['current'], latest=data['latest']))
self.textEdit.setText(data['changelog'])
# restore check state
self.checkBox.setChecked(self.settings.value('updates/noautoupdate', False, bool))
# Connections
self.skipThisversionButton.clicked.connect(self.skipThisversion)
self.remindMeLaterButton.clicked.connect(self.close)
self.installUpdateButton.clicked.connect(self.installUpdates)
self.checkBox.stateChanged.connect(self.noAutoUpdates)
def drawUI(self, song_name="blank", song_artist="blank"):
self.art = QLabel(self)
self.art.resize(50, 50)
#self.art.setpixmap(Qpixmap("".join([song_name,'.jpg'])).scaled(50,50,Qt.KeepAspectRatio,Qt.SmoothTransformation))
self.song_label = QLabel(self)
self.song_label.setText(song_name)
self.song_label.setStyleSheet("border-image: rgba(0,0); color: rgba(255,255,255); font-size: 12pt; font-weight: 600;")
self.song_label.move(60, 10)
self.song_label.resize(180, 15)
self.artist_label = QLabel(self)
self.artist_label.setText(song_artist)
self.artist_label.setStyleSheet("border-image: rgba(0,255); font-size: 12pt; font-weight: 200;")
self.artist_label.move(60, 25)
self.artist_label.resize(180, 15)
def __init__(self, user_data_control):
super().__init__()
sys.excepthook = self._displayError
self._udc = user_data_control
self.check = Qpixmap("res/check.png")
self.cancel = Qpixmap("res/cancel.png")
self.setGeometry(500, 500, 465)
self.init_ui()
self.init_window()
self.init_user_data()
self.setwindowTitle(self.APP_TITLE)
self.setwindowIcon(QIcon('res/rabbit.png'))
center(self)
self.show()
# PyQt Error Handling
def download_new(self):
dolphin_dir = self.dolphin_dir.text()
version = self.version.text()
if self.current.text() == version:
self.show_warning('You already have the most recent version.')
return
elif not os.path.isdir(dolphin_dir):
self.show_warning('Your dolphin folder path is invalid.')
self.dolphin_dir_status.setpixmap(Qpixmap("res/cancel.png"))
return
if not self.download_thread.isRunning():
if dir == 'Please Select a Dolphin Directory':
self.show_warning('Please select a dolphin folder.')
self.version.setText('')
self.download_thread.update(dolphin_dir, version)
self.download_thread.start()
def get_pixel(point):
global w, point_zat, circle
pix = Qpixmap()
if circle:
r = w.rad.value()
draw_circle(w.image, r, point)
circle = False
if point_zat:
w.p_x.setValue(point.x())
w.p_y.setValue(point.y())
draw_edges(w.image, w.edges)
point_zat = False
pix.convertFromImage(w.image)
w.scene.addpixmap(pix)
w.lock.setdisabled(False)
w.erase.setdisabled(False)
w.paint.setdisabled(False)
w.addpoint.setdisabled(False)
w.addcircle.setdisabled(False)
w.pixel.setdisabled(False)
def __init__(self):
self.scene = QGraphicsScene()
super().__init__(self.scene)
self.sheethandler = None # Will be set externally
self.setDragMode(QGraphicsView.RubberBandDrag)
self.emptySheet = True # Don't allow any modifications until a new sheet is created or loaded
self.backgroundpixmap = Qpixmap("resources/grid.jpg")
self.bgBrush = QBrush(self.backgroundpixmap)
self.scene.setBackgroundBrush(self.bgBrush)
self.modman = ModuleManager()
self.initnode = None
self.loopnode = None
#self.newSheet()
#self.loadSheet(json.loads("""{"loopnode":"85a1abbd6d86462bbdad9639086b503e","85a1abbd6d86462bbdad9639086b503e":{"inputs":[],"nodename":"drluke.builtin.Loop","pos":[0,144],"outputs":[[]]},"52667c109d734f8883c74cf1a659b675":{"inputs":[],"nodename":"drluke.builtin.Init",0],"initnode":"52667c109d734f8883c74cf1a659b675"}"""))
#self.loadRelationship(json.loads("""{"loopnode":"4e742e8ccb554213a9efe10431400637","c1e809fe45f340bfa1e68ed0a5429fb0":{"outputs":[[],[]],"pos":[431,108],"inputs":[[["dbb2a2812a4d42209e6b7aa635fca477",0]],"nodename":"drluke.testmodule.TestNode"},"dbb2a2812a4d42209e6b7aa635fca477":{"outputs":[[["c1e809fe45f340bfa1e68ed0a5429fb0","pos":[187,85],"inputs":[[["d7e6f0fe49fd4c598fdd4503bcffbd9c",["4e742e8ccb554213a9efe10431400637","d7e6f0fe49fd4c598fdd4503bcffbd9c":{"outputs":[[["dbb2a2812a4d42209e6b7aa635fca477",0]]],"inputs":[],"nodename":"drluke.builtin.Init"},"4e742e8ccb554213a9efe10431400637":{"outputs":[[["dbb2a2812a4d42209e6b7aa635fca477",200],"nodename":"drluke.builtin.Loop"},"initnode":"d7e6f0fe49fd4c598fdd4503bcffbd9c"}"""))
def __init__(self, parent=None):
super(Adventure, self).__init__(parent)
#
# Top-half of the
#
self.image_panel = QtWidgets.QLabel()
self.image_panel.setAlignment(QtCore.Qt.AlignCenter)
self.image = QtGui.Qpixmap("image.jpg")
self.image_panel.setpixmap(self.image)
self.text_panel = QtWidgets.QTextEdit()
self.text_panel.setReadOnly(True)
self.text_panel.setTextBackgroundColor(QtGui.QColor("blue"))
self.text_panel.setHtml("""<h1>Hello,World!</h1>
<p>You are in a spacIoUs ballroom with the sound of music playing all around you.</p>
""")
self.data_panel = QtWidgets.QTextEdit()
self.data_panel.setReadOnly(True)
self.input = QtWidgets.QLineEdit()
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.image_panel, 1)
hlayout = QtWidgets.QHBoxLayout()
hlayout.addWidget(self.text_panel, 3)
hlayout.addWidget(self.data_panel, 1)
layout.addLayout(hlayout, 1)
layout.addWidget(self.input)
self.setLayout(layout)
self.setwindowTitle("Westpark Adventure")
def half_color_change_left(self):
temp = self.Left_Select.currentIndex()
if temp == 1:
ASD.write(bytes('y', 'UTF-8'))
self.Half_Left.setpixmap(QtGui.Qpixmap("../_image/Color_None_Left.png"))
elif temp == 2:
ASD.write(bytes('d', 'UTF-8'))
self.Half_Left.setpixmap(QtGui.Qpixmap("../_image/Color_Red_left.png"))
elif temp == 3:
ASD.write(bytes('e', 'UTF-8'))
self.Half_Left.setpixmap(QtGui.Qpixmap("../_image/Color_Red_left.png"))
elif temp == 4:
ASD.write(bytes('f', 'UTF-8'))
self.Half_Left.setpixmap(QtGui.Qpixmap("../_image/Color_Red_left.png"))
elif temp == 0:
ASD.write(bytes('B', 'UTF-8'))
self.Half_Left.setpixmap(QtGui.Qpixmap("../_image/Color_None_Left.png"))
self.Color_Frame.setpixmap(QtGui.Qpixmap("../_image/Color_None.png"))
def half_color_change_right(self):
temp = self.Right_Select.currentIndex()
if temp == 1:
ASD.write(bytes('x', 'UTF-8'))
self.Half_Right.setpixmap(QtGui.Qpixmap("../_image/Color_None_Right.png"))
elif temp == 2:
ASD.write(bytes('a', 'UTF-8'))
self.Half_Right.setpixmap(QtGui.Qpixmap("../_image/Color_Red_Right.png"))
elif temp == 3:
ASD.write(bytes('b', 'UTF-8'))
self.Half_Right.setpixmap(QtGui.Qpixmap("../_image/Color_Green_Right.png"))
elif temp == 4:
ASD.write(bytes('c', 'UTF-8'))
self.Half_Right.setpixmap(QtGui.Qpixmap("../_image/Color_Blue_Right.png"))
elif temp == 0:
ASD.write(bytes('A', 'UTF-8'))
self.Half_Right.setpixmap(QtGui.Qpixmap("../_image/Color_None_Right.png"))
self.Color_Frame.setpixmap(QtGui.Qpixmap("../_image/Color_None.png"))
def __init__(self, parent, slider: VideoSlider):
super(VideoSliderWidget, self).__init__(parent)
self.parent = parent
self.slider = slider
self.loaderEffect = OpacityEffect()
self.loaderEffect.setEnabled(False)
self.setGraphicsEffect(self.loaderEffect)
self.setContentsMargins(0, 0)
self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.layout().setStackingMode(QStackedLayout.StackAll)
self.genlabel = QLabel(self.parent)
self.genlabel.setContentsMargins(0, 14)
self.genlabel.setpixmap(Qpixmap(':/images/generating-thumbs.png'))
self.genlabel.setAlignment(Qt.AlignCenter)
self.genlabel.hide()
sliderLayout = qgridLayout()
sliderLayout.setContentsMargins(0, 0)
sliderLayout.setSpacing(0)
sliderLayout.addWidget(self.slider, 0)
sliderLayout.addWidget(self.genlabel, 0)
sliderWidget = QWidget(self.parent)
sliderWidget.setLayout(sliderLayout)
self.addWidget(sliderWidget)
def showKeyRef(self) -> None:
shortcuts = QWidget(self)
shortcuts.setwindowFlags(Qt.Dialog | Qt.WindowCloseButtonHint)
shortcuts.setobjectName('shortcuts')
shortcuts.setAttribute(Qt.WA_DeleteOnClose, True)
buttons = QDialogButtonBox(QDialogButtonBox.Ok)
buttons.accepted.connect(shortcuts.close)
layout = QVBoxLayout()
# noinspection PyArgumentList
layout.addWidget(QLabel(pixmap=Qpixmap(':/images/{}/shortcuts.png'.format(self.theme))))
layout.addWidget(buttons)
shortcuts.setLayout(layout)
shortcuts.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
shortcuts.setContentsMargins(10, 10, 10)
shortcuts.setwindowModality(Qt.NonModal)
shortcuts.setwindowTitle('Keyboard shortcuts')
shortcuts.setMinimumWidth(400 if self.parent.scale == 'LOW' else 600)
shortcuts.show()
def printAbout(self):
"""
Show window with about and version information.
"""
msgBox = QMessageBox(QMessageBox.information, "About",
"About <b>" + basics.NAME + "</b>: <br><br>" + basics.NAME + " " +
"is a file encryption and decryption tool using a Trezor hardware "
"device for safety and security. Symmetric AES cryptography is used "
"at its core. <br><br>" +
"<b>" + basics.NAME + " Version: </b>" + basics.VERSION_STR +
" from " + basics.VERSION_DATE_STR +
"<br><br><b>Python Version: </b>" + sys.version.replace(" \n", "; ") +
"<br><br><b>Qt Version: </b>" + QT_VERSION_STR +
"<br><br><b>PyQt Version: </b>" + PYQT_VERSION_STR)
msgBox.setIconpixmap(Qpixmap(basics.logo_IMAGE))
msgBox.exec_()
def __init__(self, parent=None, ui_widget=None, home=None, window=None, logr=None):
global ui, MainWindow, logger
QtWidgets.QSystemTrayIcon.__init__(self, parent)
ui = parent
MainWindow = window
logger = logr
icon_img = os.path.join(home, 'src', 'tray.png')
self.right_menu = RightClickMenuIndicator(ui_widget=ui_widget,
window=window, logr=logr)
self.setContextMenu(self.right_menu)
self.activated.connect(self.onTrayIconActivated)
self.p = QtGui.Qpixmap(24, 24)
self.p.fill(QtGui.QColor("transparent"))
painter = QtGui.QPainter(self.p)
if os.path.exists(icon_img):
self.setIcon(QtGui.QIcon(icon_img))
else:
self.setIcon(QtGui.QIcon(""))
self.full_scr = 1
del painter
def epn_highlight(self):
global home, site
num = self.list2.currentRow()
move_ahead = True
if num < 0:
move_ahead = False
if self.list2.currentItem() and num < len(self.epn_arr_list) and move_ahead:
epn_h = self.list2.currentItem().text()
picn = self.get_thumbnail_image_path(num, self.epn_arr_list[num])
label_name = 'label.'+os.path.basename(picn)
path_thumb, new_title = os.path.split(picn)
new_picn = os.path.join(path_thumb, label_name)
if os.path.exists(picn):
if not picn.endswith('default.jpg'):
if not os.path.exists(new_picn):
self.image_fit_option(picn, new_picn, fit_size=6, widget=self.label)
if os.path.isfile(new_picn):
self.label.setpixmap(QtGui.Qpixmap(new_picn, "1"))
txt_file = new_title.replace('.jpg', '.txt', 1)
txt_path = os.path.join(path_thumb, txt_file)
if os.path.isfile(txt_path):
#logger.debug(txt_path)
summary = open_files(txt_path, False)
self.text.setText(summary)
def AddShapeRowLayer(self, shape, parent_item):
icon = QIcon()
icon.addpixmap(Qpixmap(":/images/shape.png"))
item_col_0 = QStandardItem(icon, "")
item_col_0.setData(QVariantShape(shape), SHAPE_OBJECT) # store a ref in our treeView element
item_col_1 = QStandardItem(shape.type)
item_col_2 = QStandardItem(str(shape.nr))
item_col_3 = QStandardItem()
parent_item.appendRow([item_col_0, item_col_1, item_col_2, item_col_3])
# Deal with the checkBoxes (shape enabled or disabled / send shape to TSP optimizer)
item_col_0.setCheckState(QtCore.Qt.Unchecked if shape.isdisabled() else QtCore.Qt.Checked)
item_col_3.setCheckState(QtCore.Qt.Checked if shape.isToolPathOptimized() else QtCore.Qt.Unchecked)
flags = QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsSelectable
if shape.allowedtochange:
flags |= QtCore.Qt.ItemIsEnabled
item_col_0.setFlags(flags | QtCore.Qt.ItemIsUserCheckable)
item_col_1.setFlags(flags)
item_col_2.setFlags(flags)
item_col_3.setFlags(flags | QtCore.Qt.ItemIsUserCheckable)
def AddCustomGCodeRowLayer(self, custom_gcode, parent_item, push_row=None):
icon = QIcon()
icon.addpixmap(Qpixmap(":/images/custom.png"))
item_col_0 = QStandardItem(icon, "") # will only display a checkBox + an icon that will never be disabled
item_col_0.setData(QtCore.QVariant(custom_gcode), CUSTOM_GCODE_OBJECT) # store a ref to the custom gcode in our treeView element
item_col_1 = QStandardItem(custom_gcode.name)
item_col_2 = QStandardItem(str(custom_gcode.nr))
item_col_3 = QStandardItem()
if push_row:
parent_item.insertRow(push_row, [item_col_0, item_col_3])
else:
parent_item.appendRow([item_col_0, item_col_3])
# Deal with the checkBoxes (shape enabled or disabled / send shape to TSP optimizer)
item_col_0.setCheckState(QtCore.Qt.Unchecked if custom_gcode.isdisabled() else QtCore.Qt.Checked)
flags = QtCore.Qt.ItemIsDragEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled
item_col_0.setFlags(flags | QtCore.Qt.ItemIsUserCheckable)
item_col_1.setFlags(flags)
item_col_2.setFlags(flags)
item_col_3.setFlags(flags)
def QpixmapFactory(image):
font = image.font
if font is None:
return None
layer = image.layer
images = font.images
if image.fileName not in images:
return None
imageColor = image.color
data = images[image.fileName]
pixmap = Qpixmap()
pixmap.loadFromData(data)
if imageColor is not None:
colorEffect = QGraphicsColorizeEffect()
colorEffect.setColor(colorToQColor(imageColor))
colorEffect.setStrength(.8)
return applyEffectTopixmap(pixmap, colorEffect)
return pixmap
def init_btn_icon(self):
"""
init button icon,including: save button?run button?show/hide console button
:return:
"""
save_icon = QIcon()
save_icon.addpixmap(Qpixmap(self.config.images + '/save.png'), QIcon.normal, QIcon.Off) # save icon
self.save_btn.setIcon(save_icon)
run_icon = QIcon()
run_icon.addpixmap(Qpixmap(self.config.images + '/run.png'), QIcon.Off) # run icon
self.run_btn.setIcon(run_icon)
console_icon = QIcon()
console_icon.addpixmap(Qpixmap(self.config.images + '/console.png'), QIcon.Off) # console icon
self.console_btn.setIcon(console_icon)
edit_data_icon = QIcon()
edit_data_icon.addpixmap(Qpixmap(self.config.images + '/edit.png'), QIcon.Off) # console icon
self.edit_data_btn.setIcon(edit_data_icon)
def set_tag_name_completer(self):
"""
set completer to tag_names_line_edit
:return:
"""
# change button icon
add_icon = QIcon()
add_icon.addpixmap(Qpixmap(self.config.images + '/add.png'), QIcon.Off)
self.add_tag_button.setIcon(add_icon)
self.add_tag_button.setToolTip("add tag")
self.tag_names_line_edit.setPlaceholderText("Tag Names")
self.tag_layout.insertWidget(0, self.tag_names_line_edit)
self.tag_list = self.dBCommandLineHelper.query_tag_all() # get all tags
tag_name_list = []
for tag in self.tag_list:
tag_name_list.append(tag.name)
cmp = TagCompleter(tag_name_list)
self.tag_names_line_edit.setCompleter(cmp)
def __init__(self, parent=None):
super().__init__()
self.parent = parent
self.setFixedHeight(100)
self.setLayout(QHBoxLayout())
self.layout().addSpacing(0)
self.logo = QLabel()
self.logo.setFixedSize(72, 72)
self.logo.setScaledContents(True)
self.logo.setpixmap(Qpixmap(":/images/lime-logo.svg"))
self.layout().addWidget(self.logo)
self.layout().addspacerItem(QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Expanding))
self.lprogressBar = LProgressBar(self.parent)
self.layout().addWidget(self.lprogressBar)
self.parent.currentChanged.connect(self.lprogressBar.setIndex)
def __init__(self):
super(StickMan, self).__init__()
self.m_sticks = True
self.m_isDead = False
self.m_pixmap = Qpixmap('images/head.png')
self.m_penColor = QColor(Qt.white)
self.m_fillColor = QColor(Qt.black)
# Set up start position of limbs.
self.m_nodes = []
for x, y in Coords:
node = Node(QPointF(x, y), self)
node.positionChanged.connect(self.childPositionChanged)
self.m_nodes.append(node)
self.m_perfectBoneLengths = []
for n1, n2 in Bones:
node1 = self.m_nodes[n1]
node2 = self.m_nodes[n2]
dist = node1.pos() - node2.pos()
self.m_perfectBoneLengths.append(math.hypot(dist.x(), dist.y()))
self.startTimer(10)
def updateColor(self, item):
pixmap = Qpixmap(16, 16)
color = QColor()
if item:
color = item.backgroundColor()
if not color.isValid():
color = self.palette().base().color()
painter = QPainter(pixmap)
painter.fillRect(0, 16, color)
lighter = color.lighter()
painter.setPen(lighter)
# light frame
painter.drawpolyline(QPoint(0, 15), QPoint(0, 0), QPoint(15, 0))
painter.setPen(color.darker())
# dark frame
painter.drawpolyline(QPoint(1, 1))
painter.end()
self.colorAction.setIcon(QIcon(pixmap))
def __init__(self, parent=None):
super(IntroPage, self).__init__(parent)
self.setTitle("Introduction")
self.setpixmap(QWizard.Watermarkpixmap,
Qpixmap(':/images/watermark1.png'))
label = QLabel("This wizard will generate a skeleton C++ class "
"deFinition,including a few functions. You simply need to "
"specify the class name and set a few options to produce a "
"header file and an implementation file for your new C++ "
"class.")
label.setWordWrap(True)
layout = QVBoxLayout()
layout.addWidget(label)
self.setLayout(layout)
def showNextPiece(self):
if self.nextPieceLabel is None:
return
dx = self.nextPiece.maxX() - self.nextPiece.minX() + 1
dy = self.nextPiece.maxY() - self.nextPiece.minY() + 1
pixmap = Qpixmap(dx * self.squareWidth(), dy * self.squareHeight())
painter = QPainter(pixmap)
painter.fillRect(pixmap.rect(), self.nextPieceLabel.palette().window())
for i in range(4):
x = self.nextPiece.x(i) - self.nextPiece.minX()
y = self.nextPiece.y(i) - self.nextPiece.minY()
self.drawSquare(painter, x * self.squareWidth(),
y * self.squareHeight(), self.nextPiece.shape())
painter.end()
self.nextPieceLabel.setpixmap(pixmap)
def mousepressEvent(self, event):
hotSpot = event.pos()
mimeData = QMimeData()
mimeData.setText(self.text())
mimeData.setData('application/x-hotspot',
'%d %d' % (hotSpot.x(), hotSpot.y()))
pixmap = Qpixmap(self.size())
self.render(pixmap)
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setpixmap(pixmap)
drag.setHotSpot(hotSpot)
dropAction = drag.exec_(Qt.copyAction | Qt.MoveAction, Qt.copyAction)
if dropAction == Qt.MoveAction:
self.close()
self.update()
def startDrag(self, supportedActions):
item = self.currentItem()
itemData = QByteArray()
dataStream = QDataStream(itemData, qiodevice.writeonly)
pixmap = Qpixmap(item.data(Qt.UserRole))
location = item.data(Qt.UserRole+1)
dataStream << pixmap << location
mimeData = QMimeData()
mimeData.setData('image/x-puzzle-piece', itemData)
drag = QDrag(self)
drag.setMimeData(mimeData)
drag.setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2))
drag.setpixmap(pixmap)
if drag.exec_(Qt.MoveAction) == Qt.MoveAction:
if self.currentItem() is not None:
self.takeItem(self.row(item))
def dropEvent(self, event):
mimeData = event.mimeData()
if mimeData.hasImage():
self.setpixmap(Qpixmap(mimeData.imageData()))
elif mimeData.hasHtml():
self.setText(mimeData.html())
self.settextformat(Qt.RichText)
elif mimeData.hasText():
self.setText(mimeData.text())
self.settextformat(Qt.PlainText)
elif mimeData.hasUrls():
self.setText("\n".join([url.path() for url in mimeData.urls()]))
else:
self.setText("Cannot display data")
self.setBackgroundRole(QPalette.Dark)
event.acceptProposedAction()
def __init__(self, parent=None):
super(DragWidget, self).__init__(parent)
self.setMinimumSize(200, 200)
self.setFrameStyle(qframe.Sunken | qframe.StyledPanel)
self.setAcceptDrops(True)
boatIcon = QLabel(self)
boatIcon.setpixmap(Qpixmap(':/images/boat.png'))
boatIcon.move(20, 20)
boatIcon.show()
boatIcon.setAttribute(Qt.WA_DeleteOnClose)
carIcon = QLabel(self)
carIcon.setpixmap(Qpixmap(':/images/car.png'))
carIcon.move(120, 20)
carIcon.show()
carIcon.setAttribute(Qt.WA_DeleteOnClose)
houseIcon = QLabel(self)
houseIcon.setpixmap(Qpixmap(':/images/house.png'))
houseIcon.move(20, 120)
houseIcon.show()
houseIcon.setAttribute(Qt.WA_DeleteOnClose)
def dropEvent(self, event):
if event.mimeData().hasFormat('application/x-dnditemdata'):
itemData = event.mimeData().data('application/x-dnditemdata')
dataStream = QDataStream(itemData, qiodevice.ReadOnly)
pixmap = Qpixmap()
offset = QPoint()
dataStream >> pixmap >> offset
newIcon = QLabel(self)
newIcon.setpixmap(pixmap)
newIcon.move(event.pos() - offset)
newIcon.show()
newIcon.setAttribute(Qt.WA_DeleteOnClose)
if event.source() == self:
event.setDropAction(Qt.MoveAction)
event.accept()
else:
event.acceptProposedAction()
else:
event.ignore()
def updateColor(self, 1))
painter.end()
self.colorAction.setIcon(QIcon(pixmap))
def reset_data(self):
"""Reset fan rpm and voltage to "---" and activate the red status icon.
Reset cpu and GPU temperature to "0"."""
# Reset fan rpm
self.ui.labelRPMFan1.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan2.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan3.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan4.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan5.setText('<b><font color="red">---</font></b>')
self.ui.labelRPMFan6.setText('<b><font color="red">---</font></b>')
# Reset fan voltage
self.ui.labelVFan1.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan2.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan3.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan4.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan5.setText('<b><font color="red">---</font></b>')
self.ui.labelVFan6.setText('<b><font color="red">---</font></b>')
# Activate the red led icon
self.ui.labelStatusFan1.setpixmap(QtGui.Qpixmap(ICON_RED_LED))
self.ui.labelStatusFan2.setpixmap(QtGui.Qpixmap(ICON_RED_LED))
self.ui.labelStatusFan3.setpixmap(QtGui.Qpixmap(ICON_RED_LED))
self.ui.labelStatusFan4.setpixmap(QtGui.Qpixmap(ICON_RED_LED))
self.ui.labelStatusFan5.setpixmap(QtGui.Qpixmap(ICON_RED_LED))
self.ui.labelStatusFan6.setpixmap(QtGui.Qpixmap(ICON_RED_LED))
# Reset temperatures
self.ui.lcdNumberCurrentcpu.display(0)
self.ui.lcdNumberCurrentGPU.display(0)
# Update status in UI
self.ui.labelPollingStatus.setText('<b><font color="red">Stopped</font></b>')
self.ui.labelHWMonStatus.setText('<b><font color="red">---</font></b>')
def change_fan_icon(self, icon, fan):
"""Update the fan status icon."""
if fan == 1:
self.ui.labelStatusFan1.setpixmap(QtGui.Qpixmap(icon))
if fan == 2:
self.ui.labelStatusFan2.setpixmap(QtGui.Qpixmap(icon))
if fan == 3:
self.ui.labelStatusFan3.setpixmap(QtGui.Qpixmap(icon))
if fan == 4:
self.ui.labelStatusFan4.setpixmap(QtGui.Qpixmap(icon))
if fan == 5:
self.ui.labelStatusFan5.setpixmap(QtGui.Qpixmap(icon))
if fan == 6:
self.ui.labelStatusFan6.setpixmap(QtGui.Qpixmap(icon))
def __init__(self):
from rockthetaskbar import icons
icon = QIcon(Qpixmap(':icon.png'))
super().__init__(icon)
menu = QMenu()
menu.addAction("cpu").triggered.connect(self.cpu)
menu.addAction("About").triggered.connect(self.about)
menu.addAction("Exit").triggered.connect(self.exit)
self.setContextMenu(menu)
self.cpu_monitor = cpuMonitor()
self.cpu_monitor.start()
def init_form(self) -> QHBoxLayout:
self.search_field = QLineEdit(self, clearButtonEnabled=True, placeholderText='Enter search criteria')
self.search_field.setobjectName('searchInput')
self.search_field.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.search_field.setFocus()
self.search_field.textChanged.connect(self.clear_filters)
self.search_field.returnpressed.connect(lambda: self.filter_table(self.search_field.text()))
self.favorites_button = QPushButton(parent=self, flat=True, cursor=Qt.PointingHandCursor,
objectName='favesButton', toolTip='Favorites', checkable=True,
toggled=self.filter_faves,
checked=self.settings.value('faves_filter', bool))
self.refresh_button = QPushButton(parent=self,
objectName='refreshButton', toolTip='Refresh', clicked=self.start_scraping)
self.dlpages_field = QComboBox(self, toolTip='Pages', editable=False, cursor=Qt.PointingHandCursor)
self.dlpages_field.addItems(('10', '20', '30', '40', '50'))
self.dlpages_field.setCurrentIndex(self.dlpages_field.findText(str(self.dl_pagecount), Qt.MatchFixedString))
self.dlpages_field.currentIndexChanged.connect(self.update_pagecount)
self.settings_button = QPushButton(parent=self, toolTip='Menu',
objectName='menuButton', cursor=Qt.PointingHandCursor)
self.settings_button.setMenu(self.settings_menu())
layout = QHBoxLayout(spacing=10)
logo = QLabel(self)
logo.setpixmap(Qpixmap(':assets/images/logo.png'))
layout.addWidget(logo)
layout.addWidget(self.search_field)
layout.addWidget(self.favorites_button)
layout.addWidget(self.refresh_button)
layout.addWidget(QLabel('Pages:'))
layout.addWidget(self.dlpages_field)
layout.addWidget(self.settings_button)
return layout
def __init__(self, parent=None):
super().__init__(parent)
self.setSubTitle(self.tr("<h2>Welcome to KaOS</h2>"))
vlayout = QVBoxLayout(self)
vlayout.addItem(QSpacerItem(20, 30, QSizePolicy.Preferred, QSizePolicy.Minimum))
hlayout = QHBoxLayout(self)
label = QLabel(self)
label.setText(self.tr("""<h1>What is KaOS?</h1>
<p>The idea behind KaOS is to create a tightly integrated rolling and<br />
transparent distribution for the modern desktop,build from scratch with<br />
a very specific focus. Focus on one DE (KDE),one toolkit (Qt) & one architecture (x86_64).<br />
Plus a focus on evaluating and selecting the most suitable tools and applications.</p>
<p>This wizard will help you personalize your KaOS workspace easily and quickly.</p>
<p>Please click <code style=color:#3498DB>Next</code> in order to begin. Click <code style=color:#3498DB>Cancel</code> anytime and changes won't be saved.</p>"""))
label.setWordWrap(True)
label.setAlignment(Qt.AlignLeft)
hlayout.addWidget(label)
kaptan_logo = QLabel(self)
kaptan_logo.setpixmap(Qpixmap(":/data/images/welcome.png"))
kaptan_logo.setAlignment(Qt.AlignRight)
kaptan_logo.setMaximumSize(157, 181)
hlayout.addWidget(kaptan_logo)
vlayout.addLayout(hlayout)
vlayout.addItem(QSpacerItem(20, 40, QSizePolicy.Preferred))
desktop_file = os.path.join(os.environ["HOME"], ".config", "autostart", "kaptan.desktop")
if os.path.exists(desktop_file):
self.checkBox = QCheckBox()
self.checkBox.setText(self.tr("Run on system startup"))
self.checkBox.setChecked(True)
self.checkBox.clicked.connect(self.autoRemove)
vlayout.addWidget(self.checkBox)
def drawUI(self):
self.play = QPushButton(self)
self.play.setIconSize(QSize(40, 40))
self.play.setIcon(QIcon(Qpixmap("play.png").scaled(40, Qt.KeepAspectRatio, Qt.SmoothTransformation)))
self.play.setStyleSheet("background-color: rgba(0,0);")
self.play.clicked.connect(lambda:self.playpause(self.play))
self.resize(50, 50)
def playpause(self, btn):
if self.playing:
os.system("""osascript -e 'tell application "iTunes" to pause'""")
self.playing = False
btn.setIcon(QIcon(Qpixmap("play.png").scaled(40, Qt.SmoothTransformation)))
else:
os.system("""osascript -e 'tell application "iTunes" to play'""")
self.playing = True
btn.setIcon(QIcon(Qpixmap("pause.png").scaled(40, Qt.SmoothTransformation)))
def drawUI(self):
self.play = QPushButton(self)
self.play.setIconSize(QSize(40, 20))
self.play.setIcon(QIcon(Qpixmap("fastforward.png").scaled(40,0);")
self.play.clicked.connect(lambda:self.forward())
self.resize(80, 40)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。