diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-09-14 22:36:31 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-09-14 22:36:31 (GMT) |
commit | 8dedc9332f259b3e5444c451e3324a8f0cf2495a (patch) | |
tree | 0be8e8d27deb5ca148fff9e8a97986e3d8aa0e9f | |
parent | cf9aac721f814db3abb67706e941c13ba28e5fcd (diff) |
Support config mode
-rwxr-xr-x | application.py | 33 | ||||
-rw-r--r-- | canvas.py | 11 |
2 files changed, 29 insertions, 15 deletions
diff --git a/application.py b/application.py index b8b34bf..c50b69f 100755 --- a/application.py +++ b/application.py @@ -100,7 +100,7 @@ class UnfullscreenButton(gtk.Window): self._reposition() -class GraphPlotter(gtk.Window): +class Application(gtk.Window): def __init__(self): gtk.Window.__init__(self) self.save_type = info.io_mode @@ -132,10 +132,12 @@ class GraphPlotter(gtk.Window): self._vbox.show() self._is_fullscreen = False + self.set_events(gtk.gdk.ALL_EVENTS_MASK) self.connect('motion-notify-event', self.motion_cb) - self.connect('expose-event', self.expose_event) + self.canvas.connect('expose-event', self.expose_event) def expose_event(self, widget, event): + logger.debug('Exposing') if not self.started: if self.file_path != None: self.canvas.read_file(self.file_path) @@ -195,6 +197,9 @@ class GraphPlotter(gtk.Window): self.set_title(appname) def stop(self): + if info.io_mode == info.CONFIG: + self.file_path = os.path.join(os.environ['HOME'], '.' + info.lower_name) + self.save() gtk.main_quit() def open(self): @@ -237,18 +242,24 @@ class GraphPlotter(gtk.Window): if __name__ == '__main__': logger.debug('Initializing Graph Plotter') import sys - if len(sys.argv) > 1: - logger.debug('Open from args %s' % sys.argv[1]) - if os.path.exists(sys.argv[1]): - file_path = sys.argv[1] - logger.debug('Found file') + if info.io_mode == info.DOCUMENT: + if len(sys.argv) > 1: + logger.debug('Open from args %s' % sys.argv[1]) + if os.path.exists(sys.argv[1]): + file_path = sys.argv[1] + logger.debug('Found file') + else: + file_path = None + logger.error('Could not find file') else: file_path = None - logger.error('Could not find file') + logger.debug('Create new file') else: - file_path = None - logger.debug('Create new file') - window = GraphPlotter() + if os.path.exists(os.path.join(os.environ['HOME'], '.' + info.lower_name)): + file_path = os.path.join(os.environ['HOME'], '.' + info.lower_name) + else: + file_path = None + window = Application() window.file_path = file_path window.show() gtk.main() @@ -25,15 +25,18 @@ import gtk class Canvas(gtk.TextView): def write_file(self, path): - pass + config_file = open(path, 'w') + config_file.write("Hello World") + config_file.close() def read_file(self, path): - pass + text_file = open(path) + self.get_buffer().set_text(text_file.read()) + text_file.close() def __init__(self, toolbar_box, activity): gtk.TextView.__init__(self) self.activity = activity - self.get_buffer().set_text('Hello World') def new(self): - pass + self.get_buffer().set_text('Hi') |