Skip to content

Commit

Permalink
Update: Support old Blender (version 2.80 to 4.1) again
Browse files Browse the repository at this point in the history
  • Loading branch information
nutti committed Oct 2, 2024
1 parent 0179aad commit 9ca5fe4
Show file tree
Hide file tree
Showing 27 changed files with 4,391 additions and 29 deletions.
43 changes: 42 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,48 @@ on: # yamllint disable-line rule:truthy
- cron: "0 7 * * *"

jobs:
build:
test-addon-blender-before-v41:
name: Test add-on
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
blender_version:
[
"2.80", "2.81", "2.82", "2.83",
"2.90", "2.91", "2.92", "2.93",
"3.0", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6",
"4.0", "4.1",
]
steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.7"

- name: Get required packages for Blender
run: |
sudo apt-get update -qq
sudo apt-get install -y blender wget python3 python3-pip zip
- name: Get required pip packages
run: pip3 install -r requirements.txt

- name: Download Blender
run: bash tools/download_blender.sh ${{ matrix.blender_version }} blender-bin

- name: Copy add-on to Blender add-on's directory
run: cp -r src/screencast_keys blender-bin/blender-v${{ matrix.blender_version }}-bin/${{ matrix.blender_version }}/scripts/addons

- name: Run add-on unittest
run: blender-bin/blender-v${{ matrix.blender_version }}-bin/blender --factory-startup --background -noaudio --python tests/python/run_tests.py
env:
SK_CONSOLE_MODE: true

test-addon-blender-after-v42:
name: Test add-on
runs-on: ubuntu-latest
strategy:
Expand Down
2 changes: 2 additions & 0 deletions src/screencast_keys/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# pylint: disable=E0601
importlib.reload(gpu_utils)
importlib.reload(utils)
importlib.reload(c_structure) # extensions.blender.org: Delete line
utils.bl_class_registry.BlClassRegistry.cleanup()
importlib.reload(preferences)
importlib.reload(ops)
Expand All @@ -50,6 +51,7 @@
import bpy
from . import gpu_utils
from . import utils
from . import c_structure # extensions.blender.org: Delete line
from . import preferences
from . import ops
from . import ui
Expand Down
108 changes: 108 additions & 0 deletions src/screencast_keys/c_structure/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# <pep8-80 compliant>

# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####


NOT_SUPPORTED = False

if "bpy" in locals():
import importlib
# pylint: disable=E0601
# pylint: disable=E0602
if compat.check_version(2, 79, 0) == 0:
importlib.reload(v279)
elif compat.check_version(2, 80, 0) == 0:
importlib.reload(v280)
elif compat.check_version(2, 81, 0) == 0:
importlib.reload(v281)
elif compat.check_version(2, 82, 0) == 0:
importlib.reload(v282)
elif compat.check_version(2, 83, 0) == 0:
importlib.reload(v283)
elif compat.check_version(2, 90, 0) == 0:
importlib.reload(v290)
elif compat.check_version(2, 91, 0) == 0:
importlib.reload(v291)
elif compat.check_version(2, 92, 0) == 0:
importlib.reload(v292)
elif compat.check_version(2, 93, 0) == 0:
importlib.reload(v293)
elif compat.check_version(3, 0, 0) == 0:
importlib.reload(v30)
elif compat.check_version(3, 1, 0) == 0:
importlib.reload(v31)
elif compat.check_version(3, 2, 0) == 0:
importlib.reload(v32)
elif compat.check_version(3, 3, 0) == 0:
importlib.reload(v33)
elif compat.check_version(3, 4, 0) == 0:
importlib.reload(v34)
elif compat.check_version(3, 5, 0) == 0:
importlib.reload(v35)
elif compat.check_version(3, 6, 0) == 0:
importlib.reload(v36)
elif compat.check_version(4, 0, 0) == 0:
importlib.reload(v40)
elif compat.check_version(4, 1, 0) == 0:
importlib.reload(v41)
else:
importlib.reload(v41)
NOT_SUPPORTED = True
else:
import bpy
from ..utils import compatibility as compat
if compat.check_version(2, 79, 0) == 0:
from .v279 import *
elif compat.check_version(2, 80, 0) == 0:
from .v280 import *
elif compat.check_version(2, 81, 0) == 0:
from .v281 import *
elif compat.check_version(2, 82, 0) == 0:
from .v282 import *
elif compat.check_version(2, 83, 0) == 0:
from .v283 import *
elif compat.check_version(2, 90, 0) == 0:
from .v290 import *
elif compat.check_version(2, 91, 0) == 0:
from .v291 import *
elif compat.check_version(2, 92, 0) == 0:
from .v292 import *
elif compat.check_version(2, 93, 0) == 0:
from .v293 import *
elif compat.check_version(3, 0, 0) == 0:
from .v30 import *
elif compat.check_version(3, 1, 0) == 0:
from .v31 import *
elif compat.check_version(3, 2, 0) == 0:
from .v32 import *
elif compat.check_version(3, 3, 0) == 0:
from .v33 import *
elif compat.check_version(3, 4, 0) == 0:
from .v34 import *
elif compat.check_version(3, 5, 0) == 0:
from .v35 import *
elif compat.check_version(3, 6, 0) == 0:
from .v36 import *
elif compat.check_version(4, 0, 0) == 0:
from .v40 import *
elif compat.check_version(4, 1, 0) == 0:
from .v41 import *
else:
from .v41 import *
NOT_SUPPORTED = True
202 changes: 202 additions & 0 deletions src/screencast_keys/c_structure/v279.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
from ctypes import (
c_void_p, c_char, c_short, c_int, c_int8,
addressof, cast, pointer,
Structure,
POINTER,
)


