Skip to content

Commit

Permalink
Merge pull request #1437 from BlazZupan/tutorials-to-workflows
Browse files Browse the repository at this point in the history
[FIX] Welcome screen (tutorial) schemas renamed to (example) workflows
  • Loading branch information
lanzagar authored Jul 10, 2016
2 parents dad2b00 + 64b64b6 commit 9bf3fa0
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
8 changes: 4 additions & 4 deletions Orange/canvas/application/canvasmain.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

from .. import config

from . import tutorials
from . import workflows

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -1369,11 +1369,11 @@ def tutorial_scheme(self, *args):
the canvas and returns QDialog.Accepted.
"""
tutors = tutorials.tutorials()
tutors = workflows.example_workflows()
items = [previewmodel.PreviewItem(path=t.abspath()) for t in tutors]
model = previewmodel.PreviewModel(items=items)
dialog = previewdialog.PreviewDialog(self)
title = self.tr("Tutorials")
title = self.tr("Example Workflows")
dialog.setWindowTitle(title)
template = ('<h3 style="font-size: 26px">\n'
#'<img height="26" src="canvas_icons:Tutorials.svg">\n'
Expand Down Expand Up @@ -1452,7 +1452,7 @@ def tutorial():
tutorials_action = \
QAction(self.tr("Tutorials"), self,
objectName="tutorials-action",
toolTip=self.tr("View YoutTube tutorials."),
toolTip=self.tr("View YouTube tutorials."),
triggered=self.tutorials,
icon=canvas_icons("YouTube.svg")
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
"""
Orange Canvas Tutorial schemes
Examples of Orange workflows
"""
import os
import io
import logging
import types
import collections
from itertools import chain

import pkg_resources
Expand All @@ -15,7 +13,7 @@


def list_schemes(package):
"""Return a list of scheme tutorials.
"""Return a list of example workflows.
"""
resources = pkg_resources.resource_listdir(package.__name__, ".")
resources = list(filter(is_ows, resources))
Expand All @@ -32,55 +30,58 @@ def default_entry_point():
return ep


def tutorial_entry_points():
"""Return an iterator over all tutorials.
def workflow_entry_points():
"""Return an iterator over all example workflows.
"""
default = default_entry_point()
return chain([default],
pkg_resources.iter_entry_points("orange.widgets.tutorials"))
pkg_resources.iter_entry_points("orange.widgets.tutorials"),
pkg_resources.iter_entry_points("orange.widgets.workflows"))


def tutorials():
"""Return all known tutorials.
def example_workflows():
"""Return all known example workflows.
"""
all_tutorials = []
for ep in tutorial_entry_points():
tutorials = None
all_workflows = []
for ep in workflow_entry_points():
workflows = None
try:
tutorials = ep.load()
workflows = ep.load()
except pkg_resources.DistributionNotFound as ex:
log.warning("Could not load tutorials from %r (%r)",
log.warning("Could not load workflows from %r (%r)",
ep.dist, ex)
continue
except ImportError:
log.error("Could not load tutorials from %r",
log.error("Could not load workflows from %r",
ep.dist, exc_info=True)
continue
except Exception:
log.error("Could not load tutorials from %r",
log.error("Could not load workflows from %r",
ep.dist, exc_info=True)
continue

if isinstance(tutorials, types.ModuleType):
package = tutorials
tutorials = list_schemes(tutorials)
tutorials = [Tutorial(t, package, ep.dist) for t in tutorials]
elif isinstance(tutorials, (types.FunctionType, types.MethodType)):
if isinstance(workflows, types.ModuleType):
package = workflows
workflows = list_schemes(workflows)
workflows = [ExampleWorkflow(wf, package, ep.dist)
for wf in workflows]
elif isinstance(workflows, (types.FunctionType, types.MethodType)):
try:
tutorials = tutorials()
workflows = example_workflows()
except Exception as ex:
log.error("A callable entry point (%r) raised an "
"unexpected error.",
ex, exc_info=True)
continue
tutorials = [Tutorial(t, package=None, distribution=ep.dist)]
workflows = [ExampleWorkflow(wf, package=None, distribution=ep.dist)
for wf in workflows]

all_tutorials.extend(tutorials)
all_workflows.extend(workflows)

return all_tutorials
return all_workflows


class Tutorial(object):
class ExampleWorkflow(object):
def __init__(self, resource, package=None, distribution=None):
self.resource = resource
self.package = package
Expand All @@ -101,7 +102,7 @@ def abspath(self):
raise ValueError("cannot resolve resource to an absolute name")

def stream(self):
"""Return the tutorial file as an open stream.
"""Return the workflow file as an open stream.
"""
if self.package is not None:
return pkg_resources.resource_stream(self.package.__name__,
Expand Down

0 comments on commit 9bf3fa0

Please sign in to comment.