Skip to content
Open
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
30 changes: 28 additions & 2 deletions src/ewoksorange/gui/canvas/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import sys
from contextlib import contextmanager

import os
from ...orange_version import ORANGE_VERSION

if ORANGE_VERSION == ORANGE_VERSION.oasys_fork:
Expand Down Expand Up @@ -78,6 +78,32 @@ def arg_parser():
from orangecanvas.main import main as _main


def _apply_registry_filter():
"""
Patches the WidgetRegistry to show categories based on an environment variable.
"""
filter_env = os.environ.get("EWOKS_WIDGET_FILTER")
if not filter_env:
return

try:
from orangecanvas.registry import WidgetRegistry
except ImportError:
try:
from Orange.canvas.registry import WidgetRegistry
except ImportError:
return

original_categories_method = WidgetRegistry.categories

def patched_categories(self):
all_cats = original_categories_method(self)
keep = {cat.strip() for cat in filter_env.split(",")}
return [c for c in all_cats if c.name in keep]

WidgetRegistry.categories = patched_categories


@contextmanager
def _temporary_log_handlers(log_level):
logger = logging.getLogger("ewoksorange")
Expand Down Expand Up @@ -119,5 +145,5 @@ def main(argv=None):
from orangecontrib.ewokstest import enable_ewokstest_category

enable_ewokstest_category()

_apply_registry_filter()
_main(argv)
Loading