changeset 1456:894a4bf35fe6

Start implement FSM editor window
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 16 Apr 2011 19:41:12 +0800
parents 8ea0d32a1864
children 416a18409603
files pyink/FSM_window.glade pyink/FSM_window.py pyink/comp_dock.py pyink/component_dock.glade
diffstat 4 files changed, 423 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pyink/FSM_window.glade	Sat Apr 16 19:41:12 2011 +0800
@@ -0,0 +1,293 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkWindow" id="FSM_main_win">
+    <property name="width_request">500</property>
+    <property name="height_request">400</property>
+    <property name="title" translatable="yes">FSM</property>
+    <property name="modal">True</property>
+    <signal name="destroy_event" handler="on_FSM_main_win_destroy_event"/>
+    <signal name="delete_event" handler="on_FSM_main_win_delete_event"/>
+    <child>
+      <object class="GtkVBox" id="vbox1">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkMenuBar" id="menubar1">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkMenuItem" id="menuitem1">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_File</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu1">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="close_window">
+                        <property name="label">gtk-close</property>
+                        <property name="visible">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                        <signal name="activate" handler="on_close_window_activate"/>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem2">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Edit</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu2">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem6">
+                        <property name="label">gtk-cut</property>
+                        <property name="visible">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem7">
+                        <property name="label">gtk-copy</property>
+                        <property name="visible">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem8">
+                        <property name="label">gtk-paste</property>
+                        <property name="visible">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem9">
+                        <property name="label">gtk-delete</property>
+                        <property name="visible">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem3">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_View</property>
+                <property name="use_underline">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkMenuItem" id="menuitem4">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">_Help</property>
+                <property name="use_underline">True</property>
+                <child type="submenu">
+                  <object class="GtkMenu" id="menu3">
+                    <property name="visible">True</property>
+                    <child>
+                      <object class="GtkImageMenuItem" id="imagemenuitem10">
+                        <property name="label">gtk-about</property>
+                        <property name="visible">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="use_stock">True</property>
+                      </object>
+                    </child>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkHandleBox" id="handlebox1">
+            <property name="visible">True</property>
+            <child>
+              <object class="GtkToolbar" id="toolbar1">
+                <property name="visible">True</property>
+                <property name="toolbar_style">icons</property>
+                <property name="icon_size">1</property>
+                <property name="icon_size_set">True</property>
+                <child>
+                  <object class="GtkToggleToolButton" id="add_state">
+                    <property name="visible">True</property>
+                    <property name="tooltip_text" translatable="yes">Add state</property>
+                    <property name="label" translatable="yes">Add State</property>
+                    <property name="use_underline">True</property>
+                    <property name="stock_id">gtk-add</property>
+                    <signal name="toggled" handler="on_add_state_toggled"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkToggleToolButton" id="move_state">
+                    <property name="visible">True</property>
+                    <property name="tooltip_text" translatable="yes">Move or select a state</property>
+                    <property name="label" translatable="yes">select &amp; move</property>
+                    <property name="use_underline">True</property>
+                    <property name="icon_name">widget-gtk-alignment</property>
+                    <signal name="toggled" handler="on_move_state_toggled"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkSeparatorToolItem" id="toolbutton1">
+                    <property name="visible">True</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkToolButton" id="zoom_in">
+                    <property name="visible">True</property>
+                    <property name="tooltip_text" translatable="yes">Zoom-in</property>
+                    <property name="label" translatable="yes">Zoom-in</property>
+                    <property name="use_underline">True</property>
+                    <property name="stock_id">gtk-zoom-in</property>
+                    <signal name="clicked" handler="on_zoom_in_clicked"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkToolButton" id="zoom_out">
+                    <property name="visible">True</property>
+                    <property name="tooltip_text" translatable="yes">Zoom-out</property>
+                    <property name="label" translatable="yes">Zoom-out</property>
+                    <property name="use_underline">True</property>
+                    <property name="stock_id">gtk-zoom-out</property>
+                    <signal name="clicked" handler="on_zoom_out_clicked"/>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="homogeneous">True</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="svg_scroll">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="hscrollbar_policy">automatic</property>
+            <property name="vscrollbar_policy">automatic</property>
+            <child>
+              <object class="GtkViewport" id="svg_box">
+                <property name="visible">True</property>
+                <property name="resize_mode">queue</property>
+                <child>
+                  <placeholder/>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkStatusbar" id="statusbar1">
+            <property name="visible">True</property>
+            <property name="spacing">5</property>
+            <child>
+              <object class="GtkHBox" id="hbox1">
+                <property name="visible">True</property>
+                <child>
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="xalign">0.10000000149011612</property>
+                    <property name="label" translatable="yes">Compnent:</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="comp_name">
+                    <property name="visible">True</property>
+                    <property name="xpad">5</property>
+                    <property name="label" translatable="yes">component1</property>
+                  </object>
+                  <packing>
+                    <property name="expand">False</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="position">3</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+  <object class="GtkMenu" id="fsm_context">
+    <property name="visible">True</property>
+    <child>
+      <object class="GtkMenuItem" id="remove_state">
+        <property name="visible">True</property>
+        <property name="tooltip_text" translatable="yes">Remove selected state or transition.</property>
+        <property name="label" translatable="yes">Remove</property>
+        <property name="use_underline">True</property>
+        <signal name="activate" handler="on_remove_state_activate"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="rename_state">
+        <property name="visible">True</property>
+        <property name="tooltip_text" translatable="yes">Change state name</property>
+        <property name="label" translatable="yes">Rename</property>
+        <property name="use_underline">True</property>
+        <signal name="activate" handler="on_rename_state_activate"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuItem" id="start_state">
+        <property name="visible">True</property>
+        <property name="tooltip_text" translatable="yes">Make the selected state as start state.</property>
+        <property name="label" translatable="yes">Start State</property>
+        <property name="use_underline">True</property>
+        <signal name="activate" handler="on_start_state_activate"/>
+      </object>
+    </child>
+  </object>
+</interface>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pyink/FSM_window.py	Sat Apr 16 19:41:12 2011 +0800
@@ -0,0 +1,90 @@
+import gtk
+import os
+
+class FSM_window_base(object):
+    def __init__(self):
+        super(FSM_window_base, self).__init__()
+        
+        dirname = os.path.dirname(__file__)
+        fname = os.path.join(dirname, 'FSM_window.glade')
+
+        builder = gtk.Builder()
+        builder.add_from_file(fname)
+
+        main_win = builder.get_object("FSM_main_win")
+        view_box = builder.get_object("view_box")
+
+        builder.connect_signals(self)
+        
+        self._builder = builder
+        self._main_win = main_win
+        self._view_box = view_box
+        pass
+
+    def show(self):
+        self._main_win.show()
+        pass
+
+    def hide(self):
+        self._main_win.hide()
+        pass
+    
+    def on_start_state_activate(self, *args):
+        pass
+    
+    def on_rename_state_activate(self, *args):
+        pass
+    
+    def on_remove_state_activate(self, *args):
+        pass
+    
+    def on_zoom_out_clicked(self, *args):
+        pass
+    
+    def on_zoom_in_clicked(self, *args):
+        pass
+    
+    def on_move_state_toggled(self, *args):
+        pass
+    
+    def on_add_state_toggled(self, *args):
+        pass
+    
+    def on_close_window_activate(self, *args):
+        pass
+
+    def on_FSM_main_win_destroy_event(self, *args):
+        pass
+    pass
+
+class FSM_window(FSM_window_base):
+    def __init__(self, close_cb, destroy_cb):
+        super(FSM_window, self).__init__()
+
+        self._close_cb = close_cb
+        self._destroy_cb = destroy_cb
+        pass
+
+    def set_svg_view(self, view):
+        self._view_box.add(view)
+        pass
+
+    def on_close_window_activate(self, *args):
+        self._close_cb()
+        pass
+    
+    def on_FSM_main_win_destroy_event(self, *args):
+        self._destroy_cb()
+        pass
+    
+    def on_FSM_main_win_delete_event(self, *args):
+        self._destroy_cb()
+        pass
+    pass
+
+if __name__ == '__main__':
+    win = FSM_window()
+    win._main_win.connect('destroy', gtk.main_quit)
+    win.show()
+    gtk.main()
+    pass
--- a/pyink/comp_dock.py	Thu Apr 14 15:24:37 2011 +0800
+++ b/pyink/comp_dock.py	Sat Apr 16 19:41:12 2011 +0800
@@ -2,6 +2,7 @@
 import os
 import data_monitor
 import pybInkscape
