~ubuntu-branches/ubuntu/gutsy/blender/gutsy-security

« back to all changes in this revision

Viewing changes to source/blender/python/api2_2x/doc/Draw.py

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ernst
  • Date: 2007-05-17 11:47:59 UTC
  • mfrom: (1.2.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20070517114759-yp4ybrnhp2u7pk66
Tags: 2.44-1
* New upstream release.
* Drop debian/patches/01_64bits_stupidity, not needed anymore: as of this
  version blender is 64 bits safe again. Adjust README.Debian accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
204
204
avoid this, assign created buttons return values to B{global} variables,
205
205
instead of ignoring them.  Examples::
206
206
 
207
 
  # avoid this, it can cause memory leaks:
208
 
  Draw.Toggle(...)
209
 
  Draw.Number(...)
210
 
  Draw.String(...)
211
 
  # this is correct -- assuming the variables are globals:
212
 
  my_toggle_button = Draw.Toggle(...)
213
 
  my_int_button = Draw.Number(...)
214
 
  my_str_button = Draw.String(...)
 
207
        # avoid this, it can cause memory leaks:
 
208
        Draw.Toggle(...)
 
209
        Draw.Number(...)
 
210
        Draw.String(...)
 
211
        # this is correct -- assuming the variables are globals:
 
212
        my_toggle_button = Draw.Toggle(...)
 
213
        my_int_button = Draw.Number(...)
 
214
        my_str_button = Draw.String(...)
215
215
 
216
216
 
217
217
@warn: Inside the windowing loop (after Draw.Register() has been executed and
221
221
"""
222
222
 
223
223
def Exit():
224
 
  """
225
 
  Exit the windowing interface.
226
 
  """
 
224
        """
 
225
        Exit the windowing interface.
 
226
        """
227
227
 
228
228
def BeginAlign():
229
 
  """
230
 
  Buttons after this function will draw aligned (button layout only).
231
 
  """
 
229
        """
 
230
        Buttons after this function will draw aligned (button layout only).
 
231
        """
232
232
 
233
233
def EndAlign():
234
 
  """
235
 
  Use after BeginAlign() to stop aligning the buttons (button layout only).
236
 
  """
 
234
        """
 
235
        Use after BeginAlign() to stop aligning the buttons (button layout only).
 
236
        """
237
237
 
 
238
def UIBlock(draw):
 
239
        """
 
240
        This function creates a popup area where buttons, lebels, sliders etc can be dwarn.
 
241
        
 
242
        @type draw: function
 
243
        @param draw: A function to draw to the popup area, taking no arguments: draw().
 
244
        
 
245
        @note: The size of the popup will expand to fit the bounds of the buttons created in the draw function.
 
246
        @note: Be sure to use the mouse coordinates to position the buttons under the mouse,
 
247
                so the popup dosnt exit as soon as it opens.
 
248
                The coordinates for buttons start 0,0 at the bottom left hand side of the screen.
 
249
        @note: Within this popup, Redraw events and the registered button callback will not work.
 
250
                For buttons to run events, use per button callbacks.
 
251
        @note: OpenGL drawing functions wont work within this popup, for text use L{Label} rather then L{Text}
 
252
        """
 
253
        
238
254
def Register(draw = None, event = None, button = None):
239
 
  """
240
 
  Register callbacks for windowing.
241
 
  @type draw: function
242
 
  @type event: function
243
 
  @type button: function
244
 
  @param draw: A function to draw the screen, taking no arguments: f().
245
 
  @param event: A function to handle keyboard and mouse input events, taking
246
 
      two arguments: f(evt, val), where:
247
 
       - 'evt' (int) is the event number;
248
 
       - 'val' (int) is the value modifier.  If val = 0, the event refers to a
249
 
       key or mouse button being released.  Otherwise it's a key/button press.
250
 
  @param button: A function to handle Draw Button events, taking one argument:
251
 
      f(evt), where:
252
 
        - 'evt' is the button number (see the I{event} parameter in L{Button}).
253
 
  @note: note that in the example at the beginning of this page Draw.Register
254
 
      is called only once.  It's not necessary to re-register the callbacks,
255
 
      they will stay until Draw.Exit is called.  It's enough to redraw the
256
 
      screen, when a relevant event is caught.
257
 
  @note: only during the B{event} callback: the L{Blender}.ascii variable holds
258
 
      the ASCII integer value (if it exists and is valid) of the current event.
259
 
  """
 
255
        """
 
256
        Register callbacks for windowing.
 
257
        @type draw: function
 
258
        @type event: function
 
259
        @type button: function
 
260
        @param draw: A function to draw the screen, taking no arguments: draw().
 
261
        @param event: A function to handle keyboard and mouse input events, taking
 
262
                two arguments: f(evt, val), where:
 
263
                        - 'evt' (int) is the event number;
 
264
                        - 'val' (int) is the value modifier.  If val = 0, the event refers to a
 
265
                        key or mouse button being released.  Otherwise it's a key/button press.
 
266
        @param button: A function to handle Draw Button events, taking one argument:
 
267
                f(evt), where:
 
268
                        - 'evt' is the button number (see the I{event} parameter in L{Button}).
 
269
        @note: note that in the example at the beginning of this page Draw.Register
 
270
                is called only once.  It's not necessary to re-register the callbacks,
 
271
                they will stay until Draw.Exit is called.  It's enough to redraw the
 
272
                screen, when a relevant event is caught.
 
273
        @note: only during the B{event} callback: the L{Blender}.ascii variable holds
 
274
                the ASCII integer value (if it exists and is valid) of the current event.
 
275
        """
260
276
 
261
277
def Redraw(after = 0):
262
 
  """
263
 
  Queue a redraw event.  Redraw events are buffered so that, regardless of how
264
 
  many events are queued, the window only receives one redraw event.
265
 
  @type after: int
266
 
  @param after: If non-zero, the redraw is processed before other input events.
267
 
  """
 
278
        """
 
279
        Queue a redraw event.  Redraw events are buffered so that, regardless of how
 
280
        many events are queued, the window only receives one redraw event.
 
281
        @type after: int
 
282
        @param after: If non-zero, the redraw is processed before other input events.
 
283
        """
268
284
 
269
285
def Draw():
270
 
  """
271
 
  Force an immediate redraw.  Forced redraws are not buffered.  In other words,
272
 
  the window is redrawn once every time this function is called.
273
 
  """
 
286
        """
 
287
        Force an immediate redraw.  Forced redraws are not buffered.  In other words,
 
288
        the window is redrawn once every time this function is called.
 
289
        """
274
290
 
275
291
def Create(value):
276
 
  """
277
 
  Create a default Button object.
278
 
  @type value: int, float, string or 3 floats
279
 
  @param value: The value to store in the button.
280
 
  @rtype: Blender Button
281
 
  @return: The Button created.
282
 
  @note: String values must have less then 400 characters.
283
 
  """
 
292
        """
 
293
        Create a default Button object.
 
294
        @type value: int, float, string or 3 floats
 
295
        @param value: The value to store in the button.
 
296
        @rtype: Blender Button
 
297
        @return: The Button created.
 
298
        @note: String values must have less then 400 characters.
 
299
        """
284
300
 
285
 
def PushButton(name, event, x, y, width, height, tooltip = None):
286
 
  """
287
 
  Create a new (push) Button object.
288
 
  @type name: string
289
 
  @param name: The string to display on the button.
290
 
  @type event: int
291
 
  @param event: The event number to pass to the button event function when
292
 
      activated.
293
 
  @type x: int
294
 
  @type y: int
295
 
  @param x: The lower left x (horizontal) coordinate of the button.
296
 
  @param y: The lower left y (vertical) coordinate of the button.
297
 
  @type width: int
298
 
  @type height: int
299
 
  @param width: The button width.
300
 
  @param height: The button height.
301
 
  @type tooltip: string
302
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
303
 
      is kept over the button).
304
 
  @note: This function used to be called only "Button".  We added an
305
 
     alternative alias to avoid a name clash with the L{Button} class/type that
306
 
     caused trouble in this documentation's generation.  The old name shouldn't
307
 
     be deprecated, use Button or PushButton (better) at your choice.
308
 
  """
 
301
def PushButton(name, event, x, y, width, height, tooltip = None, callback = None):
 
302
        """
 
303
        Create a new (push) Button object.
 
304
        @type name: string
 
305
        @param name: The string to display on the button.
 
306
        @type event: int
 
307
        @param event: The event number to pass to the button event function when
 
308
                activated.
 
309
        @type x: int
 
310
        @type y: int
 
311
        @param x: The lower left x (horizontal) coordinate of the button.
 
312
        @param y: The lower left y (vertical) coordinate of the button.
 
313
        @type width: int
 
314
        @type height: int
 
315
        @param width: The button width.
 
316
        @param height: The button height.
 
317
        @type tooltip: string
 
318
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
319
                is kept over the button).
 
