Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating to current stuff #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,42 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from . import ui
from . import operators
from . import preferences
from . import properties
from . import install


bl_info = {
"name": "My Awesome Add-on",
"description": "Single line describing my awesome add-on.",
"author": "Aaron Powell",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "Properties > Render > My Awesome Panel",
"warning": "", # used for warning icon and text in add-ons panel
"wiki_url": "http://my.wiki.url",
"tracker_url": "http://my.bugtracker.url",
"support": "COMMUNITY",
"category": "Render"
}

import bpy
"name": "My Awesome Add-on",
"description": "Single line describing my awesome add-on.",
"author": "Aaron Powell, Anthony Aragues",
"version": (0, 0, 1),
"blender": (3, 4, 0),
"location": "Properties > Render > My Awesome Panel",
"warning": "", # used for warning icon and text in add-ons panel
"wiki_url": "http://my.wiki.url",
"tracker_url": "http://my.bugtracker.url",
"support": "COMMUNITY",
"category": "Render"
}

#
# Add additional functions here
#

def register():
from . import properties
from . import ui
properties.register()
operators.register()
preferences.register()
ui.register()
install.addPackages()


def unregister():
from . import properties
from . import ui
properties.unregister()
operators.unregister()
preferences.unregister()
ui.unregister()


if __name__ == '__main__':
register()
8 changes: 8 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# ALL THE APPLICATION CONSTANTS

ADDON_PREFIX = 'TMP'
ADDON_NAME = 'Template'

ICONS_DIRECTORY = 'icons'

PIP_PACKAGES = []
39 changes: 39 additions & 0 deletions icons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
import bpy
from . import config


arrIcons = None
strDirectory = os.path.join(os.path.dirname(__file__), config.ICONS_DIRECTORY)

# 0. from . import icons
# 1. update the default path above
# 2. put initIcons in the primary register chain
# 3. put delIcons in the unregister chain
# example use = row.operator("key.set_space", text="SET",icon_value = icons.getIconId("set_space_16"))


def getIconId(strIcon):
# The initialize_icons_collection function needs to be called first.
return getIcon(strIcon).icon_id


def getIcon(strIcon, strPath=None):
if strPath == None:
strPath = os.path.join(strDirectory, strIcon + ".png")
if strIcon in arrIcons:
return arrIcons[strIcon]
try:
return arrIcons.load(strIcon, strPath, "IMAGE")
except:
print("couldn't find file for icon: ", strIcon, strPath)
return None


def initIcons():
global arrIcons
arrIcons = bpy.utils.previews.new()


def delIcons():
bpy.utils.previews.remove(arrIcons)
34 changes: 34 additions & 0 deletions install.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import bpy
import subprocess
import pathlib
import pkgutil
from . import config


def addPip(strLibrary, reinstall=False):
if pkgutil.find_loader(strLibrary) is None:
try:
python_path = bpy.app.binary_path_python
except AttributeError:
import sys
python_path = next(
(pathlib.Path(sys.prefix)/"bin").glob("python*"))

sub = subprocess.run([python_path, "-m", "ensurepip"])
if sub.returncode != 0:
return False

mode = "--upgrade"
if reinstall:
mode = "--force-reinstall"

sub = subprocess.run(
[python_path, "-m", "pip", "install", mode, "--user", strLibrary])
if sub.returncode != 0:
return False
return True


def addPackages():
for strPackage in config.PIP_PACKAGES:
addPip(strPackage)
39 changes: 39 additions & 0 deletions operators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import bpy
from . import config

# collect all the classes to register
arrClasses = []


def prefix_name(opClass):
opClass.__name__ = config.ADDON_PREFIX.upper() + '_OT_' + opClass.__name__
arrClasses.append(opClass)
return opClass


@prefix_name
class shoot_first(bpy.types.Operator):
"""first operators tooltip"""
bl_idname = f'{config.ADDON_PREFIX.lower()}.shoot_first'
bl_label = "Shoot"
bl_options = {'UNDO'}

@classmethod
def poll(cls, context):
# put stuff here as a condition fo enabling the operator return True or False for enabling
return True

def execute(self, context):
print("I shot!")
return {'FINISHED'}


#### || CLASS MAINTENANCE ||####
def register():
for i in arrClasses:
bpy.utils.register_class(i)


def unregister():
for i in reversed(arrClasses):
bpy.utils.unregister_class(i)
37 changes: 37 additions & 0 deletions preferences.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import bpy
from . import config

arrClasses = []


def prefix_name(opClass):
opClass.__name__ = config.ADDON_PREFIX.upper() + '_' + opClass.__name__
arrClasses.append(opClass)
return opClass


@prefix_name
class Preferences(bpy.types.AddonPreferences):
bl_idname = __package__

some_path: bpy.props.StringProperty(
name="Custom Folder Path",
subtype='FILE_PATH',
)

def draw(self, context):
layout = self.layout
layout.label(text="PREFERENCES")
row = layout.row()
row.prop(self, "some_path")


#### || CLASS MAINTENANCE ||####
def register():
for i in arrClasses:
bpy.utils.register_class(i)


def unregister():
for i in reversed(arrClasses):
bpy.utils.unregister_class(i)
27 changes: 23 additions & 4 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,43 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import bpy
import sys
from bpy.types import Panel
from . import config

# collect all the classes to register
arrClasses = []


def prefix_name(opClass):
opClass.__name__ = config.ADDON_PREFIX.upper() + '_PT_' + opClass.__name__
arrClasses.append(opClass)
return opClass

#
# Add additional functions here
#


@prefix_name
class MyPanel(Panel):
bl_label = 'My Awesome Panel'
bl_label = config.ADDON_NAME
bl_space_type = 'PROPERTIES'
bl_region_type= 'WINDOW'
bl_region_type = 'WINDOW'
bl_context = 'render'

def draw(self, context):
row = self.layout.row()
row.prop(context.scene, 'my_property')
row.op()


#### || CLASS MAINTENANCE ||####
def register():
bpy.utils.register_class(MyPanel)
for i in arrClasses:
bpy.utils.register_class(i)


def unregister():
bpy.utils.unregister_class(MyPanel)
for i in reversed(arrClasses):
bpy.utils.unregister_class(i)
Loading