-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
preferences.py
42 lines (33 loc) · 1.31 KB
/
preferences.py
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
import bpy
class IGcodePreferences(bpy.types.AddonPreferences):
bl_idname = __package__
def draw(self, context):
import importlib
from .utils_pip import Pip
Pip._ensure_user_site_package()
layout = self.layout
flag = importlib.util.find_spec('regex') is not None and importlib.util.find_spec('tqdm') is not None
if flag:
layout.label(text='Regex and Tqdm loaded.', icon='INFO')
else:
layout.label(text='import-G-code requires Regex and Tqdm!', icon='ERROR')
row = layout.row()
row.operator('igcode.installer')
class IGcodeInstaller(bpy.types.Operator):
bl_idname = "igcode.installer"
bl_label = "Install Regex and Tqdm"
bl_description = ("Install Regex and Tqdm")
def execute(self, context):
try:
from .utils_pip import Pip
# Pip.upgrade_pip()
Pip.install('regex')
Pip.install('tqdm')
import re
from tqdm import tqdm
for _ in tqdm(range(1)):
print(re.__version__)
self.report({'INFO'}, 'Successfully installed Re and Tqdm.')
except ModuleNotFoundError:
self.report({'ERROR'}, 'Could not install Regex and Tqdm, Kindly install it manually.')
return {'FINISHED'}