本文整理汇总了Python中gui.Gui.draw方法的典型用法代码示例。如果您正苦于以下问题:Python Gui.draw方法的具体用法?Python Gui.draw怎么用?Python Gui.draw使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gui.Gui
的用法示例。
在下文中一共展示了Gui.draw方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import draw [as 别名]
#.........这里部分代码省略.........
pb=ProgressBar(100.0)
pb.setBaseColor( Color(255,255,0) )
pb.setForegroundColor( Color(0,255,255) )
pb.setSize(100, 20)
pb.setPosition(300, 300)
pb.setValue(50.0)
c.add(w,0,100)
c.add(b)
c.add(b2)
c.add(xyz,10,10)
c.add(pb)
check=Checkbox("Ye what? GET BACK HERE BOY!")
check.setActionEventId("Checkbox")
check.addActionListener(a)
text=TextField("Hey Hey Hey Hey Hey Hey Hey Hey")
text.setBackgroundColor( Color(255,255,255,255) )
text.setMaxSize(150)
text2=TextBox("Hey, HeyTrapped in a window!\nWhat's goin' onTrapped in a window!\ntodays???Trapped in a window!")
text2.setTabSize(10)
sc=ScrollArea(text2)
sc.setSize(200,100)
rBox=Container()
r1=RadioButton("1984","Dystopia")
r2=RadioButton("Fahrenheit 451","Dystopia")
r3=RadioButton("Brave New World","Dystopia")
rBox.add(r1,0,0)
rBox.add(r2,0,r1.getY()+r1.getHeight())
rBox.add(r3,0,r2.getY()+r2.getHeight())
label=Label("WE AIN'T GOT IT")
ico_image=Image.load("C:\Python25\Projects\Guichan\May.bmp")
ico=Icon(ico_image)
lb=ListBox( List_ListModel(["Bollocks!","Never!","Cuppa tea, mate?","Hello!","Goodbye!","OK Computer!","Oh Inverted World!","How To Disappear Completely!","Hold Still!","It Takes A Train To Cry!","A","B","C","D","E","F","G","H","I",]) )
sc2=ScrollArea(lb)
sc2.setSize(125,100)
lb.setWidth(110)
slider=Slider(0,100)
slider.setOrientation(Slider.Orientation.VERTICAL)
slider.setSize(15,100)
slider.setActionEventId("Slider")
#slider.addActionListener(a)
ib=ImageButton(ico_image)
ta=TabbedArea()
c.add(w2)
ta.addTab("Text",[ (text,0,0), (sc,0,50) ])
ta.addTab("Check",check)
ta.addTab("Radio",rBox)
ta.addTab("List",[ (sc2,0,0) ])
ta.addTab("Label",label)
ta.addTab("Icon",[ (ico,0,0), (ib,100,0) ])
ta.addTab("Slider",slider)
ta.setSize(300,300)
w2.add(ta,0,0)
g.setGraphics(gr)
w2.resizeToContent()
w.setSize(300,300)
g.setInput(i)
g.setTop(c)
clock=pygame.time.Clock()
g.mDirtyRect.addRect( Rectangle(0,0,640,480) )
done=False
while done == False:
clock.tick(0)
for event in pygame.event.get():
if event.type==KEYDOWN:
if event.key == K_ESCAPE:
c.remove(b)
c.remove(b2)
done=True
elif event.key == K_RETURN:
w=Window("It'a window!")
w.add(Checkbox("Kool thing"))
w.resizeToContent()
c.add(w, 10, 10)
elif event.key == K_LEFT:
pb.setValue( pb.getValue()-1.0 )
elif event.key == K_RIGHT:
pb.setValue( pb.getValue()+1.0 )
if event.type == ACTIVEEVENT:
if event.gain == 1:
g.mDirtyRect.addRect( Rectangle(0,0,640,480) )
i.pushInput(event)
g.logic()
b2.setCaption( str( int(clock.get_fps()) ) )
fRect=GuichanToPygameDirtyRect(g.mDirtyRect.getList())
#for ix in fRect: screen.fill((255,0,0),ix)
screen.fill((255,0,0))
g.draw()
#pygame.display.update( GuichanToPygameDirtyRect(g.mDirtyRect.getList()) )
pygame.display.update()
g.mDirtyRect.clearList()
示例2: __init__
# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import draw [as 别名]
#.........这里部分代码省略.........
self.background.addLayer(layer)
def setupShip(self,filename):
domLevel = parse(filename)
shipNodes = domLevel.getElementsByTagName("ship")
shipNode = shipNodes[0]
self.mainbody = Body()
for node in shipNode.childNodes:
if node.localName == "position":
position = node.getAttribute('value')
values = position.split(',')
self.mainbody.setPosition(float(values[0]),float(values[1]))
if node.localName == "mobile":
m = Mobile()
for childnode in node.childNodes:
if childnode.localName == "position":
values = childnode.getAttribute('value').split(',')
m.setPosition(float(values[0]),float(values[1]))
if childnode.localName == "velocity":
values = childnode.getAttribute('value').split(',')
m.setVelocity(float(values[0]),float(values[1]))
if childnode.localName == "thrust":
values = childnode.getAttribute('value').split(',')
m.setThrustVector(float(values[0]),float(values[1]))
m.setInitialThrustVector(float(values[0]),float(values[1]))
if childnode.localName == "mass":
value = childnode.getAttribute('value')
m.setMass(float(value))
if childnode.localName == "radius":
value = childnode.getAttribute('value')
m.setRadius(float(value))
if childnode.localName == "texture":
value = childnode.getAttribute('value')
m.setTexture(TextureHelper.loadTextureFromFile(value))
#if childnode.localName == "physicalPoints":
# for ppointnode in childnode.childNodes:
# if ppointnode.localName == "point":
# values = ppointnode.getAttribute('value').split(',')
# m.addPhysicalPoint(Vector2d(float(values[0]),float(values[1])))
m.setupPhysicalPoint()
self.mainbody.addMobile(m)
self.mainbody.init()
focus_position = self.mainbody.getPosition()
self.world.addMobile(self.mainbody)
def setupWorld(self,filename):
self.world.reset()
domLevel = parse(filename)
worldNodes = domLevel.getElementsByTagName("world")
for node in worldNodes[0].childNodes:
if node.localName == "gravity":
values = node.getAttribute('value').split(',')
self.world.setGravity(float(values[0]),float(values[1]))
if node.localName == "landingzone":
values = node.getAttribute('value').split(',')
self.world.setLandingzone(Landingzone(float(values[0]),float(values[1]),float(values[2]),float(values[3]),TextureHelper.loadTextureFromFile('checker.png')))
h = Config.getint('graphics', 'height')
w = Config.getint('graphics', 'width')
p0 = Plane(1,0,-10)
p1 = Plane(0,-1,h-10)
p2 = Plane(-1,0,w-10)
p3 = Plane(0,1,-64)
self.world.addPlane(p0)
self.world.addPlane(p1)
self.world.addPlane(p2)
self.world.addPlane(p3)
#self.world.setGravity(0.0,-1.8)
def setupGame(self):
self.setupMenu()
def updateGame(self,canvas):
if self.mainbody != 0:
self.camera.follow(self.mainbody)
self.camera.setup(canvas)
self.background.draw(canvas)
self.world.draw(canvas)
self.gui.draw(canvas)
self.world.step(1/60.)
if self.gameIsRunning():
res = self.checkVictoryCondition()
if res != 0:
if res == -1:
self.gui.messaging.displayText('FAIL ! !',200)
self.gameResult = -1
Clock.schedule_once(self.setupLevel, 5)
if res == 1:
self.gui.messaging.displayText('SUCCESS ! !',200)
self.gameResult = 1
self.currentLevel += 1
Clock.schedule_once(self.setupLevel, 5)
def on_touch_down(self, touch):
worldpos = self.camera.screenToWorld(touch.pos[0],touch.pos[1])
self.world.on_touch_down(worldpos)
self.gui.on_touch_down(touch)
示例3: Minesweeper
# 需要导入模块: from gui import Gui [as 别名]
# 或者: from gui.Gui import draw [as 别名]
class Minesweeper(object):
"""
Main game application
"""
def __init__(self, difficulty, use_ai, total_games):
# read settings file
with open('settings.yaml', 'r') as f:
settings = yaml.load(f)
self.rows = settings[difficulty]["rows"]
self.cols = settings[difficulty]["columns"]
self.mines = settings[difficulty]["mines"]
self.width = settings[difficulty]["width"]
self.height = settings[difficulty]["height"]
self.size = self.width, self.height
# pygame setup
self._running = True # used to stop game loop
self.screen = self.setup_screen()
# scorekeeping
self.start_time = time.time()
self.time_elapsed = 0
self.score = 0
self.lost_game = False
self.won_game = False
# game board setup
# AI / autoplay
self.use_ai = use_ai
# create board and gui
self.board = Board(self.width, self.height, self.rows, self.cols, self.mines, self.screen, 36)
self.gui = Gui(self.board, self)
# autoplay or enter event loop
if self.use_ai:
self.autoplay(total_games)
self.loop()
def autoplay(self, times_to_play):
"""
Automatically play minesweeper a certain number of times.
:param times_to_play: int
"""
for i in range(times_to_play):
print "\n### Playthrough", i
# draw the starting board; also draws scores
self.draw()
# play 1 game
solver.Solver.play_best_guess(self)
# reset board
self.reset_game()
def game_over(self):
# unflag and reveal all cells
for i in xrange(self.rows):
for j in xrange(self.cols):
self.board.cells[i][j].revealed = True
def reset_game(self):
# reset score and draw new board
self.lost_game = False
self.won_game = False
self.score = 0
self.start_time = time.time()
self.time_elapsed = 0
self.board.reset()
self.draw()
def flag_cell(self, i, j):
"""
Flags cell and redraws board when user right-clicks or control-clicks cell
:param i: cell row
:param j: cell column
"""
# do not flag revealed squares
if not self.board.cells[i][j].revealed:
if self.board.cells[i][j].flagged == True:
self.board.cells[i][j].flagged = False
else:
self.board.cells[i][j].flagged = True
if self.test_did_win():
self.game_over()
def reveal_cell(self, row, col):
"""
Mark a cell as revealed and if it's not a mine
#.........这里部分代码省略.........