cdk 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cdk.rb +7 -866
  3. data/lib/cdk/cdk_objs.rb +46 -423
  4. data/lib/cdk/components.rb +28 -0
  5. data/lib/cdk/{alphalist.rb → components/alphalist.rb} +9 -6
  6. data/lib/cdk/components/button.rb +405 -0
  7. data/lib/cdk/{buttonbox.rb → components/buttonbox.rb} +11 -11
  8. data/lib/cdk/{calendar.rb → components/calendar.rb} +13 -13
  9. data/lib/cdk/components/dialog.rb +343 -0
  10. data/lib/cdk/{dscale.rb → components/dscale.rb} +0 -0
  11. data/lib/cdk/{entry.rb → components/entry.rb} +18 -18
  12. data/lib/cdk/{fscale.rb → components/fscale.rb} +1 -1
  13. data/lib/cdk/{fselect.rb → components/fselect.rb} +16 -13
  14. data/lib/cdk/{fslider.rb → components/fslider.rb} +1 -1
  15. data/lib/cdk/components/graph.rb +386 -0
  16. data/lib/cdk/{histogram.rb → components/histogram.rb} +3 -3
  17. data/lib/cdk/{itemlist.rb → components/itemlist.rb} +14 -14
  18. data/lib/cdk/{label.rb → components/label.rb} +7 -7
  19. data/lib/cdk/{marquee.rb → components/marquee.rb} +7 -7
  20. data/lib/cdk/{matrix.rb → components/matrix.rb} +27 -27
  21. data/lib/cdk/{mentry.rb → components/mentry.rb} +18 -18
  22. data/lib/cdk/{menu.rb → components/menu.rb} +18 -18
  23. data/lib/cdk/{radio.rb → components/radio.rb} +12 -12
  24. data/lib/cdk/{scale.rb → components/scale.rb} +13 -13
  25. data/lib/cdk/{scroll.rb → components/scroll.rb} +23 -386
  26. data/lib/cdk/{scroller.rb → components/scroller.rb} +1 -1
  27. data/lib/cdk/{selection.rb → components/selection.rb} +14 -14
  28. data/lib/cdk/{slider.rb → components/slider.rb} +15 -15
  29. data/lib/cdk/{swindow.rb → components/swindow.rb} +14 -14
  30. data/lib/cdk/{template.rb → components/template.rb} +18 -18
  31. data/lib/cdk/{uscale.rb → components/uscale.rb} +0 -0
  32. data/lib/cdk/{uslider.rb → components/uslider.rb} +0 -0
  33. data/lib/cdk/{viewer.rb → components/viewer.rb} +88 -18
  34. data/lib/cdk/constants.rb +54 -0
  35. data/lib/cdk/display.rb +30 -35
  36. data/lib/cdk/draw.rb +4 -6
  37. data/lib/cdk/helpers/file.rb +43 -0
  38. data/lib/cdk/helpers/types.rb +13 -0
  39. data/lib/cdk/helpers/window.rb +64 -0
  40. data/lib/cdk/mixins/alignments.rb +55 -0
  41. data/lib/cdk/mixins/bindings.rb +73 -0
  42. data/lib/cdk/mixins/borders.rb +62 -0
  43. data/lib/cdk/mixins/common_controls.rb +14 -0
  44. data/lib/cdk/mixins/converters.rb +358 -0
  45. data/lib/cdk/mixins/exit_conditions.rb +31 -0
  46. data/lib/cdk/mixins/focusable.rb +17 -0
  47. data/lib/cdk/mixins/formattable.rb +15 -0
  48. data/lib/cdk/mixins/has_screen.rb +23 -0
  49. data/lib/cdk/mixins/has_title.rb +64 -0
  50. data/lib/cdk/mixins/justifications.rb +26 -0
  51. data/lib/cdk/mixins/list_support.rb +31 -0
  52. data/lib/cdk/mixins/movement.rb +140 -0
  53. data/lib/cdk/mixins/window_hooks.rb +18 -0
  54. data/lib/cdk/mixins/window_input.rb +61 -0
  55. data/lib/cdk/screen.rb +27 -3
  56. metadata +51 -29
  57. data/lib/cdk/dialog.rb +0 -727
@@ -1,4 +1,4 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
2
 
3
3
  module CDK
4
4
  class BUTTONBOX < CDK::CDKOBJS
@@ -40,7 +40,7 @@ module CDK
40
40
  # Translate the buttons string to a chtype array
