Ejemplo n.º 1
0
    def __init__(self, header, content, state=None, on_expand=None):
        """
		Create a drop-down expander control. Consists of a button that the user clicks to open the control, display the content below

		:param header: the contents of the header button
		:param content: the content that is displayed when open
		:param state: the state; either in the form of a boolean which will be the initial state - True for open, False for closed - or a live value that contains the state
		:param on_expand: a callback invoked when the expander is expanded or contracted; of the form function(state)
		:return: the expander control
		"""
        self.__header = header
        self.__content = content

        self.expand = EventHandler()

        def expand_fn(x):
            self.state.value = x
            if on_expand is not None:
                on_expand(x)

        if state is None:
            self.state = LiveValue(False)
            self.__expand_fn = expand_fn
        elif isinstance(state, bool):
            self.state = LiveValue(state)
            self.__expand_fn = expand_fn
        elif isinstance(state, LiveValue):
            self.state = state
            self.__expand_fn = expand_fn
        elif isinstance(state, AbstractLive):
            self.state = state
            self.__expand_fn = on_expand
        else:
            raise TypeError, 'state must be None, a bool or an AbstractLive, not an {0}'.format(
                type(state).__name__)
Ejemplo n.º 2
0
 def __init__(self, tool_container, container, node_type_name, initial_name,
              node_create_fn):
     super(NewNodeTool, self).__init__(tool_container)
     self.__name = LiveValue(initial_name)
     self.__container = container
     self.__node_type_name = node_type_name
     self.__node_create_fn = node_create_fn
Ejemplo n.º 3
0
	def __setstate__(self, state):
		self.__blocks = state.get('blocks')
		if self.__blocks is None:
			self.__blocks = []
		self.__incr = IncrementalValueMonitor()
		self._module = None
		self.__execution_state = LiveValue()
		self.__exec_state_init()
Ejemplo n.º 4
0
	def __init__(self, blocks=None):
		if blocks is None:
			blocks = [NotebookBlockCode(self)]
		self.__blocks = blocks
		self.__incr = IncrementalValueMonitor()
		self._module = None
		self.__execution_state = LiveValue()
		self.__exec_state_init()
Ejemplo n.º 5
0
	def __init__(self, notebook, language, var_name='src'):
		super(NotebookBlockSource, self).__init__(notebook)
		try:
			code_type = self.__language_to_type_map[language]
		except KeyError:
			raise ValueError, 'Invalid language {0}'.format(language)

		self.__code = code_type()
		self.__var_name = LiveValue(var_name)
		self.__incr = IncrementalValueMonitor()
Ejemplo n.º 6
0
	def _present_header(self, fragment):
		gui = LiveValue(Html('<span></span>'))
		header = self._present_header_contents(fragment)

		contents = [
			'<div>',
			'<table><tr><td>',
			self._present_menu(fragment, gui),
			'</td><td>',
			header,
			'</td></tr></table>',
			'</div>',
			'<div class="project_gui_container">',
			gui,
			'</div>'
		]

		return Html(*contents)
Ejemplo n.º 7
0
    def __present__(self, fragment):
        create_gui = LiveValue(Html('<span></span>'))

        header = self._present_header(fragment)

        contents = [
            '<div class="project_package">',
            header,
            create_gui,
            '<div class="project_container_contents">',
        ]

        xs = self._contents[:]
        xs.sort(key=lambda x: (not isinstance(x, ProjectContainer), x.name))

        for x in xs:
            contents.extend(['<div>', x, '</div>'])

        contents.extend(['</div>', '</div>'])
        return Html(*contents)
Ejemplo n.º 8
0
def fetch_from_web_file_chooser(on_downloaded, on_cancel, user_agent=None):
    """
	Create a download form with an input box for a url

	:param on_downloaded: a callback that is invoked when the user chooses a file. It is of the form function(event, name, fp) where event is the triggering event, name is the file name and fp is a file like object
	:param on_cancel: a callback that is invoked when the user clicks the cancel button. Form: function(event)
	:param user_agent: the user agent to pass to the server
	"""
    if user_agent is None:
        user_agent = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.13 (KHTML, like Gecko) Chrome/24.0.1284.0 Safari/537.13'
    url_live = LiveValue('')

    def on_fetch(event):
        url = url_live.static_value
        url_l = url.lower()
        if not url_l.startswith('http://') and not url_l.startswith(
                'https://'):
            url = 'http://' + url
        request = urllib2.Request(url)
        request.add_header('User-Agent', user_agent)
        opener = urllib2.build_opener()
        fp = opener.open(request)

        r = urlparse.urlparse(url)
        name = r.path.split('/')[-1]

        on_downloaded(event, name, fp)

    def _on_cancel(event):
        on_cancel(event)

    return Html('<div><span class="gui_label">URL: </span>',
                text_entry.live_text_entry(url_live, width="40em"),
                '</div>', '<table>', '<tr><td>',
                button.button('Cancel', _on_cancel), '</td><td>',
                button.button('Fetch',
                              on_fetch), '</td></tr>', '</table>', '</div>')
Ejemplo n.º 9
0
	def __setstate__(self, state):
		super(NotebookBlockText, self).__setstate__(state)
		self.__text = LiveValue(state.get('text', ''))
Ejemplo n.º 10
0
	def __init__(self, notebook, text=None):
		super(NotebookBlockText, self).__init__(notebook)
		if text is None:
			text = ''
		self.__text = LiveValue(text)
Ejemplo n.º 11
0
	def __setstate__(self, state):
		super(NotebookBlockSource, self).__setstate__(state)
		self.__code = state.get('code')
		self.__var_name = LiveValue(state.get('var_name'))
		self.__incr = IncrementalValueMonitor()
Ejemplo n.º 12
0
	def __init__(self, doc_list):
		super(DownloadIPynbFromWebTool, self).__init__()
		self.__doc_list = doc_list
		self.__url = LiveValue('')
Ejemplo n.º 13
0
	def __init__(self, doc_list, document_factory, initial_name):
		super(NewDocumentTool, self).__init__()
		self.__doc_list = doc_list
		self.__document_factory = document_factory
		self.__name = LiveValue(initial_name)
Ejemplo n.º 14
0
 def __init__(self, tool_container, node):
     super(RenameNodeTool, self).__init__(tool_container)
     self.__node = node
     self.__name = LiveValue(node.name)