fix: name conflict + responsive enum

This commit is contained in:
Fabian 2021-06-11 12:13:23 +02:00
parent cb0962b484
commit b87e733ddc
3 changed files with 51 additions and 26 deletions

View File

@ -911,7 +911,7 @@ class SessionPresetServerAdd(bpy.types.Operator):
bl_description = "add the current server to the server preset list"
bl_options = {"REGISTER"}
name : bpy.props.StringProperty(default="server_preset") # TODO: add name iteration
name : bpy.props.StringProperty(default="server_preset")
@classmethod
def poll(cls, context):
@ -920,18 +920,25 @@ class SessionPresetServerAdd(bpy.types.Operator):
def execute(self, context):
assert(context)
if True : # TODO : add condition if name already in list
True # TODO : add window pop to ask confirmation
settings = utils.get_preferences()
runtime_settings = context.window_manager.session
if settings.server_name in settings.server_preset.keys():
bpy.ops.session.preset_server_overwrite('INVOKE_DEFAULT')
return {'FINISHED'}
new_server = settings.server_preset.add()
settings = utils.get_preferences()
new_server.name = settings.server_name
new_server.server_ip = settings.ip
new_server.server_port = settings.port
new_server.server_password = "admin" # TODO: add password
new_server.server_password = runtime_settings.password
settings.server_preset_interface = settings.server_name
return {'FINISHED'}
@ -969,16 +976,30 @@ class SessionPresetServerOverwrite(bpy.types.Operator):
return True
def execute(self, context):
assert(context)
settings = utils.get_preferences()
runtime_settings = context.window_manager.session
old_server = settings.server_preset.get(settings.server_name)
old_server.server_ip = settings.ip
old_server.server_port = settings.port
old_server.server_password = runtime_settings.password
settings.server_preset_interface = settings.server_name
self.report({'INFO'}, "Server overwrite")
return {'FINISHED'}
def invoke(self, context, event):
assert(context)
settings = utils.get_preferences()
return context.window_manager.invoke_confirm(self, event)
# def draw(self, context):
# row = self.layout
# row.prop(self, "prop1", text="Overwrite the server")
# row.prop(self, "prop2", text="Keep the server")
def menu_func_import(self, context):

View File

@ -65,10 +65,11 @@ def update_ip(self, context):
logging.error("Wrong IP format")
self['ip'] = "127.0.0.1"
def update_server_preset(self, context):
def update_server_preset_interface(self, context):
self.server_name = self.server_preset.get(self.server_preset_interface).name
self.ip = self.server_preset.get(self.server_preset_interface).server_ip
self.port = self.server_preset.get(self.server_preset_interface).server_port
self.password = self.server_preset.get(self.server_preset_interface).server_password
# TODO: do password
def update_directory(self, context):
@ -169,8 +170,8 @@ class SessionPrefs(bpy.types.AddonPreferences):
)
server_name: bpy.props.StringProperty(
name="server_name",
description="Name of the server",
default='server_001',
description="Custom name of the server",
default='local host',
)
sync_flags: bpy.props.PointerProperty(
type=ReplicationFlags
@ -349,7 +350,7 @@ class SessionPrefs(bpy.types.AddonPreferences):
name="servers",
description="servers enum",
items=server_list_callback,
update=update_server_preset,
update=update_server_preset_interface,
)
# Custom panel
@ -451,9 +452,8 @@ class SessionPrefs(bpy.types.AddonPreferences):
new_db.icon = type_module_class.bl_icon
new_db.bl_name = type_module_class.bl_id
# custom at launch server preset
def generate_server_preset_localhost(self):
# self.server_preset.clear()
new_server = self.server_preset.add()
new_server.name = "local host"
@ -461,6 +461,14 @@ class SessionPrefs(bpy.types.AddonPreferences):
new_server.server_port = 5555
new_server.server_password = "admin"
def generate_server_preset_publicsession(self):
new_server = self.server_preset.add()
new_server.name = "public session"
new_server.server_ip = "51.75.71.183"
new_server.server_port = 5555
new_server.server_password = "admin"
def client_list_callback(scene, context):
from . import operators
@ -580,9 +588,13 @@ def register():
logging.debug('Generating bl_types preferences')
prefs.generate_supported_types()
# at launch server presets
if 'local host' not in prefs.server_preset:
prefs.generate_server_preset_localhost()
if 'public session' not in prefs.server_preset:
prefs.generate_server_preset_publicsession()
def unregister():
from bpy.utils import unregister_class

View File

@ -179,14 +179,6 @@ class SESSION_PT_settings_network(bpy.types.Panel):
col.operator("session.preset_server_add", icon='ADD', text="")
col.operator("session.preset_server_remove", icon='REMOVE', text="")
# for servers in settings.supported_servers:
# row = box.row()
# row.prop(servers, "use_as_filter", text="")
# row = box.row()
# row.template_list("SERVER_group","server_group",settings,"server_group", settings, "active_server", rows=3)
# col = row.column(align=True)
row = box.row()
row.prop(settings, "server_name", text="name")
row = box.row()