From 57514d97ca2d99a1d804d64562d6cc2cff85a18d Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Thu, 20 Mar 2014 09:11:04 -0400 Subject: [PATCH 1/2] Allow setting source to empty string to clear text, if it wasnt empty before. --- kivy/uix/rst.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kivy/uix/rst.py b/kivy/uix/rst.py index af69aabf8..f21452ba9 100644 --- a/kivy/uix/rst.py +++ b/kivy/uix/rst.py @@ -516,6 +516,9 @@ class RstDocument(ScrollView): super(RstDocument, self).__init__(**kwargs) def on_source(self, instance, value): + if not value: + self.text = '' + return if self.document_root is None: # set the documentation root to the directory name of the # first tile @@ -544,8 +547,6 @@ class RstDocument(ScrollView): The result will be stored in :attr:`toctrees` with the ``filename`` as key. ''' - if filename in self.toctrees: - return with open(filename, 'rb') as fd: text = fd.read().decode(encoding, errors) From 766acfdb78de4afd5df37c2bddf3d435a896a9be Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Thu, 27 Mar 2014 01:31:20 -0400 Subject: [PATCH 2/2] Allow loading from file ref, even if source has not been used before. Setting source to '' wont clear text now. --- kivy/uix/rst.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kivy/uix/rst.py b/kivy/uix/rst.py index f21452ba9..29c61e6e2 100644 --- a/kivy/uix/rst.py +++ b/kivy/uix/rst.py @@ -56,7 +56,7 @@ document. __all__ = ('RstDocument', ) import os -from os.path import dirname, join, exists +from os.path import dirname, join, exists, abspath from kivy.clock import Clock from kivy.compat import PY2 from kivy.properties import ObjectProperty, NumericProperty, \ @@ -517,12 +517,11 @@ class RstDocument(ScrollView): def on_source(self, instance, value): if not value: - self.text = '' return if self.document_root is None: # set the documentation root to the directory name of the # first tile - self.document_root = dirname(value) + self.document_root = abspath(dirname(value)) self._load_from_source() def on_text(self, instance, value): @@ -621,11 +620,10 @@ class RstDocument(ScrollView): .. versionadded:: 1.3.0 ''' # check if it's a file ? - if self.document_root is not None and ref.endswith('.rst'): - filename = join(self.document_root, ref) - if exists(filename): - self.source = filename - return + if ref.endswith('.rst'): + # whether it's a valid or invalid file, let source deal with it + self.source = ref + return # get the association ref = self.refs_assoc.get(ref, ref)