320
        @type callback: function
 
321
        @param callback: an optional argument so this button can have its own
 
322
                callback function. the function will run whenever this button is pressed.
 
323
                This function must accept 2 arguments (event, val).
 
324
        @note: This function used to be called only "Button".  We added an
 
325
                alternative alias to avoid a name clash with the L{Button} class/type that
 
326
                caused trouble in this documentation's generation.  The old name shouldn't
 
327
                be deprecated, use Button or PushButton (better) at your choice.
 
328
        """
309
329
 
310
330
def PupMenu(name, maxrow = None):
311
 
  """
312
 
  Create a pop-up menu.
313
 
 
314
 
  The menu options are specified through the 'name' parameter, like with
315
 
  L{Menu}: options are followed by a format code and separated by the '|'
316
 
  character.  Valid format codes are:
317
 
    - %t - The option should be used as the title of the pop-up;
318
 
    - %l - insert a separating line (only works if 'maxrow' isn't given);
319
 
    - %xB{N} - Chosen this option, PupMenu should return the integer B{N}.
320
 
 
321
 
  Example::
322
 
    name = "OK?%t|QUIT BLENDER"  # if no %xN int is set, indices start from 1
323
 
    result = Draw.PupMenu(name)
324
 
    if result:
325
 
      Draw.PupMenu("Really?%t|Yes|No")
326
 
 
327
 
  @type name: string
328
 
  @param name: The format string to define the contents of the button.
329
 
  @type maxrow: int
330
 
  @param maxrow: The maximum number of rows for each column in the pop-up.
331
 
  @rtype: int
332
 
  @return: the chosen entry number or -1 if none was chosen.
333
 
  """
 
331
        """
 
332
        Create a pop-up menu.
 
333
 
 
334
        The menu options are specified through the 'name' parameter, like with
 
335
        L{Menu}: options are followed by a format code and separated by the '|'
 
336
        character.  Valid format codes are:
 
337
                - %t - The option should be used as the title of the pop-up;
 
338
                - %l - insert a separating line (only works if 'maxrow' isn't given);
 
339
                - %xB{N} - Chosen this option, PupMenu should return the integer B{N}.
 
340
 
 
341
        Example::
 
342
                name = "OK?%t|QUIT BLENDER"  # if no %xN int is set, indices start from 1
 
343
                result = Draw.PupMenu(name)
 
344
                if result:
 
345
                        Draw.PupMenu("Really?%t|Yes|No")
 
346
 
 
347
        @type name: string
 
348
        @param name: The format string to define the contents of the button.
 
349
        @type maxrow: int
 
350
        @param maxrow: The maximum number of rows for each column in the pop-up.
 
351
        @rtype: int
 
352
        @return: the chosen entry number or -1 if none was chosen.
 
353
        """
334
354
 
335
355
def PupIntInput(text, default, min, max):
336
 
  """
337
 
  Create an integer number input pop-up.
338
 
 
339
 
  This allows python to use Blender's integer number pop-up input.
340
 
 
341
 
  Example::
342
 
    default = 50
343
 
    min = 0
344
 
    max = 100
345
 
 
346
 
    msg = "Set this value between 0 and 100"
347
 
    result = Draw.PupIntInput(msg, default, min, max)
348
 
    if result != None:
349
 
      print result
350
 
    else:
351
 
      print 'no user input'
352
 
    
353
 
  @type text: string
354
 
  @param text: The text that is displayed in the pop-up.
355
 
  @type default: int
356
 
  @param default: The value that the pop-up is set to initially.
357
 
  @type min: int
358
 
  @param min: The lowest value the pop-up will allow.
359
 
  @type max: int
360
 
  @param max: The highest value the pop-up will allow.
361
 
  @rtype: int
362
 
  @return: the number chosen or None if none was chosen.
363
 
  """
 
356
        """
 
357
        Create an integer number input pop-up.
 
358
 
 
359
        This allows python to use Blender's integer number pop-up input.
 
360
 
 
361
        Example::
 
362
                default = 50
 
363
                min = 0
 
364
                max = 100
 
365
 
 
366
                msg = "Set this value between 0 and 100"
 
367
                result = Draw.PupIntInput(msg, default, min, max)
 
368
                if result != None:
 
369
                        print result
 
370
                else:
 
371
                        print 'no user input'
 
372
 
 
373
        @type text: string
 
374
        @param text: The text that is displayed in the pop-up.
 
375
        @type default: int
 
376
        @param default: The value that the pop-up is set to initially.
 
377
        @type min: int
 
378
        @param min: The lowest value the pop-up will allow.
 
379
        @type max: int
 
380
        @param max: The highest value the pop-up will allow.
 
381
        @rtype: int
 
382
        @return: the number chosen or None if none was chosen.
 
383
        """
364
384
 
365
385
def PupFloatInput(text, default, min, max, clickStep, floatLen):
366
 
  """
367
 
  Create a floating point number input pop-up.
368
 
  
369
 
  This allows python to use Blender's floating point pop-up input.
370
 
 
371
 
  Example::
372
 
    default = 50
373
 
    min = 0.0
374
 
    max = 10.0
375
 
    clickStep = 100
376
 
    floatLen = 3
377
 
 
378
 
    msg = "Set this value between 0 and 100"
379
 
    result = Draw.PupFloatInput(msg, default, min, max, clickStep, floatLen)
380
 
    if result != None:
381
 
      print result
382
 
    else:
383
 
      print 'no user input'
384
 
    
385
 
  @type text: string
386
 
  @param text: The text that is displayed in the pop-up.
387
 
  @type default: float
388
 
  @param default: The value that the pop-up is set to initially.
389
 
  @type min: float
390
 
  @param min: The lowest value the pop-up will allow.
391
 
  @type max: float
392
 
  @param max: The highest value the pop-up will allow.
393
 
  @type clickStep: int
394
 
  @param clickStep: How much is incremented per user click, 100 will increment 1.0, 10 will increment 0.1 etc.
395
 
  @type floatLen: int
396
 
  @param floatLen: The number of decimal places to display, between 2 and 4.
397
 
  @rtype: float
398
 
  @return: the number chosen or None if none was chosen.
399
 
  """
 
386
        """
 
387
        Create a floating point number input pop-up.
 
388
 
 
389
        This allows python to use Blender's floating point pop-up input.
 
390
 
 
391
        Example::
 
392
                default = 50
 
393
                min = 0.0
 
394
                max = 10.0
 
395
                clickStep = 100
 
396
                floatLen = 3
 
397
 
 
398
                msg = "Set this value between 0 and 100"
 
399
                result = Draw.PupFloatInput(msg, default, min, max, clickStep, floatLen)
 
400
                if result != None:
 
401
                        print result
 
402
                else:
 
403
                        print 'no user input'
 
404
        
 
405
        @type text: string
 
406
        @param text: The text that is displayed in the pop-up.
 
407
        @type default: float
 
408
        @param default: The value that the pop-up is set to initially.
 
409
        @type min: float
 
410
        @param min: The lowest value the pop-up will allow.
 
411
        @type max: float
 
412
        @param max: The highest value the pop-up will allow.
 
413
        @type clickStep: int
 
414
        @param clickStep: How much is incremented per user click, 100 will increment 1.0, 10 will increment 0.1 etc.
 
415
        @type floatLen: int
 
416
        @param floatLen: The number of decimal places to display, between 2 and 4.
 
417
        @rtype: float
 
418
        @return: the number chosen or None if none was chosen.
 
419
        """
400
420
 
401
421
def PupStrInput(text, default, max = 20):
402
 
  """
403
 
  Create a string input pop-up.
404
 
  
405
 
  This allows python to use Blender's string pop-up input.
406
 
 
407
 
  Example::
408
 
    Blender.Draw.PupStrInput("Name:", "untitled", 25)
409
 
    
410
 
  @type text: string
411
 
  @param text: The text that is displayed in the pop-up.
412
 
  @type default: string
413
 
  @param default: The value that the pop-up is set to initially.  If it's longer
414
 
      then 'max', it's truncated.
415
 
  @type max: int
416
 
  @param max: The most characters the pop-up input will allow.  If not given
417
 
      it defaults to 20 chars.  It should be in the range [1, 100].
418
 
  @rtype: string
419
 
  @return: The text entered by the user or None if none was chosen.
420
 
  """
 
422
        """
 
423
        Create a string input pop-up.
 
424
 
 
425
        This allows python to use Blender's string pop-up input.
 
426
 
 
427
        Example::
 
428
                Blender.Draw.PupStrInput("Name:", "untitled", 25)
 
429
        
 
430
        @type text: string
 
431
        @param text: The text that is displayed in the pop-up.
 
432
        @type default: string
 
433
        @param default: The value that the pop-up is set to initially.  If it's longer
 
434
                then 'max', it's truncated.
 
435
        @type max: int
 
436
        @param max: The most characters the pop-up input will allow.  If not given
 
437
                it defaults to 20 chars.  It should be in the range [1, 100].
 
438
        @rtype: string
 
439
        @return: The text entered by the user or None if none was chosen.
 
440
        """
421
441
 
422
442
def PupBlock(title, sequence):
423
443
        """
463
483
        @return: 1 if the pop-up is confirmed, 0 otherwise
464
484
        """
465
485
 
466
 
def Menu(name, event, x, y, width, height, default, tooltip = None):
467
 
  """
468
 
  Create a new Menu Button object.
469
 
  
470
 
  The menu options are specified through the 'name' of the button.  Options are
471
 
  I{followed} by a format code and separated by the '|' (pipe) character.  Valid
472
 
  format codes are:
473
 
    - %t - The option should be used as the title;
474
 
    - %l - Insert a separating line;
475
 
    - %xB{N} - The option should set the integer B{N} in the button value.
476
 
 
477
 
  Example::
478
 
    name = "The Title %t|First Entry %x1|Second Entry %x2|Third Entry %x3"
479
 
    menu = Draw.Menu(name, 2, 60, 120, 200, 40, 3, "Just a test menu.")
480
 
    # note that, since default = 3, the "Third Entry"
481
 
    # will appear as the default choice in the Menu.
482
 
 
483
 
  @type name: string
484
 
  @param name: The format string to define the contents of the button.
485
 
  @type event: int
486
 
  @param event: The event number to pass to the button event function when
487
 
      activated.
488
 
  @type x: int
489
 
  @type y: int
490
 
  @param x: The lower left x (horizontal) coordinate of the button.
491
 
  @param y: The lower left y (vertical) coordinate of the button.
492
 
  @type width: int
493
 
  @type height: int
494
 
  @param width: The button width.
495
 
  @param height: The button height.
496
 
  @type default: int
497
 
  @param default: The number of the option to be selected by default.
498
 
  @type tooltip: string
499
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
500
 
      is kept over the button).
501
 
  @rtype: Blender Button
502
 
  @return: The Button created.
503
 
  """
504
 
 
505
 
def Toggle(name, event, x, y, width, height, default, tooltip = None):
506
 
  """
507
 
  Create a new Toggle Button object.
508
 
  @type name: string
509
 
  @param name: The string to display on the button.
510
 
  @type event: int
511
 
  @param event: The event number to pass to the button event function when
512
 
      activated.
513
 
  @type x: int
514
 
  @type y: int
515
 
  @param x: The lower left x (horizontal) coordinate of the button.
516
 
  @param y: The lower left y (vertical) coordinate of the button.
517
 
  @type width: int
518
 
  @type height: int
519
 
  @param width: The button width.
520
 
  @param height: The button height.
521
 
  @type default: int
522
 
  @param default:  The value specifying the default state:
523
 
      (0 for "up", 1 for "down").
524
 
  @type tooltip: string
525
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
526
 
      is kept over the button).
