Commits

Sven Hendriks committed 9b3c08e Merge

Merged default head into production.

  • Participants
  • Parent commits 8636e8a, ae1a1b2
  • Branches production
  • Tags 0.0.2

Comments (0)

Files changed (4)

 ^.*\.pyc
 ^.*\.egg-info
 ^.*\.orig
+lyne/version.py
+

File example_files/example_01.lyne

+canvas_coords:
+  ? &id001 !!python/object:lyne.lib.tree.Tree
+    is_leaf: false
+    node: !!python/object:lyne.lib.node.OperatorNode {_operator: '*', _value: 262111617}
+    parents: []
+    subtrees:
+    - &id002 !!python/object:lyne.lib.tree.Tree
+      is_leaf: true
+      node: !!python/object:lyne.lib.node.CountingNode {_value: 16000}
+      parents:
+      - &id003 !!python/object:lyne.lib.tree.Tree
+        is_leaf: false
+        node: !!python/object:lyne.lib.node.OperatorNode {_operator: '>>', _value: 999}
+        parents:
+        - &id004 !!python/object:lyne.lib.tree.Tree
+          is_leaf: false
+          node: !!python/object:lyne.lib.node.OperatorNode {_operator: '|', _value: 16383}
+          parents:
+          - *id001
+          subtrees:
+          - *id002
+          - *id003
+          - &id005 !!python/object:lyne.lib.tree.Tree
+            is_leaf: false
+            node: !!python/object:lyne.lib.node.OperatorNode {_operator: '>>', _value: 62}
+            parents:
+            - *id004
+            subtrees:
+            - *id002
+            - &id006 !!python/object:lyne.lib.tree.Tree
+              is_leaf: true
+              node: !!python/object:lyne.lib.node.ConstantNode {_value: 8}
+              parents:
+              - *id005
+              subtrees: []
+        subtrees:
+        - *id002
+        - &id007 !!python/object:lyne.lib.tree.Tree
+          is_leaf: true
+          node: !!python/object:lyne.lib.node.ConstantNode {_value: 4}
+          parents:
+          - *id003
+          subtrees: []
+      - *id004
+      - *id005
+      - *id001
+      subtrees: []
+    - *id004
+  : [62.0, 504.0]
+  *id006: [464.0, 136.0]
+  *id005: [364.0, 291.0]
+  *id007: [320.0, 143.0]
+  *id002: [96.0, 141.0]
+  *id003: [226.0, 272.0]
+  *id004: [153.0, 374.0]
+tree_items:
+- *id003
+- *id004
+- *id002
+- *id007
+- *id006
+- *id005
+- *id001

File lyne/__init__.py

 
 LYNE_BASE_PATH = os.path.dirname(os.path.realpath(__file__))
 
+try:
+    import lyne.version
+except ImportError, msg:
+    __version__ = '<Unknown> (%s)' % (msg,)
+else:
+    try:
+        __version__ = '%s (%s)' % (lyne.version.tags[0],
+                                   lyne.version.revision_id)
+    except AttributeError, msg:
+        __version__ = '<Unknown> (module "version" is missing expected ' \
+                      'attribute: %s)' % (msg,)
+

File lyne/gui/main.py

 import yaml
 
 from Tkinter import *
+import tkFileDialog
 
-from lyne import LYNE_BASE_PATH
+from lyne import LYNE_BASE_PATH, __version__
 from lyne.lib import *
 from lyne.lib.tree import *
 from lyne.lib.node import *
 
 logger = logging.getLogger('lyne.gui')
 
-class App(Frame):
+class LyneGUI(Frame):
     line_classes = (LineWArrow, SplineLineWArrow)
     node_classes = (CountingNode, ConstantNode, OperatorNode)
 
         self._sound_thread = None
 
     def _create_widgets(self):
+        # Install menu
+        # ============
+        menubar = Menu(self)
+
+        file_menu = Menu(menubar)
+        file_menu.add_command(label='Open file', command=self._load)
+        file_menu.add_command(label='Save file', command=self._save)
+        file_menu.add_separator()
+        file_menu.add_command(label='Quit', command=self.quit_app)
+
+        menubar.add_cascade(label="File", menu=file_menu)
+        
+        self.master.config(menu=menubar)
+
+        # define options for opening or saving a file
+        self._file_opts = {}
+        self._file_opts['filetypes'] = [('Lyne files', '.lyne'),
+                                        ('All files', '.*')]
+        self._file_opts['initialdir'] = '~'
+
         # Install the toolbar
         # ===================
         self._toolbar_active_button_index = IntVar()
         button_bar = Frame(self)
         button_bar.pack(fill=X)
 
-        # A button for closing the app and quiting
-        Button(button_bar, text='Quit App', command=self.quit_app).pack(side=LEFT)
-
         # A button for stopping the sound generating thread
         Button(button_bar, text='Stop Noise', 
                command=self._stop_noise).pack(side=LEFT)
 
-        # A button to save the tree structure
-        Button(button_bar, text='Save to File', command=self._save).pack(side=LEFT)
-
-        # A button to load a tree structure from file
-        Button(button_bar, text='Load from File', command=self._load).pack(side=LEFT)
-
         # A button to clear the canvas
         Button(button_bar, text='Clear Canvas',
                command=self._clear_canvas).pack(side=LEFT)
             incorporates both the view as well as the underlying
             data model of the tree(s).
         '''
+        outfile = tkFileDialog.asksaveasfile(mode='w', **self._file_opts)
+
+        if outfile == None:
+            return # short circuit; user has chosen to abort
+
+        self._file_opts['initialdir'] = os.path.dirname(outfile.name)
+
         data = {'tree_items': 
                     [w._tree for w in self._tree_item_widgets.values()],
                 'canvas_coords': 
                     dict((w_obj._tree, self._canvas.coords(w_id)) 
                         for w_id, w_obj in self._tree_item_widgets.iteritems())}
 
-        filename = 'out.yaml'
-        outfile = open(filename, 'w')
-
         yaml.dump(data, outfile)
-
         outfile.close()
 
     def _load(self):
             self._tree_item_widgets[w_id_1].attach_line(line_obj, LINE_HEAD)
             self._tree_item_widgets[w_id_2].attach_line(line_obj, LINE_TAIL)
 
+        infile = tkFileDialog.askopenfile(mode='r', **self._file_opts)
+
+        if infile == None:
+            return # short circuit; user has chosen to abort
+        
+        self._file_opts['initialdir'] = os.path.dirname(infile.name)
+
         # clear canvas
         self._clear_canvas()
 
         # load data from file
-        filename = 'out.yaml'
-        infile = open(filename, 'r')
-
         data = yaml.load(infile)
-
         infile.close()
 
         # construct canvas and data model from data read from file
     logging.basicConfig(level=loglevel,
                         format='[%(asctime)s] %(levelname)s: %(message)s')
 
+    logger.info('Starting lyne %s' % (__version__,))
     logger.info('Initializing main app ...')
     root = Tk()
-    app = App(root)
+    app = LyneGUI(root)
+
+    # set the application title
+    app.master.title('Lyne | Sound Synthesizer')
 
     logger.info('Entering main loop ...')
     app.mainloop()