class Link(Structure):
"""Defined in source/blender/makesdna/DNA_listBase.h"""


# pylint: disable=W0212
Link._fields_ = [
("next", POINTER(Link)), # struct Link
("prev", POINTER(Link)), # struct Link
]


class ListBase(Structure):
# pylint: disable=W0201
"""Defined in source/blender/makesdna/DNA_listBase.h"""

def remove(self, vlink):
"""Ref: BLI_remlink"""

link = vlink
if not vlink:
return

if link.next:
link.next.contents.prev = link.prev
if link.prev:
link.prev.contents.next = link.next

if self.last == addressof(link):
self.last = cast(link.prev, c_void_p)
if self.first == addressof(link):
self.first = cast(link.next, c_void_p)

def find(self, number):
"""Ref: BLI_findlink"""

link = None
if number >= 0:
link = cast(c_void_p(self.first), POINTER(Link))
while link and number != 0:
number -= 1
link = link.contents.next
return link.contents if link else None

def insert_after(self, vprevlink, vnewlink):
"""Ref: BLI_insertlinkafter"""

prevlink = vprevlink
newlink = vnewlink

if not newlink:
return

def gen_ptr(link):
if isinstance(link, (int, type(None))):
return cast(c_void_p(link), POINTER(Link))
else:
return pointer(link)

if not self.first:
self.first = self.last = addressof(newlink)
return

if not prevlink:
newlink.prev = None
newlink.next = gen_ptr(self.first)
newlink.next.contents.prev = gen_ptr(newlink)
self.first = addressof(newlink)
return

if self.last == addressof(prevlink):
self.last = addressof(newlink)

newlink.next = prevlink.next
newlink.prev = gen_ptr(prevlink)
prevlink.next = gen_ptr(newlink)
if newlink.next:
newlink.next.prev = gen_ptr(newlink)


# pylint: disable=W0212
ListBase._fields_ = [
("first", c_void_p),
("last", c_void_p),
]


# pylint: disable=C0103
class wmWindow(Structure):
"""Defined in source/blender/makesdna/DNA_windowmanager_types.h"""


# pylint: disable=W0212
wmWindow._fields_ = [
("next", POINTER(wmWindow)),
("prev", POINTER(wmWindow)),

("ghostwin", c_void_p),

("screen", c_void_p), # struct bScreen
("newscreen", c_void_p), # struct bScreen
("screenname", c_char * 64),

("posx", c_short),
("posy", c_short),
("sizex", c_short),
("sizey", c_short),
("windowstate", c_short),
("monitor", c_short),
("active", c_short),
("cursor", c_short),
("lastcursor", c_short),
("modalcursor", c_short),
("grabcursor", c_short),
("addmousemove", c_short),
("multisamples", c_short),
("pad", c_short * 3),

("winid", c_int),

("lock_pie_event", c_short),
("last_pie_event", c_short),

("eventstate", c_void_p), # struct wmEvent

("curswin", c_void_p), # struct wmSubWindow

("tweak", c_void_p), # struct wmGesture

("ime_data", c_void_p), # struct wmIMEData

("drawmethod", c_int),
("drawfail", c_int),
("drawdata", ListBase),

("queue", ListBase),
("handlers", ListBase),
("modalhandlers", ListBase),

("subwindows", ListBase),
("gesture", ListBase),

("stereo3d_format", c_void_p), # struct Stereo3dFormat
]


# pylint: disable=C0103
class wmOperator(Structure):
"""Defined in source/blender/makesdna/DNA_windowmanager_types.h"""


# pylint: disable=W0212
wmOperator._fields_ = [
("next", POINTER(wmOperator)),
("prev", POINTER(wmOperator)),

("idname", c_char * 64),
("properties", c_void_p), # IDProperty

("type", c_void_p), # struct wmOperatorType
("customdata", c_void_p),
("py_instance", c_void_p),

("ptr", c_void_p), # struct PointerRNA
("reports", c_void_p), # struct ReportList

("macro", ListBase),
("opm", POINTER(wmOperator)),
("layout", c_void_p), # struct uiLayout
("flag", c_short),
("_pad", c_short * 3),
]


# pylint: disable=C0103
class wmEventHandler(Structure):
"""Defined in source/blender/windowmanager/wm_event_system.h"""


# pylint: disable=W0212
wmEventHandler._fields_ = [
# from struct wmEventHandler
("next", POINTER(wmEventHandler)),
("prev", POINTER(wmEventHandler)),

("type", c_int8), # enum eWM_EventHandlerType
("flag", c_char),

("keymap", c_void_p), # struct wmKeyMap
("bblocal", c_void_p), # struct rcti
("bbwin", c_void_p), # struct rcti

# from struct wmEventHandler_Op
("op", POINTER(wmOperator)),
]
Loading

0 comments on commit 9ca5fe4

Please sign in to comment.