527
 
  @rtype: Blender Button
528
 
  @return: The Button created.
529
 
  """
 
486
def Menu(name, event, x, y, width, height, default, tooltip = None, callback = None):
 
487
        """
 
488
        Create a new Menu Button object.
 
489
 
 
490
        The menu options are specified through the 'name' of the button.  Options are
 
491
        I{followed} by a format code and separated by the '|' (pipe) character.  Valid
 
492
        format codes are:
 
493
                - %t - The option should be used as the title;
 
494
                - %l - Insert a separating line;
 
495
                - %xB{N} - The option should set the integer B{N} in the button value.
 
496
 
 
497
        Example::
 
498
                name = "The Title %t|First Entry %x1|Second Entry %x2|Third Entry %x3"
 
499
                menu = Draw.Menu(name, 2, 60, 120, 200, 40, 3, "Just a test menu.")
 
500
                # note that, since default = 3, the "Third Entry"
 
501
                # will appear as the default choice in the Menu.
 
502
 
 
503
        @type name: string
 
504
        @param name: The format string to define the contents of the button.
 
505
        @type event: int
 
506
        @param event: The event number to pass to the button event function when
 
507
                activated.
 
508
        @type x: int
 
509
        @type y: int
 
510
        @param x: The lower left x (horizontal) coordinate of the button.
 
