Em 06-09-2011 13:35, Aaron Meurer escreveu:
I would remove this isinstance call.

    Ok, done.

Other than that one comment, this looks good.  I didn't try applying
it to test it, though (I'll wait for the actual patch to do that).

Aaron Meurer

My first SymPy patch is attached, it is very simple. It was my first time with git commit, etc, so I have not yet mastered using github and just used the "quick patch variant".

This new setting "num_columns" for pretty printing will make possible to use SymPy pretty printing in user interfaces for smartphones and tablets (Maemo, Symbian, Android, etc) when there is no terminal.

        Roberto Colistete Jr.

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

>From fac2c6e26c1cf71859a64ce79bb4ddf1ac391961 Mon Sep 17 00:00:00 2001
From: Roberto Colistete-Jr <[email protected]>
Date: Mon, 12 Sep 2011 12:08:08 -0300
Subject: [PATCH] pretty printing new setting : num_columns.

---
 sympy/interactive/printing.py       |    6 +++---
 sympy/printing/pretty/pretty.py     |    3 +++
 sympy/printing/pretty/stringpict.py |    9 +++++++--
 3 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/sympy/interactive/printing.py b/sympy/interactive/printing.py
index 0efc78c..9b2d8d2 100644
--- a/sympy/interactive/printing.py
+++ b/sympy/interactive/printing.py
@@ -61,7 +61,7 @@ def result_display(self, arg):
     else:
         ip.set_hook('result_display', result_display)
 
-def init_printing(pretty_print=True, order=None, use_unicode=None, wrap_line=None, no_global=False, ip=None):
+def init_printing(pretty_print=True, order=None, use_unicode=None, wrap_line=None, num_columns=None, no_global=False, ip=None):
     """Initializes pretty-printer depending on the environment. """
     from sympy.printing.printer import Printer
 
@@ -71,12 +71,12 @@ def init_printing(pretty_print=True, order=None, use_unicode=None, wrap_line=Non
         from sympy.printing import sstrrepr as stringify_func
 
     if not no_global:
-        Printer.set_global_settings(order=order, use_unicode=use_unicode, wrap_line=wrap_line)
+        Printer.set_global_settings(order=order, use_unicode=use_unicode, wrap_line=wrap_line, num_columns=num_columns)
     else:
         _stringify_func = stringify_func
 
         if pretty_print:
-            stringify_func = lambda expr: _stringify_func(expr, order=order, use_unicode=use_unicode, wrap_line=wrap_line)
+            stringify_func = lambda expr: _stringify_func(expr, order=order, use_unicode=use_unicode, wrap_line=wrap_line, num_columns=num_columns)
         else:
             stringify_func = lambda expr: _stringify_func(expr, order=order)
 
diff --git a/sympy/printing/pretty/pretty.py b/sympy/printing/pretty/pretty.py
index f232943..b1fe8a5 100644
--- a/sympy/printing/pretty/pretty.py
+++ b/sympy/printing/pretty/pretty.py
@@ -23,6 +23,7 @@ class PrettyPrinter(Printer):
         "full_prec": "auto",
         "use_unicode": None,
         "wrap_line": True,
+        "num_columns": None,
     }
 
     def __init__(self, settings=None):
@@ -1218,6 +1219,8 @@ def pretty(expr, **settings):
     ---------
     expr: the expression to print
     wrap_line: line wrapping enabled/disabled, should be a boolean value (default to True)
+    num_columns: number of columns before line breaking (default to None which reads the 
+        terminal width), it is useful when using SymPy without terminal.
     use_unicode: use unicode characters, such as the Greek letter pi instead of
         the string pi. Values should be boolean or None
     full_prec: use full precision. Default to "auto"
diff --git a/sympy/printing/pretty/stringpict.py b/sympy/printing/pretty/stringpict.py
index 64739bf..17833a4 100644
--- a/sympy/printing/pretty/stringpict.py
+++ b/sympy/printing/pretty/stringpict.py
@@ -241,8 +241,13 @@ def render(self, * args, **kwargs):
         if kwargs["wrap_line"] is False:
             return "\n".join(self.picture)
 
-        # Attempt to get a terminal width
-        ncols = self.terminal_width()
+        if kwargs["num_columns"] is not None:
+            # Read the argument num_columns if it is not None
+            ncols = kwargs["num_columns"]
+        else:
+            # Attempt to get a terminal width
+            ncols = self.terminal_width()
+
         ncols -= 2
         if ncols <= 0:
             ncols = 78
-- 
1.7.0.4

Reply via email to