Exemplo n.º 1
0
    def append(self,
               filename: str = "",
               text: str = "",
               code: Code = None) -> "ActionsBuilder":
        """Adds an :class:`purdy.actions.Append` action

        :param filename: name of a file to read for :class:`purdy.content.Code` 
                         content.  If both this and `text` is given,
                         `filename` is used first

        :param text: text to read for :class:`purdy.content.Code` content.

        :param code: a :class:`purdy.content.Code` object containing the source
                     code to insert. If all `code`, `filename` and `text` are 
                     given, `code` will be used first.

        :return: self
        """
        return self._add_action(
            Append(self.__code_box, self._create_code(filename, text, code)))
Exemplo n.º 2
0
from purdy.actions import Append, Wait, Transition, Fold
from purdy.content import Code
from purdy.ui import SimpleScreen, VirtualCodeBox

screen = SimpleScreen(starting_line_number=10)
code_box = screen.code_box
blob = Code('../display_code/simple.repl')
blob2 = Code('../display_code/traceback.repl')
blob3 = Code('../display_code/decorator.repl')

vbox = VirtualCodeBox(starting_line_number=20, display_mode='urwid')

# prep vbox for copy
vbox.perform_actions([
    Append(vbox, blob3),
    Fold(vbox, 2, 2),
])

actions = [
    Append(code_box, blob2),
    Wait(),
    Transition(code_box),  # test transition to empty
    Append(code_box, blob),
    Wait(),

    # Test Wait after Transition and code box copy
    Transition(code_box, code_box_to_copy=vbox),
    Wait(),
    Append(code_box, blob2),
]
Exemplo n.º 3
0
#!/usr/bin/env python

### Example purdy library code
#
# Demonstrates the Sleep action

from purdy.actions import Append, Sleep
from purdy.content import Code
from purdy.ui import SimpleScreen

screen = SimpleScreen(starting_line_number=10)
code_box = screen.code_box
blob = Code('../display_code/simple.repl')