511
        @param y: The lower left y (vertical) coordinate of the button.
 
512
        @type width: int
 
513
        @type height: int
 
514
        @param width: The button width.
 
515
        @param height: The button height.
 
516
        @type default: int
 
517
        @param default: The number of the option to be selected by default.
 
518
        @type tooltip: string
 
519
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
520
                is kept over the button).
 
521
        @type callback: function
 
522
        @param callback: an optional argument so this button can have its own
 
523
                callback function. the function will run whenever this button is pressed.
 
524
                This function must accept 2 arguments (event, val).
 
525
        @rtype: Blender Button
 
526
        @return: The Button created.
 
527
        """
 
528
 
 
529
def Toggle(name, event, x, y, width, height, default, tooltip = None, callback = None):
 
530
        """
 
531
        Create a new Toggle Button object.
 
532
        @type name: string
 
533
        @param name: The string to display on the button.
 
534
        @type event: int
 
535
        @param event: The event number to pass to the button event function when
 
536
                activated.
 
537
        @type x: int
 
538
        @type y: int
 
539
        @param x: The lower left x (horizontal) coordinate of the button.
 
540
        @param y: The lower left y (vertical) coordinate of the button.
 
541
        @type width: int
 
542
        @type height: int
 
543
        @param width: The button width.
 
544
        @param height: The button height.
 
545
        @type default: int
 
546
        @param default:  The value specifying the default state:
 
