from os import path
import bpy
from bpy.types import Panel, PropertyGroup, Operator, UIList, Scene
from . ui_panel import ILSPpanel
from bpy.props import (BoolProperty, EnumProperty, PointerProperty, IntProperty,
FloatProperty, CollectionProperty, StringProperty)
from . import versions
########################################################################
# PROPERTIES
########################################################################
[docs]
class UpdateProperties(PropertyGroup):
[docs]
def check(self, context):
return True
def _updateRemoteBranch(self, context):
branch = self.remote_branch
versions = context.scene.ILSP_remote_versions
try:
self.remote_version = versions[branch][0]
except Exception:
pass
remote_branch: EnumProperty(
name='',
description="Remote Branch",
items=[('DEVELOPER', 'DEVELOPER', ''),
('RELEASE', 'RELEASE', '')],
update=_updateRemoteBranch
)
def _remoteVersionItems(self, context):
myItems = context.scene.ILSP_remote_versions[self.remote_branch]
items = []
for item in myItems:
items.append((item, item, ''))
return items
remote_version: EnumProperty(
name='',
description="Remote Version",
items=_remoteVersionItems,
)
token: StringProperty(
name="token",
description="Token"
)
details: BoolProperty(
name="Details",
description="Details",
default=False,
)
########################################################################
# PANELs
########################################################################
[docs]
class ILSP_PT_update(ILSPpanel, Panel):
bl_label = 'LIATool (0.5.1)'
bl_options = {'DEFAULT_CLOSED'}
[docs]
@classmethod
def poll(cls, context):
return True
def _enabled(self, context):
return True
[docs]
def draw(self, context):
layout = self.layout
layout.use_property_split = False
layout.use_property_decorate = False
for branch in context.scene.ILSP_update:
update = context.scene.ILSP_update[branch]
if update is not None:
layout.label(text='Addon Update Available: ' + branch + ' (' + update + ')', icon_value=3)
update = context.scene.ilsp_update
addonTokenExists = path.isfile(context.scene.ILSP_tokenPath)
row = layout.row(align=True)
if addonTokenExists:
col = layout.column(align=True)
grid = col.grid_flow(columns=2, align=True)
grid.enabled = True
grid.prop(update, 'remote_branch')
grid.operator("addon.refresh", text="Refresh")
grid.prop(update, 'remote_version')
grid.operator("addon.download", text="Download")
grid = col.grid_flow(columns=3, align=True)
grid.enabled = True
grid.label(text="")
grid.prop(update, "details", icon='PREFERENCES',
icon_only=True, emboss=False)
grid.label(text="")
if not addonTokenExists or update.details:
row = layout.row(align=True)
row.prop(update, "token")
row.operator("use.token", text='', icon='ADD')
status = update.check(context)
try:
len(status)
except Exception:
return
layout.label(text=status[1], icon_value=status[2])
########################################################################
# OPERATORS
########################################################################
[docs]
class ILSP_OT_addon_refresh(Operator):
bl_idname = "addon.refresh"
bl_label = "LIATool"
bl_description = "Addon Refresh"
[docs]
@classmethod
def poll(cls, context):
return True
[docs]
def execute(self, context):
Scene.ILSP_remote_versions = versions.remoteVersions()
return {'FINISHED'}
[docs]
class ILSP_OT_addon_download(Operator):
bl_idname = "addon.download"
bl_label = "LIATool"
bl_description = "Addon Download"
[docs]
@classmethod
def poll(cls, context):
return True
[docs]
def execute(self, context):
update = context.scene.ilsp_update
versions.downloadApp(
update.remote_branch,
update.remote_version)
return {'FINISHED'}
[docs]
class ILSP_OT_use_token(Operator):
bl_idname = "use.token"
bl_label = "LIATool"
bl_description = "Use Token"
[docs]
@classmethod
def poll(cls, context):
return True
[docs]
def execute(self, context):
update = context.scene.ilsp_update
token = update.token
status = versions.testToken(token)
if status == 200:
tokenFile = path.join(context.scene.ILSP_tokenPath)
tokenFile = open(tokenFile, "w")
tokenFile.write(token)
tokenFile.close()
Scene.ILSP_remote_versions = versions.remoteVersions()
update.token = 'VALID TOKEN'
else:
update.token = 'INVALID TOKEN'
return {'FINISHED'}