class Rabbit::Theme::Applier

Constants

NORMALIZED_HEIGHT
NORMALIZED_WIDTH

Those constants are meaningless. :p

Public Class Methods

new(theme, &callback) click to toggle source
Calls superclass method Rabbit::Theme::Searcher.new
# File lib/rabbit/theme/applier.rb, line 241
def initialize(theme, &callback)
  super()
  @theme = theme
  @callback = callback
  dirty_count_clean
  @match_cache = {}
  @current_target = nil
  class << slides
    def elements
      self
    end
  end
end

Public Instance Methods

[](name) click to toggle source
# File lib/rabbit/theme/applier.rb, line 309
def [](name)
  instance_variable_get("@#{name}")
end
apply_theme(name) click to toggle source
# File lib/rabbit/theme/applier.rb, line 255
def apply_theme(name)
  entry = find_theme(name)
  src = File.open(entry.theme_file, "r:utf-8") do |f|
    f.read
  end
  in_theme(entry) do
    instance_eval(normalize_source(src), entry.theme_file)
  end
end
make_container(ary) click to toggle source
# File lib/rabbit/theme/applier.rb, line 265
def make_container(ary)
  ElementContainer.new(self, ary)
end
normalized_height() click to toggle source
# File lib/rabbit/theme/applier.rb, line 281
def normalized_height
  NORMALIZED_HEIGHT / Canvas::INTERNAL_DPI
end
normalized_size(s) click to toggle source
# File lib/rabbit/theme/applier.rb, line 285
def normalized_size(s)
  ((s / canvas.width.to_f) * normalized_width).ceil
end
normalized_width() click to toggle source
# File lib/rabbit/theme/applier.rb, line 277
def normalized_width
  NORMALIZED_WIDTH / Canvas::INTERNAL_DPI
end
normalized_x(sx) click to toggle source
# File lib/rabbit/theme/applier.rb, line 289
def normalized_x(sx)
  ((sx / canvas.width.to_f) * normalized_width).ceil
end
normalized_y(sy) click to toggle source
# File lib/rabbit/theme/applier.rb, line 293
def normalized_y(sy)
  ((sy / canvas.height.to_f) * normalized_height).ceil
end
screen_size(n) click to toggle source
# File lib/rabbit/theme/applier.rb, line 297
def screen_size(n)
  ((canvas.width * n) / normalized_width).ceil
end
screen_x(nx) click to toggle source
# File lib/rabbit/theme/applier.rb, line 301
def screen_x(nx)
  ((canvas.width * nx) / normalized_width).ceil
end
screen_y(ny) click to toggle source
# File lib/rabbit/theme/applier.rb, line 305
def screen_y(ny)
  ((canvas.height * ny) / normalized_height).ceil
end
to_container(obj) click to toggle source
# File lib/rabbit/theme/applier.rb, line 269
def to_container(obj)
  if obj.is_a?(ElementContainer)
    obj
  else
    make_container([obj])
  end
end

Private Instance Methods

_match(current, *paths) click to toggle source
# File lib/rabbit/theme/applier.rb, line 454
def _match(current, *paths)
  last_path_index = paths.size - 1
  paths.each_with_index do |path, i|
    current = _match_with_cache(current, path, i == last_path_index) do
      current = ignore_wait_block(current) unless i == last_path_index
      if path.nil?
        slides
      elsif path == "**"
        all_sub_elements(current)
      else
        if path == "*"
          working = current # all OK
        else
          working = current.find_all do |element|
            path === element
          end
        end

        if i != last_path_index
          working.inject([]) do |result, elem|
            if elem.respond_to?(:elements)
              result + elem.elements
            else
              result << elem
            end
          end
        else
          working
        end

      end
    end
  end
  current
end
_match_with_cache(current, path, last_path) { || ... } click to toggle source
# File lib/rabbit/theme/applier.rb, line 490
def _match_with_cache(current, path, last_path)
  key = [current, path, last_path]
  @match_cache[key] ||= yield
  @match_cache[key]
