~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: 2005-11-06 12:40:03 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051106124003-3pgs7tcg5rox96xg
Tags: 2.37a-1.1
* Non-maintainer upload.
* Split out parts of 01_SConstruct_debian.dpatch again: root_build_dir
  really needs to get adjusted before the clean target runs - closes: #333958,
  see #288882 for reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
Draw
7
7
====
8
8
 
 
9
B{New}:
 
10
 - access to ascii values in L{events<Register>} callbacks;
 
11
 - 'large' fonts for L{Text} and L{GetStringWidth}.
 
12
 
9
13
This module provides access to a B{windowing interface} in Blender.  Its widgets
10
14
include many kinds of buttons: push, toggle, menu, number, string, slider,
11
15
scrollbar, plus support for text drawing.  It also includes keyboard keys and
12
 
mouse button code values in its dictionary (print dir(Blender.Draw)).
 
16
mouse button code values in its dictionary, see a list after this example.
13
17
 
14
18
Example::
15
19
 import Blender
68
72
 
69
73
 Draw.Register(gui, event, button_event)  # registering the 3 callbacks
70
74
 
71
 
@note: The example above was fixed to call Draw.Register only once.  It's
72
 
not necessary to re-register the callbacks, they will stay until Draw.Exit
73
 
is called.  It's enough to redraw the screen when a relevant event is caught.
74
 
Apologies for the confusion.
 
75
All available events:
 
76
  - ACCENTGRAVEKEY
 
77
  - AKEY
 
78
  - BACKSLASHKEY
 
79
  - BACKSPACEKEY
 
80
  - BKEY
 
81
  - CAPSLOCKKEY
 
82
  - CKEY
 
83
  - COMMAKEY
 
84
  - DELKEY
 
85
  - DKEY
 
86
  - DOWNARROWKEY
 
87
  - EIGHTKEY
 
88
  - EKEY
 
89
  - ENDKEY
 
90
  - EQUALKEY
 
91
  - ESCKEY
 
92
  - F10KEY
 
93
  - F11KEY
 
94
  - F12KEY
 
95
  - F1KEY
 
96
  - F2KEY
 
97
  - F3KEY
 
98
  - F4KEY
 
99
  - F5KEY
 
100
  - F6KEY
 
101
  - F7KEY
 
102
  - F8KEY
 
103
  - F9KEY
 
104
  - FIVEKEY
 
105
  - FKEY
 
106
  - FOURKEY
 
107
  - GKEY
 
108
  - HKEY
 
109
  - HOMEKEY
 
110
  - IKEY
 
111
  - INPUTCHANGE
 
112
  - INSERTKEY
 
113
  - JKEY
 
114
  - KEYBD
 
115
  - KKEY
 
116
  - LEFTALTKEY
 
117
  - LEFTARROWKEY
 
118
  - LEFTBRACKETKEY
 
119
  - LEFTCTRLKEY
 
120
  - LEFTMOUSE
 
121
  - LEFTSHIFTKEY
 
122
  - LINEFEEDKEY
 
123
  - LKEY
 
124
  - MIDDLEMOUSE
 
125
  - MINUSKEY
 
126
  - MKEY
 
127
  - MOUSEX
 
128
  - MOUSEY
 
129
  - NINEKEY
 
130
  - NKEY
 
131
  - OKEY
 
132
  - ONEKEY
 
133
  - PAD0
 
134
  - PAD1
 
135
  - PAD2
 
136
  - PAD3
 
137
  - PAD4
 
138
  - PAD5
 
139
  - PAD6
 
140
  - PAD7
 
141
  - PAD8
 
142
  - PAD9
 
143
  - PADASTERKEY
 
144
  - PADENTER
 
145
  - PADMINUS
 
146
  - PADPERIOD
 
147
  - PADPLUSKEY
 
148
  - PADSLASHKEY
 
149
  - PAGEDOWNKEY
 
150
  - PAGEUPKEY
 
151
  - PAUSEKEY
 
152
  - PERIODKEY
 
153
  - PKEY
 
154
  - QFULL
 
155
  - QKEY
 
156
  - QUOTEKEY
 
157
  - Q_FIRSTTIME
 
158
  - RAWKEYBD
 
159
  - REDRAW
 
160
  - RETKEY
 
161
  - RIGHTALTKEY
 
162
  - RIGHTARROWKEY
 
163
  - RIGHTBRACKETKEY
 
164
  - RIGHTCTRLKEY
 
165
  - RIGHTMOUSE
 
166
  - RIGHTSHIFTKEY
 
167
  - RKEY
 
168
  - SEMICOLONKEY
 
169
  - SEVENKEY
 
170
  - SIXKEY
 
171
  - SKEY
 
172
  - SLASHKEY
 
173
  - SPACEKEY
 
174
  - TABKEY
 
