[Bf-blender-cvs] [61ff578eab1] master: UI: add URL presets

Campbell Barton noreply at git.blender.org
Tue Aug 20 15:44:33 CEST 2019


Commit: 61ff578eab16ab627415e06c2a81b339d4be0f99
Author: Campbell Barton
Date:   Tue Aug 20 22:00:01 2019 +1000
Branches: master
https://developer.blender.org/rB61ff578eab16ab627415e06c2a81b339d4be0f99

UI: add URL presets

This adds a url-preset operator to simplify opening re-usable links.

- Standard websites have their own tool-tip.
- De-duplicate logic to get URL's that include version information.
- Reporting bugs no longer needs to have all information
  included in the URL.

D5498 by @luisbg with edits.

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

M	release/scripts/modules/bl_ui_utils/bug_report_url.py
M	release/scripts/startup/bl_operators/wm.py
M	release/scripts/startup/bl_ui/space_topbar.py
M	release/scripts/startup/bl_ui/space_userpref.py

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

diff --git a/release/scripts/modules/bl_ui_utils/bug_report_url.py b/release/scripts/modules/bl_ui_utils/bug_report_url.py
index be94b45c8ac..008eafc2c46 100644
--- a/release/scripts/modules/bl_ui_utils/bug_report_url.py
+++ b/release/scripts/modules/bl_ui_utils/bug_report_url.py
@@ -64,10 +64,7 @@ def url_prefill_from_blender(addon_info=None):
             "\n"
             "**Addon Information**\n"
         )
