rndk 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/demos/appointment.rb +40 -25
  3. data/demos/clock.rb +22 -11
  4. data/demos/fileview.rb +141 -0
  5. data/examples/01-hello-world.rb +1 -2
  6. data/examples/02-colors.rb +58 -0
  7. data/examples/03-markup.rb +70 -0
  8. data/examples/04-quick-widgets.rb +72 -0
  9. data/examples/05-position-widget.rb +3 -6
  10. data/examples/calendar.rb +104 -0
  11. data/examples/scroll.rb +106 -0
  12. data/lib/rndk/alphalist.rb +14 -14
  13. data/lib/rndk/button.rb +21 -21
  14. data/lib/rndk/buttonbox.rb +18 -18
  15. data/lib/rndk/calendar.rb +333 -240
  16. data/lib/rndk/core/color.rb +136 -0
  17. data/lib/rndk/core/display.rb +23 -12
  18. data/lib/rndk/core/draw.rb +32 -26
  19. data/lib/rndk/core/markup.rb +561 -0
  20. data/lib/rndk/core/quick_widgets.rb +232 -12
  21. data/lib/rndk/core/screen.rb +16 -17
  22. data/lib/rndk/core/utils.rb +143 -0
  23. data/lib/rndk/core/widget.rb +133 -92
  24. data/lib/rndk/dialog.rb +17 -17
  25. data/lib/rndk/entry.rb +21 -21
  26. data/lib/rndk/fselect.rb +16 -16
  27. data/lib/rndk/graph.rb +10 -10
  28. data/lib/rndk/histogram.rb +10 -10
  29. data/lib/rndk/itemlist.rb +20 -20
  30. data/lib/rndk/label.rb +66 -45
  31. data/lib/rndk/marquee.rb +10 -10
  32. data/lib/rndk/matrix.rb +27 -27
  33. data/lib/rndk/mentry.rb +22 -22
  34. data/lib/rndk/menu.rb +14 -14
  35. data/lib/rndk/radio.rb +19 -19
  36. data/lib/rndk/scale.rb +21 -21
  37. data/lib/rndk/scroll.rb +19 -19
  38. data/lib/rndk/scroller.rb +2 -0
  39. data/lib/rndk/selection.rb +20 -20
  40. data/lib/rndk/slider.rb +21 -21
  41. data/lib/rndk/swindow.rb +20 -20
  42. data/lib/rndk/template.rb +21 -21
  43. data/lib/rndk/version.rb +1 -1
  44. data/lib/rndk/viewer.rb +18 -18
  45. data/lib/rndk.rb +99 -777
  46. data/rndk.gemspec +1 -1
  47. metadata +12 -3
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Shows off the Calendar Widget, binding some keys to actions.
4
+ #
5
+ # Note: This example is quite complex.
6
+ # See file '02-colors.rb' for a better introduction
7
+ # to the calendar widget.
8
+ #
9
+ require 'rndk/calendar'
10
+
11
+ begin
12
+ # Start RNDK and Colors
13
+ rndkscreen = RNDK::Screen.new
14
+ RNDK::Color.init
15
+
16
+ title = "<C></U>RNDK Calendar Widget\n<C>Demo"
17
+
18
+ # Declare the calendar widget.
19
+ calendar = RNDK::Calendar.new(rndkscreen,
20
+ RNDK::CENTER, # x
21
+ RNDK::CENTER, # y
22
+ title,
23
+ 0, 0, 0, # current date
24
+ RNDK::Color[:red_black] | Ncurses::A_BOLD,
25
+ RNDK::Color[:green_black] | Ncurses::A_BOLD,
26
+ RNDK::Color[:yellow_black] | Ncurses::A_BOLD,
27
+ RNDK::Color[:blue_black] | Ncurses::A_REVERSE,
28
+ true,
29
+ false)
30
+
31
+ if calendar.nil?
32
+ RNDK::Screen.end_rndk
33
+
34
+ puts 'Cannot create the calendar. Is the window too small?'
35
+ exit 1
36
+ end
37
+
38
+ # Here we define the functions that will be
39
+ # executed when the user presses a key.
40
+ #
41
+ # They must be lambdas.
42
+
43
+ # This adds a marker ot the calendar.
44
+ create_calendar_mark = lambda do |object_type, calendar, client_data, key|
45
+ calendar.setMarker(calendar.day, calendar.month, calendar.year)
46
+ calendar.draw(calendar.box)
47
+ return false
48
+ end
49
+
50
+ # This removes a marker from the calendar.
51
+ remove_calendar_mark = lambda do |object_type, calendar, client_data, key|
52
+ calendar.removeMarker(calendar.day, calendar.month, calendar.year)
53
+ calendar.draw(calendar.box)
54
+ return false
55
+ end
56
+
57
+ # Here we bind the keys to the actions.
58
+ #
59
+ # They must be lambdas.
60
+
61
+ calendar.bind(:calendar, 'm', create_calendar_mark, calendar)
62
+ calendar.bind(:calendar, 'M', create_calendar_mark, calendar)
63
+ calendar.bind(:calendar, 'r', remove_calendar_mark, calendar)
64
+ calendar.bind(:calendar, 'R', remove_calendar_mark, calendar)
65
+
66
+ calendar.week_base = 0
67
+
68
+ # Let the user play with the widget.
69
+ ret_val = calendar.activate([])
70
+
71
+ # Check which day they selected.
72
+ if calendar.exit_type == :ESCAPE_HIT
73
+ mesg = [
74
+ '<C>You hit escape. No date selected.',
75
+ '',
76
+ '<C>Press any key to continue.'
77
+ ]
78
+ rndkscreen.popup_label mesg
79
+
80
+ elsif calendar.exit_type == :NORMAL
81
+ mesg = [
82
+ 'You selected the following date',
83
+ '<C></B/16>%02d/%02d/%d (dd/mm/yyyy)' % [
84
+ calendar.day, calendar.month, calendar.year],
85
+ '<C>Press any key to continue.'
86
+ ]
87
+ rndkscreen.popup_label mesg
88
+ end
89
+
90
+ # Finishing up and printing message
91
+ RNDK::Screen.end_rndk
92
+
93
+ puts 'Selected Time: %s' % ret_val.ctime unless ret_val.nil?
94
+
95
+ # Just in case something bad happens.
96
+ rescue Exception => e
97
+ RNDK::Screen.end_rndk
98
+
99
+ puts e
100
+ puts e.inspect
101
+ puts e.backtrace
102
+ exit 1
103
+ end
104
+
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Displays a Scroll list with the current
4
+ # directory's files.
5
+ #
6
+ # You can also modify it at runtime with the keys:
7
+ #
8
+ # * 'a' adds item
9
+ # * 'i' inserts item
10
+ # * 'd' deletes item
11
+ #
12
+ require 'rndk/scroll'
13
+
14
+ # It creates new labels to add to the Scroll List.
15
+ #
16
+ # Ignore this for now, read the rest first.
17
+ $count = 0
18
+ def new_label(prefix)
19
+ result = "%s%d" % [prefix, $count]
20
+ $count += 1
21
+ return result
22
+ end
23
+
24
+ begin
25
+ # Set up RNDK and colors
26
+ rndkscreen = RNDK::Screen.new
27
+ RNDK::Draw.initRNDKColor
28
+
29
+ # Use the current directory list to fill the radio list
30
+ item = []
31
+ count = RNDK.getDirectoryContents(".", item)
32
+
33
+ # Create the scrolling list.
34
+ scroll_list = RNDK::SCROLL.new(rndkscreen,
35
+ RNDK::CENTER, # x
36
+ RNDK::CENTER, # y
37
+ RNDK::RIGHT, # scrollbar position
38
+ 10, # height
39
+ 50, # width
40
+ "<C></5>Pick a file", # title
41
+ item,
42
+ count,
43
+ true,
44
+ Ncurses::A_REVERSE,
45
+ true, # box
46
+ false) # shadow
47
+
48
+ if scroll_list.nil?
49
+ RNDK::Screen.end_rndk
50
+
51
+ puts "Cannot make scrolling list. Is the window too small?"
52
+ exit 1
53
+ end
54
+
55
+ # These are the functions that will modify the
56
+ # Scroll List at runtime.
57
+
58
+ addItemCB = lambda do |type, widget, client_data, input|
59
+ widget.addItem(ScrollExample.newLabel("add"))
60
+ widget.screen.refresh
61
+ return true
62
+ end
63
+
64
+ insItemCB = lambda do |type, widget, client_data, input|
65
+ widget.insertItem(ScrollExample.newLabel("insert"))
66
+ widget.screen.refresh
67
+ return true
68
+ end
69
+
70
+ delItemCB = lambda do |type, widget, client_data, input|
71
+ widget.deleteItem(widget.getCurrentItem)
72
+ widget.screen.refresh
73
+ return true
74
+ end
75
+
76
+ # And this is how we bind keys to actions.
77
+ #
78
+ # It only accepts lambdas.
79
+
80
+ scroll_list.bind(:SCROLL, 'a', addItemCB, nil)
81
+ scroll_list.bind(:SCROLL, 'i', insItemCB, nil);
82
+ scroll_list.bind(:SCROLL, 'd', delItemCB, nil);
83
+
84
+ # Activate the scrolling list.
85
+ selection = scroll_list.activate('')
86
+
87
+ # Determine how the widget was exited
88
+ msg = []
89
+ if scroll_list.exit_type == :ESCAPE_HIT
90
+ msg = ['<C>You hit escape. No file selected',
91
+ '',
92
+ '<C>Press any key to continue.']
93
+
94
+ elsif scroll_list.exit_type == :NORMAL
95
+ the_item = RNDK.chtype2Char scroll_list.item[selection]
96
+
97
+ msg = ['<C>You selected the following file',
98
+ "<C>%.*s" % [236, the_item], # FIXME magic number
99
+ "<C>Press any key to continue."]
100
+ end
101
+ rndkscreen.popup_label msg
102
+
103
+ # Exit
104
+ RNDK::Screen.end_rndk
105
+ end
106
+
@@ -22,7 +22,7 @@ module RNDK
22
22
  return nil
