| Descrizione |
|---|
| Questa piccola macro è dedicata agli utenti di Windows 10. I caratteri del visualizzatore per utilizzare ShapeString sono vuoti e questa piccola macro può aiutare a vedere facilmente il carattere da utilizzare. Versione macro: 03.00 Ultima modifica: 2025-06-24 Versione FreeCAD: 0.18 e superiore Download: ToolBar Icon Autore: Mario52 |
| Autore |
| Mario52 |
| Download |
| ToolBar Icon |
| Link |
| Raccolta di macro Come installare le macro Personalizzare la toolbar |
| Versione macro |
| 03.00 |
| Data ultima modifica |
| 2025-06-24 |
| Versioni di FreeCAD |
| 0.18 e superiore |
| Scorciatoia |
| Nessuna |
| Vedere anche |
| Nessuno |
Questa piccola macro è dedicata agli utenti di Windows 10. I font dentro il visualizzatore per utilizzare ShapeString sono invisibili e questa piccola macro può aiutare a vedere il font in modo chiaro.
Macro Fonts Win10 PYMP
Lanciare la macro, cercare il font e applicarlo.

Finestra della macro per i caratteri PYMP Win10
Menu → Tools → User parameter : BaseApp/Preferences/Macros/FCMmacros/Fonts Win10 PYMP
false la modalità di testo normale (e nera), elimina la switchFontComBoxtrue consente la switchFontComBoxfalse (e switchModeTextList = true) modalità di testo più veloce (a colori) nell'elenco ComboBoxtrue l'elenco (e switchModeTextList = true) in ComboBox viene visualizzato in fontFamily, più lento ma più bello!false matplotlib.font_manager.findSystemFonts ("C: /", "ttf")
true fontman.findSystemFonts (self.pathFont)
Macro Fonts Win10 PYMP.FCMacro
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
"""
***************************************************************************
* Copyright (c) 2019 2020 2025 <mario52> *
* *
* This file is a supplement to the FreeCAD CAx development system. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License (LGPL) *
* as published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* for detail see the LICENCE text file. *
** **
* Use at your own risk. The author assumes no liability for data loss. *
* It is advised to backup your data frequently. *
* If you do not trust the software do not use it. *
** **
* This software is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this macro; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* USA *
***************************************************************************
* WARNING! All changes in this file will be lost and *
* may cause malfunction of the program *
***************************************************************************
"""
#Macro_Fonts_Win10_PYMP 10/05/2019, 06/06/2020, 24/06/2025
#
###############################################################################################
#OS: Windows 10 (10.0) #OS: Ubuntu 20.04 LTS
#Word size of OS: 64-bit #Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit #Word size of FreeCAD: 64-bit
#Version: 0.19.21280 (Git) #Version: 0.18.16131 (Git) AppImage
#Build type: Release #Build type: Release
#Branch: master #Branch: (HEAD detached at 0.18.3)
#Hash: 6f3160db3e88733536c7eaf97ad7d6ebd21baccd#Hash: 3129ae4296e40ed20e7b3d460b86e6969acbe1c3
#Python version: 3.6.8 #Python version: 3.6.7
#Qt version: 5.12.1 #Qt version: 5.6.2
#Coin version: 4.0.0a #Coin version: 4.0.0a
#OCC version: 7.3.0 #OCC version: 7.3.0
#Locale: French/Mars (fr_MA) #
################################################################################################
#
__title__ = "Fonts Win10 PYMP"
__author__ = "Mario52"
__url__ = "https://wiki.freecad.org/Macro_Fonts_ Win10_PYMP"
__version__ = "03.00"
__date__ = "2025/06/25" #YYYY/MM/DD
__icon__ = "https://wiki.freecad.org/images/f/fa/Macro_Fonts_Win10_PYMP.png"
__Gist__ = "https://gist.github.com/mario52a/e7aa19a9dc8ea28ad4f03944ffc8f731"
__Wiki__ = "https://wiki.freecad.org/Macro_Fonts_Win10_PYMP"
#
import PySide
try:
from PySide import QtWidgets
from PySide.QtWidgets import *
except Exception:
None
from PySide import QtGui , QtCore
from PySide.QtGui import *
from PySide.QtCore import *
#
import Draft, Part, PartGui, FreeCADGui, FreeCAD, FreeCADGui
from FreeCAD import Base
import os, time, sys, shutil
import math
from math import sqrt, pi, sin, cos, asin
App=FreeCAD
Gui=FreeCADGui
try:
import webbrowser
except Exception:
None
global ui ; ui = ""
#path#################################################################
global path #
#path = FreeCAD.ConfigGet("AppHomePath") # path FreeCAD installation
#path = FreeCAD.ConfigGet("UserAppData") # path FreeCAD User data
#path = "your path" # your directory path
param = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macro") # macro path
path = param.GetString("MacroPath","") + "/" # macro path
path = path.replace("\\","/") # convert the "\" to "/"
#FreeCAD.Console.PrintMessage( "Path for the icons : " + path + "\n")#
######################################################################
#### matplotlib debut 1/5 #################################################################
## https://matplotlib.org/stable/tutorials/text/text_props.html
## https://forum.freecad.org/viewtopic.php?p=698722#p698722
import re
import operator
from operator import itemgetter #, attrgetter, methodcaller # pour sort
import platform
global newPolicePath
global PolicePath
global originalFontName
global originalFontPath
global searchFontName
global searchMyFavoriteFont
global Remove_favorite ; Remove_favorite = []
global comptMono ; comptMono = 0
global comptMONOSPACE ; comptMONOSPACE = 0
global comptUNISPACE ; comptUNISPACE = 0
if platform.system() == "Windows" :
PolicePath = newPolicePath = originalFontPath = "C:/Windows/Fonts/"
originalFontName = "ARIAL"
elif platform.system() == "Linux" :
PolicePath = newPolicePath = originalFontPath = "/usr/share/fonts/"
originalFontName = "UBUNTU-M"
elif platform.system() == "Darwin":
PolicePath = newPolicePath = originalFontPath = "/Library/Fonts/"
originalFontName = "Arial"
#import glob
#files_TTF = glob.glob(self.pathFont + "/*.TTF")
##################################
import matplotlib
import matplotlib.font_manager
import matplotlib.font_manager as fontman
import matplotlib.font_manager as fontconfig
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
from matplotlib import rc
#from matplotlib.ft2font import FT2Font
##################################
#### Config Begin matplotlib font #######################
# # https://en.wikipedia.org/wiki/Web_colors
global setColorTTF ; setColorTTF = "blue" # .TTF color by "extension name" or hexa "#0000FF"
global setColorFON ; setColorFON = "orange" # .FON color by "extension name" or hexa "#FFA500"
global setColorOTF ; setColorOTF = "green" # .OTF color by "extension name" or hexa "#008000"
global setColorPOL ; setColorPOL = "black" # .OTHER color by "extension name" or hexa "#000000"
#####
global switchModeTextList; switchModeTextList= 1 # 0 = mode text normal (et noir) coupe le switchFontComBox
# 1 = permet le switchFontComBox 1 (default)
#####
global switchFontComBox ; switchFontComBox = 0 # 0 = (et switchModeTextList= 1) mode texte (en couleur) dans liste ComboBox plus rapide (default)
# 1 = (et switchModeTextList= 1) fontFamily dans liste ComboBox plus lent mais plus beau!
#####
global setSystemFonts ; setSystemFonts = 1 # 0 = matplotlib.font_manager.findSystemFonts("C:/", "ttf")
# fait toutes les fontes (dans tous les dossiers et sous dossiers du DD) time !!
# 1 = fontman.findSystemFonts(self.pathFont)
# fait toutes les fontes du repertoire (et dans tous les sous dossiers) (default)
#####
global seTtextAlignement ; seTtextAlignement = 0 # 0 = AlignLeft (default)
# 1 = AlignCenter
# 2 = AlignRight
#####
global setFontByDefault ; setFontByDefault = "ARIAL" # Font by Default
#####
global setLastFontPath ; setLastFontPath = PolicePath#directory font by start
#####
global switchMONOSPACE ; switchMONOSPACE = 0 # 0 = mode normal
# 1 = affiche uniquement les fontes monospace
global searchMyFavoriteFont #;searchMyFavoriteFont =
#
#### Config End matplotlib font #########################
###### Read Configuration begin ####
seTtextAlignement = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetInt("seTtextAlignement")
setSystemFonts = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("setSystemFonts")
switchFontComBox = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchFontComBox")
switchModeTextList = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchModeTextList")
setFontByDefault = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("setFontByDefault")
setLastFontPath = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("setLastFontPath")
switchMONOSPACE = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetBool("switchMONOSPACE")
#### Favorite
searchMyFavoriteFont = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).GetString("searchMyFavoriteFont")
if searchMyFavoriteFont == "":
searchMyFavoriteFont = FreeCAD.ConfigGet("UserAppData") + "MyFavoriteFont"
searchMyFavoriteFont = searchMyFavoriteFont.replace(u"\\","/") # convert the "\" to "/"
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("searchMyFavoriteFont",searchMyFavoriteFont)
global lenFavoriteSaved
if os.path.exists(searchMyFavoriteFont):
lenFavoriteSaved = 0
lenFavoriteSaved = len(os.listdir(searchMyFavoriteFont))
else:
try:
os.mkdir(searchMyFavoriteFont)
lenFavoriteSaved = 0
except Exception:
None
#### Favorite
if setLastFontPath == "":
setLastFontPath = PolicePath
else:
PolicePath = setLastFontPath
if setFontByDefault == "":
if platform.system() == "Windows" :
setFontByDefault = "ARIAL"
elif platform.system() == "Linux" :
setFontByDefault = "UBUNTU-M"
elif platform.system() == "Darwin":
setFontByDefault = "Arial"
searchFontName = setFontByDefault
###### Read Configuration end ####
homeIcon = [
"24 24 14 1",
" c None",
". c #EF2929",
"+ c #A40000",
"@ c #DDDFDC",
"# c #888A85",
"$ c #DDDEDB",
"% c #DCDEDB",
"& c #DCDEDC",
"* c #DBDDDA",
"= c #BABDB6",
"- c #555753",
"; c #729FCF",
"> c #3465A4",
", c #8191AA",
" ",
" ",
" .+ ",
" ..++ ",
" ....++ ",
" .....+++ ",
" ....@#++++ ",
" ....@@@#++++ ",
" ....@@@@@#++++ ",
" ....@@@@$@@#++++ ",
" ....@@@$@@%@@#++++ ",
" ....@@@@@@@@%@@#++++ ",
" ...@@@%%%%&%%*@@#+++ ",
" ..@@@@@@@@@@@@@@@#++ ",
" #@@=#---@@=====@# ",
" #@@=#---@@;>>>;@# ",
" #@@,#---@@;>>>;@# ",
" #@@,#---@@;>>>;@# ",
" #@@=#---@@-----@# ",
" #@@=#---@@@@@@@@# ",
" #@@=##--@@@@@@@@# ",
" ################# ",
" ",
" "]
folderNewIcon = [
"24 24 11 1",
" c None",
". c #FCE94F",
"+ c #EDD400",
"@ c #555753",
"# c #BABDB6",
"$ c #2B4F89",
"% c #D3D7CF",
"& c #5479AB",
"* c #B8BBB5",
"= c #B6BAB4",
"- c #2E5089",
" ...... ",
"........ ",
"........ ",
".+++++++ ",
".+.....+@@@@@@@@@@@@ ",
".+......###########@ ",
".+....$$$$$########@ ",
" +....$%%%$$$$$$$$$$$$& ",
" @####$$$$$$$$$$$$$$$$& ",
" @####$$$$$$$$$$$$$$$$& ",
" @###$$$$$$$$$$$$$$$$& ",
" @#*$$$$$$$$$$$$$$$$$& ",
" @#=$$$$$$$$$$$$$$$$$& ",
" @#=$$$$$$$$$$$$$$$$$& ",
" @#=$$$$$$$$$$$$$$$&&& ",
" @##$$$$$$$$$$$$$$$& ",
" @$$$$$$$$$$$$$$$$& ",
" @$-$$$$$$$$$$$$$$& ",
" @$$$$$$$$$$$$$$$&& ",
" &&&&&&&&&&&&&&&&& ",
" ",
" ",
" ",
" "]
helpIcon = [
"24 24 4 1",
" c None",
". c #016AC5",
"+ c #F8F8FF",
"@ c #FFFFFF",
"........................",
".++++++++++++++++++++++.",
".++++++++++++++++++++++.",
".++..................++.",
".++..................++.",
".++......@@@@@@......++.",
".++.....@@@@@@@@.....++.",
".++.....@@@..@@@.....++.",
".++.....@@....@@.....++.",
".++.....@@....@@.....++.",
".++...........@@.....++.",
".++..........@@@.....++.",
".++.........@@@......++.",
".++........@@@.......++.",
".++........@@........++.",
".++........@@........++.",
".++..................++.",
".++........@@........++.",
".++........@@........++.",
".++..................++.",
".++..................++.",
".++++++++++++++++++++++.",
".++++++++++++++++++++++.",
"........................"]
validIcon = [
"24 24 3 1",
" c None",
". c #4E9A06",
"+ c #FFFFFF",
" ",
" ",
" ",
" . ",
" .+. ",
" .+.+. ",
" .+...+. ",
" .+.....+. ",
" . .+.......+.",
" .+. .+.......+. ",
" .+.+. .+.......+. ",
" .+...+. .+.......+. ",
" .+.....+.+.......+. ",
".+.......+.......+. ",
" .+.............+. ",
" .+...........+. ",
" .+.........+. ",
" .+.......+. ",
" .+.....+. ",
" .+...+. ",
" .+.+. ",
" .+. ",
" . ",
" "]
paintIcon = [
"24 24 9 1",
" c None",
". c #16D0D2",
"+ c #D3D7CF",
"@ c #C17D11",
"# c #EDD400",
"$ c #73D216",
"% c #F57900",
"& c #3465A4",
"* c #CC0000",
" .... ",
" +++ .... @@@@ ",
" ++#### .... $$$ @@@@ ",
" ++####%%%...&&$$$ @@@@ ",
" ####%%% &&&&$$$ @@@@ ",
" ####%%%+&&&&** ",
" $$$$ ++&&&&**##%%% ",
"@@@@$$$$ ++++ ***##%%% ",
"@@@@$$$$ ++++ ####%%% ",
"@@@@ &&&$$$$## ",
"@@@$$$$ %%&&&$$$$ %%%% ",
" $$$$ %%&***$$$ %%%% ",
"...$$$$ %%%***$$$ %%%% ",
"...$$$$*** ***&&&+%%%% ",
"....%%%***### &&&+++@@@@",
"....%%%***### &&&+++@@@@",
" +++%% ### .... @@@@",
" +++ &&& $$$..####@@@@",
" +++ &&****$$..#### ",
" #### &&****$&&&###**** ",
" ####+++**...&&&###**** ",
" ####+++**...&&&& **** ",
" ####+++ ...&&&& **** ",
" .... "]
quitIcon = [
"24 24 3 1",
" c None",
". c #FFFFFF",
"+ c #CC0000",
" .... ",
"++++++++++....++++++++++",
"+.......++....++.......+",
"+.......++....++.......+",
"+.......++....++.......+",
"+...++++++....++++++...+",
"+...++++++....++++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...+++++......+++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+...++++++++++++++++...+",
"+......................+",
"+......................+",
"+......................+",
"++++++++++++++++++++++++"]
setIconTTF = [
"16 16 6 1",
" c None",
". c #204A87",
"+ c None",
"@ c #729FCF",
"# c #CC0000",
"$ c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++#####++++@@+@",
".+++$#$$$++@+@+@",
".++++#$+++++++@+",
".++++#$#####++++",
".++++#$+$#$$$+++",
".++++#$++#$+++++",
".@++++$++#$+###+",
".@@++++++#$+#$$$",
"..@@+++++#$+#$++",
"...@@+++++$+###+",
"....@@++++++#$$$",
".....@@+++++#$++",
"......@@+++++$++",
"................"]
setIconFON = [
"16 16 6 1",
" c None",
". c #204A87",
"+ c None",
"@ c #F57900",
"# c #CC0000",
"$ c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++###++++++@@+@",
".++#$$$++++@+@+@",
".++#$+++++++++@+",
".++###+###++++++",
".++#$$$#$#$+++++",
".++#$++#$#$+++++",
".@++$++#$#$##+#+",
".@@++++#$#$##$#$",
"..@@+++###$#$##$",
"...@@+++$$$#$##$",
"....@@+++++#$+#$",
".....@@++++#$+#$",
"......@@++++$++$",
"................"]
setIconOTF = [
"16 16 6 1",
" c None",
". c #204A87",
"+ c None",
"@ c #4E9A06",
"# c #CC0000",
"$ c #EDD400",
".+++++++++++@@@@",
".++++++++@+@++@@",
".++###++++++@@+@",
".++#$#$++++@+@+@",
".++#$#$+++++++@+",
".++#$#$###++++++",
".++#$#$+#$$+++++",
".++###$+#$++++++",
".@++$$$+#$+###++",
".@@+++++#$+#$$$+",
"..@@++++#$+#$+++",
"...@@++++$+###++",
"....@@+++++#$$$+",
".....@@++++#$+++",
"......@@++++$+++",
"................"]
setIconPOL = [
"16 16 12 1",
" c None",
". c #204A87",
"+ c None",
"@ c #06989A",
"# c #73D216",
"$ c #000000",
"% c #75507B",
"& c #729FCF",
"* c #CC0000",
"= c #F57900",
"- c #EDD400",
"; c #4E9A06",
".+++++++++++@#$%",
".++++++++$+#++&$",
".++***++++++=@+%",
".++*-*-++++*+&+$",
".++*-*-+++++++*+",
".++***-***++++++",
".++*---*-*-+++++",
".++*-++*-*-+++++",
".$++-++*-*-*++++",
".*@++++*-*-*-+++",
"..#*+++***-*-+++",
"...;#+++---*-+++",
"....%=+++++*-+++",
".....;$++++****+",
"......@%++++----",
"................"]
setIconFavori = [
"24 24 9 1",
" c None",
". c #000000",
"+ c #840203",
"@ c #C91408",
"# c #AC372A",
"$ c #CD3D32",
"% c #D3421E",
"& c #D95D36",
"* c #D3694C",
" ",
" ",
" +++++ +++++ ",
" ++@@@++ ++@@@++ ",
" +@@@@@@+++@@@@@@+ ",
" +@@@@@@@@+@@@@@@@@+ ",
" ++@@@@@@@@@@@@@@@@@++ ",
" +@@@@@@@@@@@@@@@@@@@+ ",
" +@@@@@@@@@@@@@@@@@@@+ ",
" +@@@@@@@@@@@@@@@@@@@+ ",
" ++@@@@@@@@@@@@@@@@@++ ",
" +@@@@@@@@@@@@@@@@@+ ",
" +@@@@@@@@@@@@@@@+ ",
" +@@@@@@@@@@@@@+ ",
" +@@@@@@@@@@@+ ",
" +@@@@@@@@@+ ",
" +@@@@@@@+ ",
" +@@@@@+ ",
" +@@@+ ",
" +@+ ",
" + ",
" ",
" ",
" "]
setIconFavoriActive = [
"24 24 5 1",
" c None",
". c #CC0000",
"+ c #A40000",
"@ c #EDD400",
"# c #2E3436",
" ",
" ",
" +++++ +++++@@ ",
" ++...++ ++..@@@@ ",
" +......+++..@@@##@@ ",
" +........+..@@@##@@@ ",
" ++...........@###@@@+ ",
" +............##@@@..+ ",
" +..........###@@@...+ ",
" +........####.......+ ",
" ++........#........++ ",
" +.................+ ",
" +...............+ ",
" @+.............+ ",
" @@@++..........+ ",
" @@@@++........+ ",
" @@@@ +.......+ ",
" +.....+ ",
" +...+ ",
" +.+ ",
" + ",
" ",
" ",
" "]
setIconFavoriStore = [
"24 24 9 1",
" c None",
". c #A30500",
"+ c #CA1108",
"@ c #3C4A83",
"# c #28508A",
"$ c #324E88",
"% c #555755",
"& c #5879AB",
"* c #BBBBB3",
" .. .. ",
" .++. .++. ",
" .++++..++++. ",
".++++++++++++. ",
".++++++++++++.%%%%%% ",
".++++++++++++.*****% ",
".++++++++++++.*****% ",
" .++++++++++.@########& ",
" .++++++++.##########& ",
" %.++++++.$##########& ",
" %*.++++.############& ",
" %**.++.$############& ",
" %**$..##############& ",
" %**#@###############& ",
" %**###############&&& ",
" %**###############& ",
" %################& ",
" %################& ",
" %###############&& ",
" &&&&&&&&&&&&&&&&& ",
" ",
" ",
" ",
" "]
setIconFavoriDelete = [
"24 24 4 1",
" c None",
". c #A40000",
"+ c #2E3436",
"@ c #CC0000",
" .. .. ",
" .@@. .@@. ++++",
" .@@@@++++@@. +...+",
".@@@@@+@@@+@@. +....+",
".@@@@@+@@@@+@. +.....+",
".@@@@@+@@@@@+. +.....+ ",
".@@@@@+@@@@@@+ +.....+ ",
" .@@@@@+@@@@..+.....+ ",
" .@@@@@+@@........+ ",
" .@@@@@+........+ ",
" .@@@@.+......+ ",
" .@@.+........+ ",
" ..+..........+ ",
" +.....+......+ ",
" +.....+ +......+ ",
" +.....+ +......+ ",
" +.....+ +......+",
" +.....+ +.....+",
" +.....+ +....+",
" +.....+ +...+",
" +....+ ++++",
" +...+ ",
" ++++ ",
" "]
def createSpace(texte): # detecte majuscule et ajoute un espace devant la lettre
# return createSpace(TexTe) = Tex Te , if createSpace(TEXTE) = TEXTE
if texte.isupper():
stringSpace = texte
else:
try:
stringSpace = texte[0]
for i in texte[1:]:
if re.search(r"[A-Z]", i): i = " " + i
stringSpace += i
except Exception:
stringSpace = texte
return stringSpace
def family(chaine):
# return family(chaine)[1] = Family , family(chaine)[2] = typeCar (form [a, b, c ...]
famille = typeCar = ""
try:
if chaine.find('-') != -1:
famille = chaine[:chaine.find('-')]
typeCar = chaine[chaine.find('-')+1:]
else:
famille = chaine
typeCar = ""
except Exception:
famille = chaine
typeCar = ""
typeCar = str(createSpace(typeCar)).split()
return [createSpace(famille), typeCar]
class MyLabelPatience(): # fenetre image d'attente de chargement
global path
label = QLabel()
label.setText("<img src=" + path + "Macro_Fonts_Win10_PYMP.png><b><center>Wait please</center> \n\n<center>i search the fonts !\n\n</right></b>")
ecran = FreeCADGui.getMainWindow().frameGeometry()
xF = 250; yF = 250
xW = (ecran.width()/2) - (xF/2)
yW = (ecran.height()/2)- (yF/2)
label.setGeometry(xW, yW, xF, yF)
label.setStyleSheet(u"QLabel {background-color : #F0C300;font: 12pt; }");
label.setWindowFlags(QtCore.Qt.WindowFlags(QtCore.Qt.FramelessWindowHint)) # pas de bords
label.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
#### matplotlib fin 1/5 #################################################################
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def __init__(self ):
self.window = MainWindow
global path #
self.path = path
#### matplotlib font textEdit
self.nomPolice = "Arial"
self.FontTextSize = 20
self.fonteComp = ""
self.font = QtGui.QFont()
####font textEdit
self.FontSize = 10.0
self.red = (204.0 / 255.0)
self.green = (204.0 / 255.0)
self.blue = (204.0 / 255.0)
self.alpha = 1.0 # 1.0 = visibility max (opacity)
self.tableau = [] #Index (), [chemin plus nom fichier (nomPathPolice), nom sans extension (nomSimple), nomSimpleExt (nomSimple + Ext)]
self.index = 0 #Index ()
#### matplotlib font textEdit
def searchFont(self,pathSearch):
global ui
global setSystemFonts
global seTtextAlignement
global switchFontComBox
global switchModeTextList
global setFontByDefault
global searchFontName
global switchMONOSPACE
global Remove_favorite
global searchMyFavoriteFont
global comptMono
global comptMONOSPACE
global comptUNISPACE
MyLabelPatience.label.show()
FreeCADGui.updateGui() # rafraichi l'ecran
files_All_Fonts = ""
##https://matplotlib.org/_modules/matplotlib/font_manager.html
##font_manager._get_win32_installed_fonts()
if setSystemFonts == 0:
files_All_Fonts = matplotlib.font_manager.findSystemFonts(pathSearch, "ttf") # fait toutes les fontes ? ()
else:
files_All_Fonts = fontman.findSystemFonts(pathSearch) # fait toutes les fontes (et dans tous les sous dossiers)
if len(files_All_Fonts) > 0:
self.tableau = []
self.index = 0
self.comboBoxPy.clear()
self.lineEdit_NameFile.clear()
comptMono = comptMONOSPACE = comptUNISPACE = 0
for fonte in files_All_Fonts:
####
nomPathPolice = nomFichier = nomSimpleExt = nomSimple = nomExtension = nameName = ""
####
nomPathPolice = fonte.replace("\\","/") # convert the "\" to "/"
nomFichier = nomPathPolice.split("/") # complet split
nomSimpleExt = nomFichier[-1] # nom avec extension
nomSimple = nomFichier[-1][:-4] # nom sans extension
nomExtension = nomSimpleExt[nomSimpleExt.rfind('.')+1:].upper() # extension
####
try:
# nameFamily = matplotlib.font_manager.FontProperties(fname=fonte).get_family() ##['sans-serif']
# nameStyle = matplotlib.font_manager.FontProperties(fname=fonte).get_style() #normal
# nameVariant = matplotlib.font_manager.FontProperties(fname=fonte).get_variant() #normal
# nameWeight = matplotlib.font_manager.FontProperties(fname=fonte).get_weight() #normal
# nameStretch = matplotlib.font_manager.FontProperties(fname=fonte).get_stretch() #normal
# nameFileComp = matplotlib.font_manager.FontProperties(fname=fonte).get_file() ##c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf
# nameSize = matplotlib.font_manager.FontProperties(fname=fonte).get_size() #10.0
nameName = matplotlib.font_manager.FontProperties(fname=fonte).get_name() ##Noto Naskh Arabic UI
# ##familyName = matplotlib.font_manager.get_font(fonte).family_name # same nameName
# nameSizePoint = matplotlib.font_manager.FontProperties(fname=fonte).get_size_in_points() #10.0
# nameSlant = matplotlib.font_manager.FontProperties(fname=fonte).get_slant() #normal
# namePattern = matplotlib.font_manager.FontProperties(fname=fonte).get_fontconfig_pattern() #:family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:file=c:\windows\fonts\NotoNaskhArabicUI-Regular.ttf:size=10.0
except Exception:
nameFamily = nameStyle = nameVariant = nameWeight = nameStretch = nameFileComp = nameSize = nameName = nameSizePoint = nameSlant = namePattern = ""
if nameName == "" :
nameName = nomSimple
#### MONOSPACE ####
if self.checkBox_0.isChecked():
if "MONO" in nameName.upper():
comptMono += 1
self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
elif "MONOSPACE" in nameName.upper():
comptMONOSPACE += 1
self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
elif "UNISPACE" in nameName.upper():
comptUNISPACE += 1
self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
else:
self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
#### MONOSPACE ####
self.tableau = sorted(self.tableau, key=itemgetter(3)) # sorted by nomSimple.upper()
try:
for line in range(len(self.tableau)): # enleve les doubles (bon)
if self.tableau[line][2] == self.tableau[line + 1][2]: # enleve les doubles (bon)
del(self.tableau[line + 1]) # enleve les doubles (bon)
except Exception:
None
self.comboBoxPy.clear()
for line in range(len(self.tableau)):
try:
self.tableau[line][0] = line # ajoute le numero de ligne
if self.tableau[line][2].upper() == searchFontName.upper(): # detecte la fonte de base
self.index = line
PolicePath = self.tableau[line][1]
####Section common color and font begin ######################
model = self.comboBoxPy.model()
if switchModeTextList == 1:
if self.tableau[line][4] == "TTF":
item = QtGui.QStandardItem(QtGui.QPixmap(setIconTTF), str(line))
item.setForeground(QtGui.QColor(setColorTTF))
elif self.tableau[line][4] == "FON":
item = QtGui.QStandardItem(QtGui.QPixmap(setIconFON), str(line))
item.setForeground(QtGui.QColor(setColorFON))
elif self.tableau[line][4] == "OTF":
item = QtGui.QStandardItem(QtGui.QPixmap(setIconOTF), str(line))
item.setForeground(QtGui.QColor(setColorOTF))
else:
item = QtGui.QStandardItem(QtGui.QPixmap(setIconPOL), str(line))
item.setForeground(QtGui.QColor(setColorPOL))
if seTtextAlignement == 0:
item.setTextAlignment(QtCore.Qt.AlignLeft)
elif seTtextAlignement == 1:
item.setTextAlignment(QtCore.Qt.AlignCenter)
elif seTtextAlignement == 2:
item.setTextAlignment(QtCore.Qt.AlignRight)
else:
self.comboBoxPy.addItem(self.tableau[line][2])
model.appendRow(item)
else:
self.comboBoxPy.addItem("")
self.comboBoxPy.setItemText(line, self.tableau[line][2])
####Section item color and font end ##########################
####Section setfont Family switchFontComBox begin#############
if (switchFontComBox == 1) and (switchModeTextList == 1):
typeCar = font = ""
font = QtGui.QFont()
#font = item.font()
typeCar = family(self.tableau[line][2])[1]
font.setBold(False)
font.setItalic(False)
if len(typeCar) > 0:
for option in typeCar:
if option == "Bold":
font.setBold(True)
if (option == "Italic") or (option == "It") or (option == "Slanted"):
font.setItalic(True)
if option == "Oblique":
font.setItalic(True)
#'Bold''Regular''Slanted''Italic''Medium''Extra''Light''Condensed''Black''It''Semibold'
font.setFamily(self.tableau[line][5])
font.setPixelSize(15)
if switchModeTextList == 1:
item.setFont(font)
else:
self.comboBoxPy.addItem("")
####Section setfont Family switchFontComBox end###############
except Exception:
FreeCAD.Console.PrintMessage("searchFont()")
None
#for i in self.tableau: print(i)
if len(self.tableau) != 0:
font = QtGui.QFont()
font.setFamily(self.tableau[self.index][5])
font.setPointSize(self.FontTextSize)
self.textEditFont.setFont(font)
self.textEditFont.setToolTip("Your text here" + "\n"
"Title (" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") = (index file, number file font)" + "\n"
"Version " + __version__ + " : " + __date__ + ") of " + __title__ + ")" + "\n\n"
"It is possible that a font is not visible in its normal design," + "\n"
"but it is normal in the 3DView, sorry !")
self.lineEdit_NameFile.setText("(" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") " + self.tableau[self.index][1])
self.comboBoxPy.setCurrentIndex(self.index)
self.fonteComp = self.tableau[self.index][1]
else:
self.PB_systemPath.setStyleSheet(u"QPushButton {background-color: rgb(0, 204, 0)}")
self.PB_newPathFont.setStyleSheet(u"QPushButton {background-color: rgb(0, 204, 0)}")
if len(os.listdir(searchMyFavoriteFont)) != 0:
self.PB_favorite.setStyleSheet(u"QPushButton {background-color: rgb(0, 204, 0)}")
#### Remove favorite ####
if len(Remove_favorite) != 0:
for toRemove in Remove_favorite:
print(toRemove)
try:
os.remove(toRemove)
except Exception:
None
print("ouille")
lenFavoriteSaved = len(os.listdir(searchMyFavoriteFont))
self.PB_Save_favorite.setText(_fromUtf8("Save Favorite (" + str(lenFavoriteSaved) + ")"))
Remove_favorite = []
self.PB_Remove_favorite.setText(_fromUtf8("Remove Favorite"))
#### Remove favorite ####
MyLabelPatience.label.close()
def setupUi(self, MainWindow):
global ui
global PolicePath
global lenFavoriteSaved
global switchMONOSPACE
self.window = MainWindow
MainWindow.setObjectName(("MainWindow"))
MainWindow.resize(470, 250)
# MainWindow.setMinimumSize(QtCore.QSize(470, 250))
# MainWindow.setMaximumSize(QtCore.QSize(470, 250))
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(("centralwidget"))
self.groupBox_00 = QGroupBox()
self.groupBox_01 = QGroupBox()
self.groupBox_02 = QGroupBox()
self.textEditFont = QTextEdit(self.centralwidget)
self.lineEdit_NameFile = QLineEdit(self.centralwidget)
self.PB_color = QPushButton(self.centralwidget)
self.PB_color.setIcon(QtGui.QIcon(QtGui.QPixmap(paintIcon))) # icone dans une variable
self.PB_color.clicked.connect(self.on_PB_color) # ""
self.doubleSpinBox_1 = QDoubleSpinBox(self.centralwidget)
self.doubleSpinBox_1.setMinimum(0.0)
self.doubleSpinBox_1.setMaximum(10000.0)
self.doubleSpinBox_1.setSingleStep(1.0)
self.doubleSpinBox_1.setValue(self.FontSize)
self.doubleSpinBox_1.valueChanged.connect(self.on_doubleSpinBox_1_valueChanged)# ""
self.checkBox_0 = QCheckBox(self.centralwidget)
self.checkBox_0.setChecked(switchMONOSPACE)
self.checkBox_0.clicked.connect(self.on_checkBox_0_clicked)
self.checkBox_1 = QCheckBox(self.centralwidget)
self.checkBox_1.setChecked(False)
# self.checkBox_1.clicked.connect(self.on_checkBox_1_clicked)
self.doubleSpinBox_2 = QDoubleSpinBox(self.centralwidget)
self.doubleSpinBox_2.setMinimum(0.0)
self.doubleSpinBox_2.setMaximum(10000.0)
self.doubleSpinBox_2.setSingleStep(1.0)
self.doubleSpinBox_2.setValue(self.FontTextSize)
self.doubleSpinBox_2.valueChanged.connect(self.on_doubleSpinBox_2_valueChanged)#connect on def "on_doubleSpinBox_2_valueChanged"
self.PU_Exit = QPushButton(self.centralwidget)
self.PU_Exit.setIcon(QtGui.QIcon(QtGui.QPixmap(quitIcon))) # icone dans une variable
self.PU_Exit.clicked.connect(self.on_PU_Exit)
self.PB_newPathFont = QPushButton(self.centralwidget)
self.PB_newPathFont.setIcon(QtGui.QIcon(QtGui.QPixmap(folderNewIcon)))# icone dans une variable
self.PB_newPathFont.clicked.connect(self.on_PB_newPathFont)
self.PB_systemPath = QPushButton(self.centralwidget)
self.PB_systemPath.setIcon(QtGui.QIcon(QtGui.QPixmap(homeIcon))) # icone dans une variable
self.PB_systemPath.clicked.connect(self.on_PB_systemPath)
self.PB_favorite = QPushButton(self.centralwidget)
self.PB_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavori))) # icone dans une variable
self.PB_favorite.clicked.connect(self.on_PB_favorite)
self.PB_Save_favorite = QPushButton(self.centralwidget)
self.PB_Save_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavoriStore))) # icone dans une variable
self.PB_Save_favorite.clicked.connect(self.on_PB_Save_favorite)
self.PB_Remove_favorite = QPushButton(self.centralwidget)
self.PB_Remove_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavoriDelete))) # icone dans une variable
self.PB_Remove_favorite.clicked.connect(self.on_PB_Remove_favorite)
if setLastFontPath != searchMyFavoriteFont:
self.PB_Remove_favorite.setEnabled(False)
else:
self.PB_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavoriActive))) # icone dans une variable
self.PB_Save_favorite.setEnabled(False)
self.PB_Remove_favorite.setEnabled(True)
self.PB_OK = QPushButton(self.centralwidget)
self.PB_OK.setIcon(QtGui.QIcon(QtGui.QPixmap(validIcon))) # icone dans une variable
self.PB_OK.clicked.connect(self.on_PB_OK)
self.PB_Help = QPushButton()
self.PB_Help.setIcon(QtGui.QIcon(QtGui.QPixmap(helpIcon))) # icone dans une variable
self.PB_Help.clicked.connect(self.on_PB_Help)
####
self.comboBoxPy = QComboBox(self.centralwidget)
ui.searchFont(PolicePath)
# ui.on_fontComboBoxPython(self.index)
QtCore.QObject.connect(self.comboBoxPy, QtCore.SIGNAL("currentIndexChanged(int)"), self.on_fontComboBoxPython)
####
####Layout#########################################################
gridLayout_00_Font = QGridLayout(self.centralwidget) # cadre principal
gridLayout_00_Font.addWidget(self.groupBox_00) # cadre groupbox principal
gridLayout_01_Font = QGridLayout(self.groupBox_00) # groupBox_00
self.gridLayout_Font_Font = QGridLayout(self.groupBox_01)
self.gridLayout_Font_Font.setContentsMargins(10, 10, 10, 10)
self.gridLayout_Font_Font.addWidget(self.textEditFont, 0, 0, 1, 1)
self.gridLayout_Font_Font.addWidget(self.lineEdit_NameFile, 1, 0, 1, 1)
self.gridLayout_Font_Font.addWidget(self.comboBoxPy, 2, 0, 1, 1)
gridLayout_01_Font.addWidget(self.groupBox_01, 0, 0, 1, 1)
####
self.gridLayout_Command_Font = QGridLayout(self.groupBox_02)
self.gridLayout_Command_Font.setContentsMargins(10, 10, 10, 10)
self.gridLayout_Command_Font.addWidget(self.PB_color, 0, 0, 1, 1)
self.gridLayout_Command_Font.addWidget(self.doubleSpinBox_1, 0, 1, 1, 1)
self.gridLayout_Command_Font.addWidget(self.checkBox_0, 0, 2, 1, 1)
self.gridLayout_Command_Font.addWidget(self.checkBox_1, 0, 3, 1, 1)
self.gridLayout_Command_Font.addWidget(self.doubleSpinBox_2, 0, 4, 1, 1)
##
self.gridLayout_Command_Font.addWidget(self.PB_newPathFont, 1, 0, 1, 1)
self.gridLayout_Command_Font.addWidget(self.PB_systemPath, 1, 1, 1, 1)
self.gridLayout_Command_Font.addWidget(self.PB_favorite, 1, 2, 1, 1)
self.gridLayout_Command_Font.addWidget(self.PB_Save_favorite, 1, 3, 1, 1)
self.gridLayout_Command_Font.addWidget(self.PB_Remove_favorite, 1, 4, 1, 1)
##
self.gridLayout_Command_Font.addWidget(self.PU_Exit, 2, 0, 1, 1)
self.gridLayout_Command_Font.addWidget(self.PB_OK, 2, 1, 1, 1)
self.gridLayout_Command_Font.addWidget(self.PB_Help, 2, 4, 1, 1)
gridLayout_01_Font.addWidget(self.groupBox_02, 2, 0, 1, 1)
####Layout#########################################################
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
global lenFavoriteSaved
global comptMono
global comptMONOSPACE
global comptUNISPACE
MainWindow.setWindowTitle(_fromUtf8(__title__))
MainWindow.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # PySide cette fonction met la fenetre en avant
MainWindow.setWindowIcon(QtGui.QIcon(_fromUtf8(self.path + "Macro_Fonts_Win10_PYMP.png"))) # change l'icone de la fenetre principale
self.groupBox_00.setTitle(_fromUtf8("ver : " + __version__ + " : " + __date__ + " (rmu)"))
self.groupBox_01.setTitle(_fromUtf8("Font"))
self.textEditFont.setText("Your text here (IWT)")
self.textEditFont.setToolTip("Your text here" + "\n"
"Title (" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") = (index file, number file font)" + "\n"
"Version " + __version__ + " : " + __date__ + ") of " + __title__ + ")" + "\n\n"
"It is possible that a font is not visible in its normal design," + "\n"
"but it is normal in the 3DView, sorry !")
self.lineEdit_NameFile.setToolTip("Complete path and name of Font file")
self.comboBoxPy.setToolTip("<html><body>"
"Choice your Font" + "<br>" +
"<br>"
"You must modify the configuration of display" + "<br>"
"Menu Edit parameter: User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__ + ":" + "<br><br>"
"####" + "<br>"
"switchModeTextList = 1"
"<BLOCKQUOTE>" + "# 0 = mode text normal (the switchFontComBox is enabled)" + "<br>"
"# 1 = switchFontComBox authorized (default)" + "</BLOCKQUOTE>"
"#####" + "<br>"
"switchFontComBox = 1"
"<BLOCKQUOTE>" + "# 0 = mode text in color .. faster" + "<br>"
"# 1 = fontFamily listed ComboBox slower but beautiful (default)" + "</BLOCKQUOTE>"
"#####" + "<br>"
"setSystemFonts = 1"
"<BLOCKQUOTE>" + "# 0 = matplotlib.font_manager.findSystemFonts" + "<br>"
"## all fonts in System font" + "<br>"
"# 1 = fontman.findSystemFonts(self.pathFont) (default)" + "<br>"
"## all fonts in all directory and sub directory" + "</BLOCKQUOTE>"
"#####" + "<br>" +
"seTtextAlignement = 0"
"<BLOCKQUOTE>" + "# 0 = AlignLeft (default)" + "<br>"
"# 1 = AlignCenter" + "<br>"
"# 2 = AlignRight" + "</BLOCKQUOTE>"
"#####" + "<br>"
"setFontByDefault = ""ARIAL"" # ARIAL"
"#####" + "<br>"
"setLastFontPath = PolicePath # directory font by start" + "<br><br>"
"####" + "<br>"
"Actual configuration : " + str(switchModeTextList) + ", " + str(switchFontComBox) + ", " + str(setSystemFonts) + ", " +
str(seTtextAlignement) + ", " + str(setFontByDefault) + ", " + str(setLastFontPath) + "<br><br>"
"####" + "<br>"
"Read the info"
"</body></html>")
####
self.groupBox_02.setTitle(_fromUtf8("Command"))
self.PB_OK.setText(_fromUtf8("Ok"))
self.PB_OK.setToolTip(_fromUtf8("Validate"))
self.PB_color.setText(_fromUtf8("Color"))
self.PB_color.setToolTip(_fromUtf8("Text color"))
self.doubleSpinBox_1.setToolTip(_fromUtf8("Dimension of the Shape"))
self.doubleSpinBox_1.setSuffix(" mm")
self.checkBox_0.setText(_fromUtf8("MonoSpace"))
if self.checkBox_0.isChecked():
self.checkBox_0.setToolTip(_fromUtf8("Search only the MONOSPACE, UNISPACE fonts" + "\n" +
"Number Mono : " + str(comptMono) + "\n" +
"Number MONOSPACE : " + str(comptMONOSPACE) + "\n" +
"Number UNISPACE : " + str(comptUNISPACE)))
else:
self.checkBox_0.setToolTip(_fromUtf8("Search only the MONOSPACE, UNISPACE fonts"))
self.checkBox_1.setText(_fromUtf8("Text"))
self.checkBox_1.setToolTip(_fromUtf8("Create text"))
self.PB_newPathFont.setText(_fromUtf8("New folder"))
self.PB_newPathFont.setToolTip(_fromUtf8("New directory font"))
self.doubleSpinBox_2.setToolTip(_fromUtf8("Dimension of text in window macro"))
self.doubleSpinBox_2.setSuffix(" mm")
self.PU_Exit.setText(_fromUtf8("Exit"))
self.PU_Exit.setToolTip(_fromUtf8("Quit Fonts Win10 PYMP bye bye"))
self.PB_Help.setText(_fromUtf8("Help"))
self.PB_Help.setToolTip(_fromUtf8("Help on line " + __version__ + " " + __date__ + " rmu"))
self.PB_systemPath.setText(_fromUtf8("Origin"))
self.PB_systemPath.setToolTip(_fromUtf8("Return origin font system"))
self.PB_favorite.setText(_fromUtf8("Favorite"))
self.PB_favorite.setToolTip(_fromUtf8("<html><body>" +
"Search in the favorite fonts directory" + "<br><br>" +
"Actual : " + "<br>" + "<b>" + searchMyFavoriteFont + "</b>" + "<br><br>" +
"For change the favorite directory go to : " + "<br><br>" +
"<b>" + "User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__ + "</b>" + "<br><br>" +
"modify the variable : " + "<b>" + "'searchMyFavoriteFont'" + "</b>" + "<br>"
"</html></body>" ))
self.PB_Save_favorite.setText(_fromUtf8("Save Favorite (" + str(lenFavoriteSaved) + ")"))
self.PB_Save_favorite.setToolTip(_fromUtf8("<html><body>" +
"Save the favorite fonts displayed in directory" + "<br><br>" +
"Actual : " + "<b>" + searchMyFavoriteFont + "</b>" + "<br><br>" +
"Number : " + "<b>" + str(lenFavoriteSaved) + "</b>" + " file(s)" + "<br>" +
"</html></body>"))
self.PB_Remove_favorite.setText(_fromUtf8("Remove Favorite"))
self.PB_Remove_favorite.setToolTip(_fromUtf8("<html><body>" +
"Store the favorite font(s) to be displayed for delete" + "<br><br>" +
"The file(s) are deleted after change directory" + "<br><br>" +
"EX: push button " + "<b>" + "'New folder'" + "</b>" + " or " + "<b>" + "'Origin'" + "</b>" + "<br><br>" +
"If not the file(s) remain in place " + "<font color='red'>" + "<i>" + "(not deleted)" + "</i>" + "</font>" + "<br>"
"</html></body>"))
def on_doubleSpinBox_1_valueChanged(self,value): #
self.FontSize = value
def on_checkBox_0_clicked(self):
global ui
global switchMONOSPACE
#global searchMyFavoriteFont
switchMONOSPACE = self.checkBox_0.isChecked()
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchMONOSPACE", switchMONOSPACE) # True or False
#ui.searchFont(searchMyFavoriteFont)
def on_doubleSpinBox_2_valueChanged(self,value):
self.FontTextSize = value
self.font.setPointSize(self.FontTextSize)
self.textEditFont.setCurrentFont(self.font)
self.textEditFont.setFont(self.font)
def on_fontComboBoxPython(self,indeX): # 0: for fontComboBoxPython
global setFontByDefault
if len(self.tableau) != 0:
self.index = indeX
self.lineEdit_NameFile.setText("(" + str(self.index + 1) + "/" + str(len(self.tableau)) + ") " + self.tableau[self.index][1])
famille = typeCar = self.font = ""
self.font = QtGui.QFont()
typeCar = family(self.tableau[self.index][2])[1]
self.font.setBold(False)
self.font.setItalic(False)
if len(typeCar) > 0:
for option in typeCar:
if option == "Bold":
self.font.setBold(True)
if (option == "Italic") or (option == "It") or (option == "Slanted"):
self.font.setItalic(True)
if option == "Oblique":
self.font.setItalic(True)
#'Bold''Regular''Slanted''Italic''Medium''Extra''Light''Condensed''Black''It''Semibold'#+
self.font.setFamily(self.tableau[self.index][5])
self.font.setPointSize(self.FontTextSize)
self.textEditFont.setCurrentFont(self.font)
self.textEditFont.setFont(self.font)
####
self.fonteComp = self.tableau[self.index][1]
setFontByDefault = self.tableau[self.index][2]
# FreeCAD.Console.PrintMessage(str(self.index) + " , " + self.tableau[self.index][1] + " , " + self.tableau[self.index][2] + " , ' " + famille + "' , ' " + typeCar + " ' \n")
def on_PB_OK(self):
if len(self.tableau) != 0:
texte = self.textEditFont.toPlainText()
if texte != "":
FreeCAD.ActiveDocument.openTransaction("ShStr (" + texte[:15] + "...)") # memorise les actions (avec annuler restore)
tx = Draft.makeShapeString(String=texte, FontFile = self.fonteComp, Size = self.FontSize, Tracking = 0.0)
tx.Label = self.tableau[self.index][2]
tx.ViewObject.ShapeColor = (self.red, self.green, self.blue) # color of ShapeString
## section Texte
if self.checkBox_1.isChecked():
FreeCAD.ActiveDocument.openTransaction("Text (" + texte[:15] + "...)") # memorise les actions (avec annuler restore)
tx2 = Draft.makeText([texte],point=FreeCAD.Vector(0.0,0.0,0.0))
tx2.ViewObject.FontName = self.tableau[self.index][1]
tx2.ViewObject.TextColor = (self.red, self.green, self.blue) # color of text
tx2.ViewObject.FontSize = self.FontSize
tx2.Label = self.tableau[self.index][2]
FreeCAD.Console.PrintMessage("___________________" + "\n")
FreeCAD.Console.PrintMessage(texte + "\n")
FreeCAD.Console.PrintMessage(self.tableau[self.index][1] + "\n")
FreeCAD.Console.PrintMessage(self.tableau[self.index][2] + "\n")
FreeCAD.Console.PrintMessage(str(self.FontSize) + "\n")
FreeCAD.Console.PrintMessage("___________________" + "\n")
FreeCAD.ActiveDocument.recompute()
else:
FreeCAD.Console.PrintMessage("Not string" + "\n")
def on_PB_color(self):
self.PB_color.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.window.hide()
couleur = QColorDialog.getColor()
if couleur.isValid():
self.red = couleur.redF()
self.green = couleur.greenF()
self.blue = couleur.blueF()
self.alpha = couleur.alphaF()
self.PB_color.setStyleSheet(u"QPushButton {background-color: }" + couleur.name())
self.window.show()
def on_PB_newPathFont(self):
global ui
global newPolicePath
global setSystemFonts
global setLastFontPath
self.PB_systemPath.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_newPathFont.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_favorite.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavori))) # icone dans une variable
self.PB_Save_favorite.setEnabled(True)
self.PB_Remove_favorite.setEnabled(False)
newPolicePath = str(QFileDialog.getExistingDirectory(None, "Select new font directory", newPolicePath, QFileDialog.ShowDirsOnly))
if newPolicePath:
setLastFontPath = newPolicePath
ui.searchFont(newPolicePath)
setSystemFonts = 1
def on_PB_systemPath(self):
global ui
global setSystemFonts
global originalFontPath
global originalFontName
global setLastFontPath
global searchFontName
self.PB_systemPath.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_newPathFont.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_favorite.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavori))) # icone dans une variable
self.PB_Save_favorite.setEnabled(True)
self.PB_Remove_favorite.setEnabled(False)
#setSystemFonts = 1
setLastFontPath = originalFontPath
searchFontName = originalFontName
ui.searchFont(originalFontPath)
def on_PB_favorite(self):
global ui
global setLastFontPath
global searchMyFavoriteFont
if len(os.listdir(searchMyFavoriteFont)) != 0:
self.PB_systemPath.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_newPathFont.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_favorite.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_favorite.setIcon(QtGui.QIcon(QtGui.QPixmap(setIconFavoriActive))) # icone dans une variable
self.PB_Save_favorite.setEnabled(False)
self.PB_Remove_favorite.setEnabled(True)
self.PB_Remove_favorite.setText(_fromUtf8("Remove Favorite"))
setSystemFonts = 1
setLastFontPath = searchMyFavoriteFont
ui.searchFont(searchMyFavoriteFont)
else:
self.PB_favorite.setStyleSheet(u"QPushButton {background-color: rgb(204, 0, 0)}")
self.PB_favorite.setText(_fromUtf8("Empty"))
def on_PB_Save_favorite(self):
global ui
global searchMyFavoriteFont
if (len(self.tableau) != 0):
original = self.tableau[self.index][1]
copieFavori = searchMyFavoriteFont + "/" + self.tableau[self.index][2] + "." + self.tableau[self.index][4]
if (original != copieFavori):
try:
self.PB_Save_favorite.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_Remove_favorite.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
if os.path.exists(searchMyFavoriteFont):
shutil.copy(original, copieFavori)
else:
try:
os.mkdir(searchMyFavoriteFont)
shutil.copy(original, copieFavori)
except Exception:
self.PB_Save_favorite.setStyleSheet(u"QPushButton {background-color: rgb(204, 0, 0)}")
self.PB_Remove_favorite.setStyleSheet(u"QPushButton {background-color: rgb(204, 0, 0)}")
lenFavoriteSaved = len(os.listdir(searchMyFavoriteFont))
self.PB_favorite.setStyleSheet(u"QPushButton {background-color: QPalette.Base}")
self.PB_Save_favorite.setText(_fromUtf8("Save Favorite (" + str(lenFavoriteSaved) + ")"))
self.PB_Remove_favorite.setText(_fromUtf8("Remove Favorite"))
self.PB_favorite.setText(_fromUtf8("Favorite"))
except Exception:
None
def on_PB_Remove_favorite(self):
global ui
global searchMyFavoriteFont
global Remove_favorite
if len(self.tableau) != 0:
##self.tableau.append([0, nomPathPolice, nomSimple, nomSimpleExt.upper(), nomExtension.upper(), nameName])
actual = self.tableau[self.index][1].upper()
favori = (searchMyFavoriteFont + "/" + self.tableau[self.index][3]).upper()
if actual == favori:
toRemove = self.tableau[self.index][1]
Remove_favorite.append(toRemove)
Remove_favorite = list(set(Remove_favorite)) # efface doublons
self.PB_Remove_favorite.setText(_fromUtf8("Remove Favorite " + str(len(Remove_favorite))))
#os.remove(toRemove)
#lenFavoriteSaved = len(os.listdir(searchMyFavoriteFont))
#self.PB_Save_favorite.setText(_fromUtf8("Save Favorite (" + str(lenFavoriteSaved) + ")"))
#ui.searchFont(searchMyFavoriteFont)
def on_PB_Help(self): # Help Wiki
self.PB_Help.setStyleSheet(u"QPushButton {background-color: QPalette.Base}") #red
try:
webbrowser.open(__Wiki__)
App.Console.PrintMessage("https://wiki.freecad.org/Macro_Fonts_ Win10_PYMP" + "\n")
except Exception:
self.PB_Help.setStyleSheet(u"QPushButton {border-width: 2px; border-style: solid; border-color: red}") #red
self.PB_Help.setText(u"Not access")
def on_PU_Exit(self): # Exit
global switchModeTextList
global switchFontComBox
global setSystemFonts
global seTtextAlignement
global setFontByDefault
global setLastFontPath
global switchMONOSPACE
###### Write Configuration begin ####
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("setLastFontPath", setLastFontPath) # "PolicePath"
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("setFontByDefault", setFontByDefault) # "Arial"
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchModeTextList", switchModeTextList) # True or False
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchFontComBox", switchFontComBox) # True or False
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("setSystemFonts", setSystemFonts) # True or False
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetInt("seTtextAlignement", seTtextAlignement) # 0, 1, 2
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetBool("switchMONOSPACE", switchMONOSPACE) # True or False
###### Write Configuration end ####
App.Console.PrintMessage("Fin " + __title__ + "\n")
self.window.hide()
####
FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Macros/FCMmacros/" + __title__).SetString("Version",__version__ + " (" + __date__ + ")")#
doc = FreeCAD.ActiveDocument
if doc == None:
doc = FreeCAD.newDocument()
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
Sul forum TTF Text Font
Le mie macro in mario52a gists
Versione = "03.00" Data = 24/06/2025 : tornato a PySide e aggiunto: search monospace, create preferite fonts in a directory
Version = "2.0 Date = 2020/06/06 : Aggiunto al layout pulsante e icona
Version = "00.01" Date = "2019/05/10"