+import FSM_window
 
 
 ## \brief User interface for management components and their timelines.
@@ -159,6 +160,7 @@
         super(comp_dock_ui, self).__init__()
         
         self._locker = domview_ui
+        self._fsm_editor_win = None
         pass
 
     def _drop_undo(self):
@@ -274,6 +276,26 @@
         timeline_name = self._current_timeline()
         domview_ui.switch_timeline(timeline_name)
         pass
+
+    def _show_FSM_editor(self):
+        if not self._fsm_editor_win:
+            def FSM_editor_close():
+                self._fsm_editor_win.hide()
+                pass
+            def FSM_editor_destroy():
+                self._fsm_editor_win = None
+                pass
+            fsm_win = FSM_window.FSM_window(FSM_editor_close,
+                                            FSM_editor_destroy)
+            self._fsm_editor_win = fsm_win
+        else:
+            fsm_win = self._fsm_editor_win
+            pass
+        fsm_win.show()
+        pass
+
+    def _show_FSM_for_comp(self, comp_name):
+        pass
     
     def on_add_comp_clicked(self, *args):
         self._add_component()
@@ -299,7 +321,7 @@
         self._switch_component()
         self._drop_undo()
         pass
-    
+
     ## \brief Handle of changing component name.
     #
     def on_cellrenderer_comp_edited(self, renderer, path,
@@ -344,6 +366,14 @@
         self._switch_component()
         self._drop_undo()
         pass
+
+    ## \brief User clicks "State Machine" on context menu for a component.
+    #
+    def on_edit_FSM_activate(self, *args):
+        self._show_FSM_editor()
+        comp_name = self._current_component()
+        self._show_FSM_for_comp(comp_name)
+        pass
     
     def on_add_timeline_clicked(self, *args):
         self._add_timeline()
--- a/pyink/component_dock.glade	Thu Apr 14 15:24:37 2011 +0800
+++ b/pyink/component_dock.glade	Sat Apr 16 19:41:12 2011 +0800
@@ -229,6 +229,15 @@
         <signal name="activate" handler="on_switch_component_activate"/>
       </object>
     </child>
+    <child>
+      <object class="GtkMenuItem" id="edit_FSM">
+        <property name="visible">True</property>
+        <property name="tooltip_text" translatable="yes">Edit FSM of the component.</property>
+        <property name="label" translatable="yes">State Machine</property>
+        <property name="use_underline">True</property>
+        <signal name="activate" handler="on_edit_FSM_activate"/>
+      </object>
+    </child>
   </object>
   <object class="GtkMenu" id="timelines_menu">
     <property name="visible">True</property>