175
  - THREEKEY
 
176
  - TIMER0
 
177
  - TIMER1
 
178
  - TIMER2
 
179
  - TIMER3
 
180
  - TKEY
 
181
  - TWOKEY
 
182
  - UKEY
 
183
  - UPARROWKEY
 
184
  - VKEY
 
185
  - WHEELDOWNMOUSE
 
186
  - WHEELUPMOUSE
 
187
  - WINCLOSE
 
188
  - WINFREEZE
 
189
  - WINQUIT
 
190
  - WINTHAW
 
191
  - WKEY
 
192
  - XKEY
 
193
  - YKEY
 
194
  - ZEROKEY
 
195
  - ZKEY
 
196
 
 
197
@note: function Button has an alias: L{PushButton}.
 
198
 
 
199
@warn: B{very important}: if using your script causes "Error totblock"
 
200
messages when Blender exits (meaning that memory has been leaked), this may
 
201
have been caused by an ignored return value from one of the button types.  To
 
202
avoid this, assign created buttons return values to B{global} variables,
 
203
instead of ignoring them.  Examples::
 
204
 
 
205
  # avoid this, it can cause memory leaks:
 
206
  Draw.Toggle(...)
 
207
  Draw.Number(...)
 
208
  Draw.String(...)
 
209
  # this is correct -- assuming the variables are globals:
 
210
  my_toggle_button = Draw.Toggle(...)
 
211
  my_int_button = Draw.Number(...)
 
212
  my_str_button = Draw.String(...)
 
213
 
75
214
 
76
215
@warn: Inside the windowing loop (after Draw.Register() has been executed and
77
216
before Draw.Exit() is called), don't use the redraw functions from other
99
238
  @param button: A function to handle Draw Button events, taking one argument:
100
239
      f(evt), where:
101
240
        - 'evt' is the button number (see the I{event} parameter in L{Button}).
 
241
  @note: note that in the example at the beginning of this page Draw.Register
 
242
      is called only once.  It's not necessary to re-register the callbacks,
 
243
      they will stay until Draw.Exit is called.  It's enough to redraw the
 
244
      screen, when a relevant event is caught.
 
245
  @note: only during the B{event} callback: the L{Blender}.ascii variable holds
 
246
      the ascii integer value (if it exists and is valid) of the current event.
102
247
  """
103
248
 
104
249
def Redraw(after = 0):
124
269
  @return: The Button created.
125
270
  """
126
271
 
127
 
def Button(name, event, x, y, width, height, tooltip = None):
 
272
def PushButton(name, event, x, y, width, height, tooltip = None):
128
273
  """
129
274
  Create a new (push) Button object.
130
275
  @type name: string
143
288
  @type tooltip: string
144
289
  @param tooltip: The button's tooltip (the string that appears when the mouse
145
290
      is kept over the button).
 
291
  @note: This function used to be called only "Button".  We added an
 
292
     alternative alias to avoid a name clash with the L{Button} class/type that
 
293
     caused trouble in this documentation's generation.  The old name shouldn't
 
294
     be deprecated, use Button or PushButton (better) at your choice.
146
295
  """
147
296
 
148
297
def PupMenu(name, maxrow = None):
170
319
  @return: the chosen entry number or -1 if none was chosen.
171
320
  """
172
321
 
 
322
def PupIntInput(text, default, min, max):
 
323
  """
 
324
  Create an integer number input pop-up.
 
325
 
 
326
  This allows python to use Blender's integer number popup input.
 
327
 
 
328
  Example::
 
329
    default = 50
 
330
    min = 0
 
331
    max = 100
 
332
 
 
333
    msg = "Set this value between 0 and 100"
 
334
    result = Draw.PupIntInput(msg, default, min, max)
 
335
    if result != None:
 
336
      print result
 
337
    else:
 
338
      print 'no user input'
 
339
    
 
340
  @type text: string
 
341
  @param text: The text that is displayed in the popup.
 
342
  @type default: int
 
343
  @param default: The value that the popup is set to initially.
 
344
  @type min: int
 
345
  @param min: The lowest value the popup will allow.
 
346
  @type max: int
 
347
  @param max: The highest value the popup will allow.
 
348
  @rtype: int
 
349
  @return: the number chosen or None if none was chosen.
 
350
  """
 
351
 
 
352
def PupFloatInput(text, default, min, max, clickStep, floatLen):
 
353
  """
 
354
  Create a floating point number input pop-up.
 
355
  
 
356
  This allows python to use Blender's floating point popup input.
 
357
 
 
358
  Example::
 
359
    default = 50
 
360
    min = 0.0
 
361
    max = 10.0
 
362
    clickStep = 100
 
363
    floatLen = 3
 
364
 
 
365
    msg = "Set this value between 0 and 100"
 