41
41
  (0...button_count).each do |x|
42
42
  button_len = []
43
- @button << CDK.char2Chtype(buttons[x], button_len ,[])
43
+ @button << char2Chtype(buttons[x], button_len ,[])
44
44
  @button_len << button_len[0]
45
45
  end
46
46
 
@@ -69,7 +69,7 @@ module CDK
69
69
  # Now we have to readjust the x and y positions
70
70
  xtmp = [x_pos]
71
71
  ytmp = [y_pos]
72
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
72
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
73
73
  xpos = xtmp[0]
74
74
  ypos = ytmp[0]
75
75
 
@@ -153,7 +153,7 @@ module CDK
153
153
  last_button = @button_count - 1
154
154
  pp_return = 1
155
155
  ret = -1
156
- complete = false
156
+ @complete = false
157
157
 
158
158
  # Set the exit type
159
159
  self.setExitType(0)
@@ -167,7 +167,7 @@ module CDK
167
167
  if pp_return != 0
168
168
  # Check for a key binding.
169
169
  if self.checkBind(:BUTTONBOX, input)
170
- complete = true
170
+ @complete = true
171
171
  else
172
172
  case input
173
173
  when Ncurses::KEY_LEFT, Ncurses::KEY_BTAB, Ncurses::KEY_BACKSPACE
@@ -199,25 +199,25 @@ module CDK
199
199
  @screen.refresh
200
200
  when CDK::KEY_ESC
201
201
  self.setExitType(input)
202
- complete = true
202
+ @complete = true
203
203
  when Ncurses::ERR
204
204
  self.setExitType(input)
205
- complete = true
205
+ @complete = true
206
206
  when CDK::KEY_RETURN, Ncurses::KEY_ENTER
207
207
  self.setExitType(input)
208
208
  ret = @current_button
209
- complete = true
209
+ @complete = true
210
210
  end
211
211
  end
212
212
 
213
- if !complete && !(@post_process_func.nil?)
213
+ if !@complete && !(@post_process_func.nil?)
214
214
  @post_process_func.call(:BUTTONBOX, self, @post_process_data,
215
215
  input)
216
216
  end
217
217
 
218
218
  end
219
219
 
220
- unless complete
220
+ unless @complete
221
221
  self.drawButtons
222
222
  self.setExitType(0)
223
223
  end
@@ -298,7 +298,7 @@ module CDK
298
298
  if cur_row >= 0 && cur_col >= 0
299
299
  @win.wmove(cur_row, cur_col)
300
300
  end
301
- @win.wrefresh
301
+ wrefresh
302
302
  end
303
303
 
304
304
  # This erases the buttonbox box from the screen.
@@ -1,4 +1,4 @@
1
- require_relative 'cdk_objs'
1
+ require_relative '../cdk_objs'
2
2
 
3
3
  module CDK
4
4
  class CALENDAR < CDK::CDKOBJS
@@ -84,7 +84,7 @@ module CDK
84
84
  # Rejustify the x and y positions if we need to.
85
85
  xtmp = [xplace]
86
86
  ytmp = [yplace]
87
- CDK.alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
87
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
88
88
  xpos = xtmp[0]
89
89
  ypos = ytmp[0]
90
90
 
@@ -203,7 +203,7 @@ module CDK
203
203
  # Declare local variables
204
204
  pp_return = 1
205
205
  ret = -1
206
- complete = false
206
+ @complete = false
207
207
 
208
208
  # Set the exit type
209
209
  self.setExitType(0)
@@ -222,7 +222,7 @@ module CDK
222
222
  # Check a predefined binding
223
223
  if self.checkBind(:CALENDAR, input)
224
224
  self.checkEarlyExit
225
- complete = true
225
+ @complete = true
226
226
  else
227
227
  case input
228
228
  when Ncurses::KEY_UP
@@ -249,14 +249,14 @@ module CDK
249
249
  self.setDate(-1, -1, -1)
250
250
  when CDK::KEY_ESC
251
251
  self.setExitType(input)
252
- complete = true
252
+ @complete = true
253
253
  when Ncurses::ERR
254
254
  self.setExitType(input)
255
- complete = true
255
+ @complete = true
256
256
  when CDK::KEY_TAB, CDK::KEY_RETURN, Ncurses::KEY_ENTER
257
257
  self.setExitType(input)
258
258
  ret = self.getCurrentTime
259
- complete = true
259
+ @complete = true
260
260
  when CDK::REFRESH
