def _updateButtonColor(self, color): """Generate color preview pixmap and place it on button""" pixmap = QPixmap(128, 18) qcolour = QColor(0, 0, 0) qcolour.setNamedColor(color) pixmap.fill(qcolour) self.setIcon(QIcon(pixmap)) self.setIconSize(QSize(128, 18)) self.color = color
def drawBackground(self, painter, rect): super().drawBackground(painter, rect) pic_path = f'{os.path.dirname(os.path.realpath(__file__))}/{self.bg}' pic = QPixmap(pic_path) self.setSceneRect(QRectF(pic.rect())) painter.drawPixmap(self.sceneRect().toRect(), pic, pic.rect()) self.bgSet = True
def icon_from_resources(self, path: Union[str, ColoredIcon]) -> QIcon: "Fetch icon from Qt resources, and invert if in night mode." if self.night_mode: cache = self._icon_cache_light else: cache = self._icon_cache_dark if isinstance(path, str): key = path else: key = f"{path.path}-{path.color}" icon = cache.get(key) if icon: return icon if isinstance(path, str): # default black/white icon = QIcon(path) if self.night_mode: img = icon.pixmap(self._icon_size, self._icon_size).toImage() img.invertPixels() icon = QIcon(QPixmap(img)) else: # specified colours icon = QIcon(path.path) pixmap = icon.pixmap(16) painter = QPainter(pixmap) painter.setCompositionMode(QPainter.CompositionMode_SourceIn) painter.fillRect(pixmap.rect(), QColor(path.current_color(self.night_mode))) painter.end() icon = QIcon(pixmap) return icon return cache.setdefault(path, icon)
def show_reinforcement(picture, sound, duration): system("mplayer " + sound + " >/dev/null 2>/dev/null &") #play_sound(sound) # this doesn't seem to work for some reason mw.splash = QSplashScreen(QPixmap(picture)) mw.splash.move(*flashPosition) mw.splash.show() mw.splash.move(*flashPosition) QTimer.singleShot(duration, mw.splash.close)
def __init__(self, parent: QWidget, mw: AnkiQt, on_close: Callable[[], None]): super().__init__(None, Qt.Window) self._open = True self._parent = parent self._close_callback = on_close self.mw = mw icon = QIcon() icon.addPixmap(QPixmap(":/icons/anki.png"), QIcon.Normal, QIcon.Off) self.setWindowIcon(icon)
def __init__(self, parent: QWidget, mw: AnkiQt, on_close: Callable[[], None]) -> None: super().__init__(None, Qt.Window) mw.garbage_collect_on_dialog_finish(self) self._open = True self._parent = parent self._close_callback = on_close self.mw = mw icon = QIcon() icon.addPixmap(QPixmap(":/icons/anki.png"), QIcon.Normal, QIcon.Off) disable_help_button(self) self.setWindowIcon(icon)
def icon_from_resources(self, path: str) -> QIcon: "Fetch icon from Qt resources, and invert if in night mode." icon = self._icon_cache.get(path) if icon: return icon icon = QIcon(path) if self.night_mode: img = icon.pixmap(self._icon_size, self._icon_size).toImage() img.invertPixels() icon = QIcon(QPixmap(img)) return self._icon_cache.setdefault(path, icon)
def show_multiple_reinforcements(*reinf_tuples): sounds = [tup[1] for tup in reinf_tuples] mplayer_commands = [ "(mplayer " + sound + " >/dev/null 2>/dev/null)" for sound in sounds ] command = "( " + " && ".join(mplayer_commands) + " ) &" system(command) # For now, only show the first picture picture = reinf_tuples[0][0] mw.splash = QSplashScreen(QPixmap(picture)) mw.splash.move(*flashPosition) mw.splash.show() mw.splash.move(*flashPosition) QTimer.singleShot(reinf_tuples[0][2], mw.splash.close)
def create_menu_entry(editor, e, parentmenu): if e.get('IconInMenu', False): y = QLabel() path = join(icon_path, e['IconInMenu']) # never defined!!!! pixmap = QPixmap(path) y.setPixmap(pixmap) else: t = editor.my_label_text(e, True) y = QLabel(t) # https://stackoverflow.com/a/6876509 y.setAutoFillBackground(True) stylesheet = editor.return_stylesheet(e) y.setStyleSheet(stylesheet) x = QWidgetAction(parentmenu) x.setDefaultWidget(y) cat = e["Category"] se = e.get("Setting", e.get("Category", False)) x.triggered.connect( lambda _, a=cat, b=se: my_highlight_helper(editor, a, b)) return x
def getAudio(parent, encode=True): "Record and return filename" # record first if not Recorder: showWarning("pyaudio not installed") return r = Recorder() mb = QMessageBox(parent) restoreGeom(mb, "audioRecorder") mb.setWindowTitle("Anki") mb.setIconPixmap(QPixmap(":/icons/media-record.png")) but = QPushButton(_("Save")) mb.addButton(but, QMessageBox.AcceptRole) but = QPushButton(_("Cancel")) mb.addButton(but, QMessageBox.RejectRole) mb.setEscapeButton(but) t = time.time() r.start() time.sleep(r.startupDelay) QApplication.instance().processEvents() while not mb.clickedButton(): txt = _("Recording...<br>Time: %0.1f") mb.setText(txt % (time.time() - t)) mb.show() QApplication.instance().processEvents() if mb.clickedButton() == mb.escapeButton(): r.stop() return saveGeom(mb, "audioRecorder") # ensure at least a second captured while time.time() - t < 1: time.sleep(0.1) r.stop() # process r.postprocess(encode) return r.file()
def get_pixmap(self, relative_path: str): return QPixmap(f"{self._prefix}:{relative_path}")
from anknotes.constants import * ### Anki Imports try: from aqt.qt import QIcon, QPixmap except Exception: pass try: icoEvernoteWeb = QIcon(FILES.GRAPHICS.ICON.EVERNOTE_WEB) icoEvernoteArtcore = QIcon(FILES.GRAPHICS.ICON.EVERNOTE_ARTCORE) icoTomato = QIcon(FILES.GRAPHICS.ICON.TOMATO) imgEvernoteWeb = QPixmap(FILES.GRAPHICS.IMAGE.EVERNOTE_WEB, "PNG") imgEvernoteWebMsgBox = imgEvernoteWeb.scaledToWidth(64) except Exception: pass