actions = [
    Append(code_box, blob),
    Sleep(3),
    Append(code_box, blob),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 4
0
#!/usr/bin/env python

### Example purdy library code
#
# Demonstrates a split screen with content that exceeds the window size

from purdy.actions import Append
from purdy.content import Code
from purdy.ui import SplitScreen

code1 = Code('../display_code/console.repl')
code2 = Code('../display_code/console.repl')

screen = SplitScreen(max_height=30)

actions = [
    Append(screen.code_boxes[0], code1),
    Append(screen.code_boxes[1], code2),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 5
0
from purdy.content import Code
from purdy.settings import settings
from purdy.ui import SplitScreen

settings['movie_mode'] = 500

py_code = Code('../display_code/code.py')
con_code = Code('../display_code/simple.repl')

screen = SplitScreen(settings, top_starting_line_number=-1,
    top_auto_scroll=False)
py_box = screen.top
con_box = screen.bottom

actions = [
    Append(py_box, py_code),
    Wait(),
    AppendTypewriter(con_box, con_code),
    Wait(),
    StopMovie(),
    Wait(),
    Highlight(py_box, 4, True),
    Wait(),
    Highlight(con_box, 3, True),
    Wait(),
    Highlight(py_box, 4, False),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 6
0
#!/usr/bin/env python

### Example purdy library code
#
# Displays a colourized Python REPL session to the screen

from purdy.actions import Append
from purdy.content import Code
from purdy.ui import SimpleScreen

screen = SimpleScreen()
blob = Code('../display_code/console.repl')
actions = [
    Append(screen.code_box, blob),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 7
0
#!/usr/bin/env python

### Example purdy library code
#
# Demonstrates the use of compact dividers

from purdy.actions import Append
from purdy.content import Code
from purdy.ui import SplitScreen

screen = SplitScreen(compact=True)
top = screen.top
bottom = screen.bottom

blob = Code('../display_code/console.repl')
actions = [
    Append(top, blob),
    Append(bottom, blob),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 8
0
#!/usr/bin/env python

### Example purdy library code
#
# Shows a split screen session with two code boxes on top and a third below.

from purdy.actions import Append
from purdy.content import Code
from purdy.ui import Screen, CodeBox, TwinCodeBox

py_code = Code(filename='../display_code/code.py')
con_code = Code(filename='../display_code/console.repl')

screen = Screen(rows=[
    TwinCodeBox(left_starting_line_number=1, right_weight=2, height=14),
    CodeBox(auto_scroll=False)
])

actions = [
    Append(screen.code_boxes[0], py_code),
    Append(screen.code_boxes[1], con_code),
    Append(screen.code_boxes[2], con_code),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 9
0
undefined
> a
3
> let b = '4'
undefined
> b
'4'
> b == a
false
> b === a
false
> if(a) {
...   console.log(a)
... }
3
undefined
> c
Uncaught ReferenceError: c is not defined
"""

node = Code(text=text, lexer_name='node')

actions = [
    Append(code_box, js),
    Wait(),
    AppendTypewriter(code_box, node),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 10
0
#!/usr/bin/env python

### Example purdy library code
#
# Demonstrates a split screen with a large top window

from purdy.actions import (Append, AppendTypewriter, Highlight, StopMovie,
                           Wait)
from purdy.content import Code
from purdy.settings import settings
from purdy.ui import SplitScreen

settings['movie_mode'] = 2

original = Code('../display_code/code.py')
code1 = original.subset(3, 18)
code2 = original.subset(28, 39)

screen = SplitScreen(settings, top_height=15)

actions = [
    Append(screen.top, code1),
    Append(screen.bottom, code2),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 11
0

def do_something(foo, bar=3):
    with open('zzz_output.txt', 'a') as f:
        f.write(f'Doing something {foo} {bar}\n')


def undo_something(foo, bar=3):
    with open('zzz_output.txt', 'a') as f:
        f.write(f'Undoing something {foo} {bar}\n')


screen = SimpleScreen(starting_line_number=10)
code_box = screen.code_box
first = Code(text="First things first")
second = Code(text="Second things second")
third = Code(text="Now read zzz_output.txt file to check it worked")

actions = [
    Append(code_box, first),
    Wait(),
    RunFunction(do_something, undo_something, 'FOO', bar=42),
    Wait(),
    Append(code_box, second),
    Wait(),
    Append(code_box, third),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 12
0
def do_something(foo, bar=3):
    with open('zzz_output.txt', 'a') as f:
        f.write(f'Doing something {foo} {bar}\n')


def undo_something(foo, bar=3):
    with open('zzz_output.txt', 'a') as f:
        f.write(f'Undoing something {foo} {bar}\n')


screen = SimpleScreen(starting_line_number=10)
code_box = screen.code_box
first = Code(text="First things first")
second = Code(text="Second things second")
third = Code(text="Now read zzz_output.txt file to check it worked")

actions = [
    Append(code_box, first),
    Wait(),
    RunFunction(do_something, undo_something, 'FOO', bar=42),
    Wait(),
    Append(code_box, second),
    Wait(),
    Append(code_box, third),
    RunFunction(something_else, None),
    Append(code_box, Code(text='after parameterless function')),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 13
0
#!/usr/bin/env python

### Example purdy library code
#
# Demonstrates the code folding mechanism

from purdy.actions import Append, Fold, Wait, Clear
from purdy.content import Code
from purdy.ui import SimpleScreen

code = Code('../display_code/code.py')

screen = SimpleScreen(starting_line_number=1)
box = screen.code_box

actions = [
    Append(box, code),
    Wait(),
    Fold(box, 20, 23),
    Wait(),
    Fold(box, 27),
    Wait(),
    Clear(box),           # test long fold without wait, used to crash
    Append(box, code),
    Fold(box, 2),
]

if __name__ == '__main__':
    screen.run(actions)
Exemplo n.º 14
0
        # Fold the numbers in the following
        # a
        # 1
        # 2
        # b
        return


    def should_be_culled():
        pass
"""

before = Code(text=SOURCE)
after = Code(text=SOURCE).left_justify()
after.python_portion('show_only_this_function')
after.insert_line(1, "# After")
after.remove_lines(3, 2)
after.replace_line(8, '    # Was replaced')
after.inline_replace(9, 41, 'done$')
after.fold_lines(13, 14)
after.remove_double_blanks()

actions = [
    Append(box, before),
    Wait(),
    Transition(box, after),
]

if __name__ == '__main__':
    screen.run(actions)