Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktmag committed Mar 18, 2023
1 parent 389ff9c commit cb55a13
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 41 deletions.
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,40 @@
# sphinxcontrib-panopto
A Sphinx extension for embedding Panopto videos
This module defines a directive, `ggb`. It takes a single, required
argument, a geogebra tube ID::

.. ggb:: 1264951

The referenced geogebra applet will be embedded into HTML output.
Installation
============
1. Install this extension:

python setup.py build
sudo python setup.py install OR python setup.py install --user

2. Move 'layout.html' to your '_templates' directory
(if there is already a custom layout file then copy lines 2-7 of
'layout.html' and paste to that file).

3. Add 'ggbextension.ggb' to your extensions in 'conf.py'

Options
=======

There are 5 optional parameters.
"width" and "height" are the applet width and height, the defaults are 700 px width and 400 px height.

"img" is the location of an image file to be put in place of the applet into latex output, relative to the _build/latex folder (or wherever the generated latex output ends up). If the img parameter is not listed no image is included in the output.

"imgwidth" is the width of that image, default value is 8cm.


"zoom_drag" (default setting: false) to control whether the user can drag the applet image around and zoom in and out.

.. ggb:: 1264951
:width: 846
:height: 664
:img: ../../_static/hi_logo.jpg
:imgwidth: 4cm
:zoom_drag: true
38 changes: 0 additions & 38 deletions README.txt

This file was deleted.

8 changes: 5 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@


setup(
name="panoptoextension",
version="1.0",
name="sphinxcontrib-panopto",
version="2.0",
description="Sphinx panopto applet extension",
author="Solrun Einarsdottir",
author_email="solrun.einarsdottir@gmail.com",
maintainer="Benedikt Magnusson",
maintainer_email="bsm@hi.is",
packages=find_packages(),
include_package_data=True,
install_requires=requires,
namespace_packages=["panoptoextension"],
namespace_packages=["sphinxcontrib"],
)
1 change: 1 addition & 0 deletions sphinxcontrib/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__("pkg_resources").declare_namespace(__name__)
Binary file added sphinxcontrib/__pycache__/panopto.cpython-310.pyc
Binary file not shown.
80 changes: 80 additions & 0 deletions sphinxcontrib/panopto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from docutils import nodes
from docutils.parsers.rst import directives

try:
from sphinx.util.compat import Directive
except ImportError:
from docutils.parsers.rst import Directive


class panopto(nodes.General, nodes.Element):
pass


def html_visit_panopto_node(self, node):
self.body.append("<figure>")
self.body.append(
"<iframe src='https://rec.hi.is/Panopto/Pages/Embed.aspx?id="
+ node["id"]
+ "' width="
+ node["width"]
+ " height="
+ node["height"]
+ " style=padding: 0px; border: 1px solid #464646; frameborder='0'>"
)
self.body.append("</iframe>")
self.body.append("</figure>")


def tex_visit_panopto_node(self, node):
if node["img"] != None:
self.body.append("\n\n")
self.body.append("\\begin{center}\n")
self.body.append(
"\\includegraphics[width="
+ node["imgwidth"]
+ ",keepaspectratio=true]{"
+ node["img"]
+ "}\n"
)
self.body.append("\\end{center}")
self.body.append("\n\n")


def html_depart_panopto_node(self, node):
pass


def tex_depart_panopto_node(self, node):
pass


class PANOPTO(Directive):
has_content = True
required_arguments = 1
optional_arguments = 2
final_argument_whitespace = False
option_spec = {
"width": directives.unchanged,
"height": directives.unchanged,
}

def run(self):
node = panopto()
node["id"] = self.arguments[0]
node["width"] = self.options.get("width", "700")
node["height"] = self.options.get("height", "400")

return [node]


def setup(app):
app.add_node(
panopto,
html=(html_visit_panopto_node, html_depart_panopto_node),
latex=(tex_visit_panopto_node, tex_depart_panopto_node),
)
app.add_directive("panopto", PANOPTO)

0 comments on commit cb55a13

Please sign in to comment.