Beispiel #1
0
    def draw_filled_hexagon(self, position, fill_color, number=None):
        qpainter = self.painter

        pen = data.QPen(data.Qt.SolidLine)
        pen.setColor(fill_color)
        brush = data.QBrush(data.Qt.SolidPattern)
        brush.setColor(fill_color)
        qpainter.setBrush(brush)
        qpainter.setPen(pen)
        hex_points = list(
            HexBuilder.generate_hexagon_points(self.edge_length, position))
        x_correction = self.edge_length / 2
        y_correction = self.edge_length / (2 * math.tan(math.radians(30)))
        hex_points = [(x - x_correction, y - y_correction)
                      for x, y in hex_points]
        hex_qpoints = [data.QPoint(*x) for x in hex_points]
        qpainter.drawPolygon(*hex_qpoints)

        if (self.SHOW_FIELD_NUMBERS == True) and (number != None):
            font = data.QFont('Courier', 8)
            font.setBold(True)
            qpainter.setFont(font)
            pen = data.QPen(data.Qt.SolidLine)
            pen.setColor(data.QColor(0, 0, 0))
            qpainter.setPen(pen)

            font_metric = data.QFontMetrics(font)
            x = position[0] - font_metric.width(str(number)) / 2
            y = position[1] + font_metric.height() / 4

            qpainter.drawText(data.QPoint(x, y), str(number))
Beispiel #2
0
 def draw_line_hexagon(self, 
                       position, 
                       line_width, 
                       line_color,
                       paint_enabled=[True,True,True,True,True,True],
                       shadow=False):
     qpainter = self.painter
     
     if line_width == 0:
         return
     
     pen = data.QPen(data.Qt.SolidLine)
     pen.setCapStyle(data.Qt.RoundCap)
     pen.setJoinStyle(data.Qt.RoundJoin)
     pen.setWidth(line_width)
     pen.setColor(line_color)
     qpainter.setPen(pen)
     hex_points = list(
         HexBuilder.generate_hexagon_points(self.edge_length, position)
     )
     x_correction = self.edge_length / 2
     y_correction = self.edge_length / (2 * math.tan(math.radians(30)))
     hex_points = [(x-x_correction, y-y_correction) for x, y in hex_points]
     hex_lines = []
     
     for i in range(len(hex_points)):
         if paint_enabled[i] == False:
             continue
         n = i + 1
         if n > (len(hex_points)-1):
             n = 0
         hex_lines.append(
             data.QLine(
                 data.QPoint(*hex_points[i]), 
                 data.QPoint(*hex_points[n])
             )
         )
     if hex_lines:
         if shadow == True:
             shadow_0_color = data.QColor(line_color)
             shadow_0_color.setAlpha(64)
             shadow_1_color = data.QColor(line_color)
             shadow_1_color.setAlpha(128)
             
             pen.setWidth(line_width*2.0)
             pen.setColor(shadow_0_color)
             qpainter.setPen(pen)
             qpainter.drawLines(*hex_lines)
             pen.setWidth(line_width*1.5)
             pen.setColor(shadow_1_color)
             qpainter.setPen(pen)
             qpainter.drawLines(*hex_lines)
             pen.setWidth(line_width)
             pen.setColor(line_color)
             qpainter.setPen(pen)
             qpainter.drawLines(*hex_lines)
         else:
             qpainter.drawLines(*hex_lines)
Beispiel #3
0
 def init_extra_button(self, 
                       parent, 
                       main_form, 
                       input_extra_pixmap, 
                       input_extra_function=None, 
                       input_extra_function_text=""):   
     #Store the parent and main form references
     self._parent     = parent
     self.main_form  = main_form
     #Initialize the extra button
     self.extra_button = data.QLabel(self)
     width   = int(self.geometry().width() * self.extra_button_size_factor)
     height  = int(self.geometry().height() * self.extra_button_size_factor)
     self.extra_button_position = data.QPoint(
                                     self.geometry().width()*2/3-width, 
                                     self.geometry().height()*1/4
                                     )
     rectangle   = data.QRect(self.extra_button_position, data.QSize(width, height))
     self.extra_button.setGeometry(rectangle)
     self.extra_button_stored_pixmap = input_extra_pixmap
     self.extra_button.setPixmap(input_extra_pixmap)
     self.extra_button.setScaledContents(True)
     #Store the function options
     self.extra_button_function      = input_extra_function
     self.extra_button_function_text = input_extra_function_text
     #Set the extra button opacity to low
     self._set_extra_button_opacity(self.OPACITY_LOW)
     #Overridden the extra buttons events
     self.extra_button.mousePressEvent   = self.extra_button_click
     self.extra_button.enterEvent        = self.extra_button_enter_event
     self.extra_button.leaveEvent        = self.extra_button_leave_event
