def print_map(controller): print(str(controller.map)) screen = gui.initPyGame(controller.get_size_of_map()) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False image = gui.image(controller.map) screen.blit(image, (0, 0)) pygame.display.flip() pygame.quit()
def page(arg): ## Name of this Page # print(arg.curpage) ## SAVE PROPERTIES arg.hprops = sn(**{}) arg.hobjs = sn(**{}) arg.hvars = sn(**{}) arg.hprops.__dict__[arg.curpage] = sn(**{}) arg.hobjs.__dict__[arg.curpage] = sn(**{}) arg.hvars.__dict__[arg.curpage] = sn(**{}) ####################### GUI ELEMENTS ######################### h = sn(**{}) ## Optional Variables for Guided Positioning margin = 30 spacing = 10 small = 150 medium = 225 large = 300 height = 40 h.bg = sn( **{ ## gui.image(arg,"imagename", "image.jpg", (w,h))) "obj": gui.image(arg, "pg_1-bg", "bg.jpg", (g.frameWidth, g.frameHeight)), "pos": sn(**{ "x": 0, "y": 0, "w": g.frameWidth, "h": g.frameHeight, }) }) ### LABEL h.label1 = sn( **{ ## gui.label(arg,"style","align","text") "obj": gui.label(arg, "labelSmall", "center", "Hello There!"), "pos": sn(**{ "x": margin, "y": 300, "w": medium, "h": height, }) }) ### ENTRY h.myEntry = sn( ** { ## gui.entry(arg,"style","align","text", name="entryName" ,password=True, keyboard=True, type=number), "obj": gui.entry(arg, "entryMedium", "center", "Edit me!", name="myEntry", password=True, keyboard=True), "pos": sn(**{ "x": 10, "y": 10, "w": 150, "h": 30, }) }) h.btnTest1 = sn( **{ ## gui.button(arg,"style","unused","text",lambda: fcn(arg)), ## Function Wont Work on Quick View "obj": gui.button(arg, "btnBig", "center", "Push Me!", lambda: arg.fcn_main.testFcn(arg)), "pos": sn(**{ "x": margin, "y": 200, "w": medium, "h": height, }) }) h.btnTest2 = sn( **{ ## gui.button(arg,"style","unused","text",lambda: fcn(arg)), "obj": gui.button(arg, "btnBig", "center", "NEXT PAGE", lambda: gui.showPage(arg, "pg_testing")), "pos": sn( **{ "x": margin, "y": h.btnTest1.pos.y + h.btnTest1.pos.h + spacing, "w": medium, "h": height, }) }) # data = ["Entry1", "fsfs"] ## ["Entry 1" , "Entry 2"] h.listbox1 = sn( **{ "obj": gui.listbox(arg, data, "listbox1"), "pos": sn( **{ "x": margin + medium + spacing, "y": margin, "w": large, "h": 300, }) }) data = ["Entry 1", "Entry 2"] h.dropdown1 = sn( **{ "obj": gui.dropdown(arg, "ddstyle", "center", data, "dropdown1"), "pos": sn(**{ "x": 600, "y": 20, "w": 180, "h": 35, }) }) rsp = db(arg, "getPathologist") data = [] for dt in rsp: data.append([dt["name"], dt["status"]]) h.table1 = sn( **{ "obj": gui.ttk.Treeview(arg.master), "pos": sn(**{ "x": 70, "y": 180, "w": 650, "h": 200, }), "table": sn( **{ "columns": [ sn(**{ "title": "Name", "width": 500 }), sn(**{ "title": "Status", "width": 150 }), # sn(**{"title" : "Brand", "width" : 150}), # sn(**{"title" : "Equipment", "width" : 200}), # sn(**{"title" : "Tag", "width" : 100}), ], "data": [[]], }), }) # For Scrollbar h.table1Scroll = sn( **{ "obj": gui.ttk.Scrollbar( arg.master, orient="vertical", command=h.table1.obj.yview), "pos": sn(**{ "x": 725, "y": 180, "w": 25, "h": 200, }) }) h.table1.obj.configure(yscrollcommand=h.table1Scroll.obj.set) # self.canvas.bind('<Button-1>', self.clicked) # self.canvas.bind('<Double-1>', self.double_click) # self.canvas.bind('<ButtonRelease-1>', self.button_released) # self.canvas.bind('<B1-Motion>', self.moved) # Bind double click even on table1 data/row. h.table1.obj.bind( '<Double-1>', lambda event, t=h.table1.obj: arg.fcn_gui3.table1Double_ClickEven(arg)) # "data" : [ # ["Felipe Templo Jr, MD","ON-DUTY"], # ["Jeffrey S. So, MD, DPSP","OFF-DUTY"], # ["Francis G. Moria, MD, MSc FPSP","OFF-DUTY"], # ["Jose Maria C. Avila, MD","ON-DUTY"], # ["Michelle Anne M. Latoy, MD","ON-DUTY"], # ["Aida Isabel Mendoza, MD","OFF-DUTY"], # ["Charles Harris, MD","OFF-DUTY"], # ["Felipe Templo Jr, MD","ON-DUTY"], # ["Jeffrey S. So, MD, DPSP","OFF-DUTY"], # ["Francis G. Moria, MD, MSc FPSP","OFF-DUTY"], # ["Jose Maria C. Avila, MD","ON-DUTY"], # ["Michelle Anne M. Latoy, MD","ON-DUTY"], # ["Aida Isabel Mendoza, MD","OFF-DUTY"], # ["Charles Harris, MD","OFF-DUTY"], # ], # h.scrollAlone = sn(**{ # "obj": gui.scroll(arg,"scrollstyle","center"), # "pos": sn(**{ # "x": h.listbox1.pos.x + h.listbox1.pos.w + spacing, # "y": margin, # "w": 50, # "h": 300, # }) # }) # data = ["Entry1 - ON-DUTY","fsfs - OFF-DUTY"] ## ["Entry 1" , "Entry 2"] # h.listbox1 = sn(**{ # "obj" : gui.listbox(arg,data,"listbox1"), # "pos": sn(**{ # "x": 70, # "y": 180, # "w": 645, # "h": 200, # }) # }) # For Scrollbar # h.listScroll = sn(**{ # "obj" : ttk.Scrollbar(master, orient="vertical", # # command=handle["listbox1"]["element"].yview), # command=h.listbox1.obj.yview), # "pos" : sn(**{ # "x": 200, # "y": 50, # "w": 40, # "h": 720, # }) # }) # ##### SUB PROPERTIES OF THE ABOVE HANDLES # h.listbox1.obj.configure(yscrollcommand=h.listScroll.obj.set); h.checkbox = sn( **{ ## gui.checkbox(arg,"yourText", lambda: test(arg)), "obj": gui.checkbox(arg, "yourText", lambda: test(arg)), "pos": sn(**{ "x": 10, "y": 10, "w": 150, "h": 30, }) }) # array 0 is the default value. optionList1 = ('a', 'a', 'b', 'c') h.combobox = sn( ** { ## ttk.OptionMenu(arg.master,v1,*optionList1, command=lambda selected:test123123(selected)) "obj": gui.combobox(arg, optionList1, lambda selected_val: test(selected_val)), "pos": sn(**{ "x": 50, "y": 10, "w": 150, "h": 30, }) }) h.progressbar = sn( ** { ## tttk.Progressbar(arg.master, orient = orient, length = length, mode = mode) "obj": gui.progressbar(arg), "pos": sn(**{ "x": 100, "y": 10, "w": 150, "h": 30, }) }) gui.hpropsobjs(arg, h) return h
def run(self): for event in pygame.event.get(): if event.type == pygame.QUIT: return elif event.type == pygame.VIDEORESIZE: pygame.display.set_mode( (event.size[0], event.size[1] - GRID_CELL_SIZE), pygame.RESIZABLE) break pygame.init() self.screen = pygame.display.get_surface() if self.screen: self.screensize = self.screen.get_size() else: info = pygame.display.Info() self.screensize = (info.current_w, info.current_h) self.screen = pygame.display.set_mode(self.screensize) screensize = self.screensize decksel = False c8sheader = gui.label((100, 300), (200, 75), _('Crazy Eights'), (0, 128, 0)) c8s2p = gui.button((100, 400), (200, 35), _("Two players")) c8s3p = gui.button((100, 450), (200, 35), _("Three players")) c8s4p = gui.button((100, 500), (200, 35), _("Four players")) c8sframe = gui.frame((c8sheader, c8s2p, c8s3p, c8s4p), (75, 275), (250, 275)) maindeck = gui.button((50, screensize[1] - 75), (85, 35), _("Deck")) mainphoto = gui.button((screensize[0] - 200, screensize[1] - 75), (160, 35), _("Photo deck")) mainheader = gui.image((50, 25), (screensize[0] - 100, 200), 'fiftytwo.png', -1) mainframe = gui.frame((mainheader, maindeck, mainphoto), (25, screensize[1] - 100), (screensize[0] - 50, 75)) deckselexit = gui.button((screensize[0] - 215, screensize[1] - 145), (115, 35), _("Cancel")) deckfromjournal = gui.button( (screensize[0] - 445, screensize[1] - 145), (200, 35), _("from Journal")) deckselregular = gui.image( (115, 115), (crazyeights.card_width(), crazyeights.card_height()), 'back.regular.png') deckselgnome = gui.image( (300, 115), (crazyeights.card_width(), crazyeights.card_height()), 'back.gnome.png') deckselparis = gui.image( (485, 115), (crazyeights.card_width(), crazyeights.card_height()), 'back.paris.png') deckselshapes = gui.image( (670, 115), (crazyeights.card_width(), crazyeights.card_height()), 'back.shapes.png') self.deckseluser = gui.image( (855, 115), (crazyeights.card_width(), crazyeights.card_height()), 'back.user.png') deckselpopup = gui.popup( (deckselexit, deckfromjournal, deckselregular, deckselgnome, deckselparis, deckselshapes, self.deckseluser), (100, 100), (screensize[0] - 200, screensize[1] - 200)) mouseposition = [0, 0, 0] self.screen.fill((192, 64, 255)) # Set the name of the players names = [] names.append('l' + _('You')) names.append('a' + _('XO player #1')) names.append('a' + _('XO player #2')) names.append('a' + _('XO player #3')) names.append('a' + _('The XO')) fpslimiter = pygame.time.Clock() while True: fpslimiter.tick(20) while Gtk.events_pending(): Gtk.main_iteration() for event in pygame.event.get(): if event.type == pygame.MOUSEMOTION: mouseposition[0] = event.pos[0] mouseposition[1] = event.pos[1] elif event.type == pygame.MOUSEBUTTONDOWN: mouseposition[2] = 1 elif event.type == pygame.MOUSEBUTTONUP: mouseposition[2] = 0 if not decksel and c8s2p.detect_click(event.pos): crazyeights.main((names[4], names[0]), screensize) self.screen.fill(MMCOL) pygame.event.set_allowed(pygame.MOUSEMOTION) elif not decksel and c8s3p.detect_click(event.pos): crazyeights.main((names[1], names[2], names[0]), screensize) self.screen.fill(MMCOL) pygame.event.set_allowed(pygame.MOUSEMOTION) elif not decksel and c8s4p.detect_click(event.pos): crazyeights.main( (names[1], names[2], names[0], names[3]), screensize) self.screen.fill(MMCOL) pygame.event.set_allowed(pygame.MOUSEMOTION) elif not decksel and maindeck.detect_click(event.pos): decksel = True elif not decksel and mainphoto.detect_click(event.pos): self.photo() self.screen.fill(MMCOL) elif decksel and deckselexit.detect_click(event.pos): decksel = False self.screen.fill(MMCOL) elif decksel and deckfromjournal.detect_click(event.pos): picture = self.parent.load_image_from_journal() if picture: self.update_user_deck(picture.file_path) self.screen.fill(MMCOL) elif decksel and deckselgnome.detect_click(event.pos): deck.deck = 'gnome' decksel = False self.screen.fill(MMCOL) elif decksel and deckselregular.detect_click(event.pos): deck.deck = 'regular' decksel = False self.screen.fill(MMCOL) elif decksel and deckselparis.detect_click(event.pos): deck.deck = 'paris' decksel = False self.screen.fill(MMCOL) elif decksel and deckselshapes.detect_click(event.pos): deck.deck = 'shapes' decksel = False self.screen.fill(MMCOL) elif decksel and self.deckseluser.detect_click(event.pos): deck.deck = 'user' decksel = False self.screen.fill(MMCOL) if not decksel: c8sframe.update() c8sframe.draw(self.screen, mouseposition) mainframe.update() mainframe.draw(self.screen, mouseposition) else: deckselpopup.update() deckselpopup.draw(self.screen, mouseposition) pygame.display.flip()
def photo(self): screensize = self.screensize mouseposition = [0, 0, 0] self.screen = pygame.display.get_surface() fpslimiter = pygame.time.Clock() photodynamic = gui.image((125, 125), (640, 480), 'back.regular.png') photoreturn = gui.button((screensize[0] - 300, screensize[1] - 175), (150, 35), _("Cancel")) photopopup = gui.popup((photodynamic, photoreturn), (100, 100), (screensize[0] - 200, screensize[1] - 200)) pygame.camera.init() cams = pygame.camera.list_cameras() if cams: photocamera = pygame.camera.Camera(cams[0], (640, 480), 'RGB') photocamera.start() photocamera.set_controls(True, False) camera_size = photocamera.get_size() capture = pygame.surface.Surface(camera_size, 0, self.screen) photodynamic.image = photocamera.get_image(capture) running = True while running: fpslimiter.tick(20) photodynamic.image = photocamera.get_image(capture) while Gtk.events_pending(): Gtk.main_iteration() for event in pygame.event.get(): """if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: photodynamic.image = photocamera.get_image(capture)""" if event.type == pygame.MOUSEMOTION: mouseposition[0] = event.pos[0] mouseposition[1] = event.pos[1] elif event.type == pygame.MOUSEBUTTONDOWN: mouseposition[2] = 1 self.flush_queue() elif event.type == pygame.MOUSEBUTTONUP: mouseposition[2] = 0 if photoreturn.detect_click(event.pos): running = False elif photodynamic.detect_click(event.pos): r = photodynamic.image.get_rect() r.x = mouseposition[0] - 125 r.y = mouseposition[1] - 125 r.w = 156 r.h = 244 sub = photodynamic.image.subsurface(r) # borde negro pygame.draw.rect(sub, (0, 0, 0), (0, 0, r.w, r.h), 3) pygame.image.save(sub, 'data/back.user.png') self.deckseluser.image = sub deck.deck = 'user' running = False photopopup.update() photopopup.draw(self.screen, mouseposition) r = self.screen.get_rect() r.x = 125 r.y = 125 r.w = 640 r.h = 480 self.screen.set_clip(r) r.x = mouseposition[0] r.y = mouseposition[1] r.w = 156 r.h = 244 pygame.draw.rect(self.screen, (255, 0, 0), r, 4) self.screen.set_clip() pygame.display.flip() photocamera.stop()
def main(): gui.image() say("Hello. I am here to help you. What do you want me to do?") gui.gif()