547
                (0 for "up", 1 for "down").
 
548
        @type tooltip: string
 
549
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
550
                is kept over the button).
 
551
        @type callback: function
 
552
        @param callback: an optional argument so this button can have its own
 
553
                callback function. the function will run whenever this button is pressed.
 
554
                This function must accept 2 arguments (event, val).
 
555
        @rtype: Blender Button
 
556
        @return: The Button created.
 
557
        """
530
558
 
531
559
def Slider(name, event, x, y, width, height, initial, min, max, realtime = 1,
532
 
           tooltip = None):
533
 
  """
534
 
  Create a new Slider Button object.
535
 
  @type name: string
536
 
  @param name: The string to display on the button.
537
 
  @type event: int
538
 
  @param event: The event number to pass to the button event function when
539
 
      activated.
540
 
  @type x: int
541
 
  @type y: int
542
 
  @param x: The lower left x (horizontal) coordinate of the button.
543
 
  @param y: The lower left y (vertical) coordinate of the button.
544
 
  @type width: int
545
 
  @type height: int
546
 
  @param width: The button width.
547
 
  @param height: The button height.
548
 
  @type initial: int or float
549
 
  @type min: int or float
550
 
  @type max: int or float
551
 
  @param initial:  The initial value.
552
 
  @param min:  The minimum value.
553
 
  @param max:  The maximum value.
554
 
  @type realtime: int
555
 
  @param realtime: If non-zero (the default), the slider will emit events as
556
 
      it is edited.
557
 
  @type tooltip: string
558
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
559
 
      is kept over the button).
560
 
  @rtype: Blender Button
561
 
  @return: The Button created.
562
 
  """
 
560
                        tooltip = None, callback = None):
 
561
        """
 
562
        Create a new Slider Button object.
 
563
        @type name: string
 
564
        @param name: The string to display on the button.
 
565
        @type event: int
 
566
        @param event: The event number to pass to the button event function when
 
567
                activated.
 
568
        @type x: int
 
569
        @type y: int
 
570
        @param x: The lower left x (horizontal) coordinate of the button.
 
571
        @param y: The lower left y (vertical) coordinate of the button.
 
572
        @type width: int
 
573
        @type height: int
 
574
        @param width: The button width.
 
575
        @param height: The button height.
 
576
        @type initial: int or float
 
577
        @type min: int or float
 
578
        @type max: int or float
 
579
        @param initial:  The initial value.
 
580
        @param min:  The minimum value.
 
581
        @param max:  The maximum value.
 
582
        @type realtime: int
 
583
        @param realtime: If non-zero (the default), the slider will emit events as
 
584
                it is edited.
 
585
        @type tooltip: string
 
586
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
587
                is kept over the button).
 
588
                
 
589
        @type callback: function
 
590
        @param callback: an optional argument so this button can have its own
 
591
                callback function. the function will run whenever this button is pressed.
 
592
                This function must accept 2 arguments (event, val).
 
593
        @rtype: Blender Button
 
594
        @return: The Button created.
 
595
        @note: slider callbacks will not work if the realtime setting is enabled.
 
596
        """
563
597
 
564
598
#def Scrollbar(event, x, y, width, height, initial, min, max, realtime = 1,
565
599
#           tooltip = None):
592
626
#  @return: The Button created.
593
627
#  """
594
628
 
595
 
def ColorPicker(event, x, y, width, height, initial, tooltip = None):
596
 
  """
597
 
  Create a new Color Picker Button object.
598
 
  @type event: int
599
 
  @param event: The event number to pass to the button event function when
600
 
      activated.
601
 
  @type x: int
602
 
  @type y: int
603
 
  @param x: The lower left x (horizontal) coordinate of the button.
604
 
  @param y: The lower left y (vertical) coordinate of the button.
605
 
  @type width: int
606
 
  @type height: int
607
 
  @param width: The button width.
608
 
  @param height: The button height.
609
 
  @type initial: 3-float tuple
610
 
  @param initial:  The initial color value. All values must be between 0 and 1
611
 
  @type tooltip: string
612
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
613
 
      is kept over the button).
614
 
  @rtype: Blender Button
615
 
  @return: The Button created.
616
 
  @note: The color picker will not work if the Register's event function is None.
617
 
  @note: Using the same button variable with more then 1 button at a time will corrupt memory.
618
 
  """
619
 
 
620
 
def Normal(event, x, y, width, height, initial, tooltip = None):
621
 
  """
622
 
  Create a new Normal button, this allows you to set a 3d vector by rotating a sphere.
623
 
  @type event: int
624
 
  @param event: The event number to pass to the button event function when
625
 
      activated.
626
 
  @type x: int
627
 
  @type y: int
628
 
  @param x: The lower left x (horizontal) coordinate of the button.
629
 
  @param y: The lower left y (vertical) coordinate of the button.
630
 
  @type width: int
631
 
  @type height: int
632
 
  @param width: The button width - non square normal buttons .
633
 
  @param height: The button height.
634
 
  @type initial: 3-float tuple
635
 
  @param initial:  The initial vector value.
636
 
  @type tooltip: string
637
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
638
 
      is kept over the button).
639
 
  @rtype: Blender Button
640
 
  @return: The Button created.
641
 
  @note: The normal button will not work if the Register's event function is None.
642
 
  @note: Using the same button variable with more then 1 button at a time will corrupt memory.
643
 
  """
644
 
 
645
 