Beispiel #4
0
 def scale(self, width_scale_factor=1, height_scale_factor=1):
     """Scale the size of the function wheel and all of its child widgets"""
     #Scale the function wheel form
     geo = self.geometry()
     new_width = int(geo.width() * width_scale_factor)
     new_height = int(geo.height() * height_scale_factor)
     rectangle = data.QRect(
         geo.topLeft(), 
         data.QSize(new_width, new_height)
     )
     self.setGeometry(rectangle)
     #Scale all of the function wheel child widgets
     for button in self.children():
         geo = button.geometry()
         new_topLeft = data.QPoint(
             int(geo.topLeft().x() * width_scale_factor),
             int(geo.topLeft().y() * height_scale_factor)
         )
         new_width = int(geo.width() * width_scale_factor)
         new_height = int(geo.height() * height_scale_factor)
         new_size = data.QSize(new_width, new_height)
         rectangle   = data.QRect(new_topLeft, new_size)
         button.setGeometry(rectangle)
     #Center to main form
     self.center(self.size())
Beispiel #5
0
 def center(self, size):
     """
     Center the settings GUI manipulator to the main form,
     according to the size parameter
     """
     x_offset = int((self.main_form.size().width() - size.width()) / 2)
     y_offset = int((self.main_form.size().height()*93/100 - size.height()) / 2)
     rectangle_top_left  = data.QPoint(x_offset, y_offset)
     rectangle_size = size
     rectangle = data.QRect(rectangle_top_left, rectangle_size)
     self.setGeometry(rectangle)
Beispiel #6
0
 def center(self):
     if self.parent() != None:
         qr = self.frameGeometry()
         geo = self.parent().frameGeometry()
         cp = data.QPoint((geo.width() / 2) - (qr.width() / 2),
                          (geo.height() / 2) - (qr.height() / 2))
         self.move(cp)
     else:
         qr = self.frameGeometry()
         cp = data.QDesktopWidget().availableGeometry().center()
         qr.moveCenter(cp)
         self.move(qr.topLeft())
Beispiel #7
0
    def draw_full_hexagon(self, position, fill_color, line_width, line_color):
        qpainter = self.painter

        pen = data.QPen(data.Qt.SolidLine)
        pen.setColor(line_color)
        pen.setCapStyle(data.Qt.RoundCap)
        pen.setWidth(line_width)
        brush = data.QBrush(data.Qt.SolidPattern)
        brush.setColor(fill_color)
        qpainter.setBrush(brush)
        qpainter.setPen(pen)
        hex_points = list(
            HexBuilder.generate_hexagon_points(self.edge_length, position))
        x_correction = self.edge_length / 2
        y_correction = self.edge_length / (2 * math.tan(math.radians(30)))
        hex_points = [(x - x_correction, y - y_correction)
                      for x, y in hex_points]
        hex_qpoints = [data.QPoint(*x) for x in hex_points]
        qpainter.drawPolygon(*hex_qpoints)
