Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds canvas to color dict in rstdocument #882

Merged
merged 5 commits into from

3 participants

shayneoneill Gabriel Pettier Mathieu Virbel
shayneoneill

This adds 'canvas' to the dict of colors in an RstDocument. As it stands canvas.before or canvas is not particularly useful for dealing with an RstDocument. This adds 'canvas' to the colors dictproperty allowing the background color to be updated

shayneoneill

Critique welcome. First time I've done a push request!

Gabriel Pettier
Owner

I think i would call it background instead of canvas, as this one can be confusing on the role of this value.

shayneoneill

Ok. That seems sensible. I might give that a try. Not entirely sure the best way to update my pull request though :/

kivy/uix/rst.py
@@ -72,12 +72,15 @@
from kivy.animation import Animation
from kivy.logger import Logger
-from docutils.parsers import rst
-from docutils.parsers.rst import roles
-from docutils import nodes, frontend, utils
-from docutils.parsers.rst import Directive, directives
-from docutils.parsers.rst.roles import set_classes
-
+try:

Let me know if I'm doing this part right. It seemed dropping out of the whole app with a warning about the import seemed the best approach to me, because I cant see how one could possibly recover from the error.. Maybe this is incorrect?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
kivy/uix/rst.py
@@ -411,6 +415,7 @@ class RstDocument(ScrollView):
'''
colors = DictProperty({
+ 'background': 'ffffff',

Is 'ffffff' an appropriate replacement for .9 .905 .910 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mathieu Virbel
Owner

Well, i could merge, without the exception approach.

You could try/catch to display a simpler message, but re-raise the exception then. Otherwise, you will fail on the next usage of something from the docutils.

shayneoneill

I think though that not having docutils is a showstopper bug, in that the code will simply crash later on without much assistance as to why however, and since docutils isnt standard library the developer does need to know that its needed , if he's developing from raw sources.

Whats the prefered approach for dealing with this sort of dependency?

Mathieu Virbel
Owner

Just re-raise the exception. Don't hide the original exception :)

shayneoneill

Right but the original exception isn't really that user friendly, I figured actually explaining it (because its going to affect the majority of non technical users, since docutils is non-standard and not that common) might be a better approach?

Mathieu Virbel
Owner

You can explain, but not move the exception so something else. It explicit to have a ImportError docutils.XXX than AttributeError or KeyError later during execution. But i didn't tested :)

shayneoneill

Ah ok. Maybe I'm misunderstanding how the exception system works. Is there an example around somewhere I can look at for a prefered way of doing it?

shayneoneill

I'll freely admit python exceptions are something I've never actually bothered to read the manual for lol. Which is a bit lame considering how long I've been tinkering with python for haha

shayneoneill

Ok for now, lets drop it and worry about that later I guess.

Mathieu Virbel tito merged commit bb1befb into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 5 additions and 4 deletions.
  1. +5 −4 kivy/uix/rst.py
9 kivy/uix/rst.py
View
@@ -71,13 +71,12 @@
from kivy.uix.anchorlayout import AnchorLayout
from kivy.animation import Animation
from kivy.logger import Logger
-
from docutils.parsers import rst
from docutils.parsers.rst import roles
from docutils import nodes, frontend, utils
from docutils.parsers.rst import Directive, directives
from docutils.parsers.rst.roles import set_classes
-
+
#
# Handle some additional roles
@@ -116,13 +115,15 @@ def run(self):
Builder.load_string('''
#:import parse_color kivy.parser.parse_color
+
+
<RstDocument>:
content: content
scatter: scatter
do_scroll_x: False
canvas:
Color:
- rgb: .9, .905, .910
+ rgb: parse_color(root.colors['background'])
Rectangle:
pos: self.pos
size: self.size
@@ -381,7 +382,6 @@ class RstDocument(ScrollView):
'''Base widget used to store an Rst document. See module documentation for
more information.
'''
-
source = StringProperty(None)
'''Filename of the RST document.
@@ -411,6 +411,7 @@ class RstDocument(ScrollView):
'''
colors = DictProperty({
+ 'background': 'e5e6e9',
'link': 'ce5c00',
'paragraph': '202020',
'title': '204a87',
Something went wrong with that request. Please try again.