def Number(name, event, x, y, width, height, initial, min, max, tooltip = None):
646
 
  """
647
 
  Create a new Number Button object.
648
 
  @type name: string
649
 
  @param name: The string to display on the button.
650
 
  @type event: int
651
 
  @param event: The event number to pass to the button event function when
652
 
      activated.
653
 
  @type x: int
654
 
  @type y: int
655
 
  @param x: The lower left x (horizontal) coordinate of the button.
656
 
  @param y: The lower left y (vertical) coordinate of the button.
657
 
  @type width: int
658
 
  @type height: int
659
 
  @param width: The button width.
660
 
  @param height: The button height.
661
 
  @type initial: int or float
662
 
  @type min: int or float
663
 
  @type max: int or float
664
 
  @param initial:  The initial value.
665
 
  @param min:  The minimum value.
666
 
  @param max:  The maximum value.
667
 
  @type tooltip: string
668
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
669
 
      is kept over the button).
670
 
  @rtype: Blender Button
671
 
  @return: The Button created.
672
 
 
673
 
  I{B{Example:}}
674
 
 
675
 
  This example draws a single floating point value::
676
 
    from Blender import Draw
677
 
    b= Draw.Create(0.0) # Data for floating point button
678
 
    def bevent(evt):
679
 
      print 'My Button event:', evt
680
 
    def gui():
681
 
      global b
682
 
      b= Draw.Number('value: ', 1000, 0,0, 200, 20, b.val, 0,10, 'some text tip')
683
 
 
684
 
    Draw.Register(gui, None, bevent) # we are not going to worry about keyboard and mouse events
685
 
  """
686
 
 
687
 
 
688
 
def String(name, event, x, y, width, height, initial, length, tooltip = None):
689
 
  """
690
 
  Create a new String Button object.
691
 
  @type name: string
692
 
  @param name: The string to display on the button.
693
 
  @type event: int
694
 
  @param event: The event number to pass to the button event function when
695
 
      activated.
696
 
  @type x: int
697
 
  @type y: int
698
 
  @param x: The lower left x (horizontal) coordinate of the button.
699
 
  @param y: The lower left y (vertical) coordinate of the button.
700
 
  @type width: int
701
 
  @type height: int
702
 
  @param width: The button width.
703
 
  @param height: The button height.
704
 
  @type initial: string
705
 
  @param initial: The string to display initially.
706
 
  @type length: int
707
 
  @param length: The maximum input length.
708
 
  @type tooltip: string
709
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
710
 
      is kept over the button).
711
 
  @rtype: Blender Button
712
 
  @return: The Button created.
713
 
  """
 
629
def ColorPicker(event, x, y, width, height, initial, tooltip = None, callback = None):
 
630
        """
 
631
        Create a new Color Picker Button object.
 
632
        @type event: int
 
633
        @param event: The event number to pass to the button event function when
 
634
                activated.
 
635
        @type x: int
 
636
        @type y: int
 
637
        @param x: The lower left x (horizontal) coordinate of the button.
 
638
        @param y: The lower left y (vertical) coordinate of the button.
 
639
        @type width: int
 
640
        @type height: int
 
641
        @param width: The button width.
 
642
        @param height: The button height.
 
643
        @type initial: 3-float tuple
 
644
        @param initial:  The initial color value. All values must be between 0 and 1
 
645
        @type tooltip: string
 
646
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
647
                is kept over the button).
 
648
        @type callback: function
 
649
        @param callback: an optional argument so this button can have its own
 
650
                callback function. the function will run whenever this button is pressed.
 
651
                This function must accept 2 arguments (event, val).
 
652
        @rtype: Blender Button
 
653
        @return: The Button created.
 
654
        @note: The color picker will not work if the Register's event function is None.
 
655
        @note: Using the same button variable with more then 1 button at a time will corrupt memory.
 
656
        """
 
657
 
 
658
def Normal(event, x, y, width, height, initial, tooltip = None, callback = None):
 
659
        """
 
660
        Create a new Normal button, this allows you to set a 3d vector by rotating a sphere.
 
661
        @type event: int
 
662
        @param event: The event number to pass to the button event function when
 
663
                activated.
 
664
        @type x: int
 
665
        @type y: int
 
666
        @param x: The lower left x (horizontal) coordinate of the button.
 
667
        @param y: The lower left y (vertical) coordinate of the button.
 
668
        @type width: int
 
669
        @type height: int
 
670
        @param width: The button width - non square normal buttons .
 
671
        @param height: The button height.
 
672
        @type initial: 3-float tuple
 
673
        @param initial:  The initial vector value.
 
674
        @type tooltip: string
 
675
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
676
                is kept over the button).
 
677
        @type callback: function
 
678
        @param callback: an optional argument so this button can have its own
 
679
                callback function. the function will run whenever this button is pressed.
 
680
                This function must accept 2 arguments (event, val).
 
681
        @rtype: Blender Button
 
682
        @return: The Button created.
 
683
        @note: The normal button will not work if the Register's event function is None.
 
684
        @note: Using the same button variable with more then 1 button at a time will corrupt memory.
 
685
        """
 
686
 
 
687
def Number(name, event, x, y, width, height, initial, min, max, tooltip = None, callback = None):
 
688
        """
 
689
        Create a new Number Button object.
 
690
        @type name: string
 
691
        @param name: The string to display on the button.
 
692
        @type event: int
 
693
        @param event: The event number to pass to the button event function when
 
694
                activated.
 
695
        @type x: int
 
696
        @type y: int
 
697
        @param x: The lower left x (horizontal) coordinate of the button.
 
698
        @param y: The lower left y (vertical) coordinate of the button.
 
699
        @type width: int
 
700
        @type height: int
 
701
        @param width: The button width.
 
702
        @param height: The button height.
 
703
        @type initial: int or float
 
704
        @type min: int or float
 
705
        @type max: int or float
 
706
        @param initial:  The initial value.
 
707
        @param min:  The minimum value.
 
708
        @param max:  The maximum value.
 
709
        @type tooltip: string
 
710
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
711
                is kept over the button).
 
712
        @type callback: function
 
713
        @param callback: an optional argument so this button can have its own
 
714
                callback function. the function will run whenever this button is pressed.
 
715
                This function must accept 2 arguments (event, val).
 
716
        @rtype: Blender Button
 
717
        @return: The Button created.
 
718
 
 
719
        I{B{Example:}}
 
720
 
 
721
        This example draws a single floating point value::
 
722
                from Blender import Draw
 
723
                b= Draw.Create(0.0) # Data for floating point button
 
724
                def bevent(evt):
 
725
                        print 'My Button event:', evt
 
726
                def gui():
 
727
                        global b
 
728
                        b= Draw.Number('value: ', 1000, 0,0, 200, 20, b.val, 0,10, 'some text tip')
 
729
 
 
730
                Draw.Register(gui, None, bevent) # we are not going to worry about keyboard and mouse events
 
731
        """
 