366
    result = Draw.PupFloatInput(msg, default, min, max, clickStep, floatLen)
 
367
    if result != None:
 
368
      print result
 
369
    else:
 
370
      print 'no user input'
 
371
    
 
372
  @type text: string
 
373
  @param text: The text that is displayed in the popup.
 
374
  @type default: float
 
375
  @param default: The value that the popup is set to initially.
 
376
  @type min: float
 
377
  @param min: The lowest value the popup will allow.
 
378
  @type max: float
 
379
  @param max: The highest value the popup will allow.
 
380
  @type clickStep: int
 
381
  @param clickStep: How much is incremented per user click, 100 will increment 1.0, 10 will increment 0.1 etc.
 
382
  @type floatLen: int
 
383
  @param floatLen: The number of decimal places to display, between 2 and 4.
 
384
  @rtype: float
 
385
  @return: the number chosen or None if none was chosen.
 
386
  """
 
387
 
 
388
def PupStrInput(text, default, max = 20):
 
389
  """
 
390
  Create a string input pop-up.
 
391
  
 
392
  This allows python to use Blender's string popup input.
 
393
 
 
394
  Example::
 
395
    Blender.Draw.PupStrInput("Name:", "untitled", 25)
 
396
    
 
397
  @type text: string
 
398
  @param text: The text that is displayed in the popup.
 
399
  @type default: string
 
400
  @param default: The value that the popup is set to initially.  If it's longer
 
401
      then 'max', it's truncated.
 
402
  @type max: int
 
403
  @param max: The most characters the popup input will allow.  If not given
 
404
      it defaults to 20 chars.  It should be in the range [1, 100].
 
405
  @rtype: string
 
406
  @return: The text entered by the user or None if none was chosen.
 
407
  """
 
408
 
173
409
def Menu(name, event, x, y, width, height, default, tooltip = None):
174
410
  """
175
411
  Create a new Menu Button object.
238
474
def Slider(name, event, x, y, width, height, initial, min, max, realtime = 1,
239
475
           tooltip = None):
240
476
  """
241
 
  Create a new Toggle Button object.
 
477
  Create a new Slider Button object.
242
478
  @type name: string
243
479
  @param name: The string to display on the button.
244
480
  @type event: int
268
504
  @return: The Button created.
269
505
  """
270
506
 
271
 
def Scrollbar(event, x, y, width, height, initial, min, max, realtime = 1,
272
 
           tooltip = None):
273
 
  """
274
 
  Create a new Scrollbar Button object.
275
 
  @type event: int
276
 
  @param event: The event number to pass to the button event function when
277
 
      activated.
278
 
  @type x: int
279
 
  @type y: int
280
 
  @param x: The lower left x (horizontal) coordinate of the button.
281
 
  @param y: The lower left y (vertical) coordinate of the button.
282
 
  @type width: int
283
 
  @type height: int
284
 
  @param width: The button width.
285
 
  @param height: The button height.
286
 
  @type initial: int or float
287
 
  @type min: int or float
288
 
  @type max: int or float
289
 
  @param initial:  The initial value.
290
 
  @param min:  The minimum value.
291
 
  @param max:  The maximum value.
292
 
  @type realtime: int
293
 
  @param realtime: If non-zero (the default), the slider will emit events as
294
 
      it is edited.
295
 
  @type tooltip: string
296
 
  @param tooltip: The button's tooltip (the string that appears when the mouse
297
 
      is kept over the button).
298
 
  @rtype: Blender Button
299
 
  @return: The Button created.
300
 
  """
 
507
#def Scrollbar(event, x, y, width, height, initial, min, max, realtime = 1,
 
508
#           tooltip = None):
 
509
#  """
 
510
#  Create a new Scrollbar Button object.
 
511
#  @type event: int
 
512
#  @param event: The event number to pass to the button event function when
 
513
#      activated.
 
514
#  @type x: int
 
515
#  @type y: int
 
516
#  @param x: The lower left x (horizontal) coordinate of the button.
 
517
#  @param y: The lower left y (vertical) coordinate of the button.
 
518
#  @type width: int
 
519
#  @type height: int
 
520
#  @param width: The button width.
 
521
#  @param height: The button height.
 
522
#  @type initial: int or float
 
523
#  @type min: int or float
 
524
#  @type max: int or float
 
525
#  @param initial:  The initial value.
 
526
#  @param min:  The minimum value.
 
527
#  @param max:  The maximum value.
 
528
#  @type realtime: int
 
529
#  @param realtime: If non-zero (the default), the slider will emit events as
 
530
#      it is edited.
 
531
#  @type tooltip: string
 
532
#  @param tooltip: The button's tooltip (the string that appears when the mouse
 
533
#      is kept over the button).
 
534
#  @rtype: Blender Button
 
535
#  @return: The Button created.
 
536
#  """
301
537
 
