本文整理汇总了Python中display.Display类的典型用法代码示例。如果您正苦于以下问题:Python Display类的具体用法?Python Display怎么用?Python Display使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Display类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(myAddr, clAddr):
myDisplay = Display()
myDisplay.init()
backSender = BackSender(clAddr)
# start threads
displayThread = threading.Thread(None, displayMain, 'display', (myDisplay, ))
displayThread.start()
serverThread = threading.Thread(None, displayServerMain, 'displayserver', (myDisplay, myAddr))
serverThread.start()
connectTread = threading.Thread(None, connectMain, 'connection', (myAddr, backSender))
connectTread.start()
inputThread = threading.Thread(None, inputMain, 'input', (myDisplay, backSender))
inputThread.start()
# wait till threads end
while displayThread.is_alive() and serverThread.is_alive():
try:
littlePause = 0.1
displayThread.join(littlePause)
except KeyboardInterrupt:
logging.info('exit on keyboard interrupt')
myDisplay.quit = True
except Exception as err:
logging.error('unhandled exception in main thread:')
logging.error(str(err))
logging.debug(traceback.format_exc())
示例2: run_game
def run_game(size):
gol = GameOfLife(size)
display = Display()
while True:
display.show_board(gol.get_board())
time.sleep(1)
示例3: __init__
class Test:
def __init__(self, stream):
self.display = Display()
self.stream = Stream(stream)
def parse(self):
if not self.stream.line:
return False
parse = self.stream.line.split('#')
if len(parse) == 2:
try:
self.result = int(parse[0].rstrip(' '))
self.message = parse[1].rstrip(' ')
except:
return False
if self.result != 0 and self.result != 1:
return False
return True
return False
def launch(self):
sucess = 0
total = 0
while self.stream.read():
if self.parse():
if self.result == 1:
sucess += 1
else:
self.display.error("Error on" + self.message)
total += 1
self.display.summary(sucess, total)
示例4: OutputHandler
class OutputHandler(object):
def __init__(self, outputs, pars, neuron2NoteConversion=4):
self.pars = pars
super(OutputHandler, self).__init__()
self.display = Display(pars['N_col'], pars['N_row'],\
['Ne', 'Ni', 's_e', 's_i', 'tau_e', 'tau_i', 'midi_ext_e', 'midi_ext_i',
'cam_ext', 'cam_external_max'], 'lines', screenSize=pars['screen_size'])
pm.init()
self.__output = outputs
if Visuals.NAME in self.__output:
self.__output[Visuals.NAME].note_on(1)
# self.__membraneViewer = Test()
self.__now = time.time()
self.__activeNotes = set()
self.__neuron2NoteConversion = neuron2NoteConversion
def __setupInputs(self, inputList):
self.__input = {}
for name in inputList:
self.__input[name] = \
self.__getDevice(self.__name2Identifier[name], type = 'input')
def update(self,fired):
# print 'es feuern', fired
neuron_ids = intersect1d(fired, self.pars['note_ids'])
self.__checkKeyChange(neuron_ids)
n_fired = neuron_ids.__len__()
if n_fired > 0:
for neuron_id in neuron_ids:
for name, output in self.__output.iteritems():
output.note_on(neuron_id)
# self.__membraneViewer.move()
# display spikes and update display
self.display.update_fired(fired)
self.display.update_pars(
['cam_ext', 'midi_ext_e', 'midi_ext_i', 's_e', 's_i',
'tau_e', 'tau_i', 'cam_external_max'])
pygame.display.update()
def turnOff(self):
for outputName in self.__output.iterkeys():
if outputName == NeuronNotes.NAME:
self.__output[outputName].turnAllOff()
def __checkKeyChange(self, neuron_ids):
if len(neuron_ids)>20:
self.__neuron2NoteConversion = (1 if self.__neuron2NoteConversion==7 else 7)
self.__output[NeuronNotes.NAME].setNeuron2NoteConversion(
self.__neuron2NoteConversion
)
# [output.setNeuron2NoteConversion(self.__neuron2NoteConversion) for
# name, output in self.__output.iteritems()]
print '----------------------------------------key change'
示例5: run
def run():
dis = Display()
start_time = arrow.now()
while True:
td = fmt_timedelta(start=start_time)
print td
dis.simple_static_message(td)
sleep(1)
示例6: example2
def example2():
coefficients = np.array([[4.1, 2],
[2, 4]], dtype='float')
constraints = np.array([[40],
[32]], dtype='float')
objective = np.array([80, 55])
simplex = Simplex(coefficients=coefficients, constraints=constraints, objective=objective)
display = Display(simplex_init=simplex)
display.run_simplex()
示例7: example1
def example1():
coefficients = np.array([[1, 1],
[1, -1]], dtype='float')
constraints = np.array([[4],
[2]], dtype='float')
objective = np.array([3, 2])
simplex = Simplex(coefficients=coefficients, constraints=constraints, objective=objective)
display = Display(simplex_init=simplex)
display.run_simplex()
示例8: Browser
class Browser(object):
display = None
browser = None
def __init__(self, downloaded_data_dir=None, implicitly_wait_seconds=10, is_visible=False, profile_directory=None):
if not is_visible:
self.display = Display()
self.downloaded_data_dir = downloaded_data_dir
self.start_browser(downloaded_data_dir, implicitly_wait_seconds, profile_directory)
def __enter__(self):
return self
def __exit__(self, type, value, trace):
if type and self.downloaded_data_dir:
try:
save_to = join(self.downloaded_data_dir, 'error_screenshot_' + datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S"))
self.browser.save_screenshot(save_to)
except:
pass
self.close()
def start_browser(self, downloaded_data_dir=None, implicitly_wait_seconds=10, profile_directory=None):
profile = webdriver.FirefoxProfile(profile_directory)
if downloaded_data_dir:
'''start browser with profile'''
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", downloaded_data_dir)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/csv,text/csv")
profile.set_preference("browser.download.manager.scanWhenDone", False)
profile.set_preference("browser.download.manager.showAlertOnComplete", True)
profile.set_preference("browser.download.manager.useWindow", False)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
self.browser = webdriver.Firefox(firefox_profile=profile)
self.browser.implicitly_wait(implicitly_wait_seconds)
def get_browser(self):
if self.browser:
return self.browser
raise Exception("browser don't exist")
def close_browser(self):
'''browser.quit() closes the browser & deleted the temp files'''
if self.browser:
try:
self.browser.quit()
except Exception as e:
log.error("error closing browser, reason: " + str(e))
self.browser = None
def close(self):
self.close_browser()
if self.display:
self.display.stop_display()
示例9: print
class Session:
"""
for stand-alone usage by the ox-user.
?for collaborative sessions see CoSession
"""
print("DEL import Session")
def __init__(self, name, window):
self._name = name
self._dis = Display(window)
self._co = Coach()
self._co.register(self, self._dis)
self._dis.register(self, self._co)
self._co.create_exercises() #TODO.WN091101 replace by storing Exerc.s
self._calcs = None #pop !
def run(self):
"""as long as user does exercises"""
#print("in Session.run")
self._co.request_exercise()
self._dis.init_calc() #TODOWN091101 take Exercise as argument
def notify(self, (msg, data)):
'''called by the observed objects'''
#print('in Session.notify: msg=,data=', msg, data)
if msg == 'setting-done': # from Coach
self._ex = data
self._calcs = data._generate_calcs()
self._key = data.get_topic()
(self._calcs).reverse()
_calc = (self._calcs).pop()
#print('in Session.notify: calc=', _calc)
_lines, self._input = data.format(_calc)
self._dis.display_calc(_lines)
self._curr_in = self._input.pop() #need _curr_in in notify
self._dis.create_entryline(self._curr_in)
# create_entryline sets the callback from gtk to Display
if msg == 'digit-done': # from Display
#print('in Session.notify, digit-done: _input=', self._input)
(lino, pos, dig, proterr, protok, li) = self._curr_in
self._dis.create_entryline((lino, -1, dig, proterr, protok, li))
if len(self._input) > 0:
self._curr_in = self._input.pop()
self._dis.create_entryline(self._curr_in)
else: # start new calc
self._dis.show_progress()
if len(self._calcs) > 0:
_calc = (self._calcs).pop()
print('in Session.notify: calc=', _calc)
_lines, self._input = self._ex.format(_calc)
self._dis.display_calc(_lines)
self._curr_in = self._input.pop() #need _curr_in in notify
self._dis.create_entryline(self._curr_in)
# create_entryline sets the callback from gtk to Display
else:
self._dis.finish_calc()
示例10: run
def run(self):
self.setup_logging()
scheduler = BlockingScheduler()
weather = Weather(scheduler, zip=self._args['zip'], station=self._args['station'])
dimmer = Dimmer(scheduler)
display = Display(weather, dimmer)
display.start()
scheduler.start()
示例11: run_from_txt
def run_from_txt():
with open("lp.txt") as file:
content = file.read()
kw = {}
exec(content, globals(), kw)
A = np.array(kw['A'])
b = np.array(kw['b'])
c = np.array(kw['c'])
d = Display(Simplex(coefficients=A, constraints=b, objective=c))
d.run_simplex()
示例12: example3
def example3():
coefficients = np.array([[2, 1, 0],
[1, 2, -2],
[0, 1, 2]], dtype='float')
constraints = np.array([[10],
[20],
[ 5]], dtype='float')
objective = np.array([2, -1, 2])
simplex = Simplex(coefficients=coefficients, constraints=constraints, objective=objective)
display = Display(simplex_init=simplex)
display.run_simplex()
示例13: Simulator
class Simulator(object):
def __init__(self, config={}, size=(8, 8), frames_per_second=30, foreground=False):
try:
game_name = config["game"]
del config["game"]
except KeyError:
game_name = DEFAULT_GAME
game = GAMES[game_name]
self.GAME_CODE = GAME_CODES[game_name]
self.arena = game(**config)
self.display = Display(self.arena, self.GAME_CODE)
self.foreground = foreground
self.frames_per_second = frames_per_second
if not self.foreground:
self._loop_thread = threading.Thread(target=self._main_loop, args=(frames_per_second,))
self._loop_thread.setDaemon(True)
self._loop_thread.start()
def run(self):
if not self.foreground:
raise RuntimeError("Simulator runs in the background. Try passing foreground=True")
self._main_loop(self.frames_per_second)
def set_robots(self, robots):
self.robots = robots
def _main_loop(self, frames_per_second):
clock = pygame.time.Clock()
while True:
if any(
event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE)
for event in pygame.event.get()
):
break
self.display.tick(1 / frames_per_second)
clock.tick(frames_per_second)
for robot in self.robots:
try:
robot.raiseExc(KeyboardInterrupt)
except threading.ThreadError:
pass
pygame.quit()
sys.exit(0)
示例14: Game
class Game(object):
def __init__(self):
self.clock = pygame.time.Clock()
self.display = Display()
self.game_state = GameState()
self.control_state = ControlState()
def run(self):
pygame.init()
while True:
self.control_state.update()
self.game_state.update(self.control_state)
self.display.update(self.game_state)
self.clock.tick(60)
示例15: Life
class Life(object):
__display = None
grid_size = [100, 100]
def __init__(self):
self.__display = Display(title='PyLife', grid_size=self.grid_size, width=800, height=800)
def initial_seed(self):
cells = {}
for x in range(self.grid_size[0]):
for y in range(self.grid_size[1]):
if random.randint(0, 1) == 1:
cells[(x, y)] = 1
return cells
def get_cell_neighbours(self, item, cells):
neighbours = 0
for x in range(-1, 2):
for y in range(-1, 2):
cell = (item[0] + x, item[1] + y)
if cell[0] in range(0, self.grid_size[0]) and cell[1] in range(0, self.grid_size[1]) and cell in cells:
if (x == 0 and y == 0) is False:
neighbours += 1
return neighbours
def get_cells(self, cells):
new_cells = {}
for x in range(self.grid_size[0]):
for y in range(self.grid_size[1]):
neighbours = self.get_cell_neighbours((x, y), cells)
if ((x, y) in cells) and (neighbours == 2 or neighbours == 3):
new_cells[(x, y)] = 1
elif ((x, y) in cells) is False and neighbours == 3:
new_cells[(x, y)] = 1
del cells
return new_cells
def run(self):
cells = self.initial_seed()
while True:
if self.__display.update() is False:
self.__display.quit()
sys.exit(0)
cells = self.get_cells(cells)
for cell in cells:
self.__display.draw(cell[0], cell[1])