Beispiel #8
0
    def draw_line_hexagon_no_double_paint(
            self,
            position,
            line_width,
            line_color,
            paint_enabled=[True, True, True, True, True, True],
            shadow=False):
        qpainter = self.painter

        if line_width == 0:
            return

        pen = data.QPen(data.Qt.SolidLine)
        pen.setCapStyle(data.Qt.RoundCap)
        pen.setJoinStyle(data.Qt.RoundJoin)
        pen.setWidth(line_width)
        pen.setColor(line_color)
        qpainter.setPen(pen)
        hex_points = list(
            HexBuilder.generate_hexagon_points(self.edge_length, position))
        x_correction = self.edge_length / 2
        y_correction = self.edge_length / (2 * math.tan(math.radians(30)))
        hex_points = [(x - x_correction, y - y_correction)
                      for x, y in hex_points]
        hex_lines = []

        def line_test(in_line):
            DIFF = 3
            line = in_line
            reversed_line = (line[1], line[0])
            x1, y1 = line[0]
            x2, y2 = line[1]
            xr1, yr1 = reversed_line[0]
            xr2, yr2 = reversed_line[1]
            for l in self.stored_lines:
                xl1, yl1 = l[0]
                xl2, yl2 = l[1]
                if (abs(xl1 - x1) < DIFF and abs(yl1 - y1) < DIFF
                        and abs(xl2 - x2) < DIFF and abs(yl2 - y2) < DIFF):
                    if not (line in self.stored_lines):
                        self.stored_lines.append(line)
                        #self.stored_lines.append(reversed_line)
                    return False
                elif (abs(xl1 - xr1) < DIFF and abs(yl1 - yr1) < DIFF
                      and abs(xl2 - xr2) < DIFF and abs(yl2 - yr2) < DIFF):
                    if not (reversed_line in self.stored_lines):
                        self.stored_lines.append(line)
                        #self.stored_lines.append(reversed_line)
                    return False
            else:
                self.stored_lines.append(line)
                self.stored_lines.append(reversed_line)
                return True

        for i in range(len(hex_points)):
            if paint_enabled[i] == False:
                continue
            n = i + 1
            if n > (len(hex_points) - 1):
                n = 0
            if line_test((hex_points[i], hex_points[n])) == True:
                hex_lines.append(
                    data.QLine(data.QPoint(*hex_points[i]),
                               data.QPoint(*hex_points[n])))
        if hex_lines:
            if shadow == True:
                shadow_0_color = data.QColor(line_color)
                shadow_0_color.setAlpha(64)
                shadow_1_color = data.QColor(line_color)
                shadow_1_color.setAlpha(128)

                pen.setWidth(line_width * 2.0)
                pen.setColor(shadow_0_color)
                qpainter.setPen(pen)
                qpainter.drawLines(*hex_lines)
                pen.setWidth(line_width * 1.5)
                pen.setColor(shadow_1_color)
                qpainter.setPen(pen)
                qpainter.drawLines(*hex_lines)
                pen.setWidth(line_width)
                pen.setColor(line_color)
                qpainter.setPen(pen)
                qpainter.drawLines(*hex_lines)
            else:
                qpainter.drawLines(*hex_lines)
