Skip to content

Commit

Permalink
add helper to recognize own event
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Jan 13, 2016
1 parent 4e4283e commit 80ae26a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 4 additions & 10 deletions library/cwm/examples/object_api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Simple example to demonstrate object API for CWM

require_relative "example_helper"

require "cwm/widget"
Expand All @@ -21,14 +23,6 @@ def label
def store(_widget, _event)
@result = value
end

def handle(widget, _event)
return if widget != widget_id

Yast::Builtins.y2milestone("int handle called")

nil
end
end

class GenerateButton < CWM::PushButtonWidget
Expand All @@ -41,8 +35,8 @@ def label
_("Generate Lucky Number")
end

def handle(widget, _event)
return if widget != widget_id
def handle(widget, event)
return unless my_event?(widget, event)

Yast::Builtins.y2milestone("handle called")
@lucky_number.value = rand(1000)
Expand Down
8 changes: 5 additions & 3 deletions library/cwm/examples/object_api_enabling.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This example is here to demonstrate how can be widgets easily enabled/disabled from other widgets

require_relative "example_helper"

require "cwm/widget"
Expand All @@ -23,7 +25,7 @@ def store(_widget, _event)
end

def handle(widget, event)
return if widget != event["ID"]
return unless my_event?(widget, event)

Yast::Builtins.y2milestone("int handle called")

Expand All @@ -47,7 +49,7 @@ def init(_widget)
end

def handle(widget, event)
return if widget != event["ID"]
return unless my_event?(widget, event)

Yast::Builtins.y2milestone("enable handle called")
@lucky_number.enable
Expand All @@ -73,7 +75,7 @@ def label
end

def handle(widget, event)
return if widget != event["ID"]
return unless my_event?(widget, event)

Yast::Builtins.y2milestone("disable handle called")
@lucky_number.disable
Expand Down
5 changes: 5 additions & 0 deletions library/cwm/src/lib/cwm/widget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def disable

protected

# helper to check if event is invoked by this widget
def my_event?(widget, event)
return widget == event["ID"]
end

# shortcut from Yast namespace to avoid including whole namespace
# TODO: kill converts in CWM module, to avoid this workaround for funrefs
def fun_ref(*args)
Expand Down

0 comments on commit 80ae26a

Please sign in to comment.