2 Commits 065b57c136 ... 1fb13b71b4

Author SHA1 Message Date
  grindhold 1fb13b71b4 examples: fixed warnings 3 years ago
  grindhold a1e5234340 gtkflow: fix 100% cpu load on unfocus 3 years ago
3 changed files with 21 additions and 8 deletions
  1. 2 0
      examples/colors.py
  2. 6 4
      examples/scrolling_multidock.py
  3. 13 4
      libgtkflow/nodeview.vala

+ 2 - 0
examples/colors.py

@@ -2,6 +2,8 @@
 
 import gi
 gi.require_version('Gtk', '3.0')
+gi.require_version('GFlow', '0.6')
+gi.require_version('GtkFlow', '0.6')
 
 from gi.repository import GLib
 from gi.repository import Gtk

+ 6 - 4
examples/scrolling_multidock.py

@@ -2,6 +2,8 @@
 
 import gi
 gi.require_version('Gtk', '3.0')
+gi.require_version('GFlow', '0.6')
+gi.require_version('GtkFlow', '0.6')
 
 from gi.repository import GLib
 from gi.repository import Gtk
@@ -153,17 +155,17 @@ class Calculator(object):
         self.sw = Gtk.ScrolledWindow()
 
         hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 0)
-        create_numbernode_button = Gtk.Button("Create NumberNode")
+        create_numbernode_button = Gtk.Button.new_with_label("Create NumberNode")
         create_numbernode_button.connect("clicked", self.do_create_numbernode)
         hbox.add(create_numbernode_button)
-        create_addnode_button = Gtk.Button("Create OperationNode")
+        create_addnode_button = Gtk.Button.new_with_label("Create OperationNode")
         create_addnode_button.connect("clicked", self.do_create_addnode)
         hbox.add(create_addnode_button)
-        create_printnode_button = Gtk.Button("Create PrintNode")
+        create_printnode_button = Gtk.Button.new_with_label("Create PrintNode")
         create_printnode_button.connect("clicked", self.do_create_printnode)
         hbox.add(create_printnode_button)
 
-        self.sw.add_with_viewport(self.nv)
+        self.sw.add(self.nv)
         vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
         vbox.pack_start(hbox, False, False, 0)
         vbox.pack_start(self.sw, True, True, 0)

+ 13 - 4
libgtkflow/nodeview.vala

@@ -70,9 +70,7 @@ namespace GtkFlow {
          * Example:  red would be "ff0000"
          */
         public virtual signal string color_calculation(GLib.Value v) {
-            Gtk.StyleContext sc = this.get_style_context();
-            Gdk.RGBA fg = sc.get_color(Gtk.StateFlags.NORMAL);
-            return "%2x%2x%2x".printf(col_f2h(fg.red), col_f2h(fg.green), col_f2h(fg.blue));
+            return this.default_connector_color;
         }
 
         /**
@@ -106,6 +104,12 @@ namespace GtkFlow {
         public bool allow_recursion {get; set; default=false;}
 
         /**
+         * Used to store fg color at iniialization as getting this on the
+         * fly has lead to endless-loop-problems.
+         */
+        private string default_connector_color = "000000";
+
+        /**
          * Creates a new empty {@link NodeView}
          */
         public NodeView() {
@@ -115,6 +119,10 @@ namespace GtkFlow {
             this.motion_notify_event.connect((e)=>{ return this.do_motion_notify_event(e); });
             this.button_press_event.connect((e)=>{ return this.do_button_press_event(e); });
             this.button_release_event.connect((e)=>{ return this.do_button_release_event(e); });
+
+            Gtk.StyleContext sc = this.get_style_context();
+            Gdk.RGBA fg = sc.get_color(Gtk.StateFlags.NORMAL);
+            this.default_connector_color = "%2x%2x%2x".printf(col_f2h(fg.red), col_f2h(fg.green), col_f2h(fg.blue));
         }
 
         private void add_common(Node n) {
@@ -931,7 +939,8 @@ namespace GtkFlow {
                         cr.save();
                         if (source != null && source.val != null) {
                             double r=0, g=0, b=0;
-                            this.hex2col(color_calculation(source.val),out r, out g, out b);
+                            string hexcol = color_calculation(source.val);
+                            this.hex2col(hexcol ,out r, out g, out b);
                             cr.set_source_rgba(r,g,b,1.0);
                         }
                         cr.move_to(source_pos.x, source_pos.y);