def displayModel(self): mapinfo = self._getMapInfo() log.msg('displaying map %s' % (mapinfo['name'], )) self.model = Model(pygame.image.load(fs.downloads(mapinfo['name']))) self.main.blit(self.model.background, (0, 0)) for n, character in enumerate(self._getCharacterInfo()): icon_image = pygame.image.load(fs.downloads(character['name'])) icon = Icon() self.model.icons.append(icon) icon.image = icon_image icon.xy = n * 80, n * 80 self.main.blit(icon.image, icon.xy)
def displayModel(self): mapinfo = self._getMapInfo() log.msg('displaying map %s' % (mapinfo['name'],)) self.model = Model(pygame.image.load(fs.downloads(mapinfo['name']))) self.main.blit(self.model.background, (0,0)) for n, character in enumerate(self._getCharacterInfo()): icon_image = pygame.image.load(fs.downloads(character['name'])) icon = Icon() self.model.icons.append(icon) icon.image = icon_image icon.xy = n*80, n*80 self.main.blit(icon.image, icon.xy)
def displayMap(self): mapinfo = self._getMapInfo() log.msg('displaying map %s' % (mapinfo['name'],)) image_object = pygame.image.load(fs.downloads(mapinfo['name'])) self.view.setMap(image_object) # self.view.addCharacter # self.view.addItem # self.view.addText # self.view.addSound self.view.clearObscurement()
def checkFile(self, fileinfo): try: f = file(fs.downloads(fileinfo['name']), 'rb') digest = md5.md5(f.read()).hexdigest() print 'Got file; checksum:', digest if digest == fileinfo['md5']: print 'md5 ok for %s' % (fileinfo['name'],) return except EnvironmentError: pass raise ValueError("File was not received correctly: %s" % ( str(fileinfo),))
def checkFile(self, fileinfo): try: f = file(fs.downloads(fileinfo['name']), 'rb') digest = md5.md5(f.read()).hexdigest() print 'Got file; checksum:', digest if digest == fileinfo['md5']: print 'md5 ok for %s' % (fileinfo['name'], ) return except EnvironmentError: pass raise ValueError("File was not received correctly: %s" % (str(fileinfo), ))
def _getNextFile(self, fileinfos): try: fi = fileinfos.next() try: # do we already have the file? let's find out. self.checkFile(fi) return defer.maybeDeferred(self._getNextFile, fileinfos) except ValueError: log.msg('Getting file at %s' % (fi['uri'],)) uri = 'http://%s:%s%s' % (self.server, HTTPPORT, fi['uri'], ) return downloadPage(uri, fs.downloads(fi['name']) ).addErrback(log.err ).addCallback(lambda _: self.checkFile(fi) ).addCallback(lambda _: self._getNextFile(fileinfos) ) except StopIteration: return
def _getNextFile(self, fileinfos): try: fi = fileinfos.next() try: # do we already have the file? let's find out. self.checkFile(fi) return defer.maybeDeferred(self._getNextFile, fileinfos) except ValueError: log.msg('Getting file at %s' % (fi['uri'], )) uri = 'http://%s:%s%s' % ( self.server, HTTPPORT, fi['uri'], ) return downloadPage(uri, fs.downloads(fi['name'])).addErrback( log.err).addCallback( lambda _: self.checkFile(fi)).addCallback( lambda _: self._getNextFile(fileinfos)) except StopIteration: return
def displayModel(self): if self.canvas is None: self.canvas = gnomecanvas.Canvas() self.mini = gnomecanvas.Canvas() # make canvas draw widgets in the NW corner... self.canvas.set_center_scroll_region(False) self.mini.set_center_scroll_region(False) # out with the old self.gw_viewport1.destroy() # in with the new self.gw_scrolledwindow1.add(self.canvas) self.canvas.show() self.gw_frame_align.add(self.mini) self.mini.show() self.canvas.connect('button-press-event', self.on_canvas_button_press_event) self.canvas.connect('button-release-event', self.on_canvas_button_release_event) self.canvas.connect('motion-notify-event', self.on_canvas_motion_notify_event) self.mini.connect('button-press-event', self.on_mini_button_press_event) self.mini.connect('button-release-event', self.on_mini_button_release_event) self.mini.connect('motion-notify-event', self.on_mini_motion_notify_event) # the mini is always in zoom mode self.mini_operation = Magnify(self.mini, self.canvas) self.mini_operation.beginState() # TODO - clear canvas & mini for a new map # draw map at 100% on canvas mapinfo = self.fileinfos['map'] log.msg('displaying map %s' % (mapinfo['name'], )) self.bg = gdk.pixbuf_new_from_file(fs.downloads(mapinfo['name'])) root = self.canvas.root() root.add("GnomeCanvasPixbuf", pixbuf=self.bg) self.canvas.set_scroll_region(0, 0, self.bg.get_width(), self.bg.get_height()) # fit map in mini ratio = fitBoxInWidget(self.gw_frame_align, self.bg.get_width(), self.bg.get_height()) self.mini.root().add("GnomeCanvasPixbuf", pixbuf=self.bg) self.mini.set_pixels_per_unit(ratio) # draw characters for n, character in enumerate(self.fileinfos.get('character', [])): icon_image = gdk.pixbuf_new_from_file( fs.downloads(character['name'])) if character['corner'] is not None: x, y = character['corner'] root.add("GnomeCanvasPixbuf", pixbuf=icon_image, x=x, y=y) self.mini.root().add( "GnomeCanvasPixbuf", pixbuf=icon_image, x=x, y=y, ) # turn on buttons now that canvas is active self.gw_magnify_on.set_sensitive(True) self.gw_paint_on.set_sensitive(True) self.gw_pan_on.set_sensitive(True) # set obscurement obscure = self.fileinfos.get('mask/obscurement', None) if obscure: self.obscurement = gdk.pixbuf_new_from_file( fs.downloads(obscure['name'])) root.add("GnomeCanvasPixbuf", pixbuf=self.obscurement) self.mini.root().add("GnomeCanvasPixbuf", pixbuf=self.obscurement)
def displayModel(self): if self.canvas is None: self.canvas = gnomecanvas.Canvas() self.mini = gnomecanvas.Canvas() # make canvas draw widgets in the NW corner... self.canvas.set_center_scroll_region(False) self.mini.set_center_scroll_region(False) # out with the old self.gw_viewport1.destroy() # in with the new self.gw_scrolledwindow1.add(self.canvas) self.canvas.show() self.gw_frame_align.add(self.mini) self.mini.show() self.canvas.connect('button-press-event', self.on_canvas_button_press_event) self.canvas.connect('button-release-event', self.on_canvas_button_release_event) self.canvas.connect('motion-notify-event', self.on_canvas_motion_notify_event) self.mini.connect('button-press-event', self.on_mini_button_press_event) self.mini.connect('button-release-event', self.on_mini_button_release_event) self.mini.connect('motion-notify-event', self.on_mini_motion_notify_event) # the mini is always in zoom mode self.mini_operation = Magnify(self.mini, self.canvas) self.mini_operation.beginState() # TODO - clear canvas & mini for a new map # draw map at 100% on canvas mapinfo = self.fileinfos['map'] log.msg('displaying map %s' % (mapinfo['name'],)) self.bg = gdk.pixbuf_new_from_file(fs.downloads(mapinfo['name'])) root = self.canvas.root() root.add("GnomeCanvasPixbuf", pixbuf=self.bg) self.canvas.set_scroll_region(0, 0, self.bg.get_width(), self.bg.get_height() ) # fit map in mini ratio = fitBoxInWidget(self.gw_frame_align, self.bg.get_width(), self.bg.get_height()) self.mini.root().add("GnomeCanvasPixbuf", pixbuf=self.bg) self.mini.set_pixels_per_unit(ratio) # draw characters for n, character in enumerate(self.fileinfos.get('character', [])): icon_image = gdk.pixbuf_new_from_file( fs.downloads(character['name']) ) if character['corner'] is not None: x, y = character['corner'] root.add("GnomeCanvasPixbuf", pixbuf=icon_image, x=x, y=y ) self.mini.root().add("GnomeCanvasPixbuf", pixbuf=icon_image, x=x, y=y, ) # turn on buttons now that canvas is active self.gw_magnify_on.set_sensitive(True) self.gw_paint_on.set_sensitive(True) self.gw_pan_on.set_sensitive(True) # set obscurement obscure = self.fileinfos.get('mask/obscurement', None) if obscure: self.obscurement = gdk.pixbuf_new_from_file( fs.downloads(obscure['name'])) root.add("GnomeCanvasPixbuf", pixbuf=self.obscurement) self.mini.root().add("GnomeCanvasPixbuf", pixbuf=self.obscurement)