261
261
  @screen.erase
262
262
  @screen.refresh
@@ -264,12 +264,12 @@ module CDK
264
264
  end
265
265
 
266
266
  # Should we do a post-process?
267
- if !complete && !(@post_process_func.nil?)
267
+ if !@complete && !(@post_process_func.nil?)
268
268
  @post_process_func.call(:CALENDAR, self, @post_process_data, input)
269
269
  end
270
270
  end
271
271
 
272
- if !complete
272
+ if !@complete
273
273
  self.setExitType(0)
274
274
  end
275
275
 
@@ -309,7 +309,7 @@ module CDK
309
309
  @day_name[src..-1], CDK::HORIZONTAL, 0, col_len)
310
310
  end
311
311
 
312
- @win.wrefresh
312
+ wrefresh
313
313
  self.drawField
314
314
  end
315
315
 
@@ -349,7 +349,7 @@ module CDK
349
349
  day += 1
350
350
  end
351
351
  end
352
- @field_win.wrefresh
352
+ wrefresh(@field_win)
353
353
 
354
354
  # Draw the month in.
355
355
  if !(@label_win.nil?)
@@ -364,10 +364,10 @@ module CDK
364
364
  CDK::HORIZONTAL, 0, year_len)
365
365
 
366
366
  @label_win.wmove(0, 0)
367
- @label_win.wrefresh
367
+ wrefresh(@label_win)
368
368
  elsif save_y >= 0
369
369
  @input_window.wmove(save_y, save_x)
370
- @input_window.wrefresh
370
+ wrefresh(@input_window)
371
371
  end
372
372
  end
373
373
 
