[Bf-extensions-cvs] [dbc441d5] master: sun_position: cleanup UI and properties

Damien Picard noreply at git.blender.org
Fri Dec 13 11:34:18 CET 2019


Commit: dbc441d58a337cd9e3d587563bd55670edcbcd1d
Author: Damien Picard
Date:   Mon Dec 9 16:28:32 2019 +0100
Branches: master
https://developer.blender.org/rBAdbc441d58a337cd9e3d587563bd55670edcbcd1d

sun_position: cleanup UI and properties

UI for the normal mode is now split into subpanels.

===================================================================

M	sun_position/__init__.py
M	sun_position/properties.py
M	sun_position/sun_calc.py
M	sun_position/ui_sun.py

===================================================================

diff --git a/sun_position/__init__.py b/sun_position/__init__.py
index a04b3f85..5c9c35b7 100644
--- a/sun_position/__init__.py
+++ b/sun_position/__init__.py
@@ -65,6 +65,8 @@ def register():
     bpy.utils.register_class(ui_sun.SUNPOS_OT_DefaultPresets)
     bpy.utils.register_class(ui_sun.SUNPOS_MT_Presets)
     bpy.utils.register_class(ui_sun.SUNPOS_PT_Panel)
+    bpy.utils.register_class(ui_sun.SUNPOS_PT_Position)
+    bpy.utils.register_class(ui_sun.SUNPOS_PT_Time)
     bpy.utils.register_class(hdr.SUNPOS_OT_ShowHdr)
 
     bpy.app.handlers.frame_change_post.append(sun_calc.sun_handler)
@@ -73,6 +75,8 @@ def register():
 def unregister():
     bpy.utils.unregister_class(hdr.SUNPOS_OT_ShowHdr)
     bpy.utils.unregister_class(ui_sun.SUNPOS_PT_Panel)
+    bpy.utils.unregister_class(ui_sun.SUNPOS_PT_Position)
+    bpy.utils.unregister_class(ui_sun.SUNPOS_PT_Time)
     bpy.utils.unregister_class(ui_sun.SUNPOS_MT_Presets)
     bpy.utils.unregister_class(ui_sun.SUNPOS_OT_DefaultPresets)
     bpy.utils.unregister_class(ui_sun.SUNPOS_OT_AddPreset)
diff --git a/sun_position/properties.py b/sun_position/properties.py
index 5fbf1540..125b871a 100644
--- a/sun_position/properties.py
+++ b/sun_position/properties.py
@@ -45,16 +45,19 @@ class SunPosProperties(PropertyGroup):
         update=sun_update)
 
     use_daylight_savings: BoolProperty(
+        name="Daylight savings",
         description="Daylight savings time adds 1 hour to standard time",
         default=False,
         update=sun_update)
 
     use_refraction: BoolProperty(
+        name="Use refraction",
         description="Show apparent sun position due to refraction",
         default=True,
         update=sun_update)
 
     show_north: BoolProperty(
+        name="Show North",
         description="Draw line pointing north",
         default=False,
         update=north_update)
@@ -99,7 +102,7 @@ class SunPosProperties(PropertyGroup):
 
     year: IntProperty(
         name="Year",
-        min=1800, max=4000, default=TODAY.year,
+        min=1, max=4000, default=TODAY.year,
         update=sun_update)
 
     use_day_of_year: BoolProperty(
@@ -135,6 +138,7 @@ class SunPosProperties(PropertyGroup):
         update=sun_update)
 
     use_sun_object: BoolProperty(
+        name="Use object",
         description="Enable sun positioning of light object",
         default=False,
         update=sun_update)
@@ -146,6 +150,7 @@ class SunPosProperties(PropertyGroup):
         update=sun_update)
 
     use_object_collection: BoolProperty(
+        name="Use collection",
         description="Allow a collection of objects to be positioned",
         default=False,
         update=sun_update)