732
 
 
733
 
 
734
def String(name, event, x, y, width, height, initial, length, tooltip = None, callback = None):
 
735
        """
 
736
        Create a new String Button object.
 
737
        @type name: string
 
738
        @param name: The string to display on the button.
 
739
        @type event: int
 
740
        @param event: The event number to pass to the button event function when
 
741
                activated.
 
742
        @type x: int
 
743
        @type y: int
 
744
        @param x: The lower left x (horizontal) coordinate of the button.
 
745
        @param y: The lower left y (vertical) coordinate of the button.
 
746
        @type width: int
 
747
        @type height: int
 
748
        @param width: The button width.
 
749
        @param height: The button height.
 
750
        @type initial: string
 
751
        @param initial: The string to display initially.
 
752
        @type length: int
 
753
        @param length: The maximum input length.
 
754
        @type tooltip: string
 
755
        @param tooltip: The button's tooltip (the string that appears when the mouse
 
756
                is kept over the button).
 
757
        @type callback: function
 
758
        @param callback: an optional argument so this button can have its own
 
759
                callback function. the function will run whenever this button is pressed.
 
760
                This function must accept 2 arguments (event, val).
 
761
        @rtype: Blender Button
 
762
        @return: The Button created.
 
763
        """
714
764
 
715
765
def GetStringWidth(string, fontsize = 'normal'):
716
 
  """
717
 
  Get the width in pixels of a string.
718
 
  @type string: string
719
 
  @param string: A string.
720
 
  @type fontsize: string
721
 
  @param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
722
 
  @rtype: int
723
 
  @return: The width of I{string} with the chosen I{fontsize}.
724
 
  """
 
766
        """
 
767
        Get the width in pixels of a string.
 
768
        @type string: string
 
769
        @param string: A string.
 
770
        @type fontsize: string
 
771
        @param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
 
772
        @rtype: int
 
773
        @return: The width of I{string} with the chosen I{fontsize}.
 
774
        """
725
775
 
726
776
def Text(string, fontsize = 'normal'):
727
 
  """
728
 
  Draw a string on the screen.
729
 
 
730
 
  Text location is set using the OpenGL raster location functions L{BGL.glRasterPos} before the text is drawn.
731
 
  This sets the text location from the lower left corner of the current window.
732
 
 
733
 
  Text color is set using the OpenGL color functions L{BGL.glColor} before the text is drawn.
734
 
  
735
 
  @type string: string
736
 
  @param string: The text string to draw.
737
 
  @type fontsize: string
738
 
  @param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
739
 
  @rtype: int
740
 
  @return: The width of I{string} drawn with the chosen I{fontsize}.
741
 
  @note: For drawing text in the 3d view see the workaround in L{BGL.glRasterPos}
742
 
  """
 
777
        """
 
778
        Draw a string on the screen.
 
779
 
 
780
        Text location is set using the OpenGL raster location functions L{BGL.glRasterPos} before the text is drawn.
 
781
        This sets the text location from the lower left corner of the current window.
 
782
 
 
783
        Text color is set using the OpenGL color functions L{BGL.glColor} before the text is drawn.
 
784
 
 
785
        @type string: string
 
786
        @param string: The text string to draw.
 
787
        @type fontsize: string
 
788
        @param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
 
789
        @rtype: int
 
790
        @return: The width of I{string} drawn with the chosen I{fontsize}.
 
791
        @note: For drawing text in the 3d view see the workaround in L{BGL.glRasterPos}
 
792
        """
 
793
 
 
794
def Label(string, x, y, w, h):
 
795
        """
 
796
        Draw a text lable on the screen.
 
797
 
 
798
        @type string: string
 
799
        @param string: The text string to draw.
 
800
        @rtype: None
 
801
        @return: None
 
802
        """
743
803
 
