Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
dialog_box Namespace Reference

Data Structures

class  DialogBox
 

Functions

def parse_dialog_box
 
def makeRect
 
def fromValues
 
def dialog
 
def custom_run_dialog
 
def button_row
 
def alert
 
def confirm
 

Variables

float text_height = 0.1
 
float font_size = 1.0
 
float list_height = 0.0
 
tuple screen_color = GUI.GUIColor(200/255.0, 220/255.0 ,210/255.0)
 
tuple input_color = GUI.GUIColor(25/255.0, 25/255.0 ,75/255.0)
 
tuple screen_bgcolor = GUI.GUIColor(0.9,0.9,1.0,0.7)
 
tuple screen_bgcolor_nc = GUI.GUIColor(0.1,0.0,0.4)
 

Function Documentation

def dialog_box.alert (   message,
  callback = None,
  width = 1.0,
  buttonText = 'OK' 
)

Definition at line 420 of file dialog_box.py.

References button_row(), pydoc.callback, dialog(), and custom.respond().

421 def alert(message, callback=None, width=1.0, buttonText='OK'):
422  def dbcallback(db,data):
423  db.undraw()
424  custom.respond(["close"],None,db.id)
425  if callback:
426  return callback()
427 
428  dialog(["width",width, "text",message] + button_row(width, buttonText), dbcallback)
def dialog_box.button_row (   width,
  buttons 
)

Definition at line 402 of file dialog_box.py.

403 def button_row(width, *buttons):
404  items = ["height",0.05,"row"]
405  if len(buttons)==1:
406  items += ["width",(width-0.25)/2.,
407  "button",buttons[0],
408  "width",(width-0.25)/2.]
409  elif len(buttons)==2:
410  items += ["button",buttons[0],"width",(width-0.5),"button",buttons[1]]
411  elif len(buttons)==3:
412  items += ["button",buttons[0],"width",(width-0.75)/2.,
413  "button",buttons[1],"width",(width-0.75)/2.,
414  "button",buttons[2]]
415  else:
416  for b in buttons:
417  items += ["button",b]
418  items += ["endrow"]
419  return items
def dialog_box.confirm (   message,
  callback,
  width = 1.0,
  buttons = ('Cancel','OK' 
)

Definition at line 429 of file dialog_box.py.

References custom.add(), button_row(), pydoc.callback, dialog(), and custom.respond().

430 def confirm(message, callback, width=1.0, buttons=('Cancel','OK')):
431  def dbcallback(db,data):
432  db.undraw()
433  custom.respond(["close"],None,db.id)
434  arg = False
435  if data[0]!=buttons[0] and data[0]!="Cancel":
436  arg = data[0]
437  if callback:
438  return callback(arg)
439 
440  dialog(["width",width, "text",message] + button_row(width, *buttons), dbcallback)
441 
442 
443 custom.add("dialog_box",custom_run_dialog)
444 
445 
def dialog_box.custom_run_dialog (   local,
  cmd,
  args,
  id 
)

Definition at line 389 of file dialog_box.py.

References dialog(), and custom.respond().

390 def custom_run_dialog(local, cmd, args, id):
391  if VS.isserver():
392  return
393 
394  def myCallback(db,data):
395  def serverCallback(data):
396  if data[0]=='close':
397  db.undraw()
398 
399  custom.respond(data,serverCallback,id)
400  dialog(args, myCallback, Base.GetCurRoom())
401 
def dialog_box.dialog (   args,
  callback,
  room = None 
)

Definition at line 373 of file dialog_box.py.

References pydoc.callback, GUI.GUIInit(), parse_dialog_box(), and custom.run().

374 def dialog(args, callback, room=None):
375  global _gui_has_initted
376 
377  db = DialogBox(parse_dialog_box(args),callback)
378  if VS.isserver():
379  db.id = custom.run("dialog_box",args,lambda data:callback(db,data))
380  return db.id
381  if not room:
382  room=Base.GetCurRoom()
383  if not _gui_has_initted:
384  GUI.GUIInit(320,200)
385  _gui_has_initted=True
386  db.create(room)
387  db.draw()
388  GUI.GUIRootSingleton.broadcastMessage('draw',None)
def dialog_box.fromValues (   data)

Definition at line 362 of file dialog_box.py.

363 def fromValues(data):
364  action = data[0]
365  i=1
366  inputs={}
367  while i<len(data):
368  inputs[data[i]] = data[i+1]
369  i+=2
370  return action, inputs
371 
372 _gui_has_initted=False
def dialog_box.makeRect (   x,
  y,
  wid,
  hei 
)

Definition at line 82 of file dialog_box.py.

82 
83 def makeRect(x,y,wid,hei):
84  return GUI.GUIRect(x,y,wid,hei,'normalized_biased_scaled')
def dialog_box.parse_dialog_box (   args)

Definition at line 9 of file dialog_box.py.

References debug.debug, and locale.str().

9 
10 def parse_dialog_box(args):
11  i=0
12  elementsToCreate=[]
13  currentList=elementsToCreate
14  while i<len(args):
15  type=args[i]
16  i+=1
17  if type=='list':
18  id=str(args[i])
19  jlen=int(args[i+1])
20  i+=2
21  listitems=args[i:i+jlen]
22  i+=jlen
23  currentList.append(DialogBox.List(id,listitems))
24  elif type=='space' or type=='width' or type=='height':
25  if type=='height':
26  wid=0.
27  else:
28  wid=float(args[i])
29  i+=1
30  if type=='width':
31  hei=0.
32  else:
33  hei=float(args[i])
34  i+=1
35  currentList.append(DialogBox.Space(wid,hei))
36  elif type=='button' or type=='buttonspr':
37  id=str(args[i])
38  i+=1
39  if type=='buttonspr':
40  sprite=str(args[i])
41  width=float(args[i+1])
42  height=float(args[i+2])
43  i+=3
44  name=id
45  else:
46  name=id #args[i]
47  #i+=1
48  width=0.
49  height=text_height
50  sprite=None
51  currentList.append(DialogBox.Button(id,name,sprite,width,height))
52  elif type=='text' or type=="textwidth":
53  text=str(args[i])
54  i+=1
55  wid=0.
56  if type=="textwidth":
57  wid=float(args[i])
58  i+=1
59  currentList.append(DialogBox.Text(text,wid))
60  elif type=='textinput':
61  id=str(args[i])
62  initialvalue=str(args[i+1])
63  i+=2
64  currentList.append(DialogBox.TextInput(id,initialvalue))
65  elif type=='endrow':
66  currentList=elementsToCreate
67  elif type=='row':
68  currentList=[]
69  elementsToCreate.append(DialogBox.Row(currentList))
70  else:
71  debug.debug("Unknown dialog item type "+str(type))
72  return elementsToCreate

Variable Documentation

float font_size = 1.0

Definition at line 74 of file dialog_box.py.

tuple input_color = GUI.GUIColor(25/255.0, 25/255.0 ,75/255.0)

Definition at line 78 of file dialog_box.py.

float list_height = 0.0

Definition at line 76 of file dialog_box.py.

tuple screen_bgcolor = GUI.GUIColor(0.9,0.9,1.0,0.7)

Definition at line 79 of file dialog_box.py.

tuple screen_bgcolor_nc = GUI.GUIColor(0.1,0.0,0.4)

Definition at line 80 of file dialog_box.py.

tuple screen_color = GUI.GUIColor(200/255.0, 220/255.0 ,210/255.0)

Definition at line 77 of file dialog_box.py.

tuple text_height = 0.1

Definition at line 7 of file dialog_box.py.