end
activate(name, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 399
def activate(name, &block)
  canvas.activate(name, &block)
end
add_gesture_action(sequence, action=Proc.new) click to toggle source
# File lib/rabbit/theme/applier.rb, line 395
def add_gesture_action(sequence, action=Proc.new)
  canvas.add_gesture_action(sequence, action)
end
all_sub_elements(element) click to toggle source
# File lib/rabbit/theme/applier.rb, line 496
def all_sub_elements(element)
  if element.respond_to?(:inject)
    if element.respond_to?(:elements)
      elems = element.elements
    else
      elems = element
    end
    elems.inject([]) do |result, elem|
      (result << elem) + all_sub_elements(elem)
    end
  else
    []
  end
end
base_directory() click to toggle source
# File lib/rabbit/theme/applier.rb, line 635
def base_directory
  canvas.full_path(".")
end
canvas() click to toggle source
# File lib/rabbit/theme/applier.rb, line 342
def canvas
  @theme.canvas
end
connect_key(keyval, modifier=nil, flags=nil, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 599
def connect_key(keyval, modifier=nil, flags=nil, &block)
  modifier ||= Gdk::ModifierType.new
  flags ||= Gtk::AccelFlags::VISIBLE
  canvas.connect_key(keyval, modifier, flags, &block)
end
deprecated_method(current, deprecated) click to toggle source
# File lib/rabbit/theme/applier.rb, line 609
def deprecated_method(current, deprecated)
  format = _("%s is deprecated. Use %s instead.")
  message = format % [deprecated, current]
  warning(message)
end
dirtied() click to toggle source
Calls superclass method Rabbit::DirtyCount#dirtied
# File lib/rabbit/theme/applier.rb, line 594
def dirtied
  @callback.call if @callback
  super
end
disconnect_key(keyval, modifier=nil) click to toggle source
# File lib/rabbit/theme/applier.rb, line 605
def disconnect_key(keyval, modifier=nil)
  canvas.disconnect_key(keyval, modifier)
end
display?() click to toggle source
# File lib/rabbit/theme/applier.rb, line 354
def display?
  canvas.display?
end
draw_frame(*args, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 547
def draw_frame(*args, &block)
  split_targets(args) do |targets, args|
    targets.draw_frame(*args, &block)
  end
end
draw_image_mark(*args, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 533
def draw_image_mark(*args, &block)
  split_targets(args) do |targets, args|
    image_name, *args = args
    image_name = find_file(image_name)
    targets.draw_image_mark(image_name, *args, &block)
  end
end
draw_mark(*args, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 527
def draw_mark(*args, &block)
  split_targets(args) do |targets, args|
    targets.draw_mark(*args, &block)
  end
end
draw_order(*args, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 541
def draw_order(*args, &block)
  split_targets(args) do |targets, args|
    targets.draw_order(*args, &block)
  end
end
entity(key) click to toggle source
# File lib/rabbit/theme/applier.rb, line 623
def entity(key)
  Parser::Ext::Entity::TABLE[key]
end
find_font_family(target_name) click to toggle source
# File lib/rabbit/theme/applier.rb, line 407
def find_font_family(target_name)
  families = font_families.grep(/#{Regexp.escape(target_name)}/i)
  return nil if families.empty?
  if families.include?(target_name)
    target_name
  else
    families.first
  end
end
font_families() click to toggle source
# File lib/rabbit/theme/applier.rb, line 403
def font_families
  canvas.font_families.collect {|family| family.name}
end
ignore_wait_block(elements) click to toggle source
# File lib/rabbit/theme/applier.rb, line 511
def ignore_wait_block(elements)
  elements.inject([]) do |result, element|
    if element.is_a?(WaitBlock)
      result + ignore_wait_block(element.elements)
    else
      result + [element]
    end
  end
end
image_element(path, properties={}) click to toggle source
# File lib/rabbit/theme/applier.rb, line 627
def image_element(path, properties={})
  image = Parser::Ext::Image.make_image(canvas, path, properties)
  if image.nil?
    raise ImageFileDoesNotExistError.new(path)
  end
  image
end
image_load_path() click to toggle source
Calls superclass method Rabbit::Theme::Searcher#image_load_path
# File lib/rabbit/theme/applier.rb, line 643
def image_load_path
  super + [base_directory].compact
end
include_theme(name) click to toggle source
# File lib/rabbit/theme/applier.rb, line 322
def include_theme(name)
  begin
    apply_theme(name)
  rescue ThemeExit
    info($!.message) if $!.have_message?
  end
end
indent(*args, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 521
def indent(*args, &block)
  split_targets(args) do |targets, args|
    targets.indent(*args, &block)
  end
end
logger() click to toggle source
# File lib/rabbit/theme/applier.rb, line 346
def logger
  canvas.logger
end
match(*paths, &block) click to toggle source
# File lib/rabbit/theme/applier.rb, line 433
def match(*paths, &block)
  dirty
  targets = _match(slides, *paths)
  return if targets.empty?

  begin
    @current_target = make_container(targets)
    block.call(@current_target)
  ensure
    @current_target = nil
  end
end
method_missing(meth, *args, &block) click to toggle source
Calls superclass method
# File lib/rabbit/theme/applier.rb, line 446
def method_missing(meth, *args, &block)
  if @current_target
    @current_target.__send__(meth, *args, &block)
  else
    super
  end
end
name() click to toggle source
# File lib/rabbit/theme/applier.rb, line 334
def name
  @theme.name
end
normalize_source(src) click to toggle source
# File lib/rabbit/theme/applier.rb, line 314
def normalize_source(src)
  src.gsub(/(?=^|\W)@(very_)?huge_(script_)?font_size(?=$|\W)/) do |x|
    x = "x"
    x *= 2 unless $1.nil?
    "@#{x}_large_#{$2}font_size"
  end
end
print?() click to toggle source
quartz?() click to toggle source
# File lib/rabbit/theme/applier.rb, line 429
def quartz?
  Utils.quartz?
end
set_background(color) click to toggle source
# File lib/rabbit/theme/applier.rb, line 370
def set_background(color)
  canvas.background = canvas.make_color(color)
end
set_background_image(filename) click to toggle source
# File lib/rabbit/theme/applier.rb, line 374
def set_background_image(filename)
  loader = ImageLoader.new(find_file(filename))
  canvas.background_image = loader.pixbuf
end
set_font_family(target, family=@font_family) click to toggle source
# File lib/rabbit/theme/applier.rb, line 417
def set_font_family(target, family=@font_family)
  target.prop_set("font_family", family) if family
end
set_font_resolution_ratio(ratio) click to toggle source
# File lib/rabbit/theme/applier.rb, line 421
def set_font_resolution_ratio(ratio)
  canvas.font_resolution_ratio = ratio
end
set_foreground(color) click to toggle source
# File lib/rabbit/theme/applier.rb, line 366
def set_foreground(color)
  canvas.foreground = canvas.make_color(color)
end
set_graffiti_color(color) click to toggle source
# File lib/rabbit/theme/applier.rb, line 387
def set_graffiti_color(color)
  canvas.graffiti_color = Renderer::Color.parse(color)
end
set_graffiti_line_width(line_width) click to toggle source
# File lib/rabbit/theme/applier.rb, line 391
def set_graffiti_line_width(line_width)
  canvas.graffiti_line_width = line_width
end
set_progress_background(color) click to toggle source
# File lib/rabbit/theme/applier.rb, line 383
def set_progress_background(color)
  canvas.progress_background = canvas.make_color(color)
end
set_progress_foreground(*color) click to toggle source
# File lib/rabbit/theme/applier.rb, line 379
def set_progress_foreground(*color)
  canvas.progress_foreground = canvas.make_color(*color)
end
slides() click to toggle source
# File lib/rabbit/theme/applier.rb, line 338
def slides
  @theme.slides
end
slides_per_page() click to toggle source
# File lib/rabbit/theme/applier.rb, line 362
def slides_per_page
  canvas.slides_per_page
end
span(attributes, content) click to toggle source
# File lib/rabbit/theme/applier.rb, line 619
def span(attributes, content)
  tag("span", attributes, content)
end
split_targets(args) { |to_container(targets), args| ... } click to toggle source
# File lib/rabbit/theme/applier.rb, line 553
def split_targets(args)
  if args.empty? or
      !(args.first.is_a?(Element::Base) or
        args.first.is_a?(ElementContainer))
    targets = @current_target
  else
    targets, *args = args
  end

  yield [to_container(targets), args]
end
start_auto_redraw_timer(interval) click to toggle source
# File lib/rabbit/theme/applier.rb, line 565
def start_auto_redraw_timer(interval)
  canvas.start_auto_redraw_timer(interval)
end
start_auto_reload_thread(interval) click to toggle source
# File lib/rabbit/theme/applier.rb, line 583
def start_auto_reload_thread(interval)
  deprecated_method("start_auto_redraw_timer",
                    "start_auto_reload_thread")
  start_auto_redraw_timer(interval)
end
start_auto_reload_timer(interval) click to toggle source

For backward compatibility

# File lib/rabbit/theme/applier.rb, line 573
def start_auto_reload_timer(interval)
  deprecated_method("start_auto_redraw_timer",
                    "start_auto_reload_timer")
  canvas.start_auto_redraw_timer(interval)
end
stop_auto_redraw_timer() click to toggle source
# File lib/rabbit/theme/applier.rb, line 568
def stop_auto_redraw_timer
  canvas.stop_auto_redraw_timer
end
stop_auto_reload_thread() click to toggle source
# File lib/rabbit/theme/applier.rb, line 588
def stop_auto_reload_thread
  deprecated_method("stop_auto_redraw_timer",
                    "stop_auto_reload_thread")
  stop_auto_redraw_timer
end
stop_auto_reload_timer() click to toggle source
# File lib/rabbit/theme/applier.rb, line 578
def stop_auto_reload_timer
  deprecated_method("stop_auto_redraw_timer",
                    "stop_auto_reload_timer")
  canvas.stop_auto_redraw_timer
end
tag(name, attributes, content) click to toggle source
# File lib/rabbit/theme/applier.rb, line 615
def tag(name, attributes, content)
  "<#{name} #{to_attrs(attributes)}>#{content}</#{name}>"
end
theme_exit(message=nil) click to toggle source
# File lib/rabbit/theme/applier.rb, line 358
def theme_exit(message=nil)
  raise ThemeExit.new(message)
end
theme_load_path() click to toggle source
Calls superclass method Rabbit::Theme::Searcher#theme_load_path
# File lib/rabbit/theme/applier.rb, line 639
def theme_load_path
  super + [base_directory].compact
end
to_attrs(hash) click to toggle source
# File lib/rabbit/theme/applier.rb, line 330
def to_attrs(hash)
  canvas.to_attrs(hash)
end
windows?() click to toggle source
# File lib/rabbit/theme/applier.rb, line 425
def windows?
  Utils.windows?
end