Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mvidner
Created October 26, 2017 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvidner/e37e4ce292b50b4e533a414ba315a778 to your computer and use it in GitHub Desktop.
Save mvidner/e37e4ce292b50b4e533a414ba315a778 to your computer and use it in GitHub Desktop.
How to make a CustomWidget disappear but not destroying it?
#We have such a Tab, wich has a TargetsTableWidget(A customWidget has a table and buttons),
#TargetsTableWidget would be listed after class TargetsTab
class TargetsTab < ::CWM::Tab
def initialize
@target_table_widget = TargetsTableWidget.new
self.initial = false
end
def contents
VBox(
HStretch(),
VStretch(),
@target_table_widget
)
end
def label
_("Targets")
end
end
#This is class TargetTableWidget which has a table and buttons, when click the Add button,
#it will show a AddTargetWidget, which is listed following
class TargetsTableWidget < CWM::CustomWidget
include Yast
include Yast::I18n
include Yast::UIShortcuts
include Yast::Logger
def initialize
self.handle_all_events = true
@target_table = TargetTable.new
@add_target_page = AddTargetWidget.new(nil)
@edit_target_page = nil
@target_info = nil
end
def opt
[:notify]
end
def contents
VBox(
#Table(
Id(:targets_table),
@target_table,
HBox(
PushButton(Id(:add), _("Add")),
PushButton(Id(:edit), _("Edit")),
PushButton(Id(:delete), _("Delete"))
)
)
end
def handle(event)
case event["ID"]
when :add
puts "Clicked Add button!"
@add_target_page = AddTargetWidget.new(nil)
contents = VBox(@add_target_page,HStretch(),VStretch())
Yast::Wizard.CreateDialog
CWM.show(contents, caption: _("Add iSCSI Target"))
# @target_info[0] should be nil if target is not created succefully.
@target_info = @add_target_page.get_target_info()
puts "Got target_info:"
p @target_info
if
@target_info[0] != nil
target_name = @target_info[0]
@target_table.add_target_item(target_name)
end
Yast::Wizard.CloseDialog
end
end
#we have such a class which has some input fileds, a table, some buttons, I did not paste all code
class AddTargetWidget < CWM::CustomWidget
def initialize(target_name)
self.handle_all_events = true
end
def opt
[:notify]
end
def handle(event)
puts event
case event["ID"]
when :next
end
end
# The question is:
# I want to close(or make it disapper) the window AddTargetWidget, go back to the previous one.
# But can not destory AddTargetWidget,Because I still need it to run validate function. also self.disable is not working.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment