-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.vfpy
183 lines (143 loc) · 6.97 KB
/
install.vfpy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#FLM: TypeRig: Installer
# -------------------------------------------------------------------------
# ___ ___ ____
# | | | /\ TypeRig
# |___|___|__/__\
# | | / / (C) Font development kit for FontLab
# |___|/___/ (C) Vassil Kateliev, 2017-2021 (http://www.kateliev.com)
# | |\ \
# |___| \___\ www.typerig.com
#
# -------------------------------------------------------------------------
# (C) Vassil Kateliev, 2021 (http://www.kateliev.com)
# (C) Karandash Type Foundry (http://www.karandash.eu)
#--------------------------------------------------------------------------
# www.typerig.com
# No warranties. By using this you agree
# that you use it at your own risk!
# - Dependencies -----------------
from __future__ import print_function
import os
import sys
import shutil
import sysconfig
import site
from PythonQt import QtCore, QtGui
# - Init --------------------------------
app_name, app_version = 'TR | Module Installer', '1.6'
# - String ------------------------------
str_manual_label = '''
<p><b>Manual installation via Link:</b> Will generate a *.pth file containing a link pointing to your current TypeRig library folder.
Please save the generated file in a folder of your choosing and then copy it to the python installation path shown below in the Information field.</p>
'''
str_auto_pth_label = '''
<p><b>Dynamic installation via Link:</b> Will generate a special *.pth file containing a link pointing to your current TypeRig library folder and copy it into your FontLab Python folder.
Best option if you want to keep your TypeRig folder outside your FontLab installation and sync it regularly to the TypeRig GitHub repository. Regular updates will not require running the installer again, unless you move the TypeRig folder.</p>
'''
str_auto_copy_label = '''
<p><b>Static installation via Copy:</b> Will copy all the necessary files from TypeRig library folder into into your FontLab Python folder. Best if you are not planning to update TypeRig from GitHub repository. For each update/sync to GitHub repo you will need to run this script again.</p>'''
str_auto_failed = '''
<p><b>Important note: </b>If installation options fail due to OS security reasons (Access Denied) you should run FontLab with elevated privileges (administrator) and execute this script again.</p>
'''
# - Config ------------------------------
module_name = 'typerig'
module_path = 'Lib'
file_ext = '.pth'
current_folder = os.path.dirname(__file__)
libary_folder = os.path.normpath(os.path.join(current_folder, module_path))
python_folder = site.USER_SITE
if python_folder is None: python_folder = sysconfig.get_paths()['purelib']
# - Functions --------------------------
def copy_tree(path_source, path_destination):
# - Make sure the destination folder does not exist.
if os.path.exists(path_destination) and os.path.isdir(path_destination):
print('Destination path already present! Removing existing tree: {}'.format(path_destination))
shutil.rmtree(path_destination, ignore_errors=False)
# - Process
shutil.copytree(path_source, path_destination)
# - Widgets ---------------------
class dlg_install(QtGui.QDialog):
def __init__(self):
super(dlg_install, self).__init__()
# - Images
img_logo = QtGui.QPixmap(os.path.join(current_folder, 'typerig-logo.png'))
# - Labels
self.lbl_logo = QtGui.QLabel()
self.lbl_logo.setPixmap(img_logo.scaled(200, 200, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation))
self.lbl_logo.setAlignment(QtCore.Qt.AlignCenter)
self.lbl_auto_pth = QtGui.QLabel(str_auto_pth_label)
self.lbl_auto_pth.setWordWrap(True)
self.lbl_auto_pth.setTextFormat(QtCore.Qt.RichText)
self.lbl_auto_copy = QtGui.QLabel(str_auto_copy_label)
self.lbl_auto_copy.setWordWrap(True)
self.lbl_auto_copy.setTextFormat(QtCore.Qt.RichText)
self.lbl_manual = QtGui.QLabel(str_manual_label)
self.lbl_manual.setWordWrap(True)
self.lbl_manual.setTextFormat(QtCore.Qt.RichText)
self.lbl_fail = QtGui.QLabel(str_auto_failed)
self.lbl_fail.setWordWrap(True)
self.lbl_fail.setTextFormat(QtCore.Qt.RichText)
# - Group box
self.box_auto = QtGui.QGroupBox('Automatic')
self.box_manual = QtGui.QGroupBox('Manual')
self.box_info = QtGui.QGroupBox('Information')
# - Edit
self.edt_python_path = QtGui.QLineEdit()
self.edt_python_path.setText(python_folder)
# - Buttons
self.btn_install_auto_pth = QtGui.QPushButton('Auto Install via Link')
self.btn_install_auto_copy = QtGui.QPushButton('Auto Install via Copy')
self.btn_install_manual_pth = QtGui.QPushButton('Manual Install via Link')
self.btn_install_auto_pth.clicked.connect(self.install_auto_pth)
self.btn_install_auto_copy.clicked.connect(self.install_auto_copy)
self.btn_install_manual_pth.clicked.connect(self.install_manual_pth)
# - Build layouts
# -- Auto install
layout_auto = QtGui.QVBoxLayout()
layout_auto.addWidget(self.lbl_auto_pth)
layout_auto.addWidget(self.btn_install_auto_pth)
layout_auto.addWidget(self.lbl_auto_copy)
layout_auto.addWidget(self.btn_install_auto_copy)
self.box_auto.setLayout(layout_auto)
# -- Manual install
layout_manual = QtGui.QVBoxLayout()
layout_manual.addWidget(self.lbl_manual)
layout_manual.addWidget(self.btn_install_manual_pth)
self.box_manual.setLayout(layout_manual)
# -- Info box
layout_info = QtGui.QVBoxLayout()
layout_info.addWidget(QtGui.QLabel('Your current FontLab Python installation path:'))
layout_info.addWidget(self.edt_python_path)
layout_info.addWidget(self.lbl_fail)
self.box_info.setLayout(layout_info)
# -- Main
layout_main = QtGui.QVBoxLayout()
layout_main.addWidget(self.lbl_logo)
layout_main.addWidget(self.box_auto)
layout_main.addWidget(self.box_manual)
layout_main.addWidget(self.box_info)
# - Set Widget
self.setLayout(layout_main)
self.setWindowTitle('%s %s' %(app_name, app_version))
self.setGeometry(300, 300, 400, 200)
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) # Always on top!!
self.show()
# - Functions -----------------------
def install_auto_copy(self):
copy_tree(os.path.join(libary_folder, module_name), os.path.join(python_folder, module_name))
print('DONE:\tTypeRig installed in: %s' %python_folder)
def install_auto_pth(self):
if not os.path.exists(python_folder):
os.makedirs(python_folder)
pth_file_name = os.path.join(python_folder, '%s%s' %(module_name, file_ext))
with open(pth_file_name, 'w') as pth_file:
pth_file.write(libary_folder)
print('DONE:\tTypeRig installed!\nNOTE:\tRun script again if you change the location of the library')
def install_manual_pth(self):
pth_folder_name = QtGui.QFileDialog.getExistingDirectory(self, 'Save Link to TypeRig Module', python_folder)
pth_file_name = os.path.join(pth_folder_name, '%s%s' %(module_name, file_ext))
with open(pth_file_name, 'w') as pth_file:
pth_file.write(libary_folder)
print('DONE:\tTypeRig Link created!\n\tPlease copy file: %s into your python path: %s' %(pth_file_name, python_folder))
# - RUN ------------------------------
dialog = dlg_install()