def fontDatabase_has_font(font): """ This is helper function checks if a certain font family exists on the current system. """ fontDatabase = QFontDatabase() families = fontDatabase.families() return (font.family() in families)
def update_label_font_display(self, newLabelFont): """ Update the displayed font properties for a newly selected label font. Updated properties are font style, size, example text. """ # block signals from to avoid that update_current_label_font # is called multiple times. We'll call it once at the end self.labelStyleComboBox.blockSignals(True) self.labelSizeComboBox.blockSignals(True) fontFamily = newLabelFont.family() fontDatabase = QFontDatabase() availableStyles = fontDatabase.styles(fontFamily) targetStyle = fontDatabase.styleString(newLabelFont) targetStyleIndex = 0 # FIXME: There seems to be a bug in Qt 4.8 # "Normal" styleStrings are "Regular" in styles leading to # a mismatch below if QT_VERSION >= 0x040800: if targetStyle == "Normal": targetStyle = "Regular" self.labelStyleComboBox.clear() for (index, style) in enumerate(availableStyles): self.labelStyleComboBox.addItem(style) if targetStyle == style: targetStyleIndex = index self.labelStyleComboBox.setCurrentIndex(targetStyleIndex) availableSizes = fontDatabase.pointSizes(fontFamily) targetSize = newLabelFont.pointSize() targetSizeIndex = 0 self.labelSizeComboBox.clear() for (index, size) in enumerate(availableSizes): self.labelSizeComboBox.addItem(str(size)) if targetSize == size: targetSizeIndex = index self.labelSizeComboBox.setCurrentIndex(targetSizeIndex) self.update_current_label_font() # turn signals back on self.labelStyleComboBox.blockSignals(False) self.labelSizeComboBox.blockSignals(False)
def __init__(self): if (FontManager.instance is None): FontManager.instance = self self.fonts = {} for font_name in ConfigManager.getOptions('interface','Fonts'): tmp = ConfigManager.getVal('interface','Fonts',font_name) path, family = tuple(map(str.strip,tmp.split('||'))) QFontDatabase.addApplicationFont('resources/fonts/' + path) self.fonts[font_name] = QFont(family)
def __init__(self): if (FontManager.instance is None): FontManager.instance = self self.fonts = {} for font_name in ConfigManager.getOptions('interface', 'Fonts'): tmp = ConfigManager.getVal('interface', 'Fonts', font_name) path, family = tuple(map(str.strip, tmp.split('||'))) QFontDatabase.addApplicationFont('resources/fonts/' + path) self.fonts[font_name] = QFont(family)
def load_fonts(self, lrf, load_substitutions=True): font_map = {} for font in lrf.font_map: fdata = QByteArray(lrf.font_map[font].data) id = QFontDatabase.addApplicationFontFromData(fdata) if id != -1: font_map[font] = [str(i) for i in QFontDatabase.applicationFontFamilies(id)][0] if load_substitutions: base = P("fonts/liberation/*.ttf") for f in glob.glob(base): QFontDatabase.addApplicationFont(f) self.font_loader = FontLoader(font_map, self.dpi)
def addFont(self): ''' @note:: 成功或者失败 ''' font_path = self.font_path fontId = QFontDatabase.addApplicationFont(font_path) if(fontId != -1): fontInfoList = QFontDatabase.applicationFontFamilies(fontId) fontFamily = fontInfoList[0] self.__font.setFamily(fontFamily) log.info("添加字体成功") return True else: log.warning("添加字体失败") return False
def addFont(self): ''' @note:: 成功或者失败 ''' font_path = self.font_path fontId = QFontDatabase.addApplicationFont(font_path) if (fontId != -1): fontInfoList = QFontDatabase.applicationFontFamilies(fontId) fontFamily = fontInfoList[0] self.__font.setFamily(fontFamily) log.info("添加字体成功") return True else: log.warning("添加字体失败") return False
def __init__( self, parent = None ): super(XFontPickerWidget, self).__init__( parent ) # load the user interface projexui.loadUi(__file__, self) # define custom properties database = QFontDatabase() for family in sorted(database.families()): item = QTreeWidgetItem(self.uiFontTREE, [family]) item.setFont(0, QFont(family)) # set default properties # create connections self.uiSizeSPN.valueChanged.connect(self.setPointSize) self.uiFontTREE.itemDoubleClicked.connect(self.accepted)
def __init__(self, parent=None): super(XFontPickerWidget, self).__init__(parent) # load the user interface projexui.loadUi(__file__, self) # define custom properties database = QFontDatabase() for family in sorted(database.families()): item = QTreeWidgetItem(self.uiFontTREE, [family]) item.setFont(0, QFont(family)) # set default properties # create connections self.uiSizeSPN.valueChanged.connect(self.setPointSize) self.uiFontTREE.itemDoubleClicked.connect(self.accepted)
def _get_label_font_from_widget(self): """ Helper function extracting the currently selected labels font info from the widget. """ fontFamily = self.labelFontComboBox.currentFont().family() fontStyle = self.labelStyleComboBox.currentText() if self.labelSizeComboBox.currentText(): fontSize = int(self.labelSizeComboBox.currentText()) else: fontSize = 20 fontDataBase = QFontDatabase() newLabelFont = fontDataBase.font(fontFamily, fontStyle, fontSize) return newLabelFont
def load_fonts(self, lrf, load_substitutions=True): font_map = {} for font in lrf.font_map: fdata = QByteArray(lrf.font_map[font].data) id = QFontDatabase.addApplicationFontFromData(fdata) if id != -1: font_map[font] = [ str(i) for i in QFontDatabase.applicationFontFamilies(id) ][0] if load_substitutions: base = P('fonts/liberation/*.ttf') for f in glob.glob(base): QFontDatabase.addApplicationFont(f) self.font_loader = FontLoader(font_map, self.dpi)
def __init__(self, verify=True): from PyQt4.QtGui import QFontDatabase mainURL = 'https://api.themoviedb.org/3/genre/movie/list' params = {'api_key': tmdb_apiKey} response = requests.get(mainURL, params=params, verify=verify) data = response.json() genres_tup = data['genres'] self._genres = { genre_row['name']: genre_row['id'] for genre_row in genres_tup } self._genres_rev = { genre_row['id']: genre_row['name'] for genre_row in genres_tup } self._genres['ALL'] = -1 self._genres_rev[-1] = 'ALL' # ## now load in the fonts for fontFile in glob.glob( os.path.join(mainDir, 'resources', '*.ttf')): QFontDatabase.addApplicationFont(fontFile)
def _width_with_metrics(self, text): # Return the width of this piece of text when rendered using this # font. fontName = self.font["BaseFont"].name at = fontName.find("+") if at != -1: fontName = fontName[at + 1:] if "-" in fontName: family, style = fontName.split("-")[:2] elif " " in fontName: family, style = fontName.split(" ")[:2] elif "," in fontName: family, style = fontName.split(",")[:2] else: family = fontName style = "" font = QFontDatabase().font(family, style, self.size) font.setPointSizeF(self.size) fm = QFontMetricsF(font) return fm.width(text)
def _width_with_metrics(self, text): # Return the width of this piece of text when rendered using this # font. fontName = self.font["BaseFont"].name at = fontName.find("+") if at != -1: fontName = fontName[at+1:] if "-" in fontName: family, style = fontName.split("-")[:2] elif " " in fontName: family, style = fontName.split(" ")[:2] elif "," in fontName: family, style = fontName.split(",")[:2] else: family = fontName style = "" font = QFontDatabase().font(family, style, self.size) font.setPointSizeF(self.size) fm = QFontMetricsF(font) return fm.width(text)
def _setPlatformDefaults(self): """Set default values, which depend on platform """ """Monaco - old Mac font, Menlo - modern Mac font, Monospace - default for other platforms """ fontFamilies = ("Menlo", "Monaco", "Monospace") availableFontFamilies = QFontDatabase().families() for fontFamily in fontFamilies: if fontFamily in availableFontFamilies: self._data['Qutepart']['Font']['Family'] = fontFamily break else: self._data['Qutepart']['Font']['Family'] = 'Monospace' self._data['PlatformDefaultsHaveBeenSet'] = True
def importTheme(filename, widget, schemeWidget): """Loads the colors theme from a file""" try: d = ET.parse(filename) root = d.getroot() if root.tag != 'frescobaldi-theme': raise ValueError(_("No theme found.")) except Exception as e: QMessageBox.critical( widget, app.caption(_("Error")), _("Can't read from source:\n\n{url}\n\n{error}").format( url=filename, error=e)) return schemeWidget.scheme.blockSignals(True) key = schemeWidget.addScheme(root.get('name')) schemeWidget.scheme.blockSignals(False) tfd = textformats.TextFormatData(key) fontElt = root.find('font') defaultfont = "Lucida Console" if os.name == "nt" else "monospace" if fontElt.get('fontFamily') in QFontDatabase().families(): fontFamily = fontElt.get('fontFamily') else: fontFamily = defaultfont font = QFont(fontFamily) font.setPointSizeF(float(fontElt.get('fontSize'))) tfd.font = font for elt in root.find('baseColors'): tfd.baseColors[elt.tag] = QColor(elt.get('color')) for elt in root.find('defaultStyles'): tfd.defaultStyles[elt.tag] = eltToStyle(elt) for style in root.find('allStyles'): if not style in tfd.allStyles: tfd.allStyles[style] = {} for elt in style: tfd.allStyles[style.tag][elt.tag] = eltToStyle(elt) widget.addSchemeData(key, tfd) schemeWidget.disableDefault(False) schemeWidget.currentChanged.emit() schemeWidget.changed.emit()
def _setPlatformDefaults(self): """Set default values, which depend on platform """ """Monaco - old Mac font, Menlo - modern Mac font, Consolas - default font for Windows Vista+ Lucida Console - on Windows XP Monospace - default for other platforms """ fontFamilies = ("Menlo", "Monaco", "Monospace", "Consolas", "Lucida Console") availableFontFamilies = QFontDatabase().families() for fontFamily in fontFamilies: if fontFamily in availableFontFamilies: self._data['Qutepart']['Font']['Family'] = fontFamily break else: self._data['Qutepart']['Font']['Family'] = 'Monospace' self._data['Qutepart']['Font']['Size'] = max( QApplication.instance().font().pointSize(), 12) self._data['PlatformDefaultsHaveBeenSet'] = True
def font_is_installed(font): """Check if font is installed""" return [fam for fam in QFontDatabase().families() if unicode(fam)==font]
def __init__(self, debug=False): self.app = QApplication(['Turpial'] + sys.argv) Base.__init__(self) QWidget.__init__(self) self.debug = debug for font_path in self.fonts: QFontDatabase.addApplicationFont(font_path) #database = QFontDatabase() #for f in database.families(): # print f self.templates_path = os.path.realpath( os.path.join(os.path.dirname(__file__), 'templates')) self.setWindowTitle('Turpial') self.app.setApplicationName('Turpial') self.setWindowIcon(QIcon(self.get_image_path('turpial.svg'))) self.resize(320, 480) self.center_on_screen() self.ignore_quit = True self.showed = True self.core_ready = False self.timers = {} self.extra_friends = [] self.update_box = UpdateBox(self) self.profile_dialog = ProfileDialog(self) self.profile_dialog.options_clicked.connect(self.show_profile_menu) self.image_view = ImageView(self) self.queue_dialog = QueueDialog(self) self.core = CoreWorker() self.core.ready.connect(self.after_core_initialized) self.core.status_updated.connect(self.after_update_status) self.core.status_broadcasted.connect(self.after_broadcast_status) self.core.status_repeated.connect(self.after_repeat_status) self.core.status_deleted.connect(self.after_delete_status) self.core.message_deleted.connect(self.after_delete_message) self.core.message_sent.connect(self.after_send_message) self.core.column_updated.connect(self.after_update_column) self.core.account_saved.connect(self.after_save_account) self.core.account_loaded.connect(self.after_load_account) self.core.account_deleted.connect(self.after_delete_account) self.core.column_saved.connect(self.after_save_column) self.core.column_deleted.connect(self.after_delete_column) self.core.status_marked_as_favorite.connect( self.after_marking_status_as_favorite) self.core.status_unmarked_as_favorite.connect( self.after_unmarking_status_as_favorite) self.core.fetched_user_profile.connect(self.after_get_user_profile) self.core.urls_shorted.connect(self.update_box.after_short_url) self.core.media_uploaded.connect(self.update_box.after_upload_media) self.core.friends_list_updated.connect( self.update_box.update_friends_list) self.core.user_muted.connect(self.after_mute_user) self.core.user_unmuted.connect(self.after_unmute_user) self.core.user_blocked.connect(self.after_block_user) self.core.user_reported_as_spam.connect(self.after_report_user_as_spam) self.core.user_followed.connect(self.after_follow_user) self.core.user_unfollowed.connect(self.after_unfollow_user) self.core.status_from_conversation.connect( self.after_get_status_from_conversation) self.core.fetched_profile_image.connect(self.after_get_profile_image) self.core.fetched_avatar.connect(self.update_profile_avatar) self.core.fetched_image_preview.connect(self.after_get_image_preview) self.core.status_pushed_to_queue.connect( self.after_push_status_to_queue) self.core.status_poped_from_queue.connect( self.after_pop_status_from_queue) self.core.status_posted_from_queue.connect( self.after_post_status_from_queue) self.core.status_deleted_from_queue.connect( self.after_delete_status_from_queue) self.core.queue_cleared.connect(self.after_clear_queue) self.core.exception_raised.connect(self.on_exception) self.core.start() self._container = Container(self) self.os_notifications = OSNotificationSystem(self.images_path) self.sounds = SoundSystem(self.sounds_path) self.dock = Dock(self) self.dock.accounts_clicked.connect(self.show_accounts_dialog) self.dock.columns_clicked.connect(self.show_column_menu) self.dock.search_clicked.connect(self.show_search_dialog) self.dock.updates_clicked.connect(self.show_update_box) self.dock.messages_clicked.connect( self.show_friends_dialog_for_direct_message) self.dock.queue_clicked.connect(self.show_queue_dialog) #self.dock.filters_clicked.connect(self.show_filters_dialog) self.dock.preferences_clicked.connect(self.show_preferences_dialog) self.tray = TrayIcon(self) self.tray.toggled.connect(self.toggle_tray_icon) self.tray.updates_clicked.connect(self.show_update_box) self.tray.messages_clicked.connect( self.show_friends_dialog_for_direct_message) self.tray.settings_clicked.connect(self.show_preferences_dialog) layout = QVBoxLayout() layout.setSpacing(0) layout.setMargin(0) layout.setContentsMargins(0, 0, 0, 0) layout.addLayout(self._container, 1) layout.addWidget(self.dock) self.setLayout(layout)
elif col+1 in schedule.employees[row].free_days: item.setBackground(FREE_GREEN) table_widget.setItem(row, col, item) def _set_month_label(self, label_widget, year, month): label_widget.setText(unicode(year) + '. ' + calendar.month_name[month]) def about(self): """Show about dialog.""" about = AboutDialog(self) about.exec_() def help(self): """Show help dialog.""" help = HelpDialog(self) help.show() def notimplemented(self): QMessageBox.information(self, u'Not implemented', u'This function is not implemented!\n' u'If you need it, you can hire me for developing it.\n' u'Check About menu!') if __name__ == "__main__": app = QApplication(sys.argv) QFontDatabase.addApplicationFont(':/font/general_foundicons.ttf') form = MainWindow() form.show() sys.exit(app.exec_())
# -*- coding: utf-8 -*- ''' Created on 13 abr. 2017 @author: javit ''' from PyQt4.QtGui import QSplashScreen, QFontDatabase, QFont, QLabel, QProgressBar QFontDatabase.addApplicationFont("./fonts/EXO2REGULAR.TTF") class SplashScreen(QSplashScreen): ''' Splash con logos mostrado al inicio de la aplicacion ''' def __init__(self, pixmap): super(SplashScreen, self).__init__(pixmap) self._title = QLabel(self) self._title.setGeometry(50 * self.width() / 100, 20 * self.height() / 100, 50 * self.width() / 100, 11 * self.height() / 100) self._title.setStyleSheet('QLabel { color : rgb(191,180,110); }') font = QFont('Exo 2') font.setPixelSize(36) font.setBold(True) font.setItalic(True) self._title.setFont(font) font = QFont('Exo 2') font.setPixelSize(16)
IMC.dictPath = os.path.join(base, u"dict") # Initialize the font system. We need a monospaced font with clear visual # separation between 0/O, 1/l, etc, and a good complement of Unicode, with # at a minimum full support of Greek, Cyrillic and Hebrew. These features are # found in Liberation Mono, which is free, and by Courier New, which is less # readable but is bundled in most OSs by default, and by Everson Mono. # We prefer Liberation Mono, but set that or Courier New as the default font family # and as our App's default font. pqMain uses it as a default when # reading the font family name from the saved settings. pqMsgs.noteEvent("Setting up default font name") lm_name = QString(u'Liberation Mono') qfdb = QFontDatabase() qf = qfdb.font(lm_name, QString(u'Regular'), 12) if qf.family() == lm_name: # Lib. Mono is installed in this system, good to go IMC.defaultFontFamily = lm_name else: # Let's try to install Lib. Mono. Was it bundled with us? fpath = os.path.join(base, u"fonts") if os.path.exists(fpath): # It was; add each .ttf in it to the Qt font database # We are *assuming* that what's in fonts is Liberation Mono Regular # for sure, and optionally other variants like bold. for fname in os.listdir(fpath): if fname.endswith(u'.ttf'): qfdb.addApplicationFont(QString(os.path.join(fpath, fname))) IMC.defaultFontFamily = lm_name
def __init__(self, debug=False): self.app = QApplication(["Turpial"] + sys.argv) Base.__init__(self) QWidget.__init__(self) self.debug = debug for font_path in self.fonts: QFontDatabase.addApplicationFont(font_path) # database = QFontDatabase() # for f in database.families(): # print f self.templates_path = os.path.realpath(os.path.join(os.path.dirname(__file__), "templates")) self.setWindowTitle("Turpial") self.app.setApplicationName("Turpial") self.setWindowIcon(QIcon(self.get_image_path("turpial.svg"))) self.resize(320, 480) self.center_on_screen() self.ignore_quit = True self.showed = True self.core_ready = False self.timers = {} self.extra_friends = [] self.update_box = UpdateBox(self) self.profile_dialog = ProfileDialog(self) self.profile_dialog.options_clicked.connect(self.show_profile_menu) self.image_view = ImageView(self) self.queue_dialog = QueueDialog(self) self.core = CoreWorker() self.core.ready.connect(self.after_core_initialized) self.core.status_updated.connect(self.after_update_status) self.core.status_broadcasted.connect(self.after_broadcast_status) self.core.status_repeated.connect(self.after_repeat_status) self.core.status_deleted.connect(self.after_delete_status) self.core.message_deleted.connect(self.after_delete_message) self.core.message_sent.connect(self.after_send_message) self.core.column_updated.connect(self.after_update_column) self.core.account_saved.connect(self.after_save_account) self.core.account_loaded.connect(self.after_load_account) self.core.account_deleted.connect(self.after_delete_account) self.core.column_saved.connect(self.after_save_column) self.core.column_deleted.connect(self.after_delete_column) self.core.status_marked_as_favorite.connect(self.after_marking_status_as_favorite) self.core.status_unmarked_as_favorite.connect(self.after_unmarking_status_as_favorite) self.core.fetched_user_profile.connect(self.after_get_user_profile) self.core.urls_shorted.connect(self.update_box.after_short_url) self.core.media_uploaded.connect(self.update_box.after_upload_media) self.core.friends_list_updated.connect(self.update_box.update_friends_list) self.core.user_muted.connect(self.after_mute_user) self.core.user_unmuted.connect(self.after_unmute_user) self.core.user_blocked.connect(self.after_block_user) self.core.user_reported_as_spam.connect(self.after_report_user_as_spam) self.core.user_followed.connect(self.after_follow_user) self.core.user_unfollowed.connect(self.after_unfollow_user) self.core.status_from_conversation.connect(self.after_get_status_from_conversation) self.core.fetched_profile_image.connect(self.after_get_profile_image) self.core.fetched_avatar.connect(self.update_profile_avatar) self.core.fetched_image_preview.connect(self.after_get_image_preview) self.core.status_pushed_to_queue.connect(self.after_push_status_to_queue) self.core.status_poped_from_queue.connect(self.after_pop_status_from_queue) self.core.status_posted_from_queue.connect(self.after_post_status_from_queue) self.core.status_deleted_from_queue.connect(self.after_delete_status_from_queue) self.core.queue_cleared.connect(self.after_clear_queue) self.core.exception_raised.connect(self.on_exception) self.core.start() self._container = Container(self) self.os_notifications = OSNotificationSystem(self.images_path) self.sounds = SoundSystem(self.sounds_path) self.dock = Dock(self) self.dock.accounts_clicked.connect(self.show_accounts_dialog) self.dock.columns_clicked.connect(self.show_column_menu) self.dock.search_clicked.connect(self.show_search_dialog) self.dock.updates_clicked.connect(self.show_update_box) self.dock.messages_clicked.connect(self.show_friends_dialog_for_direct_message) self.dock.queue_clicked.connect(self.show_queue_dialog) # self.dock.filters_clicked.connect(self.show_filters_dialog) self.dock.preferences_clicked.connect(self.show_preferences_dialog) self.tray = TrayIcon(self) self.tray.toggled.connect(self.toggle_tray_icon) self.tray.updates_clicked.connect(self.show_update_box) self.tray.messages_clicked.connect(self.show_friends_dialog_for_direct_message) self.tray.settings_clicked.connect(self.show_preferences_dialog) layout = QVBoxLayout() layout.setSpacing(0) layout.setMargin(0) layout.setContentsMargins(0, 0, 0, 0) layout.addLayout(self._container, 1) layout.addWidget(self.dock) self.setLayout(layout)
def loadCustomFonts(self): for font in FONTS_DICT.values(): # 0 ~ font name, 1 ~ extension QFontDatabase.addApplicationFont(RES + FONTS + font[0] + '.' + font[1])
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)))
IMC.dictPath = os.path.join(base,u"dict") # Initialize the font system. We need a monospaced font with clear visual # separation between 0/O, 1/l, etc, and a good complement of Unicode, with # at a minimum full support of Greek, Cyrillic and Hebrew. These features are # found in Liberation Mono, which is free, and by Courier New, which is less # readable but is bundled in most OSs by default, and by Everson Mono. # We prefer Liberation Mono, but set that or Courier New as the default font family # and as our App's default font. pqMain uses it as a default when # reading the font family name from the saved settings. pqMsgs.noteEvent("Setting up default font name") lm_name = QString(u'Liberation Mono') qfdb = QFontDatabase() qf = qfdb.font(lm_name,QString(u'Regular'),12) if qf.family() == lm_name : # Lib. Mono is installed in this system, good to go IMC.defaultFontFamily = lm_name else: # Let's try to install Lib. Mono. Was it bundled with us? fpath = os.path.join(base,u"fonts") if os.path.exists(fpath) : # It was; add each .ttf in it to the Qt font database # We are *assuming* that what's in fonts is Liberation Mono Regular # for sure, and optionally other variants like bold. for fname in os.listdir(fpath) : if fname.endswith(u'.ttf') : qfdb.addApplicationFont(QString(os.path.join(fpath,fname))) IMC.defaultFontFamily = lm_name
def populateUi(self): """ Die Graphische Oberfläche wird bevölkert. """ ## Die Icons werden hier definiert, da der Pfad zur ressourcen-DAtei nicht stimmt, wenn pyside-uic über die ui-Datei marschiert ist. self.ui.pushButton_previous.setIcon( QIcon(":/icons/images/actions/1leftarrow.png")) self.ui.pushButton_next.setIcon( QIcon(":/icons/images/actions/1rightarrow.png")) self.ui.actionNew.setIcon(QIcon(":/icons/images/actions/filenew.png")) self.ui.actionOpen.setIcon( QIcon(":/icons/images/actions/fileopen.png")) self.ui.actionSave.setIcon( QIcon(":/icons/images/actions/filesave.png")) self.ui.actionExport.setIcon( QIcon(":/icons/images/actions/fileexport.png")) self.ui.actionPrint.setIcon( QIcon(":/icons/images/actions/agt_print.png")) self.ui.actionSettings.setIcon( QIcon(":/icons/images/actions/exec.png")) self.ui.actionQuit.setIcon(QIcon(":/icons/images/actions/exit.png")) self.info = InfoWidget(self.__storage, self.__character, self) self.ui.layout_info.addWidget(self.info) attributes = AttributeWidget(self.__storage, self.__character, self) self.ui.layout_attributes.addWidget(attributes) skills = SkillWidget(self.__storage, self.__character, self) self.ui.layout_skills.addWidget(skills) #specialties = Specialties( self.__storage.traits["Skill"], self ) specialties = SpecialtiesWidget(self.__storage.traits["Skill"], self) self.ui.layout_specialties.addWidget(specialties) merits = MeritWidget(self.__storage, self.__character, self) self.ui.layout_merits.addWidget(merits) morality = MoralityWidget(self.__storage, self.__character, self) self.ui.layout_morality.addWidget(morality) self.template = TemplateWidget(self.__storage, self.__character, self) self.ui.layout_template.addWidget(self.template) if "Power" in self.__storage.traits.keys(): powers = PowerWidget(self.__storage, self.__character, self) self.ui.layout_powers.addWidget(powers) subPowers = SubPowerWidget(self.__storage, self.__character, self) self.ui.layout_subPowers.addWidget(subPowers) flaws = FlawWidget(self.__storage, self.__character, self) self.ui.layout_flaws.addWidget(flaws) self.__advantages = AdvantagesWidget(self.__storage, self.__character, self) self.ui.layout_advantages.addWidget(self.__advantages) items = ItemWidget(self.__storage, self.__character, self) self.ui.layout_items.addWidget(items) speciesSpecials = SpecialsWidget(self.__storage, self.__character, self) self.ui.layout_specials.addWidget(speciesSpecials) ## Wenn sich der Name im InfoWidget ändert, soll sich auch die Titelzeile des Programms ändern self.info.nameChanged.connect(self.setTitle) ### Wird eine neue Seite angewählt, muß das Info-Widget den Beschreibungstext speichern. #self.pageChanged.connect(self.info.saveDescription) # Die Spezialisierungen einer Fertigkeit sollen angezeigt werden. skills.specialtiesActivated.connect(specialties.showSpecialties) # Menschen haben keine übernatürlichen Kräfte, also zeige ich sie auch nicht an. self.__character.speciesChanged.connect( self.ui.selectWidget_select.disableItems) # Hintergrundbild ändert sich je nach Spezies self.__character.speciesChanged.connect(self.showBackround) ## Sämtliche Schriften in das System laden, damit ich sie auch benutzen kann. resourceFontDir = QDir(":/fonts/fonts") fontsList = resourceFontDir.entryList() for font in fontsList: QFontDatabase.addApplicationFont(resourceFontDir.filePath(font))
def font_names(): model = listmodel.ListModel(sorted(QFontDatabase().families())) model.setRoleFunction(Qt.FontRole, QFont) return model
def font_is_installed(font): """Check if font is installed""" return [ fam for fam in QFontDatabase().families() if to_text_string(fam) == font ]
def populateUi(self): """ Die Graphische Oberfläche wird bevölkert. """ ## Die Icons werden hier definiert, da der Pfad zur ressourcen-DAtei nicht stimmt, wenn pyside-uic über die ui-Datei marschiert ist. self.ui.pushButton_previous.setIcon(QIcon(":/icons/images/actions/1leftarrow.png")) self.ui.pushButton_next.setIcon(QIcon(":/icons/images/actions/1rightarrow.png")) self.ui.actionNew.setIcon(QIcon(":/icons/images/actions/filenew.png")) self.ui.actionOpen.setIcon(QIcon(":/icons/images/actions/fileopen.png")) self.ui.actionSave.setIcon(QIcon(":/icons/images/actions/filesave.png")) self.ui.actionExport.setIcon(QIcon(":/icons/images/actions/fileexport.png")) self.ui.actionPrint.setIcon(QIcon(":/icons/images/actions/agt_print.png")) self.ui.actionSettings.setIcon(QIcon(":/icons/images/actions/exec.png")) self.ui.actionQuit.setIcon(QIcon(":/icons/images/actions/exit.png")) self.info = InfoWidget(self.__storage, self.__character, self) self.ui.layout_info.addWidget( self.info ) attributes = AttributeWidget( self.__storage, self.__character, self ) self.ui.layout_attributes.addWidget( attributes ) skills = SkillWidget( self.__storage, self.__character, self ) self.ui.layout_skills.addWidget( skills ) #specialties = Specialties( self.__storage.traits["Skill"], self ) specialties = SpecialtiesWidget( self.__storage.traits["Skill"], self ) self.ui.layout_specialties.addWidget( specialties ) merits = MeritWidget( self.__storage, self.__character, self ) self.ui.layout_merits.addWidget( merits ) morality = MoralityWidget( self.__storage, self.__character, self ) self.ui.layout_morality.addWidget( morality ) self.template = TemplateWidget(self.__storage, self.__character, self) self.ui.layout_template.addWidget( self.template ) if "Power" in self.__storage.traits.keys(): powers = PowerWidget( self.__storage, self.__character, self ) self.ui.layout_powers.addWidget( powers ) subPowers = SubPowerWidget( self.__storage, self.__character, self ) self.ui.layout_subPowers.addWidget( subPowers ) flaws = FlawWidget( self.__storage, self.__character, self ) self.ui.layout_flaws.addWidget( flaws ) self.__advantages = AdvantagesWidget( self.__storage, self.__character, self ) self.ui.layout_advantages.addWidget( self.__advantages ) items = ItemWidget( self.__storage, self.__character, self ) self.ui.layout_items.addWidget( items ) speciesSpecials = SpecialsWidget(self.__storage, self.__character, self) self.ui.layout_specials.addWidget( speciesSpecials ) ## Wenn sich der Name im InfoWidget ändert, soll sich auch die Titelzeile des Programms ändern self.info.nameChanged.connect(self.setTitle) ### Wird eine neue Seite angewählt, muß das Info-Widget den Beschreibungstext speichern. #self.pageChanged.connect(self.info.saveDescription) # Die Spezialisierungen einer Fertigkeit sollen angezeigt werden. skills.specialtiesActivated.connect(specialties.showSpecialties) # Menschen haben keine übernatürlichen Kräfte, also zeige ich sie auch nicht an. self.__character.speciesChanged.connect(self.ui.selectWidget_select.disableItems) # Hintergrundbild ändert sich je nach Spezies self.__character.speciesChanged.connect(self.showBackround) ## Sämtliche Schriften in das System laden, damit ich sie auch benutzen kann. resourceFontDir = QDir(":/fonts/fonts") fontsList = resourceFontDir.entryList() for font in fontsList: QFontDatabase.addApplicationFont(resourceFontDir.filePath(font))