Commits

Sven Hendriks committed 41523da

Restyled diagram nodes a bit.

  • Participants
  • Parent commits 1c1abc3

Comments (0)

Files changed (17)

 lyne/data/images/*
+lyne/data/images_3rd_party/*
 

lyne/data/images/LICENSE

-The images in this folder were downloaded from:
-
-http://www.fatcow.com/free-icons
-
-
-Terms of Use
-------------
-
-These icon sets are licensed under a Creative Commons Attribution 3.0 License. 
-This means you can freely use these icons for any purpose, private and commercial, 
-including online services, templates, themes and software. However, you should 
-include a link to this page in your credits. The icons may not be resold, 
-sub-licensed, rented, transferred or otherwise made available for use. 
-Please link to this page on fatcow.com if you would like to spread the word.
-

lyne/data/images/cancel.gif

Removed
Old image

lyne/data/images/draw_line.gif

Removed
Old image

lyne/data/images/draw_wave.gif

Removed
Old image

lyne/data/images/handle_16x16.gif

Added
New image

lyne/data/images/handle_50x16.gif

Added
New image

lyne/data/images/sound.gif

Removed
Old image

lyne/data/images_3rd_party/LICENSE

+The images in this folder were downloaded from:
+
+http://www.fatcow.com/free-icons
+
+
+Terms of Use
+------------
+
+These icon sets are licensed under a Creative Commons Attribution 3.0 License. 
+This means you can freely use these icons for any purpose, private and commercial, 
+including online services, templates, themes and software. However, you should 
+include a link to this page in your credits. The icons may not be resold, 
+sub-licensed, rented, transferred or otherwise made available for use. 
+Please link to this page on fatcow.com if you would like to spread the word.
+

lyne/data/images_3rd_party/cancel.gif

Added
New image

lyne/data/images_3rd_party/draw_line.gif

Added
New image

lyne/data/images_3rd_party/draw_wave.gif

Added
New image

lyne/data/images_3rd_party/sound.gif

Added
New image

lyne/gui/headerbarwidget.py

     def __init__(self, *args, **kwargs):
         Tkinter.Frame.__init__(self, *args, **kwargs)
 
-        self._icon_refs = []
-        for icon_file in ('sound.gif', 'cancel.gif'):
-            self._icon_refs.append(
-                Tkinter.PhotoImage(file=os.path.join(LYNE_BASE_PATH,
-                                                     'data', 'images',
-                                                     icon_file))
-            )
+        self._icon_ref = Tkinter.PhotoImage(
+            file=os.path.join(LYNE_BASE_PATH,
+            'data', 'images_3rd_party', 'cancel.gif'))
 
-        self.handle = Tkinter.Label(self, background='black',
-                                    width=5, cursor='fleur')
+        self._handle_gif = Tkinter.PhotoImage(
+            file=os.path.join(LYNE_BASE_PATH,
+            'data', 'images', 'handle_50x16.gif'))
+
+
+        # install the drag handle
+        self.handle = Tkinter.Label(self, image=self._handle_gif,
+                                    cursor='fleur')
         self.handle.pack(side=Tkinter.LEFT, fill=Tkinter.BOTH)
 
-        self.sound_button = Tkinter.Button(self, image=self._icon_refs[0],
-                                           width=16, height=16)
-        self.sound_button.pack(side=Tkinter.LEFT)
-
-        self.quit_button = Tkinter.Button(self, image=self._icon_refs[1],
+        # install the quit button
+        self.quit_button = Tkinter.Button(self, image=self._icon_ref,
                                           width=16, height=16)
         self.quit_button.pack(side=Tkinter.LEFT)
 
         # =========================
         self._draw_line_gif = Tkinter.PhotoImage(
             file=os.path.join(LYNE_BASE_PATH, 
-                              'data', 'images', 
+                              'data', 'images_3rd_party', 
                               'draw_line.gif'))
 
         # XXX For simplicity, let's stick to one line type for now (*)

lyne/gui/plugwidget.py

-from Tkinter import *
-from ttk import *
-
-class PlugWidget(Label):
-    def __init__(self, *args, **kwargs):
-        Label.__init__(self, *args, **kwargs)
-        self.configure({
-            'background': 'orange', 
-            'width': 6, 
-            'cursor': 'crosshair'
-        })
-        Widget.bind(self, '<Enter>', self._highlight)
-        Widget.bind(self, '<Leave>', self._unhighlight)
-
-    def _highlight(self, event):
-        self.config(background='green')
-
-    def _unhighlight(self, event):
-        self.config(background='orange')
-
-
-

lyne/gui/treewidget.py

 import time
+import os
 
 import Tkinter
 import ttk
 
+from lyne import LYNE_BASE_PATH
+
 from lyne.lib.tree import Tree
 from lyne.lib.node import ConstantNode, CountingNode, OperatorNode
 from lyne.lib.stoppablethread import StoppableThread
 
-from lyne.gui.plugwidget import PlugWidget
 from lyne.gui.headerbarwidget import HeaderbarWidget
 
+
 (IN, OUT) = range(0, 2)
 
-class TreeItemWidget(Tkinter.Frame):
+
+class AbstractNodeWidgetFactory(Tkinter.Frame):
     def __init__(self, canvas):
-        Tkinter.Frame.__init__(self, canvas, borderwidth=2, 
+        Tkinter.Frame.__init__(self, canvas, borderwidth=3, 
                                relief=Tkinter.RAISED)
-
-        self._tree = None # a reference to the underlying data model item
-        self._widget = None
-
         self._lines_in = []
         self._lines_out = []
+        self._create_widgets()
 
-        self._animation_thread = None
+        Tkinter.Widget.bind(self, '<Enter>', self._highlight)
+        Tkinter.Widget.bind(self, '<Leave>', self._unhighlight)
 
-        self._create_widgets()
+        self.configure({'cursor': 'crosshair'})
+
+    def _highlight(self, event):
+        self.config(background='#FFFFFF')
+
+    def _unhighlight(self, event):
+        self.config(background='#d9d9d9')
 
     def _create_widgets(self):
         self._headerbar = HeaderbarWidget(self)
                             self._set_initial_xy)
         Tkinter.Widget.bind(self._headerbar.handle, '<B1-Motion>',
                             self._handle_item_drag)
-        Tkinter.Widget.bind(self._headerbar.sound_button, '<Button-1>',
-                            self._toggle_noise)
         Tkinter.Widget.bind(self._headerbar.quit_button, '<Button-1>',
                             self.delete)
 
-        self._plug = PlugWidget(self)
-        self._plug.pack(fill=Tkinter.X)
-
-        Tkinter.Widget.bind(self._plug, '<Button-1>', self._notify_canvas)
-   
-    def _toggle_noise(self, event):
-        self.dgw.master.toggle_noise(self)
-
-    def set_active(self):
-        self.config(background='#FF0000')
-        
-    def set_inactive(self):
-        self.config(background='#D9D9D9')
-
-    def start_animation(self):
-        if self._animation_thread == None or not self._animation_thread.isAlive():
-            self._animation_thread = StoppableThread(
-                target=self._animate)
-            self._animation_thread.start()
-
-    def stop_animation(self):
-        if self._animation_thread:
-            self._animation_thread.stop()
-
-    def _animate(self):
-        self.config(background='#00FF00')
-        time.sleep(0.25)
-        self.config(background='#FF0000')
-        time.sleep(0.75)
-
-    def _notify_canvas(self, event):
-        self.dgw.handle_item_plug_click(self._w_id)
+        Tkinter.Widget.bind(self, '<Button-1>', self._notify_canvas)
 
     def delete(self, event=None):
         # delete this widget from the canvas
         # finally, update the underlying data model
         self._tree.delete()
 
+    def _notify_canvas(self, event):
+        self.dgw.handle_item_plug_click(self._w_id)
+
+
     def _set_initial_xy(self, event):
         self.initial_x = event.x
         self.initial_y = event.y
         '''
         return False
 
+
+class TreeItemWidget(AbstractNodeWidgetFactory):
+    def __init__(self, canvas):
+        AbstractNodeWidgetFactory.__init__(self, canvas)
+
+        self._tree = None # a reference to the underlying data model item
+        self._widget = None
+
+        self._animation_thread = None
+
+        self._icon_ref = Tkinter.PhotoImage(
+            file=os.path.join(LYNE_BASE_PATH,
+            'data', 'images_3rd_party', 'sound.gif'))
+
+        self._sound_button = Tkinter.Button(
+            self, image=self._icon_ref, width=16, height=16)
+        self._sound_button.pack(side=Tkinter.RIGHT)
+
+        Tkinter.Widget.bind(self._sound_button, '<Button-1>',
+                            self._toggle_noise)
+   
+    def _toggle_noise(self, event):
+        self.dgw.master.toggle_noise(self)
+
+    def set_active(self):
+        self.config(background='#FF0000')
+        
+    def set_inactive(self):
+        self.config(background='#D9D9D9')
+
+    def start_animation(self):
+        if self._animation_thread == None or not self._animation_thread.isAlive():
+            self._animation_thread = StoppableThread(
+                target=self._animate)
+            self._animation_thread.start()
+
+    def stop_animation(self):
+        if self._animation_thread:
+            self._animation_thread.stop()
+
+    def _animate(self):
+        self.config(background='#00FF00')
+        time.sleep(0.25)
+        self.config(background='#FF0000')
+        time.sleep(0.75)
+
+
 class TreeItemConstantWidget(TreeItemWidget):
     def __init__(self, canvas, tree=None):
         TreeItemWidget.__init__(self, canvas)
+
         self._tree = Tree(ConstantNode()) if not tree else tree
-        self._widget.insert(0, str(self._tree.node._value))
 
-    def _create_widgets(self):
-        TreeItemWidget._create_widgets(self)
         self._widget = Tkinter.Entry(
             self, 
             width=5, 
             validate="key",
             validatecommand=(self.register(self._text_entered), '%W', '%P')
         )
-        self._widget.pack(fill=Tkinter.X)
+        self._widget.pack(side=Tkinter.RIGHT, fill=Tkinter.X)
+        self._widget.insert(0, str(self._tree.node._value))
 
     def _text_entered(self, widget, value):
         try:
     def has_output(self):
         return True
 
+
 class TreeItemCounterWidget(TreeItemWidget):
     def __init__(self, canvas, tree=None):
         TreeItemWidget.__init__(self, canvas)
+
         self._tree = Tree(CountingNode()) if not tree else tree
 
-    def _create_widgets(self):
-        TreeItemWidget._create_widgets(self)
-        self._widget = Tkinter.Label(self, text='count', background='white', 
-                                     width=5)
+        self._widget = Tkinter.Label(
+            self, text='count', background='white', width=5)
         self._widget.pack(fill=Tkinter.X)
 
     def has_output(self):
         return True
 
+
 class TreeItemOperatorWidget(TreeItemWidget):
     def __init__(self, canvas, tree=None):
         TreeItemWidget.__init__(self, canvas)
+
         self._tree = Tree(OperatorNode()) if not tree else tree
+
         try:
             idx = OperatorNode.allowed_operators.index(
                 self._tree.node._operator)
         except ValueError, msg:
             raise ValueError, 'Invalid operator found: %r\n[%s]' % (
                 self._tree.node._operator, msg)
+
+        self._widget = ttk.Combobox(
+            self, values=OperatorNode.allowed_operators,
+            state='readonly', width=4)
+        self._widget.pack(fill=Tkinter.X)
         self._widget.current(idx)
 
-    def _create_widgets(self):
-        TreeItemWidget._create_widgets(self)
-        self._widget = ttk.Combobox(self, values=OperatorNode.allowed_operators,
-                                state='readonly', width=4)
-        self._widget.pack(fill=Tkinter.X)
         Tkinter.Widget.bind(self._widget, '<<ComboboxSelected>>',
                             self._combobox_selected)