Beispiel #9
0
class DoubleButton(CustomButton):
    """
    A CustomButton with an extra button added to itself,
    used for when double functionality is needed, for example when
    a function has a version with or without a dialog window.
    """
    #The extra button reference
    parent                      = None
    main_form                   = None
    extra_button                = None
    extra_button_size_factor    = 1/3
    extra_button_position       = data.QPoint(0, 0)
    extra_button_stored_opacity = None
    extra_button_stored_pixmap  = None
    extra_button_function       = None
    extra_button_function_text  = None
    #Class constants
    OPACITY_LOW                 = 0.5
    OPACITY_HIGH                = 1.0
    
    def init_extra_button(self, 
                          parent, 
                          main_form, 
                          input_extra_pixmap, 
                          input_extra_function=None, 
                          input_extra_function_text=""):   
        #Store the parent and main form references
        self._parent     = parent
        self.main_form  = main_form
        #Initialize the extra button
        self.extra_button = data.QLabel(self)
        width   = int(self.geometry().width() * self.extra_button_size_factor)
        height  = int(self.geometry().height() * self.extra_button_size_factor)
        self.extra_button_position = data.QPoint(
                                        self.geometry().width()*2/3-width, 
                                        self.geometry().height()*1/4
                                        )
        rectangle   = data.QRect(self.extra_button_position, data.QSize(width, height))
        self.extra_button.setGeometry(rectangle)
        self.extra_button_stored_pixmap = input_extra_pixmap
        self.extra_button.setPixmap(input_extra_pixmap)
        self.extra_button.setScaledContents(True)
        #Store the function options
        self.extra_button_function      = input_extra_function
        self.extra_button_function_text = input_extra_function_text
        #Set the extra button opacity to low
        self._set_extra_button_opacity(self.OPACITY_LOW)
        #Overridden the extra buttons events
        self.extra_button.mousePressEvent   = self.extra_button_click
        self.extra_button.enterEvent        = self.extra_button_enter_event
        self.extra_button.leaveEvent        = self.extra_button_leave_event
    
    def extra_button_click(self, event):
        """mousePressEvent for the extra button"""
        #Execute the function if it was initialized
        if self.extra_button_function != None:
            try:
                #Set focus to the last focused widget stored on the main form
                if self.focus_last_widget == data.HexButtonFocus.TAB:
                    self.main_form.last_focused_widget.currentWidget().setFocus()
                elif self.focus_last_widget == data.HexButtonFocus.WINDOW:
                    self.main_form.last_focused_widget.setFocus()
                #Store the executed function for next cursor placement
                self.main_form.view.last_executed_function_text = self.function_text
                #Execute the buttons stored function
                self.extra_button_function()
            except Exception as ex:
                print(ex)
                message = "You need to focus one of the editor windows first!"
                self.main_form.display.repl_display_message(
                    message, 
                    message_type=data.MessageType.ERROR
                )
            #Close the function wheel
            self._parent.hide()
    
    def extra_button_enter_event(self, event):
        """Overloaded widget enter event"""
        #Check if the button is enabled
        if self.isEnabled() == True:
            self._set_extra_button_opacity(self.OPACITY_HIGH)
            #Display the stored extra buttons function text
            extra_button_font = data.QFont(
                'Courier', 
                self.stored_font.pointSize()-2, 
                weight=data.QFont.Bold
            )
            self._parent.display(
                self.extra_button_function_text, 
                extra_button_font
            )
    
    def extra_button_leave_event(self, event):
        """Overloaded widget enter event"""
        #Check if the button is enabled
        if self.isEnabled() == True:
            self._set_extra_button_opacity(self.OPACITY_LOW)
            #Clear the function text
            extra_button_font = data.QFont(
                'Courier', 
                self.stored_font.pointSize()-2, 
                weight=data.QFont.Bold
            )
            self._parent.display(
                "", 
                extra_button_font
            )
    
    def extra_button_enable(self):
        """Hide and disable the extra button"""
        self.extra_button.setVisible(True)
        self.extra_button.setEnabled(True)
    
    def extra_button_disable(self):
        """Hide and disable the extra button"""
        self.extra_button.setVisible(False)
        self.extra_button.setEnabled(False)
        self._set_extra_button_opacity(self.OPACITY_LOW)
    
    def resizeEvent(self, event):
        """Overridden resize event"""
        #Execute the superclass resize function
        super().resizeEvent(event)
        #Update the extra button geometry
        width = int(self.geometry().width() * self.extra_button_size_factor)
        height = int(self.geometry().height() * self.extra_button_size_factor)
        rectangle   = data.QRect(
                        self.extra_button_position, 
                        data.QSize(width, height)
                        )
        self.extra_button.setGeometry(rectangle)
    
    def _set_extra_button_opacity(self, input_opacity):
        """Set the opacity of the extra button"""
        #Store the opacity
        self.extra_button_stored_opacity = input_opacity
        #Create and initialize the QImage from the stored QPixmap
        button_image = self.extra_button_stored_pixmap
        image = data.QImage(
            button_image.size(), 
            data.QImage.Format_ARGB32_Premultiplied
        )
        image.fill(data.Qt.transparent)
        #Create and initialize the QPainter that will manipulate the QImage
        button_painter = data.QPainter(image)
        button_painter.setOpacity(input_opacity)
        button_painter.drawPixmap(0, 0, button_image)
        button_painter.end()
        #Display the manipulated image
        self.extra_button.setPixmap(data.QPixmap.fromImage(image))