@@ -0,0 +1,343 @@
1
+ require_relative '../cdk_objs'
2
+
3
+ module CDK
4
+ class DIALOG < CDK::CDKOBJS
5
+ attr_reader :current_button
6
+ MIN_DIALOG_WIDTH = 10
7
+
8
+ def initialize(cdkscreen, xplace, yplace, mesg, rows, button_label,
9
+ button_count, highlight, separator, box, shadow)
10
+ super()
11
+ box_width = DIALOG::MIN_DIALOG_WIDTH
12
+ max_message_width = -1
13
+ button_width = 0
14
+ xpos = xplace
15
+ ypos = yplace
16
+ temp = 0
17
+ buttonadj = 0
18
+ @info = []
19
+ @info_len = []
20
+ @info_pos = []
21
+ @button_label = []
22
+ @button_len = []
23
+ @button_pos = []
24
+
25
+ if rows <= 0 || button_count <= 0
26
+ self.destroy
27
+ return nil
28
+ end
29
+
30
+ self.setBox(box)
31
+ box_height = if separator then 1 else 0 end
32
+ box_height += rows + 2 * @border_size + 1
33
+
34
+ # Translate the string message to a chtype array
35
+ (0...rows).each do |x|
36
+ info_len = []
37
+ info_pos = []
38
+ @info << char2Chtype(mesg[x], info_len, info_pos)
39
+ @info_len << info_len[0]
40
+ @info_pos << info_pos[0]
41
+ max_message_width = [max_message_width, info_len[0]].max
42
+ end
43
+
44
+ # Translate the button label string to a chtype array
45
+ (0...button_count).each do |x|
46
+ button_len = []
47
+ @button_label << char2Chtype(button_label[x], button_len, [])
48
+ @button_len << button_len[0]
49
+ button_width += button_len[0] + 1
50
+ end
51
+
52
+ button_width -= 1
53
+
54
+ # Determine the final dimensions of the box.
55
+ box_width = [box_width, max_message_width, button_width].max
56
+ box_width = box_width + 2 + 2 * @border_size
57
+
58
+ # Now we have to readjust the x and y positions.
59
+ xtmp = [xpos]
60
+ ytmp = [ypos]
61
+ alignxy(cdkscreen.window, xtmp, ytmp, box_width, box_height)
62
+ xpos = xtmp[0]
63
+ ypos = ytmp[0]
64
+
65
+ # Set up the dialog box attributes.
66
+ @screen = cdkscreen
67
+ @parent = cdkscreen.window
68
+ @win = Ncurses::WINDOW.new(box_height, box_width, ypos, xpos)
69
+ @shadow_win = nil
70
+ @button_count = button_count
71
+ @current_button = 0
72
+ @message_rows = rows
73
+ @box_height = box_height
74
+ @box_width = box_width
75
+ @highlight = highlight
76
+ @separator = separator
77
+ @accepts_focus = true
78
+ @input_window = @win
79
+ @shadow = shadow
80
+
81
+ # If we couldn't create the window, we should return a nil value.
82
+ if @win.nil?
83
+ self.destroy
84
+ return nil
85
+ end
86
+ @win.keypad(true)
87
+
88
+ # Find the button positions.
89
+ buttonadj = (box_width - button_width) / 2
90
+ (0...button_count).each do |x|
91
+ @button_pos[x] = buttonadj
92
+ buttonadj = buttonadj + @button_len[x] + @border_size
93
+ end
94
+
95
+ # Create the string alignments.
96
+ (0...rows).each do |x|
97
+ @info_pos[x] = justify_string(box_width - 2 * @border_size,
98
+ @info_len[x], @info_pos[x])
99
+ end
100
+
101
+ # Was there a shadow?
102
+ if shadow
103
+ @shadow_win = Ncurses::WINDOW.new(box_height, box_width,
104
+ ypos + 1, xpos + 1)
105
+ end
106
+
107
+ # Register this baby.
108
+ cdkscreen.register(:DIALOG, self)
109
+ end
110
+
111
+ # This lets the user select the button.
112
+ def activate(actions)
113
+ input = 0
114
+
115
+ # Draw the dialog box.
116
+ self.draw(@box)
117
+
118
+ # Lets move to the first button.
119
+ Draw.writeChtypeAttrib(@win, @button_pos[@current_button],
120
+ @box_height - 1 - @border_size, @button_label[@current_button],
121
+ @highlight, CDK::HORIZONTAL, 0, @button_len[@current_button])
122
+ wrefresh(@win)
123
+
124
+ if actions.nil? || actions.size == 0
125
+ while true
126
+ input = self.getch([])
127
+
128
+ # Inject the character into the widget.
129
+ ret = self.inject(input)
130
+ if @exit_type != :EARLY_EXIT
131
+ return ret
132
+ end
133
+ end
134
+ else
135
+ # Inject each character one at a time.
136
+ actions.each do |action|
137
+ ret = self.inject(action)
138
+ if @exit_type != :EARLY_EXIT
139
+ return ret
140
+ end
141
+ end
142
+ end
143
+
144
+ # Set the exit type and exit
145
+ self.setExitType(0)
146
+ return -1
147
+ end
148
+
149
+ # This injects a single character into the dialog widget
150
+ def inject(input)
151
+ first_button = 0
152
+ last_button = @button_count - 1
153
+ pp_return = 1
154
+ ret = -1
155
+ @complete = false
156
+
157
+ # Set the exit type.
158
+ self.setExitType(0)
159
+
160
+ # Check if there is a pre-process function to be called.
161
+ unless @pre_process_func.nil?
162
+ pp_return = @pre_process_func.call(:DIALOG, self,
163
+ @pre_process_data, input)
164
+ end
165
+
166
+ # Should we continue?
167
+ if pp_return != 0
168
+ # Check for a key binding.
169
+ if self.checkBind(:DIALOG, input)
170
+ @complete = true
171
+ else
172
+ case input
173
+ when Ncurses::KEY_LEFT, Ncurses::KEY_BTAB, Ncurses::KEY_BACKSPACE
174
+ if @current_button == first_button
175
+ @current_button = last_button
176
+ else
177
+ @current_button -= 1
178
+ end
179
+ when Ncurses::KEY_RIGHT, CDK::KEY_TAB, ' '.ord
180
+ if @current_button == last_button
181
+ @current_button = first_button
182
+ else
183
+ @current_button += 1
184
+ end
185
+ when Ncurses::KEY_UP, Ncurses::KEY_DOWN
186
+ CDK.Beep
187
+ when CDK::REFRESH
188
+ @screen.erase
189
+ @screen.refresh
190
+ when CDK::KEY_ESC
191
+ self.setExitType(input)
192
+ @complete = true
193
+ when Ncurses::ERR
194
+ self.setExitType(input)
195
+ when Ncurses::KEY_ENTER, CDK::KEY_RETURN
196
+ self.setExitType(input)
197
+ ret = @current_button
198
+ @complete = true
199
+ end
200
+ end
201
+
202
+ # Should we call a post_process?
203
+ if !@complete && !(@post_process_func.nil?)
204
+ @post_process_func.call(:DIALOG, self,
205
+ @post_process_data, input)
206
+ end
207
+ end
208
+
209
+ unless @complete
210
+ self.drawButtons
211
+ wrefresh(@win)
212
+ self.setExitType(0)
213
+ end
214
+
215
+ @result_data = ret
216
+ return ret
217
+ end
218
+
219
+ # This moves the dialog field to the given location.
220
+ # Inherited
221
+ # def move(xplace, yplace, relative, refresh_flag)
222
+ # end
223
+
224
+ # This function draws the dialog widget.
225
+ def draw(box)
226
+ # Is there a shadow?
227
+ unless @shadow_win.nil?
228
+ Draw.drawShadow(@shadow_win)
229
+ end
230
+
231
+ # Box the widget if they asked.
232
+ if box
233
+ Draw.drawObjBox(@win, self)
234
+ end
235
+
236
+ # Draw in the message.
237
+ (0...@message_rows).each do |x|
238
+ Draw.writeChtype(@win,
239
+ @info_pos[x] + @border_size, x + @border_size, @info[x],
240
+ CDK::HORIZONTAL, 0, @info_len[x])
241
+ end
242
+
243
+ # Draw in the buttons.
244
+ self.drawButtons
245
+
246
+ wrefresh(@win)
247
+ end
248
+
249
+ # This function destroys the dialog widget.
250
+ def destroy
251
+ # Clean up the windows.
252
+ CDK.deleteCursesWindow(@win)
253
+ CDK.deleteCursesWindow(@shadow_win)
254
+
255
+ # Clean the key bindings
256
+ self.cleanBindings(:DIALOG)
257
+
258
+ # Unregister this object
259
+ CDK::SCREEN.unregister(:DIALOG, self)
260
+ end
261
+
262
+ # This function erases the dialog widget from the screen.
263
+ def erase
264
+ if self.validCDKObject
265
+ CDK.eraseCursesWindow(@win)
266
+ CDK.eraseCursesWindow(@shadow_win)
267
+ end
268
+ end
269
+
270
+ # This sets attributes of the dialog box.
271
+ def set(highlight, separator, box)
272
+ self.setHighlight(highlight)
273
+ self.setSeparator(separator)
274
+ self.setBox(box)
275
+ end
276
+
277
+ # This sets the highlight attribute for the buttons.
278
+ def setHighlight(highlight)
279
+ @highlight = highlight
280
+ end
281
+
282
+ def getHighlight
283
+ return @highlight
284
+ end
285
+
286
+ # This sets whether or not the dialog box will have a separator line.
287
+ def setSeparator(separator)
288
+ @separator = separator
289
+ end
290
+
291
+ def getSeparator
292
+ return @separator
293
+ end
294
+
295
+ # This sets the background attribute of the widget.
296
+ def setBKattr(attrib)
297
+ @win.wbkgd(attrib)
298
+ end
299
+
300
+ # This draws the dialog buttons and the separation line.
301
+ def drawButtons
302
+ (0...@button_count).each do |x|
303
+ Draw.writeChtype(@win, @button_pos[x],
304
+ @box_height -1 - @border_size,
305
+ @button_label[x], CDK::HORIZONTAL, 0,
306
+ @button_len[x])
307
+ end
308
+
309
+ # Draw the separation line.
310
+ if @separator
311
+ boxattr = @BXAttr
312
+
313
+ (1...@box_width).each do |x|
314
+ @win.mvwaddch(@box_height - 2 - @border_size, x,
315
+ Ncurses::ACS_HLINE | boxattr)
316
+ end
317
+ @win.mvwaddch(@box_height - 2 - @border_size, 0,
318
+ Ncurses::ACS_LTEE | boxattr)
319
+ @win.mvwaddch(@box_height - 2 - @border_size, @win.getmaxx - 1,
320
+ Ncurses::ACS_RTEE | boxattr)
321
+ end
322
+ Draw.writeChtypeAttrib(@win, @button_pos[@current_button],
323
+ @box_height - 1 - @border_size, @button_label[@current_button],
324
+ @highlight, CDK::HORIZONTAL, 0, @button_len[@current_button])
325
+ end
326
+
327
+ def focus
328
+ self.draw(@box)
329
+ end
330
+
331
+ def unfocus
332
+ self.draw(@box)
333
+ end
334
+
335
+ def object_type
336
+ :DIALOG
337
+ end
338
+
339
+ def position
340
+ super(@win)
341
+ end
342
+ end
343
+ end