Commits

Rob Lanphier committed aad1e68

Cleaned up imports in jsonedit

Comments (0)

Files changed (3)

 Things to get done before version 0.1
 
 On deck:
-*  Clean up imports in "jsonedit"
+*  Add alias for editing address books
 
 Roadmap
 0.1.0:
-*  Add alias for editing address books
 *  Graceful error on mismatched schema
 *  Minimal check for urwid and simpleparse (and look for /etc/lsb-release to 
    figure out the right error message)
 *  Rename "delete node" to something less compscinerdy
 *  Keep item highlighted while deleting
 *  Change "add fields" to "add items" for sequences
+*  Clean up imports in "jsonedit"
 
 # All rights reserved.
 # Licensed under BSD-style license.  See LICENSE.txt for details.
 
-import json
-import urwid.curses_display
-import urwid
 import optparse
 import sys
-import os
+import jsonwidget.termedit
 
-from jsonwidget.termedit import *
-
-# Force monochrome for now.  Will probably revisit when 0.9.9 is widely
-# deployed
-urwid.curses_display.curses.has_colors = lambda: False
-
-
-def show_form(schemafile, jsonfile):
-    form = JsonEditor(jsonfile=jsonfile, schemafile=schemafile,
-                      program_name="jsonedit 0.1pre")
+def run_editor(schemafile, jsonfile):
+    form = jsonwidget.termedit.JsonEditor(jsonfile=jsonfile, 
+                                          schemafile=schemafile,
+                                          program_name="jsonedit 0.1pre")
     form.run()
 
 
         jsonfile = args[0]
     else:
         jsonfile = None
-    show_form(options.schema, jsonfile)
+    run_editor(options.schema, jsonfile)
 
 if __name__ == "__main__":
     main()

jsonwidget/termedit.py

 from jsonwidget.pinot import *
 from jsonwidget.treetools import *
 
-
 # Series of editing widgets follows, each appropriate to a datatype or two
 
 class BaseJsonEditWidget(TreeWidget):
     These routines deal with the specifics of a JSON editor.
     """
     def __init__(self, jsonfile=None, schemafile=None, 
-                 program_name="JsonWidget"):
+                 program_name="JsonWidget", monochrome=True):
         self.file = JsonPinotFile(jsonfile=jsonfile, schemafile=schemafile)
         self.json = self.file.get_json()
         self.schema = self.json.get_schema_node()
         self.set_default_footer_helpitems([("^W", "Write/Save"), 
                                            ("^X", "Exit"),
                                            ("^D", "Delete Item")])
+        if monochrome:
+            urwid.curses_display.curses.has_colors = lambda: False
+
 
 
     def handle_delete_node_request(self):