@@ -166,6 +171,7 @@ class SunPosProperties(PropertyGroup):
         update=sun_update)
 
     use_sky_texture: BoolProperty(
+        name="Use sky texture",
         description="Enable use of Cycles' "
                     "sky texture. World nodes must be enabled, "
                     "then set color to Sky Texture",
@@ -223,39 +229,47 @@ class SunPosAddonPreferences(AddonPreferences):
     bl_idname = __package__
 
     show_time_place: BoolProperty(
+        name="Time and place presets",
         description="Show time/place presets",
         default=False)
 
     show_object_collection: BoolProperty(
-        description="Use object collection",
+        name="Collection",
+        description="Show object collection",
         default=True,
         update=sun_update)
 
     show_dms: BoolProperty(
+        name="D° M' S\"",
         description="Show lat/long degrees, minutes, seconds labels",
         default=True)
 
     show_north: BoolProperty(
+        name="Show North",
         description="Show north offset choice and slider",
         default=True,
         update=sun_update)
 
     show_refraction: BoolProperty(
+        name="Refraction",
         description="Show sun refraction choice",
         default=True,
         update=sun_update)
 
     show_az_el: BoolProperty(
+        name="Azimuth and elevation info",
         description="Show azimuth and solar elevation info",
         default=True)
 
     show_daylight_savings: BoolProperty(
+        name="Daylight savings",
         description="Show daylight savings time choice",
         default=True,
         update=sun_update)
 
     show_rise_set: BoolProperty(
-        description="Show sunrise and sunset",
+        name="Sunrise and sunset info",
+        description="Show sunrise and sunset labels",
         default=True)
 
     def draw(self, context):
@@ -266,11 +280,11 @@ class SunPosAddonPreferences(AddonPreferences):
 
         col.label(text="Show or use:")
         flow = col.grid_flow(columns=0, even_columns=True, even_rows=False, align=False)
-        flow.prop(self, "show_time_place", text="Time/place presets")
-        flow.prop(self, "show_object_collection", text="Use collection")
-        flow.prop(self, "show_dms", text="D° M' S\"")
-        flow.prop(self, "show_north", text="North offset")
-        flow.prop(self, "show_refraction", text="Refraction")
-        flow.prop(self, "show_az_el", text="Azimuth, elevation")
-        flow.prop(self, "show_daylight_savings", text="Daylight savings time")
-        flow.prop(self, "show_rise_set", text="Sunrise, sunset")
+        flow.prop(self, "show_time_place")
+        flow.prop(self, "show_object_collection")
+        flow.prop(self, "show_dms")
+        flow.prop(self, "show_north")
+        flow.prop(self, "show_refraction")
+        flow.prop(self, "show_az_el")
+        flow.prop(self, "show_daylight_savings")
+        flow.prop(self, "show_rise_set")
diff --git a/sun_position/sun_calc.py b/sun_position/sun_calc.py
index 0813fd12..5631ac0b 100644
--- a/sun_position/sun_calc.py
+++ b/sun_position/sun_calc.py
@@ -216,15 +216,7 @@ def move_sun(context):
 def update_time(context):
     sun_props = context.scene.sun_pos_properties
 
-    if not sun_props.use_day_of_year:
-        dt = datetime.date(sun_props.year, sun_props.month, sun_props.day)
-        day_of_year = dt.timetuple().tm_yday
-        if sun_props.day_of_year != day_of_year:
-            sun_props.day_of_year = day_of_year
-        sun.day = sun_props.day
-        sun.month = sun_props.month
-        sun.day_of_year = day_of_year
-    else:
+    if sun_props.use_day_of_year:
         dt = (datetime.date(sun_props.year, 1, 1) +
               datetime.timedelta(sun_props.day_of_year - 1))
         sun.day = dt.day
@@ -234,6 +226,14 @@ def update_time(context):
             sun_props.day = dt.day
         if sun_props.month != dt.month:
             sun_props.month = dt.month
+    else:
+        dt = datetime.date(sun_props.year, sun_props.month, sun_props.day)
+        day_of_year = dt.timetuple().tm_yday
+        if sun_props.day_of_year != day_of_year:
+            sun_props.day_of_year = day_of_year
+        sun.day = sun_props.day
+        sun.month = sun_props.month
+        sun.day_of_year = day_of_year
     sun.year = sun_props.year
     sun.longitude = sun_props.longitude
     sun.latitude = sun_props.latitude
diff --git a/sun_position/ui_sun.py b/sun_position/ui_sun.py
index dc809c8e..919e6e77 100644
--- a/sun_position/ui_sun.py
+++ b/sun_position/ui_sun.py
@@ -104,7 +104,6 @@ sun_props.use_daylight_savings = {}
 # -------------------------------------------------------------------
 
 class SUNPOS_PT_Panel(bpy.types.Panel):
-    bl_idname = "SUNPOS_PT_world"
     bl_space_type = "PROPERTIES"
     bl_region_type = "WINDOW"
     bl_context = "world"
@@ -118,25 +117,27 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
         self.draw_panel(context, sp, p, layout)
 
     def draw_panel(self, context, sp, p, layout):
-        self.layout.label(text="Usage mode:")
-        self.layout.prop(sp, "usage_mode", expand=True)
+        col = self.layout.column(align=True)
+        col.label(text="Usage mode:")
+        row = col.row()
+        row.prop(sp, "usage_mode", expand=True)
+        col.separator()
         if sp.usage_mode == "HDR":
             self.draw_environ_mode_panel(context, sp, p, layout)
         else:
             self.draw_normal_mode_panel(context, sp, p, layout)
 
     def draw_environ_mode_panel(self, context, sp, p, layout):
-        box = self.layout.box()
-        flow = box.grid_flow(row_major=True, columns=0, even_columns=True,
+        flow = layout.grid_flow(row_major=True, columns=0, even_columns=True,
                              even_rows=False, align=False)
 
-        col = flow.column()
+        col = flow.column(align=True)
         col.label(text="Environment texture:")
         col.prop_search(sp, "hdr_texture",
                         context.scene.world.node_tree, "nodes", text="")
         col.separator()
 
-        col = flow.column()
+        col = flow.column(align=True)
         col.label(text="Sun object:")
         col.prop_search(sp, "sun_object",
                         context.view_layer, "objects", text="")
@@ -150,15 +151,14 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
         col.separator()
 
         col = flow.column(align=True)
-        row1 = col.row()
         if sp.bind_to_sun:
             prop_text="Release binding"
         else:
             prop_text="Bind Texture to Sun "
-        row1.prop(sp, "bind_to_sun", toggle=True, icon="CONSTRAINT",
+        col.prop(sp, "bind_to_sun", toggle=True, icon="CONSTRAINT",
                   text=prop_text)
 
-        row = col.row()
+        row = col.row(align=True)
         row.enabled = not sp.bind_to_sun
         row.operator("world.sunpos_show_hdr", icon='LIGHT_SUN')
 
@@ -170,41 +170,55 @@ class SUNPOS_PT_Panel(bpy.types.Panel):
             row.operator(SUNPOS_OT_AddPreset.bl_idname, text="", icon='REMOVE').remove_active = True
             row.operator(SUNPOS_OT_DefaultPresets.bl_idname, text="", icon='FILE_REFRESH')
 
-        box = self.layout.box()
-        flow = box.grid_flow(row_major=True, columns=0, even_columns=True, even_rows=False, align=False)
-
-        col = flow.column()
-        col.prop(sp, "use_sky_texture", text="Cycles sky")
-        if sp.use_sky_texture:
-            col.prop_search(sp, "sky_texture", context.scene.world.node_tree,
-                            "nodes", text

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list