Skip to content

Commit c0cd30c

Browse files
committed
feat: Tooltip support for buttons
1 parent 1f0d66a commit c0cd30c

File tree

11 files changed

+651
-501
lines changed

11 files changed

+651
-501
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
21
__pycache__/__init__.cpython-37.pyc
32
src/Storage/
43
*.pyc
54
*.zip
6-
.build
5+
.build
6+
uv.lock

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "scripttobutton"
3+
version = "0.1.0"
4+
description = "Blender Extension that allows to add scripts as buttons."
5+
readme = "README.md"
6+
requires-python = ">=3.13"
7+
dependencies = [
8+
"fake-bpy-module>=20260302",
9+
]

src/__init__.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import bpy
22
from bpy.app.handlers import persistent
3-
from . import properties, preferences, operators, functions, panels, dynamic_panels, menus
3+
4+
from . import (
5+
dynamic_panels,
6+
functions,
7+
menus,
8+
operators,
9+
panels,
10+
preferences,
11+
properties,
12+
)
413

514
bl_info = {
615
"name": "Script To Button",
716
"author": "RivinHD",
8-
"blender": (3, 6, 0),
9-
"version": (2, 3, 2),
17+
"blender": (4, 2, 0),
18+
"version": (2, 3, 3),
1019
"location": "View3D",
1120
"category": "System",
1221
"doc_url": "https://github.com/RivinHD/ScriptToButton/wiki",
13-
"tracker_url": "https://github.com/RivinHD/ScriptToButton/issues"
22+
"tracker_url": "https://github.com/RivinHD/ScriptToButton/issues",
1423
}
1524

1625
keymaps = {}
@@ -24,13 +33,13 @@ def load_saves(dummy=None):
2433
if len(fails[0]) or len(fails[1]):
2534
message += "\n %s: " % name
2635
message += functions.create_fail_message(fails)
27-
if bpy.data.texts.find('STB Fail Message') == -1:
36+
if bpy.data.texts.find("STB Fail Message") == -1:
2837
if message != "'''":
29-
bpy.data.texts.new('STB Fail Message')
38+
bpy.data.texts.new("STB Fail Message")
3039
else:
31-
bpy.data.texts['STB Fail Message'].clear()
40+
bpy.data.texts["STB Fail Message"].clear()
3241
if message != "'''":
33-
bpy.data.texts['STB Fail Message'].write("%s'''" % message)
42+
bpy.data.texts["STB Fail Message"].write("%s'''" % message)
3443
functions.NotOneStart[0] = True
3544

3645

@@ -44,10 +53,10 @@ def register():
4453

4554
addon = bpy.context.window_manager.keyconfigs.addon
4655
if addon:
47-
km = addon.keymaps.new(name='Screen')
48-
keymaps['default'] = km
56+
km = addon.keymaps.new(name="Screen")
57+
keymaps["default"] = km
4958
items = km.keymap_items
50-
kmi = items.new("wm.call_menu", 'Y', 'PRESS', shift=True, alt=True)
59+
kmi = items.new("wm.call_menu", "Y", "PRESS", shift=True, alt=True)
5160
kmi.properties.name = "STB_MT_ButtonMenu"
5261

5362

src/blender_manifest.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ schema_version = "1.0.0"
33
# Example of manifest file for a Blender extension
44
# Change the values according to your extension
55
id = "script_to_button"
6-
version = "2.3.2"
6+
version = "2.3.3"
77
name = "Script To Button"
88
tagline = "Converts scripts to buttons"
99
maintainer = "RivinHD"

src/dynamic_panels.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
import typing
21
import bpy
3-
from bpy.types import Panel, Context, Menu
2+
from bpy.types import Context, Menu, Panel
43

54
button_classes = {}
65
panel_names = []
76

87
ui_space_types = [
9-
'CLIP_EDITOR', 'NODE_EDITOR', 'TEXT_EDITOR', 'SEQUENCE_EDITOR', 'NLA_EDITOR',
10-
'DOPESHEET_EDITOR', 'VIEW_3D', 'GRAPH_EDITOR', 'IMAGE_EDITOR'
8+
"CLIP_EDITOR",
9+
"NODE_EDITOR",
10+
"TEXT_EDITOR",
11+
"SEQUENCE_EDITOR",
12+
"NLA_EDITOR",
13+
"DOPESHEET_EDITOR",
14+
"VIEW_3D",
15+
"GRAPH_EDITOR",
16+
"IMAGE_EDITOR",
1117
] # blender spaces with UI region
1218

1319

@@ -22,6 +28,7 @@ def unregister_button_panel(name: str):
2228
def unregister_register_button_panel(name: str, register: bool):
2329
index = len(panel_names) - (not register)
2430
for space_type in ui_space_types:
31+
2532
class STB_PT_Buttons(Panel):
2633
bl_idname = "STB_PT_Buttons_%s_%s" % (index, space_type)
2734
bl_label = ""
@@ -37,7 +44,9 @@ def poll(self, context: Context) -> bool:
3744
stb = context.scene.stb
3845
area = context.area.ui_type
3946
panel = panel_names[self.bl_order]
40-
return any((button.panel == panel and area in button.areas) for button in stb)
47+
return any(
48+
(button.panel == panel and area in button.areas) for button in stb
49+
)
4150

4251
def draw_header(self, context: Context):
4352
layout = self.layout
@@ -48,21 +57,21 @@ def draw(self, context):
4857
area = context.area.ui_type
4958
panel = panel_names[self.bl_order]
5059
buttons = filter(
51-
lambda x: area in x.areas and x.panel == panel,
52-
context.scene.stb
60+
lambda x: area in x.areas and x.panel == panel, context.scene.stb
5361
)
5462
for button in sorted(buttons, key=lambda x: x.name):
5563
row = layout.row(align=True)
5664
row.prop(
57-
button, 'selected',
65+
button,
66+
"selected",
5867
toggle=True,
5968
text="",
60-
icon='RADIOBUT_ON' if button.selected else 'RADIOBUT_OFF'
69+
icon="RADIOBUT_ON" if button.selected else "RADIOBUT_OFF",
6170
)
6271
row.operator(
63-
"stb.script_button",
64-
text=button.name
72+
"stb.script_button", text=button.name
6573
).name = button.name
74+
6675
STB_PT_Buttons.__name__ = "STB_PT_Buttons_%s_%s" % (index, space_type)
6776

6877
global button_classes
@@ -86,21 +95,22 @@ def poll(self, context: Context) -> bool:
8695
return False
8796
area = context.area.ui_type
8897
panel = panel_names[self.bl_order]
89-
return any((button.panel == panel and area in button.areas) for button in stb)
98+
return any(
99+
(button.panel == panel and area in button.areas) for button in stb
100+
)
90101

91102
def draw(self, context: Context):
92103
layout = self.layout
93104
area = context.area.ui_type
94105
panel = panel_names[self.bl_order]
95106
buttons = filter(
96-
lambda x: area in x.areas and x.panel == panel,
97-
context.scene.stb
107+
lambda x: area in x.areas and x.panel == panel, context.scene.stb
98108
)
99109
for button in sorted(buttons, key=lambda x: x.name):
100110
layout.operator(
101-
"stb.script_button",
102-
text=button.name
111+
"stb.script_button", text=button.name
103112
).name = button.name
113+
104114
STB_MT_Buttons.__name__ = "STB_MT_Buttons_%s" % index
105115

106116
if register:

0 commit comments

Comments
 (0)