302
 
def Number(name, event, x, y, width, height, initial, min, max, realtime = 1,
303
 
           tooltip = None):
 
538
def Number(name, event, x, y, width, height, initial, min, max, tooltip = None):
304
539
  """
305
540
  Create a new Number Button object.
306
541
  @type name: string
322
557
  @param initial:  The initial value.
323
558
  @param min:  The minimum value.
324
559
  @param max:  The maximum value.
325
 
  @type realtime: int
326
 
  @param realtime: If non-zero (the default), the slider will emit events as
327
 
      it is edited.
328
560
  @type tooltip: string
329
561
  @param tooltip: The button's tooltip (the string that appears when the mouse
330
562
      is kept over the button).
366
598
  @type string: string
367
599
  @param string: A string.
368
600
  @type fontsize: string
369
 
  @param fontsize: The size of the font: 'normal', 'small' or 'tiny'.
 
601
  @param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
370
602
  @rtype: int
371
603
  @return: The width of I{string} with the chosen I{fontsize}.
372
604
  """
377
609
  @type string: string
378
610
  @param string: The text string to draw.
379
611
  @type fontsize: string
380
 
  @param fontsize: The size of the font: 'normal', 'small' or 'tiny'.
 
612
  @param fontsize: The size of the font: 'large', 'normal', 'small' or 'tiny'.
381
613
  @rtype: int
382
614
  @return: The width of I{string} drawn with the chosen I{fontsize}.
383
615
  """
384
616
 
 
617
def Image(image, x, y, zoomx=1.0, zoomy=1.0, clipx=0, clipy=0, clipw=-1, cliph=-1):
 
618
  """
 
619
  Draw an image on the screen.
 
620
 
 
621
  The image is drawn at the location specified by the coordinates (x,y).  A
 
622
  pair of optional zoom factors (in horizontal and vertical directions) can
 
623
  be applied to the image as it is drawn, and an additional clipping rectangle
 
624
  can be applied to extract a particular sub-region of the image to draw.
 
625
 
 
626
  Note that the clipping rectangle is given in image space coordinates.  In
 
627
  image space, the origin is located at the bottom left, with x coordinates 
 
628
  increasing to the right and y coordinates increasing upwards.  No matter 
 
629
  where the clipping rectangle is placed in image space, the lower-left pixel 
 
630
  drawn on the screen is always placed at the coordinates (x,y).  The
 
631
  clipping rectangle is itself clipped to the dimensions of the image.  If
 
632
  either the width or the height of the clipping rectangle are negative then
 
633
  the corresponding dimension (width or height) is set to include as much of 
 
634
  the image as possible.
 
635
 
 
636
  Example::
 
637
   import Blender
 
638
   from Blender import BGL, Image, Draw
 
639
 
 
640
   myimage = Image.Load('myimage.png')
 
641
 
 
642
   def gui():
 
643
        Draw.Image(myimage, 50, 50)
 
644
   def event(evt, val):
 
645
        if evt == Draw.ESCKEY:
 
646
              Draw.Exit()
 
647
 
 
648
   Draw.Register(gui, event, None)
 
649
 
 
650
  @type image: Blender.Image
 
651
  @param image: The image to draw.
 
652
  @type x: int
 
653
  @param x: The lower left x (horizontal) position of the origin of the image.
 
654
  @type y: int
 
655
  @param y: The lower left y (vertical) position of the origin of the image.
 
656
  @type zoomx: float
 
657
  @param zoomx: The x (horizontal) zoom factor to use when drawing the image.
 
658
  @type zoomy: float
 
659
  @param zoomy: The y (vertical) zoom factor to use when drawing the image.
 
660
  @type clipx: int
 
661
  @param clipx: The lower left x (horizontal) origin of the clipping rectangle
 
662
                within the image.  A value of 0 indicates the left of the
 
663
                image.
 
664
  @type clipy: int
 
665
  @param clipy: The lower left y (vertical) origin of the clipping rectangle
 
666
                within the image.  A value of 0 indicates the bottom of the
 
667
                image.
 
668
  @type clipw: int
 
669
  @param clipw: The width of the clipping rectangle within the image. If this
 
670
                value is negative then the clipping rectangle includes as much
 
671
                of the image as possible in the x (horizontal) direction.
 
672
  @type cliph: int
 
673
  @param cliph: The height of the clipping rectangle within the image. If this
 
674
                value is negative then the clipping rectangle includes as much
 
675
                of the image as possible in the y (vertical) direction.
 
676
  """
 
677
 
385
678
class Button:
386
679
  """
387
680
  The Button object
388
681
  =================
389
682
    This object represents a button in Blender's GUI.
390
683
  @type val: int or float or string (depends on button type).
391
 
  @cvar val: The button's value.
 
684
  @ivar val: The button's value.
392
685
  """