744
804
def Image(image, x, y, zoomx=1.0, zoomy=1.0, clipx=0, clipy=0, clipw=-1, cliph=-1):
745
 
  """
746
 
  Draw an image on the screen.
747
 
 
748
 
  The image is drawn at the location specified by the coordinates (x,y).  A
749
 
  pair of optional zoom factors (in horizontal and vertical directions) can
750
 
  be applied to the image as it is drawn, and an additional clipping rectangle
751
 
  can be applied to extract a particular sub-region of the image to draw.
752
 
 
753
 
  Note that the clipping rectangle is given in image space coordinates.  In
754
 
  image space, the origin is located at the bottom left, with x coordinates 
755
 
  increasing to the right and y coordinates increasing upwards.  No matter 
756
 
  where the clipping rectangle is placed in image space, the lower-left pixel 
757
 
  drawn on the screen is always placed at the coordinates (x,y).  The
758
 
  clipping rectangle is itself clipped to the dimensions of the image.  If
759
 
  either the width or the height of the clipping rectangle are negative then
760
 
  the corresponding dimension (width or height) is set to include as much of 
761
 
  the image as possible.
762
 
  
763
 
  For drawing images with alpha blending with the background you will need to enable blending as shown in the example.
764
 
  
765
 
  
766
 
 
767
 
  Example::
768
 
   import Blender
769
 
   from Blender import BGL, Image, Draw
770
 
 
771
 
   myimage = Image.Load('myimage.png')
772
 
 
773
 
   def gui():
774
 
        BGL.glEnable( BGL.GL_BLEND ) # Only needed for alpha blending images with background.
775
 
        BGL.glBlendFunc(BGL.GL_SRC_ALPHA, BGL.GL_ONE_MINUS_SRC_ALPHA) 
776
 
        
777
 
        Draw.Image(myimage, 50, 50)
778
 
        
779
 
        BGL.glDisable( BGL.GL_BLEND )
780
 
   def event(evt, val):
781
 
        if evt == Draw.ESCKEY:
782
 
              Draw.Exit()
783
 
 
784
 
   Draw.Register(gui, event, None)
785
 
 
786
 
  @type image: Blender.Image
787
 
  @param image: The image to draw.
788
 
  @type x: int
789
 
  @param x: The lower left x (horizontal) position of the origin of the image.
790
 
  @type y: int
791
 
  @param y: The lower left y (vertical) position of the origin of the image.
792
 
  @type zoomx: float
793
 
  @param zoomx: The x (horizontal) zoom factor to use when drawing the image.
794
 
  @type zoomy: float
795
 
  @param zoomy: The y (vertical) zoom factor to use when drawing the image.
796
 
  @type clipx: int
797
 
  @param clipx: The lower left x (horizontal) origin of the clipping rectangle
798
 
                within the image.  A value of 0 indicates the left of the
799
 
                image.
800
 
  @type clipy: int
801
 
  @param clipy: The lower left y (vertical) origin of the clipping rectangle
802
 
                within the image.  A value of 0 indicates the bottom of the
803
 
                image.
804
 
  @type clipw: int
805
 
  @param clipw: The width of the clipping rectangle within the image. If this
806
 
                value is negative then the clipping rectangle includes as much
807
 
                of the image as possible in the x (horizontal) direction.
808
 
  @type cliph: int
809
 
  @param cliph: The height of the clipping rectangle within the image. If this
810
 
                value is negative then the clipping rectangle includes as much
811
 
                of the image as possible in the y (vertical) direction.
812
 
  """
 
805
        """
 
806
        Draw an image on the screen.
 
807
 
 
808
        The image is drawn at the location specified by the coordinates (x,y).  A
 
809
        pair of optional zoom factors (in horizontal and vertical directions) can
 
810
        be applied to the image as it is drawn, and an additional clipping rectangle
 
811
        can be applied to extract a particular sub-region of the image to draw.
 
812
 
 
813
        Note that the clipping rectangle is given in image space coordinates.  In
 
814
        image space, the origin is located at the bottom left, with x coordinates 
 
815
        increasing to the right and y coordinates increasing upwards.  No matter 
 
816
        where the clipping rectangle is placed in image space, the lower-left pixel 
 
817
        drawn on the screen is always placed at the coordinates (x,y).  The
 
818
        clipping rectangle is itself clipped to the dimensions of the image.  If
 
819
        either the width or the height of the clipping rectangle are negative then
 
820
        the corresponding dimension (width or height) is set to include as much of 
 
821
        the image as possible.
 
822
 
 
823
        For drawing images with alpha blending with the background you will need to enable blending as shown in the example.
 
824
        
 
825
        Example::
 
826
                import Blender
 
827
                from Blender import BGL, Image, Draw
 
828
                
 
829
                myimage = Image.Load('myimage.png')
 
830
                
 
831
                def gui():
 
832
                        BGL.glEnable( BGL.GL_BLEND ) # Only needed for alpha blending images with background.
 
833
                        BGL.glBlendFunc(BGL.GL_SRC_ALPHA, BGL.GL_ONE_MINUS_SRC_ALPHA) 
 
834
                
 
835
                        Draw.Image(myimage, 50, 50)
 
836
                
 
837
                        BGL.glDisable( BGL.GL_BLEND )
 
838
                def event(evt, val):
 
839
                        if evt == Draw.ESCKEY:
 
840
                                Draw.Exit()
 
841
                
 
842
                Draw.Register(gui, event, None)
 
843
 
 
844
        @type image: Blender.Image
 
845
        @param image: The image to draw.
 
846
        @type x: int
 
847
        @param x: The lower left x (horizontal) position of the origin of the image.
 
848
        @type y: int
 
849
        @param y: The lower left y (vertical) position of the origin of the image.
 
850
        @type zoomx: float
 
851
        @param zoomx: The x (horizontal) zoom factor to use when drawing the image.
 
852
        @type zoomy: float
 
853
        @param zoomy: The y (vertical) zoom factor to use when drawing the image.
 
854
        @type clipx: int
 
855
        @param clipx: The lower left x (horizontal) origin of the clipping rectangle
 
856
                                  within the image.  A value of 0 indicates the left of the
 
857
                                  image.
 
858
        @type clipy: int
 
859
        @param clipy: The lower left y (vertical) origin of the clipping rectangle
 
860
                                  within the image.  A value of 0 indicates the bottom of the
 
861
                                  image.
 
862
        @type clipw: int
 
863
        @param clipw: The width of the clipping rectangle within the image. If this
 
864
                                  value is negative then the clipping rectangle includes as much
 
865
                                  of the image as possible in the x (horizontal) direction.
 
866
        @type cliph: int
 
867
        @param cliph: The height of the clipping rectangle within the image. If this
 
868
                                  value is negative then the clipping rectangle includes as much
 
869
                                  of the image as possible in the y (vertical) direction.
 
870
        """
813
871
 
814
872
class Button:
815
 
  """
816
 
  The Button object
817
 
  =================
818
 
    This object represents a button in Blender's GUI.
819
 
  @type val: int or float, string or 3-float tuple (depends on button type).
820
 
  @ivar val: The button's value.
821
 
  """
 
873
        """
 
874
        The Button object
 
875
        =================
 
876
                This object represents a button in Blender's GUI.
 
877
        @type val: int or float, string or 3-float tuple (depends on button type).
 
878
        @ivar val: The button's value.
 
879
        """