本文整理汇总了Python中PyQt5.QtGui.QFontDatabase.applicationFontFamilies方法的典型用法代码示例。如果您正苦于以下问题:Python QFontDatabase.applicationFontFamilies方法的具体用法?Python QFontDatabase.applicationFontFamilies怎么用?Python QFontDatabase.applicationFontFamilies使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QFontDatabase
的用法示例。
在下文中一共展示了QFontDatabase.applicationFontFamilies方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
def __init__(self):
super(MainWindow, self).__init__()
font_id = QFontDatabase.addApplicationFont("fontawesome-webfont.ttf")
if font_id is not -1:
font_db = QFontDatabase()
self.font_styles = font_db.styles('FontAwesome')
self.font_families = QFontDatabase.applicationFontFamilies(font_id)
print(self.font_styles, self.font_families)
for font_family in self.font_families:
self.font = font_db.font(font_family, self.font_styles[0], 18)
self.home()
示例2: load_font
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
def load_font(self, prefix, ttf_filename, charmap_filename, directory=None):
"""Loads a font file and the associated charmap
If `directory` is None, the files will be looked up in ./fonts/
Arguments
---------
prefix: str
prefix string to be used when accessing a given font set
ttf_filename: str
ttf font filename
charmap_filename: str
charmap filename
directory: str or None, optional
directory for font and charmap files
"""
def hook(obj):
result = {}
for key in obj:
result[key] = unichr(int(obj[key], 16))
return result
if directory is None:
directory = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'fonts')
with open(os.path.join(directory, charmap_filename), 'r') as codes:
self.charmap[prefix] = json.load(codes, object_hook=hook)
id_ = QFontDatabase.addApplicationFont(os.path.join(directory, ttf_filename))
loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)
if loadedFontFamilies:
self.fontname[prefix] = loadedFontFamilies[0]
else:
print('Font is empty')
示例3: __init__
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
def __init__(self, *args, mode=None):
QApplication.__init__(self, *args)
# Log some basic system info
try:
v = openshot.GetVersion()
log.info("openshot-qt version: %s" % info.VERSION)
log.info("libopenshot version: %s" % v.ToString())
log.info("platform: %s" % platform.platform())
log.info("processor: %s" % platform.processor())
log.info("machine: %s" % platform.machine())
log.info("python version: %s" % platform.python_version())
log.info("qt5 version: %s" % QT_VERSION_STR)
log.info("pyqt5 version: %s" % PYQT_VERSION_STR)
except:
pass
# Setup application
self.setApplicationName('openshot')
self.setApplicationVersion(info.SETUP['version'])
# Init settings
self.settings = settings.SettingStore()
self.settings.load()
# Init and attach exception handler
from classes import exceptions
sys.excepthook = exceptions.ExceptionHandler
# Init translation system
language.init_language()
# Detect minimum libopenshot version
_ = self._tr
libopenshot_version = openshot.GetVersion().ToString()
if mode != "unittest" and libopenshot_version < info.MINIMUM_LIBOPENSHOT_VERSION:
QMessageBox.warning(None, _("Wrong Version of libopenshot Detected"),
_("<b>Version %(minimum_version)s is required</b>, but %(current_version)s was detected. Please update libopenshot or download our latest installer.") %
{"minimum_version": info.MINIMUM_LIBOPENSHOT_VERSION, "current_version": libopenshot_version})
# Stop launching and exit
sys.exit()
# Tests of project data loading/saving
self.project = project_data.ProjectDataStore()
# Init Update Manager
self.updates = updates.UpdateManager()
# It is important that the project is the first listener if the key gets update
self.updates.add_listener(self.project)
# Load ui theme if not set by OS
ui_util.load_theme()
# Start libopenshot logging thread
self.logger_libopenshot = logger_libopenshot.LoggerLibOpenShot()
self.logger_libopenshot.start()
# Track which dockable window received a context menu
self.context_menu_object = None
# Set Font for any theme
if self.settings.get("theme") != "No Theme":
# Load embedded font
try:
log.info("Setting font to %s" % os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
font_id = QFontDatabase.addApplicationFont(os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
font = QFont(font_family)
font.setPointSizeF(10.5)
QApplication.setFont(font)
except Exception as ex:
log.error("Error setting Ubuntu-R.ttf QFont: %s" % str(ex))
# Set Experimental Dark Theme
if self.settings.get("theme") == "Humanity: Dark":
# Only set if dark theme selected
log.info("Setting custom dark theme")
self.setStyle(QStyleFactory.create("Fusion"))
darkPalette = self.palette()
darkPalette.setColor(QPalette.Window, QColor(53, 53, 53))
darkPalette.setColor(QPalette.WindowText, Qt.white)
darkPalette.setColor(QPalette.Base, QColor(25, 25, 25))
darkPalette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
darkPalette.setColor(QPalette.ToolTipBase, Qt.white)
darkPalette.setColor(QPalette.ToolTipText, Qt.white)
darkPalette.setColor(QPalette.Text, Qt.white)
darkPalette.setColor(QPalette.Button, QColor(53, 53, 53))
darkPalette.setColor(QPalette.ButtonText, Qt.white)
darkPalette.setColor(QPalette.BrightText, Qt.red)
darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218))
darkPalette.setColor(QPalette.HighlightedText, Qt.black)
darkPalette.setColor(QPalette.Disabled, QPalette.Text, QColor(104, 104, 104))
self.setPalette(darkPalette)
self.setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 0px solid white; }")
# Create main window
from windows.main_window import MainWindow
self.window = MainWindow(mode)
#.........这里部分代码省略.........
示例4: __init__
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
def __init__(self, *args):
QApplication.__init__(self, *args)
# Setup appication
self.setApplicationName('openshot')
self.setApplicationVersion(info.SETUP['version'])
# Init settings
self.settings = settings.SettingStore()
try:
self.settings.load()
except Exception as ex:
log.error("Couldn't load user settings. Exiting.\n{}".format(ex))
exit()
# Init translation system
language.init_language()
# Tests of project data loading/saving
self.project = project_data.ProjectDataStore()
# Init Update Manager
self.updates = updates.UpdateManager()
# It is important that the project is the first listener if the key gets update
self.updates.add_listener(self.project)
# Load ui theme if not set by OS
ui_util.load_theme()
# Track which dockable window received a context menu
self.context_menu_object = None
# Set Font for any theme
if self.settings.get("theme") != "No Theme":
# Load embedded font
log.info("Setting font to %s" % os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
font_id = QFontDatabase.addApplicationFont(os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
font = QFont(font_family)
font.setPointSizeF(10.5)
QApplication.setFont(font)
# Set Experimental Dark Theme
if self.settings.get("theme") == "Humanity: Dark":
# Only set if dark theme selected
log.info("Setting custom dark theme")
self.setStyle(QStyleFactory.create("Fusion"))
darkPalette = self.palette()
darkPalette.setColor(QPalette.Window, QColor(53, 53, 53))
darkPalette.setColor(QPalette.WindowText, Qt.white)
darkPalette.setColor(QPalette.Base, QColor(25, 25, 25))
darkPalette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
darkPalette.setColor(QPalette.ToolTipBase, Qt.white)
darkPalette.setColor(QPalette.ToolTipText, Qt.white)
darkPalette.setColor(QPalette.Text, Qt.white)
darkPalette.setColor(QPalette.Button, QColor(53, 53, 53))
darkPalette.setColor(QPalette.ButtonText, Qt.white)
darkPalette.setColor(QPalette.BrightText, Qt.red)
darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218))
darkPalette.setColor(QPalette.HighlightedText, Qt.black)
self.setPalette(darkPalette)
self.setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 0px solid white; }")
# Create main window
from windows.main_window import MainWindow
self.window = MainWindow()
self.window.show()
# Load new/blank project (which sets default profile)
self.project.load("")
log.info('Process command-line arguments: %s' % args)
if len(args[0]) == 2:
path = args[0][1]
if ".osp" in path:
# Auto load project passed as argument
self.window.open_project(path)
else:
# Auto import media file
self.window.filesTreeView.add_file(path)
示例5: load_font
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
def load_font(self, prefix, ttf_filename, charmap_filename, directory=None):
"""Loads a font file and the associated charmap.
If ``directory`` is None, the files will be looked for in ``./fonts/``.
Parameters
----------
prefix: str
Prefix string to be used when accessing a given font set
ttf_filename: str
Ttf font filename
charmap_filename: str
Charmap filename
directory: str or None, optional
Directory for font and charmap files
"""
def hook(obj):
result = {}
for key in obj:
result[key] = unichr(int(obj[key], 16))
return result
if directory is None:
directory = os.path.join(
os.path.dirname(os.path.realpath(__file__)), 'fonts')
# Load font
if QApplication.instance() is not None:
id_ = QFontDatabase.addApplicationFont(os.path.join(directory,
ttf_filename))
loadedFontFamilies = QFontDatabase.applicationFontFamilies(id_)
if(loadedFontFamilies):
self.fontname[prefix] = loadedFontFamilies[0]
else:
raise FontError(u"Font at '{0}' appears to be empty. "
"If you are on Windows 10, please read "
"https://support.microsoft.com/"
"en-us/kb/3053676 "
"to know how to prevent Windows from blocking "
"the fonts that come with QtAwesome.".format(
os.path.join(directory, ttf_filename)))
with open(os.path.join(directory, charmap_filename), 'r') as codes:
self.charmap[prefix] = json.load(codes, object_hook=hook)
# Verify that vendorized fonts are not corrupt
if not SYSTEM_FONTS:
md5_hashes = {'fontawesome-webfont.ttf':
'b06871f281fee6b241d60582ae9369b9',
'elusiveicons-webfont.ttf':
'207966b04c032d5b873fd595a211582e'}
ttf_hash = md5_hashes.get(ttf_filename, None)
if ttf_hash is not None:
hasher = hashlib.md5()
with open(os.path.join(directory, ttf_filename),
'rb') as f:
content = f.read()
hasher.update(content)
ttf_calculated_hash_code = hasher.hexdigest()
if ttf_calculated_hash_code != ttf_hash:
raise FontError(u"Font is corrupt at: '{0}'".format(
os.path.join(directory, ttf_filename)))
示例6: __init__
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
def __init__(self, *args, mode=None):
QApplication.__init__(self, *args)
# Log some basic system info
try:
v = openshot.GetVersion()
log.info("openshot-qt version: %s" % info.VERSION)
log.info("libopenshot version: %s" % v.ToString())
log.info("platform: %s" % platform.platform())
log.info("processor: %s" % platform.processor())
log.info("machine: %s" % platform.machine())
log.info("python version: %s" % platform.python_version())
log.info("qt5 version: %s" % QT_VERSION_STR)
log.info("pyqt5 version: %s" % PYQT_VERSION_STR)
except:
pass
# Setup appication
self.setApplicationName('openshot')
self.setApplicationVersion(info.SETUP['version'])
# Init settings
self.settings = settings.SettingStore()
try:
self.settings.load()
except Exception as ex:
log.error("Couldn't load user settings. Exiting.\n{}".format(ex))
exit()
# Init translation system
language.init_language()
# Tests of project data loading/saving
self.project = project_data.ProjectDataStore()
# Init Update Manager
self.updates = updates.UpdateManager()
# It is important that the project is the first listener if the key gets update
self.updates.add_listener(self.project)
# Load ui theme if not set by OS
ui_util.load_theme()
# Start libopenshot logging thread
self.logger_libopenshot = logger_libopenshot.LoggerLibOpenShot()
self.logger_libopenshot.start()
# Track which dockable window received a context menu
self.context_menu_object = None
# Set unique install id (if blank)
if not self.settings.get("unique_install_id"):
self.settings.set("unique_install_id", str(uuid4()))
# Track 1st launch metric
import classes.metrics
classes.metrics.track_metric_screen("initial-launch-screen")
# Set Font for any theme
if self.settings.get("theme") != "No Theme":
# Load embedded font
try:
log.info("Setting font to %s" % os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
font_id = QFontDatabase.addApplicationFont(os.path.join(info.IMAGES_PATH, "fonts", "Ubuntu-R.ttf"))
font_family = QFontDatabase.applicationFontFamilies(font_id)[0]
font = QFont(font_family)
font.setPointSizeF(10.5)
QApplication.setFont(font)
except Exception as ex:
log.error("Error setting Ubuntu-R.ttf QFont: %s" % str(ex))
# Set Experimental Dark Theme
if self.settings.get("theme") == "Humanity: Dark":
# Only set if dark theme selected
log.info("Setting custom dark theme")
self.setStyle(QStyleFactory.create("Fusion"))
darkPalette = self.palette()
darkPalette.setColor(QPalette.Window, QColor(53, 53, 53))
darkPalette.setColor(QPalette.WindowText, Qt.white)
darkPalette.setColor(QPalette.Base, QColor(25, 25, 25))
darkPalette.setColor(QPalette.AlternateBase, QColor(53, 53, 53))
darkPalette.setColor(QPalette.ToolTipBase, Qt.white)
darkPalette.setColor(QPalette.ToolTipText, Qt.white)
darkPalette.setColor(QPalette.Text, Qt.white)
darkPalette.setColor(QPalette.Button, QColor(53, 53, 53))
darkPalette.setColor(QPalette.ButtonText, Qt.white)
darkPalette.setColor(QPalette.BrightText, Qt.red)
darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218))
darkPalette.setColor(QPalette.HighlightedText, Qt.black)
darkPalette.setColor(QPalette.Disabled, QPalette.Text, QColor(104, 104, 104))
self.setPalette(darkPalette)
self.setStyleSheet("QToolTip { color: #ffffff; background-color: #2a82da; border: 0px solid white; }")
# Create main window
from windows.main_window import MainWindow
self.window = MainWindow(mode)
log.info('Process command-line arguments: %s' % args)
#.........这里部分代码省略.........
示例7: Report
# 需要导入模块: from PyQt5.QtGui import QFontDatabase [as 别名]
# 或者: from PyQt5.QtGui.QFontDatabase import applicationFontFamilies [as 别名]
class Report(QMainWindow):
def __init__(self):
super(Report, self).__init__()
self.status_view = "window"
self.status_colors = "light"
self.font_size = 22
self.font_database = QFontDatabase()
# add font cmtex9
self.font_file_cmtex9 = "cmtex9.ttf"
self.font_identifier_cmtex9 = QFontDatabase.addApplicationFont(
self.font_file_cmtex9
)
self.fontFamilyName_cmtex9 = self.font_database.applicationFontFamilies(
self.font_identifier_cmtex9
)[0]
self.update_font()
self.initialise_UI()
def update_font(self):
# add font cmtex9
self.font_cmtex9 = QFont(self.fontFamilyName_cmtex9, self.font_size)
# add font Courier Prime
self.font_CourierPrime = QFont("Courier Prime", self.font_size)
# set default font
self.font_current = self.font_cmtex9
self.font_current.setFixedPitch(True)
self.setFont(self.font_current)
def initialise_UI(self):
action_toggle_view = QAction("toggle view", self)
action_toggle_view.setShortcut("F11")
action_toggle_view.setStatusTip("toggle fullscreen/window view")
action_toggle_view.triggered.connect(self.toggle_view)
action_toggle_colors = QAction("toggle colors", self)
action_toggle_colors.setShortcut("Ctrl+D")
action_toggle_colors.setStatusTip("toggle light/dark colors")
action_toggle_colors.triggered.connect(self.toggle_colors)
action_set_font_size = QAction("set font size", self)
action_set_font_size.setShortcut("Ctrl+T")
action_set_font_size.setStatusTip("set font size")
action_set_font_size.triggered.connect(self.set_font_size)
action_new = QAction("new", self)
action_new.setShortcut("Ctrl+N")
action_new.setStatusTip("create new file")
action_new.triggered.connect(self.new_file)
action_save = QAction("save", self)
action_save.setShortcut("Ctrl+S")
action_save.setStatusTip("save current file")
action_save.triggered.connect(self.save_file)
action_open = QAction("open", self)
action_open.setShortcut("Ctrl+O")
action_open.setStatusTip("open a file")
action_open.triggered.connect(self.open_file)
action_close = QAction("close", self)
action_close.setShortcut("Ctrl+W")
action_close.setStatusTip("close report")
action_close.triggered.connect(self.close)
menu_bar = self.menuBar()
file_menu = menu_bar.addMenu("&file")
file_menu.addAction(action_toggle_view)
file_menu.addAction(action_toggle_colors)
file_menu.addAction(action_set_font_size)
file_menu.addAction(action_new)
file_menu.addAction(action_save)
file_menu.addAction(action_open)
file_menu.addAction(action_close)
self.text = QTextEdit(self)
self.text.setStyleSheet(
"""
QTextEdit{
color: #000000;
background-color: #ffffff;
}
"""
)
self.setCentralWidget(self.text)
self.setGeometry(300, 300, 300, 300)
self.showMaximized()
self.setWindowTitle("report")
self.show()
def toggle_view(self):
if self.status_view == "window":
#.........这里部分代码省略.........