23
23
  end
24
24
 
25
- self.setBox(box)
25
+ self.set_box(box)
26
26
 
27
27
  # If the height is a negative value, the height will be ROWS-height,
28
28
  # otherwise the height will be the given height.
@@ -206,7 +206,7 @@ module RNDK
206
206
 
207
207
  if alphalist.isBind(:ALPHALIST, input)
208
208
  result = 1 # Don't try to use this key in editing
209
- elsif (RNDK.isChar(input) &&
209
+ elsif (RNDK.is_char?(input) &&
210
210
  input.chr.match(/^[[:alnum:][:punct:]]$/)) ||
211
211
  [Ncurses::KEY_BACKSPACE, Ncurses::KEY_DC].include?(input)
212
212
  index = 0
@@ -290,12 +290,12 @@ module RNDK
290
290
 
291
291
  # This erases the alphalist from the screen.
292
292
  def erase
293
- if self.validRNDKObject
293
+ if self.valid_widget?
294
294
  @scroll_field.erase
295
295
  @entry_field.erase
296
296
 
297
- RNDK.eraseCursesWindow(@shadow_win)
298
- RNDK.eraseCursesWindow(@win)
297
+ RNDK.window_erase(@shadow_win)
298
+ RNDK.window_erase(@win)
299
299
  end
300
300
  end
301
301
 
@@ -392,8 +392,8 @@ module RNDK
392
392
  def set(list, list_size, filler_char, highlight, box)
393
393
  self.setContents(list, list_size)
394
394
  self.setFillerChar(filler_char)
395
- self.setHighlight(highlight)
396
- self.setBox(box)
395
+ self.set_highlight(highlight)
396
+ self.set_box(box)
397
397
  end
398
398
 
399
399
  # This function sets the information inside the alphalist.
@@ -444,7 +444,7 @@ module RNDK
444
444
  end
445
445
 
446
446
  # This sets the highlgith bar attributes
447
- def setHighlight(highlight)
447
+ def set_highlight(highlight)
448
448
  @highlight = highlight
449
449
  end
450
450
 
@@ -485,9 +485,9 @@ module RNDK
485
485
  end
486
486
 
487
487
  # This sets the background attribute of the widget.
488
- def setBKattr(attrib)
489
- @entry_field.setBKattr(attrib)
490
- @scroll_field.setBKattr(attrib)
488
+ def set_bg_attrib(attrib)
489
+ @entry_field.set_bg_attrib(attrib)
490
+ @scroll_field.set_bg_attrib(attrib)
491
491
  end
492
492
 
493
493
  def destroyInfo
@@ -500,14 +500,14 @@ module RNDK
500
500
  self.destroyInfo
501
501
 
502
502
  # Clean the key bindings.
503
- self.cleanBindings(:ALPHALIST)
503
+ self.clean_bindings(:ALPHALIST)
504
504
 
505
505
  @entry_field.destroy
506
506
  @scroll_field.destroy
507
507
 
508
508
  # Free up the window pointers.
509
- RNDK.deleteCursesWindow(@shadow_win)
510
- RNDK.deleteCursesWindow(@win)
509
+ RNDK.window_delete(@shadow_win)
510
+ RNDK.window_delete(@win)
511
511
 
512
512
  # Unregister the object.
513
513
  RNDK::Screen.unregister(:ALPHALIST, self)
data/lib/rndk/button.rb CHANGED
@@ -10,7 +10,7 @@ module RNDK
10
10
  xpos = xplace
11
11
  ypos = yplace
12
12
 
13
- self.setBox(box)
13
+ self.set_box(box)
14
14
  box_height = 1 + 2 * @border_size
15
15
 
16
16
  # Translate the string to a chtype array.
@@ -100,18 +100,18 @@ module RNDK
100
100
  end
101
101
 
102
102
  # Set the exit type and exit
103
- self.setExitType(0)
103
+ self.set_exit_type(0)
104
104
  return -1
105
105
  end
106
106
 
107
107
  # This sets multiple attributes of the widget.
108
108
  def set(mesg, box)
109
- self.setMessage(mesg)
110
- self.setBox(box)
109
+ self.set_message(mesg)
110
+ self.set_box(box)
111
111
  end
112
112
 
113
113
  # This sets the information within the button.
114
- def setMessage(info)
114
+ def set_message(info)
115
115
  info_len = []
116
116
  info_pos = []
117
117
  @info = RNDK.char2Chtype(info, info_len, info_pos)
@@ -124,12 +124,12 @@ module RNDK
124
124
  self.draw(box)
125
125
  end
126
126
 
127
- def getMessage
127
+ def get_message
128
128
  return @info
129
129
  end
130
130
 
131
131
  # This sets the background attribute of the widget.
132
- def setBKattr(attrib)
132
+ def set_bg_attrib(attrib)
133
133
  Ncurses.wbkgd(@win, attrib)
134
134
  end
135
135
 
@@ -171,9 +171,9 @@ module RNDK
171
171
 
172
172
  # This erases the button widget.
173
173
  def erase
174
- if self.validRNDKObject
175
- RNDK.eraseCursesWindow(@win)
176
- RNDK.eraseCursesWindow(@shadow_win)
174
+ if self.valid_widget?
175
+ RNDK.window_erase(@win)
176
+ RNDK.window_erase(@shadow_win)
177
177
  end
178
178
  end
179
179
 
@@ -203,11 +203,11 @@ module RNDK
203
203
  ydiff = current_y - ypos
204
204
 
205
205
  # Move the window to the new location.
206
- RNDK.moveCursesWindow(@win, -xdiff, -ydiff)
207
- RNDK.moveCursesWindow(@shadow_win, -xdiff, -ydiff)
206
+ RNDK.window_move(@win, -xdiff, -ydiff)
207
+ RNDK.window_move(@shadow_win, -xdiff, -ydiff)
208
208
 
209
209
  # Thouch the windows so they 'move'.
210
- RNDK::Screen.refresh_window(@screen.window)
210
+ RNDK.window_refresh(@screen.window)
211
211
 
212
212
  # Redraw the window, if they asked for it.
213
213
  if refresh_flag
@@ -304,10 +304,10 @@ module RNDK
304
304
 
305
305
  # This destroys the button object pointer.
306
306
  def destroy
307
- RNDK.deleteCursesWindow(@shadow_win)
308
- RNDK.deleteCursesWindow(@win)
307
+ RNDK.window_delete(@shadow_win)
308
+ RNDK.window_delete(@win)
309
309
 
310
- self.cleanBindings(:BUTTON)
310
+ self.clean_bindings(:BUTTON)
311
311
 
312
312
  RNDK::Screen.unregister(:BUTTON, self)
313
313
  end
@@ -317,7 +317,7 @@ module RNDK
317
317
  ret = -1
318
318
  complete = false
319
319
 
320
- self.setExitType(0)
320
+ self.set_exit_type(0)
321
321
 
322
322
  # Check a predefined binding.
323
323
  if self.checkBind(:BUTTON, input)
@@ -325,16 +325,16 @@ module RNDK
325
325
  else
326
326
  case input
327
327
  when RNDK::KEY_ESC
328
- self.setExitType(input)
328
+ self.set_exit_type(input)
329
329
  complete = true
330
330
  when Ncurses::ERR
331
- self.setExitType(input)
331
+ self.set_exit_type(input)
332
332
  complete = true
333
333
  when ' '.ord, RNDK::KEY_RETURN, Ncurses::KEY_ENTER
334
334
  unless @callback.nil?
335
335
  @callback.call(self)
336
336
  end
337
- self.setExitType(Ncurses::KEY_ENTER)
337
+ self.set_exit_type(Ncurses::KEY_ENTER)
338
338
  ret = 0
339
339
  complete = true
340
340
  when RNDK::REFRESH
@@ -346,7 +346,7 @@ module RNDK
346
346
  end
347
347
 
348
348
  unless complete
349
- self.setExitType(0)
349
+ self.set_exit_type(0)
350
350
  end
351
351
 
352
352
  @result_data = ret
@@ -21,7 +21,7 @@ module RNDK
21
21
  return nil
22
22
  end
23
23
 
24
- self.setBox(box)
24
+ self.set_box(box)
25
25
 
26
26
  # Set some default values for the widget.
27
27
  @row_adjust = 0
@@ -35,7 +35,7 @@ module RNDK
35
35
  # COLS-width, otherwise the width will be the given width.
36
36
  box_width = RNDK.setWidgetDimension(parent_width, width, 0)
37
37
 
38
- box_width = self.setTitle(title, box_width)
38
+ box_width = self.set_title(title, box_width)
39
39
 
40
40
  # Translate the buttons string to a chtype array
41
41
  (0...button_count).each do |x|
@@ -143,7 +143,7 @@ module RNDK
143
143
  end
144
144
 
145
145
  # Set the exit type and exit
146
- self.setExitType(0)
146
+ self.set_exit_type(0)
147
147
  return -1
148
148
  end
149
149
 
@@ -156,7 +156,7 @@ module RNDK
156
156
  complete = false
157
157
 
158
158
  # Set the exit type
159
- self.setExitType(0)
159
+ self.set_exit_type(0)
160
160
 
161
161
  unless @pre_process_func.nil?
162
162
  pp_return = @pre_process_func.call(:BUTTONBOX, self,
@@ -198,13 +198,13 @@ module RNDK
198
198
  @screen.erase
199
199
  @screen.refresh
200
200
  when RNDK::KEY_ESC
201
- self.setExitType(input)
201
+ self.set_exit_type(input)
202
202
  complete = true
203
203
  when Ncurses::ERR
204
- self.setExitType(input)
204
+ self.set_exit_type(input)
205
205
  complete = true
206
206
  when RNDK::KEY_RETURN, Ncurses::KEY_ENTER
207
- self.setExitType(input)
207
+ self.set_exit_type(input)
208
208
  ret = @current_button
209
209
  complete = true
210
210
  end
@@ -219,7 +219,7 @@ module RNDK
219
219
 
220
220
  unless complete
221
221
  self.drawButtons
222
- self.setExitType(0)
222
+ self.set_exit_type(0)
223
223
  end
224
224
 
225
225
  @result_data = ret
@@ -228,12 +228,12 @@ module RNDK
228
228
 
229
229
  # This sets multiple attributes of the widget.
230
230
  def set(highlight, box)
231
- self.setHighlight(highlight)
232
- self.setBox(box)
231
+ self.set_highlight(highlight)
232
+ self.set_box(box)
233
233
  end
234
234
 
235
235
  # This sets the highlight attribute for the buttonboxes
236
- def setHighlight(highlight)
236
+ def set_highlight(highlight)
237
237
  @highlight = highlight
238
238
  end
239
239
 
@@ -242,7 +242,7 @@ module RNDK
242
242
  end
243
243
 
244
244
  # This sets th background attribute of the widget.
245
- def setBKattr(attrib)
245
+ def set_bg_attrib(attrib)
246
246
  Ncurses.wbkgd(@win, attrib)
247
247
  end
248
248
 
@@ -308,9 +308,9 @@ module RNDK
308
308
 
309
309
  # This erases the buttonbox box from the screen.
310
310
  def erase
311
- if self.validRNDKObject
312
- RNDK.eraseCursesWindow @win
313
- RNDK.eraseCursesWindow @shadow_win
311
+ if self.valid_widget?
312
+ RNDK.window_erase @win
313
+ RNDK.window_erase @shadow_win
314
314
  end
315
315
  end
316
316
 
@@ -318,10 +318,10 @@ module RNDK
318
318
  def destroy
319
319
  self.cleanTitle
320
320
 
321
- RNDK.deleteCursesWindow @shadow_win
322
- RNDK.deleteCursesWindow @win
321
+ RNDK.window_delete @shadow_win
322
+ RNDK.window_delete @win
323
323
 
324
- self.cleanBindings(:BUTTONBOX)
324
+ self.clean_bindings(:BUTTONBOX)
325
325
 
326
326
  RNDK::Screen.unregister(:BUTTONBOX, self)
327
327
  end