Class: PPCurses::DateMenu

Inherits:
ChoiceMenu show all
Defined in:
lib/ppcurses/menu/date_menu.rb

Instance Attribute Summary

Attributes inherited from ChoiceMenu

#pressed_enter, #selection

Attributes inherited from Menu

#selection

Attributes inherited from BaseMenu

#menu_items, #selection, #side_wall_char, #top_bot_wall_char

Instance Method Summary collapse

Methods inherited from ChoiceMenu

#menu_selection

Methods inherited from Menu

#menu_selection, #set_global_action

Methods inherited from BaseMenu

#build_menu_items, #close, #hide, #selected_menu_name, #set_origin, #set_sub_menu

Constructor Details

#initialize(day) ⇒ DateMenu



6
7
8
9
10
# File 'lib/ppcurses/menu/date_menu.rb', line 6

def initialize(day)
  @meta_info = MetaMonth.new(day)
  find_max_menu_width
  create_window
end

Instance Method Details

#create_windowObject



33
34
35
36
37
38
# File 'lib/ppcurses/menu/date_menu.rb', line 33

def create_window
  w_height = @meta_info.month_str_array.length + 4
  w_width = @max_menu_width + 4
  @win = PPCurses::Window.new(w_height,w_width,(Curses.lines-w_height) / 2, (Curses.cols-w_width)/2)
  @win.timeout=-1
end

#dayObject



12
13
14
# File 'lib/ppcurses/menu/date_menu.rb', line 12

def day
  @meta_info.day
end

#day=(new_day) ⇒ Object



16
17
18
# File 'lib/ppcurses/menu/date_menu.rb', line 16

def day=(new_day)
  @meta_info.day = new_day
end

#find_max_menu_widthObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/ppcurses/menu/date_menu.rb', line 21

def find_max_menu_width
  @max_menu_width = 0
  
  str_array = @meta_info.month_str_array
  
  (0...str_array.length).each { |i|
    display = str_array[i]
    @max_menu_width = display.length if display.length > @max_menu_width
  }
end

#handle_menu_selection(c) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ppcurses/menu/date_menu.rb', line 69

def handle_menu_selection(c)     

  curr_day = @meta_info.day
  day_change = 0

 if c == KEY_UP    then day_change = -7 end       
 if c == KEY_DOWN  then day_change = 7  end   
 if c == KEY_LEFT  then day_change = -1 end      
 if c == KEY_RIGHT then day_change = 1  end 
 
 # Use vi key bindings for months and year
 # browsing.
 if c == 'l'       then day_change = 30   end 
 if c == 'h'       then day_change = -30  end
 if c == 'j'       then day_change = 365  end
 if c == 'k'       then day_change = -365 end
 
 if day_change != 0 
   curr_day = Date.jd(curr_day.jd + day_change)
   @meta_info.day = curr_day        
   self.show
   return true
 end
 
  false
end

#showObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/ppcurses/menu/date_menu.rb', line 41

def show
  y = 2
  x = 2

  str_array = @meta_info.month_str_array

  str_array.each_with_index { |val, i| 
     @win.setpos(y, x)
     
     if i != @meta_info.day_row 
       @win.addstr(val)
     else
       num_of_digits = @meta_info.day.day > 9 ? 2 : 1
       @win.addstr(val[0, @meta_info.day_col])
       @win.attron(Curses::A_REVERSE)
       @win.addstr(val[@meta_info.day_col, num_of_digits])
       @win.attroff(Curses::A_REVERSE) 
       @win.addstr(val[@meta_info.day_col + num_of_digits, val.length])
     end
     
     y += 1
  }

   @win.refresh

   @sub_menu.show if @sub_menu
end