Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/pycha/utils.py
diff options
context:
space:
mode:
authorAgustin Zubiaga <aguzubiaga97@gmail.com>2012-01-21 03:07:43 (GMT)
committer Agustin Zubiaga <aguzubiaga97@gmail.com>2012-01-21 03:07:43 (GMT)
commit2d3266e0ff6c20ad65cc8b0ea842097276e2a5a8 (patch)
tree979d8e2d933c704e88503f06cb1090fff24a1892 /pycha/utils.py
parentd6132743eeb60c683c89e6dd8a4d27b5816ce00d (diff)
Pycha module added, icons added, charts.py file added, simplegraph now can create a bar chart
Diffstat (limited to 'pycha/utils.py')
-rw-r--r--pycha/utils.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/pycha/utils.py b/pycha/utils.py
new file mode 100644
index 0000000..aefc5b4
--- /dev/null
+++ b/pycha/utils.py
@@ -0,0 +1,39 @@
+# Copyright(c) 2007-2010 by Lorenzo Gil Sanchez <lorenzo.gil.sanchez@gmail.com>
+# 2009-2010 by Yaco S.L. <lgs@yaco.es>
+#
+# This file is part of PyCha.
+#
+# PyCha is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# PyCha is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with PyCha. If not, see <http://www.gnu.org/licenses/>.
+
+def clamp(minValue, maxValue, value):
+ """Make sure value is between minValue and maxValue"""
+ if value < minValue:
+ return minValue
+ if value > maxValue:
+ return maxValue
+ return value
+
+
+def safe_unicode(obj, encoding=None):
+ """Return a unicode value from the argument"""
+ if isinstance(obj, unicode):
+ return obj
+ elif isinstance(obj, str):
+ if encoding is None:
+ return unicode(obj)
+ else:
+ return unicode(obj, encoding)
+ else:
+ # it may be an int or a float
+ return unicode(obj)