Пример #1
0
    def computeShapeLoc(self, coordinates, shape_sizes, desc, max_val, min_val):
        """
        Compute the coordinates and sizes of all shapes.
        """
        random = self.random
        num_shapes = self.params["num_shapes"]
        shape_list = []
        i = 0
        for j in xrange(len(desc)):

            # if not a blank space
            if desc[j] != "S":

                shape = random.randrange(1, num_shapes + 1)
                shape_obj = ShapeObject(
                    random,
                    shape,
                    coordinates[i],
                    coordinates[i + 1],
                    shape_sizes[i],
                    shape_sizes[i + 1],
                    self.scale_len,
                )
                shape_obj.computePos(max_val, min_val)
                shape_list.append(shape_obj)

            i += 2

        return shape_list
Пример #2
0
    def onClickBar(self, event):
        '''
        Determine shape clicked, then ask the user to 
        choose an image to replace current shape.
        '''
        dc = self.hidden_canvas
        pos = event.GetPosition()
        i = dc.GetRed(pos[0], pos[1])

        undo = False
        shape_list_copy = self.copyShapes()
        if i < 255:

            # Ask the user to load an image to replace selected shape
            dirname = ''
            shape = self.shape_list[i]
            shape_pos = shape.getPos()
            text_data = shape.getText()

            disabled = []
            if not self.action_stack: disabled = ['undo']

            dlg = InsertDialog(self, shape_pos, text_data, disabled=disabled)

            if dlg.ShowModal() == wx.ID_OK:
                if dlg.action == 'image':
                    path = dlg.image
                    shape.img = self.createWxImage(path, shape)

                elif dlg.action == 'text':
                    text_data = dlg.text_data
                    shape.setText(text_data)
                    self.drawHiddenBmp()

                elif dlg.action == 'color':
                    shape.color = dlg.color
                    shape.fillColor(dlg.color)

                elif dlg.action == 'color_scheme':
                    self.recolor(dlg.color_scheme)

                elif dlg.action == 'save':
                    self.save(dlg.save)

                elif dlg.action == 'delete':
                    del(self.shape_list[i])
                    self.drawHiddenBmp()

                elif dlg.action == 'move':
                    self.onMoveShape(shape, pos)

                elif dlg.action == 'resize':
                    self.onResizeShape(shape, pos)

                elif dlg.action == 'bring_forward':
                    s = self.shape_list.pop(i)
                    self.shape_list.append(s)
                    self.drawHiddenBmp()

                elif dlg.action == 'undo':
                    self.onUndo()
                    undo = True

                #if not undo:
                #    self.action_stack.append(shape_list_copy)

        else:
            # Ask the user to load an image to replace selected shape
            dirname = ''
            new_size = pos[0], pos[1], 200, 100
            disabled = ['delete', 'move', 'resize', 'bring_forward']
            if not self.action_stack: disabled.append('undo')
            dlg = InsertDialog(self, new_size, disabled = disabled)
                
            if dlg.ShowModal() == wx.ID_OK:
                # create a new shape to hold image or text
                if dlg.action == 'image' or dlg.action == 'text':
                    shape = ShapeObject(gaParams.getRandom(), 1, 0, 0, 1, 1, 10)
                    shape.clear(new_size)

                    if dlg.action == 'image':
                        path = dlg.image
                        shape.img = self.createWxImage(path, shape, original_size = True)

                    elif dlg.action == 'text':
                        text_data = dlg.text_data
                        text_data['border'] = False
                        shape.setText(text_data)

                    self.shape_list.append(shape)
                    self.drawHiddenBmp()

                # if picking new color, then user wants to change bg color
                elif dlg.action == 'color':
                    self.bgcolor = dlg.color

                elif dlg.action == 'color_scheme':
                    self.recolor(dlg.color_scheme)

                elif dlg.action == 'save':
                    self.save(dlg.save)

                elif dlg.action == 'undo':
                    self.onUndo()
                    undo = True

                #if not undo:
                #    self.action_stack.append(shape_list_copy)

            dlg.Destroy()
        self.Refresh()