File
l_object_themes.rb
Home
Path: locana/l_object_themes.rb
Modified: Fri Oct 31 18:20:02 GMT-7:00 2003

l_object_themes.rb - adds methods to the Lobject class to support styles and themes

Author: Michael Davis, mdavis@locana.org

Copyright: (C) 2000, 2001, 2002 Seva Inc. and Seva Software - www.sevasoftware.com

Home page: www.locana.org

License: Same as Ruby

Status:

To do:

History:

This module adds theme and style support to Locana via the Lobject class. A theme is a collection of styles. It is a Hash with the style name as the key and the style is a Hash of attribute/value pairs. You can load a specific theme using the -r theme.rth at runtime. If the -r is not used and a module exists with your applet name suffixed with .rth (your_applet_name.rth, for example), then your_applet_name.rth is automatically loaded.

A style is a collection of attributes. It is a Hash with the type of an object as the key and a Hash of attributes for that type of object as the value.

Here is an example:

    mytheme = {
       :default = {         # applies to all object before the more specific style is used
          :object = {:fg=>:black, :bg=>:white}
          :button = {:fg=>:black, :bg=>:gray}
       }
       :mystyle = {         # a named style, you can use :style=>:mystyle when creating your objects to reference this style
          :object = {:padx=>5, :pady=>5, :fg=>:darkblue, :bg=>:lightblue}
          :button = {:fg=>:darkblue, :bg=>:lightblue2}
       }
    }
    Locana::add_theme(mytheme)

How this works (in order of precedence, lowest to highest):

  1) gather attributes from parent objects which also uses this technique
  2) gather attributes from :object in the :default style
  3) gather attributes from the :default style where the type of the object (:button, :group, :textbox, etc) matches
  4) if any parent object supplies a :style attribute, gather attributes from :object in the parent's :style
  5) if any parent object supplies a :style attribute, gather attributes from matching object in the parent's :style
  6) if there is a :style attribute for the object, gather attributes from :object in the :style
  7) if there is a :style attribute for the object, gather attributes from matching object in the :style
  Attributes in item 1 are replaced with attributes from item 2 which are replaced with attributes from item 3, etc.

If you add multiple themes, each theme is added to the base theme. The styles in later themes will replace any exiting styles. This allows you create themes using the styles you want and then override one or more styles by adding or using a second theme.

Themes can be stored in separate .rth files such as mytheme.rth. You can change themes at runtime by using ruby -r mytheme.rth your_applet.rb

There are several global type settings that you can define in your Ruby code and/or in a theme to specify the type of behavior you desire from Locana. If you set a global value using code (let’s say you create a menu allowing the user select one of these values), the global value is stored in the Locana config file and retrieved the next time the user opens the applet. You can use applets/config_editor.rb to see and delete these values from the Locana config file. Here are the currently supported global settings:

 :gDefaultFont = [:font_name, size, attributes] - this allows you the specify a base font for all objects in Locana that don't use the font attribute.  Here are some examples:
    :gDefaultFont = [:times, 16, :italic]
    :gDefaultFont = [:courier, 16, [:italic, :bold]]
 FYI: You may have to remove the config file: rm ~/.locana/windows.cf for this to work properly, i.e. the windows are not large enough.  This removes the file that stores information about the sizes of windows.
 :gAutoSavePos = true/false
    False means locana will not automatically save the position of windows.
    True means the position of all windows are automatically saved, this can be overridden for each object using the :auto_save attribute.  The default is true.
Methods

check_for_and_load_a_theme,
Classes and Modules

Module Locana
Class Lobject

Public Instance methods
check_for_and_load_a_theme() src

This checks for a theme in the -r parameter on the command line and then looks for applet_name.rth If a theme is found, this loads it.


Seva Software


Thank you for taking the time to visit this web page. I trust you found the information contained in this page useful.
Please email any questions, concerns, or issues with this web site to webmaster@sevasoftware.com.
Please remember Seva Software when your company would benefit from an experienced database architect and software engineer.

http://www.arunadb.org http://www.locana.org http://www.ruby-lang.org http://www.coolwell.org http://www.sevasoftware.com