[Ultrapossum-cvs 214] demo/haviewer 1.6,1.7,haviewer.rb

アーカイブの一覧に戻る

Masato Taruishi taru****@sourc*****
2004年 6月 23日 (水) 03:55:01 JST


===================================================================
RCS file: demo/haviewer/haviewer.rb,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- demo/haviewer/haviewer.rb	2004/06/22 16:09:31	1.6
+++ demo/haviewer/haviewer.rb	2004/06/22 18:55:01	1.7
@@ -17,33 +17,53 @@
   OID_SINCE = OID + ".4.101.1"
 
   Green = "#00FF00"
-  DarkGreen = "#005500"
   Yellow = "#FFFF00"
-  DarkYellow = "#555500"
   Red = "#FF0000"
-  DarkRed = "#550000"
 
-  def HAViewer._icon(color)
-    on  = HAViewer._coloring(Uconv.euctou8("●"), color)
-    off_g = HAViewer._coloring(Uconv.euctou8("●"), DarkGreen )
-    off_y = HAViewer._coloring(Uconv.euctou8("●"), DarkYellow )
-    off_r = HAViewer._coloring(Uconv.euctou8("●"), DarkRed )
-    buf = ""
-    case color
-    when Green
-       buf = on + off_y + off_r
-    when Yellow
-       buf = off_g + on + off_r
-    when Red
-       buf = off_g + off_y + on
-    else
-       buf = off_g + off_y + off_r
+  class Signal
+
+    DarkGreen = "#005500"
+    DarkYellow = "#555500"
+    DarkRed = "#550000"
+    
+    def Signal._coloring(buf, color)
+      return "<span foreground=\"#{color}\"><tt>#{buf}</tt></span>"
+    end
+
+    On = {
+      "G" => Signal._coloring(Uconv.euctou8("●"), Green ),
+      "Y" => Signal._coloring(Uconv.euctou8("●"), Yellow ),
+      "R" => Signal._coloring(Uconv.euctou8("●"), Red )
+    }
+    Off = {
+      "G" => Signal._coloring(Uconv.euctou8("●"), DarkGreen ),
+      "Y" => Signal._coloring(Uconv.euctou8("●"), DarkYellow ),
+      "R" => Signal._coloring(Uconv.euctou8("●"), DarkRed )
+    }
+
+    Buf = {
+         Green => On["G"] + Off["Y"] + Off["R"],
+         Yellow => Off["G"] + On["Y"] + Off["R"],
+         Red => Off["G"] + Off["Y"] + Off["R"],
+         "" => Off["G"] + Off["Y"] + Off["R"]
+    }
+
+    def initialize(color="")
+      @color = color
+    end
+
+    def to_s
+      return "<span background=\"#000000\">(#{Buf[@color]})</span>"
+    end
+
+    def on(color="")
+      @color = color
+    end
+
+    def off
+      on
     end
-    return "<span background=\"#000000\">(#{buf})</span>"
-  end
 
-  def HAViewer._coloring(buf, color)
-    return "<span foreground=\"#{color}\"><tt>#{buf}</tt></span>"
   end
 
   class Host
@@ -53,8 +73,8 @@
       @viewer = viewer
       @list = viewer.list
       @row =****@list*****
-      @color = ""
       @status = ""
+      @sign = Signal.new
       @type = type
       update
       @t = Thread.new {
@@ -68,7 +88,7 @@
     end
 
     def update
-      @list.set_value(@row, 0, HAViewer._icon(@color)) 
+      @list.set_value(@row, 0, @sign.to_s)
       @list.set_value(@row, 1, @host)
       @list.set_value(@row, 2, @type)
       @list.set_value(@row, 3, @status)
@@ -92,24 +112,26 @@
 	end
       end
 
-      @color = ""
+      c = ""
       case @status
       when "DEAD"
-        @color = Red
+        c = Red
       when "STOP"
-        @color = Red
+        c = Red
       when "ACTIVE"
-        @color = Green
+        c = Green
       when "STANDBY"
-        @color = Green
+        c = Green
       when "RUN"
-        @color = Green
+        c = Green
       end
+      @sign.on(c)
 
     end
 
     attr_reader :row, :host
     attr_accessor :type, :status, :pid, :since
+
   end
 
 
@@ -125,6 +147,9 @@
     end
     @glade["treeview1"].set_model(@list)
 
+    @master_icon = Signal.new
+    @slave_icon = Signal.new
+
     update
 
     h = Host.new(`ultrapossum-config get MASTER`.gsub!(/MASTER="(.+)"\n/, '\1'), "master", self)
@@ -170,8 +195,10 @@
 	end
       end
     end
-    @glade["master_icon"].set_markup(HAViewer._icon(master_icon))
-    @glade["slave_icon"].set_markup(HAViewer._icon(slave_icon))
+    @master_icon.on(master_icon)
+    @slave_icon.on(slave_icon)
+    @glade["master_icon"].set_markup(@master_icon.to_s)
+    @glade["slave_icon"].set_markup(@slave_icon.to_s)
 
   end
 



Ultrapossum-cvs メーリングリストの案内
アーカイブの一覧に戻る