Skip to content

Commit

Permalink
CWM: Added DateField and TimeField widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Jan 16, 2019
1 parent 15d6751 commit 910beb2
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 1 deletion.
70 changes: 70 additions & 0 deletions library/cwm/examples/date_time.rb
@@ -0,0 +1,70 @@
# Simple example to demonstrate object API for CWM

require_relative "example_helper"

require "cwm"
require "cwm/popup"

Yast.import "CWM"

class Name < CWM::InputField
def initialize
textdomain "example"
end

def label
_("Name")
end
end

class EventDate < CWM::DateField
def initialize
textdomain "example"
end

def init
self.value = Time.now.strftime("%Y-%m-%d")
end

def label
_("Event date")
end
end

class EventTime < CWM::TimeField
def initialize
textdomain "example"
end

def init
self.value = Time.now.strftime("%H:%M:%S")
end

def label
_("Event time")
end
end


class Event < ::CWM::Popup
def initialize
textdomain "example"
end

def contents
VBox(
Name.new,
HBox(
EventDate.new,
HSpacing(1),
EventTime.new
)
)
end

def title
_("Event Example")
end
end

Event.new.run
6 changes: 5 additions & 1 deletion library/cwm/src/Makefile.am
Expand Up @@ -33,6 +33,10 @@ ycwm_DATA = \
ylibdir = @ylibdir@
ylib_DATA = lib/cwm.rb

EXTRA_DIST = $(module_DATA) $(ylib_DATA) $(ycwm_DATA)
ylibclients_DATA = \
lib/clients/test_example.rb
lib/clients/datetime_example.rb

EXTRA_DIST = $(module_DATA) $(ylib_DATA) $(ycwm_DATA) $(ylibclients_DATA)

include $(top_srcdir)/Makefile.am.common
1 change: 1 addition & 0 deletions library/cwm/src/clients/test_example.rb
@@ -0,0 +1 @@
require_relative "../../examples/date_time.rb"
14 changes: 14 additions & 0 deletions library/cwm/src/lib/cwm/common_widgets.rb
Expand Up @@ -366,4 +366,18 @@ class RichText < AbstractWidget

include ValueBasedWidget
end

class TimeField < AbstractWidget
self.widget_type = :time_field

include ValueBasedWidget
abstract_method :label
end

class DateField < AbstractWidget
self.widget_type = :date_field

include ValueBasedWidget
abstract_method :label
end
end
4 changes: 4 additions & 0 deletions library/cwm/src/modules/CWM.rb
Expand Up @@ -616,6 +616,10 @@ def prepareWidget(widget_descr)
Ops.set(w, "widget", MultiLineEdit(id_term, opt_term, label))
elsif widget == :richtext
Ops.set(w, "widget", RichText(id_term, opt_term, ""))
elsif widget == :date_field
Ops.set(w, "widget", DateField(id_term, opt_term, label))
elsif widget == :time_field
Ops.set(w, "widget", TimeField(id_term, opt_term, label))
end
end
Ops.set(w, "custom_widget", nil) # not needed any more
Expand Down

0 comments on commit 910beb2

Please sign in to comment.