def ProcessInput(self, events, pressed_keys):
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
pass
if event.type == pygame.MOUSEBUTTONDOWN:
self.start_button.isClicked(event)
self.help_button.isClicked(event)
self.difficulty_button.isClicked(event)
if event.type == pygame.MOUSEBUTTONUP:
self.start_button.isClicked(event)
self.help_button.isClicked(event)
self.difficulty_button.isClicked(event)
if event.type == pygame.MOUSEMOTION:
self.start_button.isHovered(event)
self.help_button.isHovered(event)
self.difficulty_button.isHovered(event)
python类MOUSEBUTTONUP的实例源码
def ProcessInput(self, events, pressed_keys):
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
pass
if event.type == pygame.MOUSEBUTTONDOWN:
for button in self.buttons:
button.isClicked(event)
if event.type == pygame.MOUSEBUTTONUP:
for button in self.buttons:
button.isClicked(event)
if event.type == pygame.MOUSEMOTION:
for button in self.buttons:
button.isHovered(event)
def ProcessInput(self, events, pressed_keys):
"""
Process Input from user
Inherited from SceneBase
Args: self
events - list of pygame events
pressed_keys
"""
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
pass
if event.type == pygame.MOUSEBUTTONDOWN:
self.easy_button.isClicked(event)
self.adv_button.isClicked(event)
if event.type == pygame.MOUSEBUTTONUP:
self.easy_button.isClicked(event)
self.adv_button.isClicked(event)
if event.type == pygame.MOUSEMOTION:
self.easy_button.isHovered(event)
self.adv_button.isHovered(event)
def isClicked(self, event):
if self.inRange(event.pos[0], event.pos[1]):
if event.type == pygame.MOUSEBUTTONDOWN:
self.initiated = True
if self.initiated and (event.type == pygame.MOUSEBUTTONUP):
self.engaged = True
else: #when click or release is detected outside of range make sure this is still not initiated
self.initiated = False
if self.engaged:
if self.state is STATE.ACTIVE:
self.deselect()
else:
self.select()
self.initiated = False
self.engaged = False
def handleEvents(self, event, fpsClock):
if event.type == pygame.MOUSEBUTTONDOWN:
# Play sound
self.sound_beep1.play()
if event.type == pygame.MOUSEBUTTONUP:
if (not self.layer2[0].visible):
for sprite in self.layer1: sprite.visible = False
for sprite in self.layer2: sprite.visible = True
Sound("assets/audio/enter_authorization_code.wav").play()
elif (self.pin_i == len(str(self.pin))):
# Ran out of button presses
if (self.correct == 4):
self.sound_granted.play()
from screens.main import ScreenMain
self.loadScreen(ScreenMain())
else:
self.sound_deny2.play()
self.sound_denied.play()
self.reset()
return False
def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if self.show_msg == False:
if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
lhv = len(self.home_square.value)
self.changed_since_check = True
if event.key == pygame.K_BACKSPACE:
if lhv > 0:
self.home_square.value = self.home_square.value[0:lhv - 1]
elif not self.board.grid[4][18]:
char = event.unicode
if len(char) > 0 and lhv < 2 and char in self.digits:
self.home_square.value += char
self.home_square.update_me = True
self.mainloop.redraw_needed[0] = True
elif event.type == pygame.MOUSEMOTION and self.drag:
if self.board.grid[4][18]:
self.home_square.value = ""
self.home_square.update_me = True
elif event.type == pygame.MOUSEBUTTONUP:
for each in self.board.units:
if each.is_door is True:
self.board.all_sprites_list.move_to_front(each)
def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if self.show_msg == False:
if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN:
lhv = len(self.home_square.value)
self.changed_since_check = True
if event.key == pygame.K_BACKSPACE:
if lhv > 0:
self.home_square.value = self.home_square.value[0:lhv - 1]
elif not self.board.grid[4][16]:
char = event.unicode
if len(char) > 0 and char in self.digits:
self.home_square.value = char
self.home_square.update_me = True
self.mainloop.redraw_needed[0] = True
elif event.type == pygame.MOUSEMOTION and self.drag:
if self.board.grid[4][16]:
self.home_square.value = ""
self.home_square.update_me = True
elif event.type == pygame.MOUSEBUTTONUP:
for each in self.board.units:
if each.is_door is True:
self.board.all_sprites_list.move_to_front(each)
def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if self.show_msg == False:
if event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct:
lhv = len(self.home_square.value)
self.changed_since_check = True
if event.key == pygame.K_BACKSPACE:
if lhv > 0:
self.home_square.value = self.home_square.value[0:lhv - 1]
else:
char = event.unicode
if (len(char) > 0 and lhv < 5 and char in self.digits):
self.home_square.value += char
self.home_square.update_me = True
self.mainloop.redraw_needed[0] = True
elif event.type == pygame.MOUSEBUTTONUP:
self.home_square.update_me = True
if self.board.active_ship == self.home_square.unit_id:
self.home_square.perm_outline_width = 5
self.home_square = self.ans_h
self.board.active_ship = self.home_square.unit_id
self.home_square.update_me = True
self.mainloop.redraw_needed[0] = True
def handle(self, event):
# TO DO
if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
self.mouse_dn = True
elif event.type == pygame.MOUSEBUTTONUP and event.button == 1 and self.mouse_dn:
self.menu.active_cat = self.cat_id
if self.menu.active_cat_o is not None:
if self.menu.active_cat_o != self:
self.menu.active_cat_o.deactivate()
self.activate()
self.menu.mainloop.redraw_needed[1] = True
self.menu.mainloop.redraw_needed[2] = True
elif event.type == pygame.MOUSEMOTION:
self.on_mouse_over()
def handle_event(self, event):
""" Slider event handler
:param event: event to handle
"""
if not self.visible:
return
mouse_events = [pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN, pygame.MOUSEMOTION]
if getattr(event, "source", None):
self.event_source_local = False
else:
self.event_source_local = True
if event.type in mouse_events:
pos = event.pos
if not self.bounding_box.collidepoint(pos):
return
self.mouse_action(event)
elif event.type == USER_EVENT_TYPE:
self.user_event_action(event)
def mouse_action(self, event):
""" Mouse event handler
:param event: event to handle
"""
pos = event.pos
if self.selected and not(self.last_knob_position < pos[0] < self.last_knob_position + self.knob_width and pos[1] > self.bounding_box.y) and event.type != pygame.KEYUP:
return
button_press_simulation = getattr(event, "p", None)
if event.type == pygame.MOUSEBUTTONUP and self.clicked:
self.release_action(pos)
elif event.type == pygame.MOUSEBUTTONDOWN and self.bounding_box.collidepoint(pos):
self.press_action()
elif event.type == pygame.MOUSEMOTION and (pygame.mouse.get_pressed()[0] or button_press_simulation) and self.bounding_box.collidepoint(pos) and self.clicked:
self.motion_action(pos)
def handle_command(self, d):
""" Handles commands sent from web client
:param d: command object
"""
if d["command"] == "init":
json_data = self.screen_to_json()
web_socket.send_message(json_data)
elif d["command"] == "mouse":
a = {}
a["pos"] = (d["x"], d["y"])
a["button"] = d["b"]
event = None
if d["d"] == 0:
event = pygame.event.Event(pygame.MOUSEBUTTONDOWN, **a)
elif d["d"] == 1:
event = pygame.event.Event(pygame.MOUSEBUTTONUP, **a)
elif d["d"] == 2:
event = pygame.event.Event(pygame.MOUSEMOTION, **a)
event.p = True
event.source = "browser"
thread = Thread(target=pygame.event.post, args=[event])
thread.start()
def ShowPhoto(photoFile):
screen = pygameEngine.GetScreen()
image = pygame.image.load(photoFile).convert()
image = pygame.transform.scale(image, (config.WIDTH,config.HEIGHT))
screen.blit(image, (0,0))
pygame.display.update()
sleep(1)
pygameEngine.ShowNavButtons()
i = 0
while True:
# get one pygame event
event = pygame.event.poll()
# handle events
# Button 1 = Quit
if (event.type == pygame.MOUSEBUTTONUP and event.button == 1) or (event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE) or GPIO.input(config.GPIO_NUMBER_BUTTON_1):
return -1
# Button 2 = Cycle old photos
if (event.type == pygame.MOUSEBUTTONUP and event.button == 3) or (event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN) or GPIO.input(config.GPIO_NUMBER_BUTTON_2):
return 1
# Button Esc or Q = Quit keys
if event.type == pygame.KEYDOWN and (event.key == pygame.K_ESCAPE or event.key == pygame.K_q) :
return -1
def process_events(self):
for event in pygame.event.get():
if event.type == VIDEORESIZE:
self.screen = pygame.display.set_mode(event.dict['size'], HWSURFACE | DOUBLEBUF | RESIZABLE)
print(event.dict['size'])
self.width = event.dict['size'][0]
self.height = event.dict['size'][1]
if event.type == pygame.QUIT:
return True
if event.type == pygame.MOUSEBUTTONUP:
if self.b1.rect.collidepoint(pygame.mouse.get_pos()):
self.M0 = 1
self.M1 = 0
if self.Menu1.b1.rect.collidepoint(pygame.mouse.get_pos()):
self.M0 = 0
self.M1 = 1
if self.Menu1.b4.rect.collidepoint(pygame.mouse.get_pos()):
return True
self.b1 = Button(self.width * 0.85, self.height * 0.05, self.width * 0.1, self.height * 0.05, "Menu")
self.Menu1 = MainMenu(self.width, self.height)
return False
def Refresh(self):
self.ResetKeys()
events = pygame.event.get()
for event in events:
if(event.type == pygame.KEYDOWN):
self.CheckInputCache(event.key)
self.pressed[event.key] = True
self.keyDown[event.key] = True
self.instantKey = event.key
elif(event.type == pygame.KEYUP):
self.pressed[event.key] = False
self.keyUp[event.key] = True
elif(event.type == pygame.MOUSEBUTTONDOWN):
self.pressed[self.mouseButtons[event.button-1]] = True
self.btnDown[self.mouseButtons[event.button-1]] = True
elif(event.type == pygame.MOUSEBUTTONUP):
self.pressed[self.mouseButtons[event.button-1]] = False
self.btnUp[self.mouseButtons[event.button-1]] = True
def handleEvents(self):
self.mouse = self.get(MOUSE)
for event, pos in self.context.events:
self.mouse = pos
handled = self.mode.handleEvent((event, pos))
if not handled:
if event.type == pygame.MOUSEBUTTONDOWN:
self.handleMouseDown(event, pos)
elif event.type == pygame.MOUSEMOTION:
self.handleMouseMotion(pos)
elif event.type == pygame.MOUSEBUTTONUP:
self.handleMouseUp(pos)
if self.mouse:
self.set(MOUSE, self.mouse)
def process_events(self):
""" Processes mouse events and quit event """
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.stopped = True
self.render_thread.join()
self.game_controller.cleanup()
sys.exit()
elif event.type == pygame.MOUSEBUTTONUP:
self.process_mouse_event(False, self.is_double_click())
elif event.type == pygame.MOUSEBUTTONDOWN:
self.process_mouse_event(True)
def ProcessInput(self, events, pressed_keys):
"""
Process input from user
Inherits from SceneBase
Args: self
events - pygame events
pressed_keys
"""
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
# Move to the next scene when the user pressed Enter
pass
if event.type == pygame.MOUSEBUTTONDOWN:
for button in self.buttons:
button.isClicked(event)
if self.leveling_up:
self.continue_button.isClicked(event)
if event.type == pygame.MOUSEBUTTONUP:
for button in self.buttons:
button.isClicked(event)
if self.leveling_up:
self.continue_button.isClicked(event)
if event.type == pygame.MOUSEMOTION:
#for button in self.buttons:
# button.isHovered(event)
if self.leveling_up:
self.continue_button.isHovered(event)
def _mouseup_cb(self, widget, event):
self.__button_state[event.button-1] = 0
return self._mouseevent(widget, event, pygame.MOUSEBUTTONUP)
def process_input(self):
# Process touchscreen input
from alarmpanel.button import STATE_PRESSED
for event in pygame.event.get():
if event.type is pygame.MOUSEBUTTONDOWN:
pos = pygame.mouse.get_pos()
for b in self._buttons:
if b.down(pos): break
elif event.type is pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
for b in self._buttons:
if b.up(pos): pass
# Redraw other buttons which might be stuck in the down position
elif b.state == STATE_PRESSED:
b.set_state(STATE_DEFAULT)
start.py 文件源码
项目:Physical-Image-Manipulation-Program
作者: philipptrenz
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def wait_for_mouseclick():
"""
Wait for the mouse click.
Returns: Position of mouse as touple
"""
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONUP:
pos = pygame.mouse.get_pos()
return pos
def handle_event(self, event):
""" Handle events of the GUI"""
if event.type == pygame.MOUSEBUTTONUP:
log.debug('Received a new event: %s', str(event))
pos = pygame.mouse.get_pos()
self.handle_mouseup(pos)
elif event.type == pygame.MOUSEBUTTONDOWN:
log.debug('Received a new event: %s', str(event))
pos = pygame.mouse.get_pos()
self.handle_mousedown(pos)
elif event.type == pygame.KEYDOWN:
log.debug('Received a new event: %s', str(event))
self.handle_key_pressed(event.key)
def big_bang(inic, tela,
quando_tick=lambda e: e, \
frequencia=28, \
desenhar=lambda e: pg.Surface((0,0)), \
quando_tecla=lambda e, k: e, \
quando_mouse=lambda e, x, y, ev: e, \
parar_quando=lambda e: False):
pg.init()
estado = inic
clock = pg.time.Clock()
while True:
pg.display.flip()
if parar_quando(estado):
print(estado)
sys.exit(0)
for event in pg.event.get():
if event.type == pg.QUIT:
print(estado)
sys.exit(0)
if event.type == pg.KEYDOWN:
estado = quando_tecla(estado, event.key)
elif event.type in [pg.MOUSEBUTTONDOWN, pg.MOUSEBUTTONUP, pg.MOUSEMOTION]:
x, y = pg.mouse.get_pos()
estado = quando_mouse(estado, x, y, event.type)
estado = quando_tick(estado)
tela.fill(COR_BRANCO)
desenhar(estado)
clock.tick(frequencia)
def on_release(self, event, function, *args):
if event.type == pygame.MOUSEBUTTONUP:
if event.button == 1:
if self.rect.R.collidepoint(event.pos):
function(*args) if args else function()
def on_mouse_button_release(self, event, mouse_button, function, *args):
if event.type == pygame.MOUSEBUTTONUP:
if event.button == mouse_button:
if self.rect.R.collidepoint(event.pos):
function(*args) if args else function()
def __init__(self, text, signal, align=Align.NONE):
# make a label of the text - but we only want the image
label = GuiLabel(text, (0, 0, 0), (214, 214, 214)).image
# get the contents to render themselves
border = Resources.configs.get(self.border_config)
image = add_border(label, border, Resources.get_image(border.image))
rect = pygame.Rect(0, 0, image.get_width(), image.get_height())
super().__init__(rect, image, align, False)
self.messages = [pygame.MOUSEMOTION, pygame.MOUSEBUTTONUP, pygame.MOUSEBUTTONDOWN]
self.highlight = self.get_highlight()
self.normal_image = self.image
self.signal = signal
self.changed = False
def handleEvent(self, event, clock):
handled = False
if not self.visible:
self.focussed = False
return handled
if self.groups()[0].UI_PLACEMENT_MODE:
if event.type == pygame.MOUSEBUTTONDOWN:
self.pressed_time = pygame.time.get_ticks()
self.focussed = True
if event.type == pygame.MOUSEMOTION:
if (self.focussed and pygame.time.get_ticks() - self.pressed_time > 1000):
self.long_pressed = True
self.rect.top = event.pos[1]
self.rect.left = event.pos[0]
self.dirty = 1
if event.type == pygame.MOUSEBUTTONUP:
if self.handler:
self.handler(self, event, clock)
handled = True
if self.focussed and self.long_pressed:
print event.pos[1], event.pos[0]
self.pressed_time = 0
self.long_pressed = False
self.focussed = False
return handled
def handleEvents(self, event, fpsClock):
if event.type == pygame.MOUSEBUTTONDOWN:
self.beep1.play()
if event.type == pygame.MOUSEBUTTONUP:
return False
def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if event.type == pygame.MOUSEBUTTONUP:
self.active_item = self.board.ships[self.board.active_ship]
if self.active_item.unit_id < self.shape_count:
self.create_card(self.active_item)
def handle(self, event):
gd.BoardGame.handle(self, event) # send event handling up
if self.show_msg == False:
if event.type == pygame.KEYDOWN and (event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT):
self.next_step()
elif event.type == pygame.MOUSEBUTTONUP:
if self.board.active_ship == self.next_step_btn.unit_id:
if self.cursor_pos == self.sumn1n2sl + 1:
self.level.next_board_load()
else:
self.next_step()