def on_new_picture(self): file_name = QtGui.QFileDialog.getOpenFileName( self, filter='Image (*.png)', directory=self.config.get( 'frame_image_dir', os.path.expanduser('~') ) ) if file_name: from mqme.mainwindow import MainWindow file_name = unicode(file_name) self.config.set('frame_image_dir', os.path.dirname(file_name)) MainWindow.queue.put({'name': 'config.save'}) if not 'pathes' in Config().current_file(): Config().current_file()['pathes'] = {} image_id = str(uuid.uuid1()) Config().current_file()['pathes'][image_id] = file_name frame_key = self.get_frame_key() if not frame_key in self.current_conf: self.current_conf[frame_key] = [] frame_image = FrameImage( self._scroll_areas[self._current_frame].widget(), file_name, image_id, frame_key ) frame_image.show() width, height = frame_image.ratio() x = 0.5 - (width / 2.0) y = 1.0 - height self.current_conf[frame_key].append({ 'id': image_id, 'width': width, 'height': height, 'x': x, 'y': y }) frame_image.setGeometry( 200 + x * 100, 200 + y * 100, width * 100, height * 100 )
def read_conf(self): for index in range(len(self.current_conf) - 1): frame_key = 'frame_%d' % index self._scroll_areas[index] = QtGui.QScrollArea(self) self._scroll_areas[index].setGeometry(0, 0, 400, 400) self._scroll_areas[index].setWidget(SpriteGridWidget(self)) for obj in self.current_conf[frame_key]: if obj.get('type', None) != 'conf': frame_image = FrameImage( self._scroll_areas[index].widget(), self.config.current_file()['pathes'][obj['id']], obj['id'], frame_key ) frame_image.setGeometry( 200 + obj['x'] * 100, 200 + obj['y'] * 100, obj['width'] * 100, obj['height'] * 100, ) frame_image.show() self._frames_list.addItem('Frame %d' % index) self._scroll_areas[index].hide() self._current_frame = 0 self._scroll_areas[0].show() self._frames_list.setCurrentIndex(0) frame_key = 'frame_%d' % self._current_frame conf = None for elem in self.current_conf[frame_key]: if elem.get('type', None) == 'conf': conf = elem break if conf is None: conf = {'type': 'conf'} self.current_conf[frame_key].append(conf) multiplier = conf.get('multiplier', 1) self._multiplier.setCurrentIndex(multiplier - 1)