-        fh.write((
-            "Name: {name} {version}\n"
-            "Author: {author}\n").format(**addon_info)
-        )
+        fh.write(addon_info)
 
     fh.write(
         "\n"
diff --git a/release/scripts/startup/bl_operators/wm.py b/release/scripts/startup/bl_operators/wm.py
index 67dcf37d89d..bf1c79e766f 100644
--- a/release/scripts/startup/bl_operators/wm.py
+++ b/release/scripts/startup/bl_operators/wm.py
@@ -846,6 +846,86 @@ class WM_OT_url_open(Operator):
         return {'FINISHED'}
 
 
+class WM_OT_url_open_preset(Operator):
+    """Open a preset website in the web-browser"""
+    bl_idname = "wm.url_open_preset"
+    bl_label = "Open Preset Website"
+    bl_options = {'INTERNAL'}
+
+    type: EnumProperty(
+        name="Site",
+        items=lambda self, _context: (
+            item for (item, _) in WM_OT_url_open_preset.preset_items
+        ),
+    )
+
+    id: StringProperty(
+        name="Identifier",
+        description="Optional identifier",
+    )
+
+    def _url_from_bug(self, _context):
+        from bl_ui_utils.bug_report_url import url_prefill_from_blender
+        return url_prefill_from_blender()
+
+    def _url_from_bug_addon(self, _context):
+        from bl_ui_utils.bug_report_url import url_prefill_from_blender
+        return url_prefill_from_blender(addon_info=self.id)
+
+    def _url_from_release_notes(self, _context):
+        return "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
+
+    def _url_from_manual(self, _context):
+        if bpy.app.version_cycle in {"rc", "release"}:
+            manual_version = "%d.%d" % bpy.app.version[:2]
+        else:
+            manual_version = "dev"
+        return "https://docs.blender.org/manual/en/" + manual_version + "/"
+
+    # This list is: (enum_item, url) pairs.
+    # Allow dynamically extending.
+    preset_items = [
+        # Dynamic URL's.
+        (('BUG', "Bug",
+          "Report a bug with pre-filled version information"),
+         _url_from_bug),
+        (('BUG_ADDON', "Add-On Bug",
+          "Report a bug in an add-on"),
+         _url_from_bug_addon),
+        (('RELEASE_NOTES', "Release Notes",
+          "Read about whats new in this version of Blender"),
+         _url_from_release_notes),
+        (('MANUAL', "Manual",
+          "The reference manual for this version of Blender"),
+         _url_from_manual),
+
+        # Static URL's.
+        (('FUND', "Development Fund",
+          "The donation program to support maintenance and improvements"),
+         "https://fund.blender.org"),
+        (('BLENDER', "blender.org",
+          "Blender's official web-site"),
+         "https://www.blender.org"),
+        (('CREDITS', "Credits",
+          "Lists committers to Blender's source code"),
+         "https://www.blender.org/about/credits/"),
+    ]
+
+    def execute(self, context):
+        url = None
+        type = self.type
+        for (item_id, _, _), url in self.preset_items:
+            if item_id == type:
+                if callable(url):
+                    url = url(self, context)
+                break
+
+        import webbrowser
+        webbrowser.open(url)
+
+        return {'FINISHED'}
+
+
 class WM_OT_path_open(Operator):
     """Open a path in a file browser"""
     bl_idname = "wm.path_open"
@@ -1808,23 +1888,13 @@ class WM_MT_splash(Menu):
         if found_recent:
             col2_title.label(text="Recent Files")
         else:
-            if bpy.app.version_cycle in {'rc', 'release'}:
-                manual_version = '%d.%d' % bpy.app.version[:2]
-            else:
-                manual_version = 'dev'
 
             # Links if no recent files
             col2_title.label(text="Getting Started")
 
-            col2.operator(
-                "wm.url_open", text="Manual", icon='URL'
-            ).url = "https://docs.blender.org/manual/en/" + manual_version + "/"
-            col2.operator(
-                "wm.url_open", text="Blender Website", icon='URL',
-            ).url = "https://www.blender.org"
-            col2.operator(
-                "wm.url_open", text="Credits", icon='URL',
-            ).url = "https://www.blender.org/about/credits/"
+            col2.operator("wm.url_open_preset", text="Manual", icon='URL').type = 'MANUAL'
+            col2.operator("wm.url_open_preset", text="Blender Website", icon='URL').type = 'BLENDER'
+            col2.operator("wm.url_open_preset", text="Credits", icon='URL').type = 'CREDITS'
 
         layout.separator()
 
@@ -1837,12 +1907,9 @@ class WM_MT_splash(Menu):
         col1.operator("wm.recover_last_session", icon='RECOVER_LAST')
 
         col2 = split.column()
-        col2.operator(
-            "wm.url_open", text="Release Notes", icon='URL',
-        ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
-        col2.operator(
-            "wm.url_open", text="Development Fund", icon='FUND'
-        ).url = "https://fund.blender.org"
+
+        col2.operator("wm.url_open_preset", text="Release Notes", icon='URL').type = 'RELEASE_NOTES'
+        col2.operator("wm.url_open_preset", text="Development Fund", icon='FUND').type = 'FUND'
 
         layout.separator()
         layout.separator()
@@ -1908,6 +1975,7 @@ classes = (
     WM_OT_owner_disable,
     WM_OT_owner_enable,
     WM_OT_url_open,
+    WM_OT_url_open_preset,
     WM_OT_tool_set_by_id,
     WM_OT_tool_set_by_index,
     WM_OT_toolbar,
diff --git a/release/scripts/startup/bl_ui/space_topbar.py b/release/scripts/startup/bl_ui/space_topbar.py
index f735e7b770f..d0ad9a8f31e 100644
--- a/release/scripts/startup/bl_ui/space_topbar.py
+++ b/release/scripts/startup/bl_ui/space_topbar.py
@@ -344,18 +344,12 @@ class TOPBAR_MT_app_about(Menu):
     def draw(self, _context):
         layout = self.layout
 
-        layout.operator(
-            "wm.url_open", text="Release Notes", icon='URL',
-        ).url = "https://www.blender.org/download/releases/%d-%d/" % bpy.app.version[:2]
+        layout.operator("wm.url_open_preset", text="Release Notes", icon='URL').type = 'RELEASE_NOTES'
 
         layout.separator()
 
-        layout.operator(
-            "wm.url_open", text="Blender Website", icon='URL',
-        ).url = "https://www.blender.org/"
-        layout.operator(
-            "wm.url_open", text="Credits", icon='URL',
-        ).url = "https://www.blender.org/about/credits/"
+        layout.operator("wm.url_open_preset", text="Blender Website", icon='URL').type = 'BLENDER'
+        layout.operator("wm.url_open", text="Credits", icon='URL').type = 'CREDITS'
 
         layout.separator()
 
@@ -370,9 +364,7 @@ class TOPBAR_MT_app_support(Menu):
     def draw(self, _context):
         layout = self.layout
 
-        layout.operator(
-            "wm.url_open", text="Development Fund", icon='FUND',
-        ).url = "https://fund.blender.org"
+        layout.operator("wm.url_open_preset", text="Development Fund", icon='FUND').type = 'FUND'
 
         layout.separator()
 
@@ -565,22 +557,12 @@ class TOPBAR_MT_help(Menu):
     bl_label = "Help"
 
     def draw(self, context):
-        # If 'url_prefill_from_blender' becomes slow it could be made into a separate operator
-        # to avoid constructing the bug report just to show this menu.
-        from bl_ui_utils.bug_report_url import url_prefill_from_blender
-
         layout = self.layout
 
         show_developer = context.preferences.view.show_developer_ui
 
-        if bpy.app.version_cycle in {'rc', 'release'}:
-            manual_version = '%d.%d' % bpy.app.version[:2]
-        else:
-            manual_version = 'dev'
+        layout.operator("wm.url_open_preset", text="Manual", icon='HELP',).type = 'MANUAL'
 
-        layout.operator(
-            "wm.url_open", text="Manual", icon='HELP',
-        ).url = "https://docs.blender.org/manual/en/" + manual_version + "/"
         layout.operator(
             "wm.url_open", text="Tutorials", icon='URL',
         ).url = "https://www.blender.org/tutorials"
@@ -612,9 +594,7 @@ class TOPBAR_MT_help(Menu):
 
         layout.separator()
 
-        layout.operator(
-            "wm.url_open", text="Report a Bug", icon='URL',
-        ).url = url_prefill_from_blender()
+        layout.operator("wm.url_open_preset", text="Report a Bug", icon='URL').type = 'BUG'
 
         layout.separator()
 
diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index ce4a6fb835e..8ed8eb04898 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -1708,7 +1708,6 @@ class USERPREF_PT_addons(Panel):
     def draw(self, context):
         import os
         import addon_utils
-        from bl_ui_utils.bug_report_url import url_prefill_from_blender
 
         layout = self.layout
 
@@ -1887,13 +1886,18 @@ class USERPREF_PT_addons(Panel):
                             ).url = info["wiki_url"]
                         # Only add "Report a Bug" button if tracker_url is set
                         # or the add-on is bundled (use official tracker then).
-                        if info.get("tracker_url") or not user_addon:
+                        if info.get("tracker_url"):
                             sub.operator(
                                 "wm.url_open", text="Report a Bug", icon='URL',
-                            ).url = info.get(
-                                "tracker_url",
-                                url_prefill_from_blender(info),
+                            ).url = info["tracker_url"]
+                        elif not user_addon:
+                            addon_info = ("Name: {} {}\nAuthor: {}\n").format(
+                                info["name"], info["version"], info["author"])
+                            props 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list