class RSence::Plugins::GUIPlugin__

The CUIPlugin__ is actually available as GUIPlugin from plugin bundle code using the {RSence::Plugins::GUIPlugin} class mimic method.

GUIPlugin extends {Plugin__ Plugin} by automatically initializing an {GUIParser} instance as +@gui+.

Read {Plugin__ Plugin} for usage of the API, {file:ExampleGuiPlugin Example GUIPlugin} for an example of use and {file:PluginBundles Plugin Bundles} for overall information about plugin bundle usage.

User Interface -related hooks:

Public Class Methods

bundle_type() click to toggle source

@private Class type identifier for the PluginManager. @return [:GUIPlugin]

# File lib/rsence/plugins/gui_plugin.rb, line 26
def self.bundle_type; :GUIPlugin; end

Public Instance Methods

close() click to toggle source

@private calls uninstall_client_pkgs, if a ‘client_pkgs.yaml’ file was loaded

Calls superclass method
# File lib/rsence/plugins/gui_plugin.rb, line 218
def close
  super
  uninstall_client_pkgs if @client_pkgs
end
gui_params( msg ) click to toggle source

Extend this method to return custom params to {GUIParser#init}.

Called from {#init_ui}.

By default assigns the session values as :values to use for +bind: :values.my_value_name+ in the YAML GUI file for client-side value bindings.

@param [Message] msg The message is supplied by the system.

@return [Hash] Parameters for {GUIParser#init @gui#init}

@example To provide extra parameters, do this:

def gui_params( msg )
  params = super
  params[:extra] = {
    :foo => "Foo",       # use in the GUITree as :extra.foo
    :num => 124334,      # use in the GUITree as :extra.num
    :bar => {
      :barbar => "Bar"   # use in the GUITree as :extra.bar.barbar
    }
    :arr => [1,2,4,8]    # use in the GUITree as :extra.arr
  }
  params[:more] = "More" # use in the GUITree as :more
  return params
end
# File lib/rsence/plugins/gui_plugin.rb, line 73
def gui_params( msg )
  return unless @gui
  params = super
  params[:values] = @gui.values( get_ses( msg ) )
  params
end
init() click to toggle source

In addition to {Plugin__#init Plugin#init}, also automatically initializes a {GUIParser} instance as +@gui+

@return [nil]

Calls superclass method RSence::Plugins::Localization#init
# File lib/rsence/plugins/gui_plugin.rb, line 31
def init
  super
  yaml_src = false
  [ "#{@name}.yaml", 'gui.yaml',
    "gui/#{@name}.yaml", 'gui/main.yaml'
  ].each do |yaml_name|
    yaml_src = file_read( yaml_name )
    break if yaml_src
  end
  if yaml_src
    @gui = GUIParser.new( self, yaml_src, @name )
  else
    @gui = nil
  end
  @client_pkgs = false
end
init_ui( msg ) click to toggle source

Automatically inits the UI using {GUIParser#init}

@param [Message] msg The message is supplied by the system.

@return [nil]

# File lib/rsence/plugins/gui_plugin.rb, line 234
def init_ui( msg )
  return unless @gui
  @gui.init( msg, gui_params( msg ) )
end
install_client_pkgs() click to toggle source

@private Method that implements client_pkgs.yaml loading

# File lib/rsence/plugins/gui_plugin.rb, line 81
def install_client_pkgs
  if @client_pkgs
    warn "install_client_pkgs: called with @client_pkgs defined (#{@client_pkgs.inspect}); returning" if RSence.args[:debug]
    return
  end
  client_pkgs = yaml_read( 'client_pkgs.yaml' )
  if client_pkgs

    sleep 0.1 until client_pkg.ready?
    
    if client_pkgs.has_key?('src_dir')
      src_dirs = [ client_pkgs['src_dir'] ]
    elsif client_pkgs.has_key?('src_dirs')
      src_dirs = client_pkgs['src_dirs']
    elsif client_pkgs.has_key?(:src_dirs)
      src_dirs = client_pkgs[:src_dirs]
    else
      src_dirs = false
    end

    @client_pkgs = {}
    if src_dirs
      src_dirs.each do |src_dir|
        if src_dir.start_with?('./')
          src_dir = bundle_path( src_dir[2..-1] )
        end
        client_pkg.add_src_dir( src_dir )
      end
      @client_pkgs[:src_dirs] = src_dirs
    end
    
    if client_pkgs.has_key?('packages')
      packages = client_pkgs['packages']
    elsif client_pkgs.has_key?(:packages)
      packages = client_pkgs[:packages]
    else
      packages = false
    end

    if packages
      client_pkg.add_packages( packages )
      @client_pkgs[:packages] = packages
    end

    
    if client_pkgs.has_key?('compounds')
      compounds = client_pkgs['compounds']
    elsif client_pkgs.has_key?('compound_packages')
      compounds = client_pkgs['compound_packages']
    elsif client_pkgs.has_key?(:compound_packages)
      compounds = client_pkgs[:compound_packages]
    else
      compounds = false
    end

    if compounds
      client_pkg.add_compounds( compounds )
      @client_pkgs[:compound_packages] = compounds
    end

    
    if client_pkgs.has_key?('themes')
      theme_names = client_pkgs['themes']
    elsif client_pkgs.has_key?('theme_names')
      theme_names = client_pkgs['theme_names']
    elsif client_pkgs.has_key?(:theme_names)
      theme_names = client_pkgs[:theme_names]
    else
      theme_names = false
    end

    if theme_names
      client_pkg.add_themes( theme_names )
      @client_pkgs[:theme_names] = theme_names
    end


    if client_pkgs.has_key?('gfx_formats')
      gfx_formats = client_pkgs['gfx_formats']
    elsif client_pkgs.has_key?(:gfx_formats)
      gfx_formats = client_pkgs[:gfx_formats]
    else
      gfx_formats = false
    end

    if gfx_formats
      client_pkg.add_gfx_formats( gfx_formats )
      @client_pkgs[:gfx_formats] = gfx_formats
    end

    if client_pkgs.has_key?('reserved_names')
      reserved_names = client_pkgs['reserved_names']
    elsif client_pkgs.has_key?(:reserved_names)
      reserved_names = client_pkgs[:reserved_names]
    else
      reserved_names = false
    end

    if reserved_names
      client_pkg.add_reserved_names( reserved_names )
      @client_pkgs[:reserved_names] = reserved_names
    end

    client_pkg.rebuild_client
    
  end
end
kill_ui( msg ) click to toggle source

@private Automatically kills the UI using {GUIParser#kill}

# File lib/rsence/plugins/gui_plugin.rb, line 240
def kill_ui( msg )
  return unless @gui
  @gui.kill( msg )
end
open() click to toggle source

@private calls install_client_pkgs, if a ‘client_pkgs.yaml’ file is found

Calls superclass method
# File lib/rsence/plugins/gui_plugin.rb, line 212
def open
  super
  install_client_pkgs if File.exist? bundle_path( 'client_pkgs.yaml' )
end
struct_ui( msg ) click to toggle source

@private Returns structured, processed gui tree to the caller.

# File lib/rsence/plugins/gui_plugin.rb, line 224
def struct_ui( msg )
  return {} unless @gui
  @gui.struct( msg, gui_params( msg ) )
end
uninstall_client_pkgs() click to toggle source

@private Method that implements client_pkgs.yaml unloading

# File lib/rsence/plugins/gui_plugin.rb, line 190
def uninstall_client_pkgs
  if not @client_pkgs
    warn "uninstall_client_pkgs: called without @client_pkgs defined"
  else
    if @client_pkgs.has_key?(:src_dirs)
      @client_pkgs[:src_dirs].each do |src_dir|
        src_dir = bundle_path( src_dir[2..-1] ) if src_dir.start_with?('./')
        client_pkg.del_src_dir( src_dir )
      end
    end
    sleep 0.1 until client_pkg.ready?
    client_pkg.del_reserved_names( @client_pkgs[:reserved_names] ) if @client_pkgs.has_key?(:reserved_names)
    client_pkg.del_gfx_formats(    @client_pkgs[:gfx_formats   ] ) if @client_pkgs.has_key?(:gfx_formats   )
    client_pkg.del_themes(         @client_pkgs[:theme_names   ] ) if @client_pkgs.has_key?(:theme_names   )
    client_pkg.del_compounds(      @client_pkgs[:compound_packages] ) if @client_pkgs.has_key?(:compound_packages)
    client_pkg.del_packages(       @client_pkgs[:packages].keys  ) if @client_pkgs.has_key?(:packages      )
    client_pkg.rebuild_client
  end
  @client_pkgs = false
end