fix: new UI/UX

This commit is contained in:
Fabian 2021-06-11 16:57:02 +02:00
parent 0c6491590e
commit bc24525cec
3 changed files with 84 additions and 79 deletions

View File

@ -917,21 +917,29 @@ class SessionPresetServerAdd(bpy.types.Operator):
def poll(cls, context): def poll(cls, context):
return True return True
def invoke(self, context, event):
assert(context)
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
layout = self.layout
# TODO: menu pour rentrer le nom
# TODO: override en label pour prévenir (icon) si jamais ce nom existe déjà
col = layout.column()
settings = utils.get_preferences()
col.prop(settings, "server_name", text="server name")
def execute(self, context): def execute(self, context):
assert(context) assert(context)
settings = utils.get_preferences()
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() settings = utils.get_preferences()
existing_preset = settings.server_preset.get(settings.server_name)
new_server = existing_preset if existing_preset else settings.server_preset.add()
new_server.name = settings.server_name new_server.name = settings.server_name
new_server.server_ip = settings.ip new_server.server_ip = settings.ip
new_server.server_port = settings.port new_server.server_port = settings.port
@ -941,6 +949,41 @@ class SessionPresetServerAdd(bpy.types.Operator):
return {'FINISHED'} return {'FINISHED'}
# class SessionPresetServerOverwrite(bpy.types.Operator):
# bl_idname = "session.preset_server_overwrite"
# bl_description = "Overwrite the server preset that already has this name" # TODO : or increment the name
# bl_label = "Overwrite server preset ?"
# bl_options = {'REGISTER'}
# @classmethod
# def poll(cls, context):
# return True
# def execute(self, context):
# assert(context)
# settings = utils.get_preferences()
# 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 = 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)
class SessionPresetServerRemove(bpy.types.Operator): class SessionPresetServerRemove(bpy.types.Operator):
"""Remove a server to the server list preset""" """Remove a server to the server list preset"""
bl_idname = "session.preset_server_remove" bl_idname = "session.preset_server_remove"
@ -960,43 +1003,6 @@ class SessionPresetServerRemove(bpy.types.Operator):
settings.server_preset.remove(settings.server_preset.find(settings.server_preset_interface)) settings.server_preset.remove(settings.server_preset.find(settings.server_preset_interface))
return {'FINISHED'} return {'FINISHED'}
class SessionPresetServerOverwrite(bpy.types.Operator):
bl_idname = "session.preset_server_overwrite"
bl_description = "Overwrite the server preset that already has this name" # TODO : or increment the name
bl_label = "Overwrite server preset ?"
bl_options = {'REGISTER'}
prop1: bpy.props.BoolProperty()
prop2: bpy.props.BoolProperty()
@classmethod
def poll(cls, context):
return True
def execute(self, context):
assert(context)
settings = utils.get_preferences()
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 = 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)
@ -1024,7 +1030,7 @@ classes = (
SessionPurgeOperator, SessionPurgeOperator,
SessionPresetServerAdd, SessionPresetServerAdd,
SessionPresetServerRemove, SessionPresetServerRemove,
SessionPresetServerOverwrite, # SessionPresetServerOverwrite,
) )
def update_external_dependencies(): def update_external_dependencies():

View File

@ -33,6 +33,19 @@ from replication.interface import session
IP_REGEX = re.compile("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$") IP_REGEX = re.compile("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$")
HOSTNAME_REGEX = re.compile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$") HOSTNAME_REGEX = re.compile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$")
DEFAULT_PRESETS = {
"localhost" : {
"server_ip": "localhost",
"server_port": 5555,
"server_password": "admin"
},
"public session" : {
"server_ip": "51.75.71.183",
"server_port": 5555,
"server_password": "admin"
},
}
def randomColor(): def randomColor():
"""Generate a random color """ """Generate a random color """
r = random.random() r = random.random()
@ -152,7 +165,7 @@ class SessionPrefs(bpy.types.AddonPreferences):
ip: bpy.props.StringProperty( ip: bpy.props.StringProperty(
name="ip", name="ip",
description='Distant host ip', description='Distant host ip',
default="127.0.0.1", default="localhost",
update=update_ip) update=update_ip)
username: bpy.props.StringProperty( username: bpy.props.StringProperty(
name="Username", name="Username",
@ -170,7 +183,7 @@ class SessionPrefs(bpy.types.AddonPreferences):
server_name: bpy.props.StringProperty( server_name: bpy.props.StringProperty(
name="server_name", name="server_name",
description="Custom name of the server", description="Custom name of the server",
default='local host', default='localhost',
) )
password: bpy.props.StringProperty( password: bpy.props.StringProperty(
name="password", name="password",
@ -458,21 +471,13 @@ class SessionPrefs(bpy.types.AddonPreferences):
new_db.bl_name = type_module_class.bl_id new_db.bl_name = type_module_class.bl_id
# custom at launch server preset # custom at launch server preset
def generate_server_preset_localhost(self): def generate_default_presets(self):
new_server = self.server_preset.add() for preset_name, preset_data in DEFAULT_PRESETS.items():
new_server = self.server_preset.add()
new_server.name = "local host" new_server.name = preset_name
new_server.server_ip = "127.0.0.1" new_server.server_ip = preset_data.get('server_ip')
new_server.server_port = 5555 new_server.server_port = preset_data.get('server_port')
new_server.server_password = "admin" new_server.server_password = preset_data.get('server_password',None)
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): def client_list_callback(scene, context):
@ -588,11 +593,8 @@ def register():
prefs.generate_supported_types() prefs.generate_supported_types()
# at launch server presets # at launch server presets
if 'local host' not in prefs.server_preset: prefs.generate_default_presets()
prefs.generate_server_preset_localhost()
if 'public session' not in prefs.server_preset:
prefs.generate_server_preset_publicsession()
def unregister(): def unregister():

View File

@ -156,7 +156,13 @@ class SESSION_PT_settings_network(bpy.types.Panel):
row = layout.row() row = layout.row()
row.prop(runtime_settings, "session_mode", expand=True) row.prop(runtime_settings, "session_mode", expand=True)
row = layout.row() row = layout.row()
col = row.row(align=True)
col.prop(settings, "server_preset_interface", text="")
col.operator("session.preset_server_add", icon='ADD', text="")
col.operator("session.preset_server_remove", icon='REMOVE', text="")
row = layout.row()
box = row.box() box = row.box()
if runtime_settings.session_mode == 'HOST': if runtime_settings.session_mode == 'HOST':
@ -172,15 +178,6 @@ class SESSION_PT_settings_network(bpy.types.Panel):
row = box.row() row = box.row()
row.operator("session.start", text="HOST").host = True row.operator("session.start", text="HOST").host = True
else: else:
row = box.row()
row.prop(settings, "server_preset_interface", text="Preset")
col = row.row(align=True)
col.operator("session.preset_server_add", icon='ADD', text="")
col.operator("session.preset_server_remove", icon='REMOVE', text="")
row = box.row()
row.prop(settings, "server_name", text="name")
row = box.row() row = box.row()
row.prop(settings, "ip", text="IP") row.prop(settings, "ip", text="IP")
row = box.row() row = box.row()
@ -208,7 +205,7 @@ class SESSION_PT_overwrite_server(bpy.types.Panel):
settings = get_preferences() settings = get_preferences()
layout.operator(settings.SessionPresetServerOverwrite.bl_idname) # layout.operator(settings.SessionPresetServerOverwrite.bl_idname)
class SESSION_PT_settings_user(bpy.types.Panel): class SESSION_PT_settings_user(bpy.types.Panel):
bl_idname = "MULTIUSER_SETTINGS_USER_PT_panel" bl_idname = "MULTIUSER_SETTINGS_USER_PT_panel"