Exemplo n.º 1
0
 def __init__(self, startFrame, frames):
     QGraphicsRectItem.__init__(self)
     self.setRect(startFrame * frameWidth, 0, frames * frameWidth,
                  trackHeight)
     self.setBrush(self.fill)
     self.pen.setWidth(2)
     self.setPen(self.pen)
Exemplo n.º 2
0
    def hoverEnterEvent(self, event):
        super(HooverBar, self).hoverEnterEvent(event)

        if self.gi == None:
            self.gi = QGraphicsRectItem(0, 0, 100, 100)
            self.gi.setBrush(QBrush(QColor(0, 64, 0, 192)))
            self.gi.setPen(QPen(Qt.transparent))
            self.gi.setPos(event.scenePos().x() + 20,
                           event.scenePos().y() + 20)

            x = y = 10
            w = 0
            for t in self.description:
                description = QGraphicsSimpleTextItem()
                description.setFont(self.base_font)
                description.setBrush(QBrush(Qt.white))
                description.setText(t)
                description.setParentItem(self.gi)
                description.setPos(x, y)
                y += description.boundingRect().height()
                w = max(w, description.boundingRect().width())
            y += x
            w += 2 * x

            self.gi.setRect(0, 0, w, y)
            self.scene().addItem(self.gi)
Exemplo n.º 3
0
 def __init__(self,element):
     QGraphicsRectItem.__init__(self)
     self.setFlag(QGraphicsItem.ItemIsMovable,True)
     self.setFlag(QGraphicsItem.ItemIsSelectable,True)
     self.setRect(50,50,50,50)
     self.setAcceptTouchEvents(True)
     self.setActive(True)
     self.setEnabled(True)
     self.GraphicsElement=element
Exemplo n.º 4
0
    def hoverEnterEvent(self, event):  # QGraphicsSceneHoverEvent * event )
        # BUG I had a crash running this, I suspect ownership issues regarding
        # graphics items...

        global configuration
        #mainlog.debug("hoverEnterEvent pos={}-{}".format(event.scenePos().x(),event.scenePos().y()))
        # mainlog.debug("hoverEnterEvent data={}".format(self.data))
        super(HooverBar, self).hoverEnterEvent(event)

        if self.gi == None:
            if self.hoover_text:
                self.gi = QGraphicsRectItem(0, 0, 100, 100)
                self.gi.setBrush(QBrush(QColor(0, 64, 0, 192)))
                self.gi.setPen(QPen(Qt.transparent))
                self.gi.setPos(event.scenePos().x() + 20,
                               event.scenePos().y() + 20)

                # txt = [ "" ]

                # txt = [ u"{} {}".format(self.data.production_file.order_part.human_identifier,
                #                        date_to_dmy(self.data.production_file.order_part.deadline)),
                #         nstr(self.data.production_file.order_part.description),
                #         nstr(self.data.description),
                #         _("{}x{}={}h, rest:{}h").format(self.data.production_file.order_part.qty,
                #                                         nice_round(self.data.planned_hours),
                #                                         nice_round(self.data.production_file.order_part.qty*self.data.planned_hours),
                #                                         nice_round(self.data.planned_hours*self.data.production_file.order_part.qty - self.data.done_hours))]

                x = y = 10
                w = 0
                for t in self.hoover_text:
                    description = QGraphicsSimpleTextItem()
                    description.setFont(self.base_font)
                    description.setBrush(QBrush(Qt.white))
                    description.setText(t)
                    description.setParentItem(self.gi)
                    description.setPos(x, y)
                    y += description.boundingRect().height()
                    w = max(w, description.boundingRect().width())
                y += x
                w += 2 * x

                # description.setHtml(u"|{}| <b>{}</b><br/>{}<br>{}x{}={}h".format(
                #         self.data.production_file.order_part.human_identifier,
                #         self.data.production_file.order_part.description,
                #         self.data.description,
                #         self.data.production_file.order_part.qty, self.data.planned_hours, self.data.production_file.order_part.qty*self.data.planned_hours))

                # description.setDefaultTextColor(Qt.white)
                # br = description.boundingRect()

                self.gi.setRect(0, 0, w, y)
                self.scene().addItem(self.gi)
Exemplo n.º 5
0
 def testIt(self):
     scene = QGraphicsScene()
     i1 = QGraphicsRectItem()
     scene.addItem(i1)
     i2 = QGraphicsRectItem(i1)
     i3 = QGraphicsRectItem()
     i4 = QGraphicsRectItem()
     group = scene.createItemGroup((i2, i3, i4))
     scene.removeItem(i1)
     del i1  # this shouldn't delete i2
     self.assertEqual(i2.scene(), scene)
     scene.destroyItemGroup(group)
     self.assertRaises(RuntimeError, group.type)
Exemplo n.º 6
0
    def setUp(self):
        #Acquire resources
        super(ItemRetrieve, self).setUp()
        self.scene = QGraphicsScene()

        self.topleft = QGraphicsRectItem(0, 0, 100, 100)
        self.topright = QGraphicsRectItem(100, 0, 100, 100)
        self.bottomleft = QGraphicsRectItem(0, 100, 100, 100)
        self.bottomright = QGraphicsRectItem(100, 100, 100, 100)

        self.items = [
            self.topleft, self.topright, self.bottomleft, self.bottomright
        ]

        for item in self.items:
            self.scene.addItem(item)
Exemplo n.º 7
0
    def createRect(self, x, y, Lx, Ly, pen=QPen(), brush=QBrush()):
        """
        Create a rectangle somewhere, in relative coordinates originating
        from the lower left position.
        """
        x1 = x

        # Y-position from the top, these are the coordinates used to create a
        # rect item.
        y1 = self.ysize-y-Ly
        return QGraphicsRectItem(x1,
                                 y1,
                                 Lx,
                                 Ly,
                                 pen=pen,
                                 brush=brush)
Exemplo n.º 8
0
 def testIt(self):
     scene = QGraphicsScene()
     i1 = QGraphicsRectItem()
     scene.addItem(i1)
     i2 = QGraphicsRectItem(i1)
     i3 = QGraphicsRectItem()
     i4 = QGraphicsRectItem()
     group = scene.createItemGroup((i2, i3, i4))
     scene.removeItem(i1)
     del i1  # this shouldn't delete i2
     self.assertEqual(i2.scene(), scene)
     scene.destroyItemGroup(group)
     self.assertRaises(RuntimeError, group.type)
Exemplo n.º 9
0
    def draw(self, scene, y):
        span_height = 15
        flag_height = span_height * 1.2

        min_time, max_time = day_span(self.base_time)

        # Draw a time line

        nb_hours = 12

        length = self.time_to_x(self.base_time +
                                timedelta(float(nb_hours) / 24.0))
        scene.addLine(QLineF(0, y, length, y), QPen(Qt.gray))

        x = self.base_time - timedelta(0,
                                       seconds=self.base_time.second,
                                       minutes=self.base_time.minute,
                                       microseconds=self.base_time.microsecond)
        end_x = self.base_time + timedelta(hours=12)

        while x <= end_x:
            tx = self.time_to_x(x)
            scene.addLine(QLineF(tx, y - 5, tx, y + 5), QPen(Qt.gray))

            description = QGraphicsSimpleTextItem()
            description.setText(str(x.hour))
            description.setPos(tx + 5, y)  # y - br.height()/2)
            description.setBrush(QBrush(Qt.gray))
            scene.addItem(description)

            x = x + timedelta(hours=1)

        # Draw spans

        total_time = timedelta(0)

        for start, end, description in self.spans:

            mainlog.debug("Span : {} -> {}".format(start, end))
            s = self.time_to_x(max(min_time, start))
            e = self.time_to_x(min(max_time, end))
            total_time += end - start

            # mainlog.debug("Total time += {}".format(end - start))

            glass_path(scene, s, y - span_height / 2, e - s, span_height,
                       QColor(self.span_color))

            r = HooverBar(QRect(s, y - span_height / 2, e - s, span_height),
                          None)

            if not description:
                r.description = [
                    _("Duration"),
                    duration_to_hm((end - start).total_seconds() / 3600.0)
                ]
            elif isinstance(description, list):
                r.description = description
            else:
                r.description = [description]

            scene.addItem(r)

        # Make the timeline clickable

        r = QGraphicsRectItem(QRect(0, 0, length, 30), None)
        scene.addItem(r)
        r.setPos(0, y - 15)
        r.setPen(QPen(Qt.transparent))
        r.setCursor(Qt.PointingHandCursor)
        r.setFlags(r.flags() | QGraphicsItem.ItemIsSelectable)
        r.setData(0, self.task)

        # Draw flags

        for t, kind, data, hoover_text in self.flags:
            x = self.time_to_x(t)

            # mainlog.debug("Drawing a flag on {} at {}".format(t,x))

            l = QGraphicsLineItem(0.0, float(-flag_height), 0.0,
                                  float(+flag_height), None)
            l.setPen(QPen(Qt.black))
            scene.addItem(l)
            l.setPos(x, y)

            #scene.addLine ( QLineF(x,y-flag_height,x,y+flag_height), QPen(Qt.black) )

            if kind == Timeline.START:
                scene.addRect(QRect(x, y - flag_height, 5, 5), QPen(Qt.black),
                              QBrush(Qt.black))
                scene.addRect(QRect(x, y + flag_height - 5, 5, 5),
                              QPen(Qt.black), QBrush(Qt.black))
            elif kind == Timeline.END:
                scene.addRect(QRect(x - 5, y - flag_height, 5, 5),
                              QPen(Qt.black), QBrush(Qt.black))
                scene.addRect(QRect(x - 5, y + flag_height - 5, 5, 5),
                              QPen(Qt.black), QBrush(Qt.black))

            r = HooverBar(QRect(0, 0, 10, 2 * flag_height), None)
            r.description = hoover_text
            scene.addItem(r)

            r.setPos(x - 5, y - flag_height)
            r.setPen(QPen(Qt.transparent))
            # item = scene.addRect ( QRect(x-5,y-flag_height,10,2*flag_height), QPen(Qt.white))
            r.setCursor(Qt.PointingHandCursor)
            r.setFlags(r.flags() | QGraphicsItem.ItemIsSelectable)
            r.setData(0, data)

        # Timeline's text

        description = QGraphicsSimpleTextItem()

        duration = ""
        if total_time.seconds > 60 or total_time.days > 0:
            duration = " - " + duration_to_hm(
                total_time.total_seconds() / 3600.0)

        tname = self.task_name.replace('\n', ' ')
        if len(tname) > 80:
            tname = tname[0:80] + u"..."

        description.setText(u"{}{}".format(tname, duration))
        br = QRect(0, 0,
                   description.boundingRect().width(),
                   description.boundingRect().height())
        description.setPos(0,
                           y - br.height() - flag_height)  # y - br.height()/2)

        r = QGraphicsRectItem(QRect(0, 0,
                                    br.width() + 10,
                                    br.height() + 10), None)
        r.setPos(-5,
                 y - 5 - br.height() - flag_height)  # y - br.height()/2 - 5)
        r.setPen(QPen(Qt.transparent))
        r.setBrush(QBrush(QColor(255, 255, 255, 128)))

        scene.addItem(r)
        scene.addItem(description)
Exemplo n.º 10
0
class HooverBar(QGraphicsRectItem):
    def __init__(self, *args):
        super(HooverBar, self).__init__(*args)
        self.setAcceptHoverEvents(True)
        self.gi = None
        self.description = [""]
        self.base_font = QFont()
        self.setPen(QPen(Qt.transparent))

    def hoverEnterEvent(self, event):
        super(HooverBar, self).hoverEnterEvent(event)

        if self.gi == None:
            self.gi = QGraphicsRectItem(0, 0, 100, 100)
            self.gi.setBrush(QBrush(QColor(0, 64, 0, 192)))
            self.gi.setPen(QPen(Qt.transparent))
            self.gi.setPos(event.scenePos().x() + 20,
                           event.scenePos().y() + 20)

            x = y = 10
            w = 0
            for t in self.description:
                description = QGraphicsSimpleTextItem()
                description.setFont(self.base_font)
                description.setBrush(QBrush(Qt.white))
                description.setText(t)
                description.setParentItem(self.gi)
                description.setPos(x, y)
                y += description.boundingRect().height()
                w = max(w, description.boundingRect().width())
            y += x
            w += 2 * x

            self.gi.setRect(0, 0, w, y)
            self.scene().addItem(self.gi)

    def hoverMoveEvent(self, event):
        super(HooverBar, self).hoverMoveEvent(event)

        # if self.gi:
        #     mainlog.debug("hoverMoveEvent GI pos={}-{}".format(self.gi.pos().x(),self.gi.pos().y()))
        # mainlog.debug("hoverMoveEvent pos={}-{}".format(event.scenePos().x(),event.scenePos().y()))
        if self.gi:
            self.gi.setPos(event.scenePos().x() + 20,
                           event.scenePos().y() + 20)

    def hoverLeaveEvent(self, event):
        super(HooverBar, self).hoverLeaveEvent(event)

        if self.gi:

            # QtDoc : Removes the item item and all its children from the scene.
            #         The ownership of item is passed on to the caller

            self.gi.setParentItem(None)
            # self.scene().removeItem(self.gi)
            self.gi = None
 def __init__(self, x, y, w, h):
     QGraphicsRectItem.__init__(self, x, y, w, h)
Exemplo n.º 12
0
 def __init__(self, x, y, w, h):
     QGraphicsRectItem.__init__(self, x, y, w, h)
Exemplo n.º 13
0
    def __init__(self, parent, xvals, G, ylim=(0, 1),
                 grid=True,
                 xlabel=None,
                 ylabel=None,
                 title=None,
                 colors=DEFAULT_COLORS, size=(1200, 600),
                 legend=None,
                 legendpos=None):
        """
        Initialize a bar scene

        Args:
            xvals: labels and x positions of the bars
            G: Number of bars per x value
            ylim: y limits of the figure
            xlabel: label below x-axis
            ylabel: label on left side of the y-axis
            title: figure title
            colors: color cycler
            size: size of the plot in pixels
            legend: list of legend strings to show.
            legendpos: position of legend w.r.t. default position, in pixels
        """
        super().__init__(parent=parent)
        self.setSceneRect(QRect(0, 0, *size))

        # self.setBackgroundBrush(ASCEEColors.bgBrush(0, size[0]))
        self.ylim = ylim
        N = len(xvals)
        self.N = N
        self.G = G
        self.bgs = []

        self.size = size
        xsize, ysize = size

        self.xsize = xsize
        self.ysize = ysize

        self.colors = colors

        # Size of the frame
        Lx = xsize - rightoffset - leftoffset
        Ly = ysize - topoffset - bottomoffset

        # The main frame where the bars are in.
        mainframe = self.createRect(leftoffset,
                                    bottomoffset,
                                    Lx,
                                    Ly)
        # Set the y ticks and ticklabels
        self.yticks = []
        txtmaxwidth = 0
        for i in range(nyticks):
            y = bottomoffset+Ly*i/(nyticks-1)

            ytick = self.addLine(leftoffset,
                                 y,
                                 leftoffset-ticklength,
                                 y)
            if grid:
                ygrid = self.addLine(leftoffset,
                                     y,
                                     xsize-rightoffset,
                                     y, pen=QPen(Qt.gray))

            range_ = ylim[1]-ylim[0]
            ytickval = i/(nyticks-1)*range_ + ylim[0]
            yticklabel = f'{ytickval:.0f}'
            txt = graphicsTextItem(yticklabel)
            txtwidth = txt.boundingRect().width()
            txtmaxwidth = max(txtmaxwidth, txtwidth)
            txt.setPos(leftoffset-10-txtwidth,
                       ysize - y-.022*self.ysize)
            self.addItem(txt)
            self.yticks.append(ytick)

        # Main frame added after grid lines, to get the color right
        self.addItem(mainframe)

        # Create the bars
        for g in range(G):
            bg = []
            for n in range(N):
                barrect = self.getBarRect(n, g, 0)
                baritem = QGraphicsRectItem(barrect, brush=QBrush(Qt.blue))

                self.addItem(baritem)
                bg.append(baritem)
            self.bgs.append(bg)

        # Add x ticks and ticklabels
        xticklabels = []
        for n in range(N):
            xticklabel = f'{xvals[n]}'
            txt = graphicsTextItem(xticklabel)
            txtxpos = self.getBarGroupMidPos(n)-12
            txt.setPos(txtxpos,
                       self.ysize-bottomoffset+xticklabeloffset)
            txt.rotate(-90)
            self.addItem(txt)
            xticklabels.append(txt)

        # Set xlabel
        if xlabel is not None:
            xlabel = graphicsTextItem(xlabel)
            width = xlabel.boundingRect().width()
            txtxpos = xsize/2-width/2
            txtypos = ysize - xlabelbottomoffset
            xlabel.setPos(txtxpos, txtypos)
            self.addItem(xlabel)

        # # Set ylabel
        if ylabel is not None:
            ylabel = graphicsTextItem(ylabel)
            ylabel.setPos(ylabelleftoffset,
                          (ysize-topoffset-bottomoffset)/2+topoffset)
            ylabel.rotate(-90)
            self.addItem(ylabel)

        # Set title
        if title is not None:
            title = graphicsTextItem(title)
            width = xlabel.boundingRect().width()
            txtxpos = self.xsize/2-width/2
            txtypos = (1-.998)*self.ysize
            title.setPos(txtxpos, txtypos)
            self.addItem(title)

        if legend is not None:
            maxlegtxtwidth = 0
            legposx, legposy = (0, 0) if legendpos is None else legendpos

            legpos = (xsize-rightoffset-300+legposx,
                      ysize-topoffset-30+legposy)

            dyleg = 15
            dylegtxt = dyleg
            Lylegrect = 10
            Lxlegrect = 20
            legrectmargin = 5
            boxtopleft = QPointF(legpos[0]-legrectmargin,
                                 ysize-legpos[1]-Lylegrect-legrectmargin)

            legbox = self.addRect(QRectF(0, 0, 0, 0),
                                  pen=QPen(), brush=QBrush(Qt.white))

            for i, leg in enumerate(legend):
                leglabel = legend[i]

                # The position of the legend, in screen coordinates
                pos = (legpos[0], legpos[1] - i*dyleg)
                color = self.colors[i % len(self.colors)]

                legrect = self.createRect(*pos, Lxlegrect, Lylegrect)

                legrect.setBrush(QBrush(color))
                legtxt = graphicsTextItem(leglabel)
                maxlegtxtwidth = max(maxlegtxtwidth,
                                     legtxt.boundingRect().width())

                self.addItem(legrect)
                self.addItem(legtxt)

                legtxt.setPos(legpos[0]+Lxlegrect,
                              ysize-pos[1]-dylegtxt-3)

            legboxsize = QSize(maxlegtxtwidth+Lxlegrect+2*legrectmargin,
                               (i+1)*dyleg+legrectmargin)
            legboxrect = QRectF(boxtopleft, legboxsize)
            legbox.setRect(legboxrect)
Exemplo n.º 14
0
    def reload(self, order_overview_widget, all_ops, all_operations, sort=1):

        # mainlog.debug("reload...")
        progress = QProgressDialog(_("Collecting data..."), None, 0,
                                   len(all_ops) + 3, order_overview_widget)
        progress.setWindowTitle("Horse")
        progress.setMinimumDuration(0)
        progress.setWindowModality(Qt.WindowModal)
        progress.setValue(progress.value() + 1)
        progress.show()

        for i in self.items():
            self.removeItem(i)

        self.posts_offsets = dict()
        self.drawn_operations_data = dict()

        self.cursor = QGraphicsRectItem(0, 0, 50, 300)
        self.cursor.setBrush(QBrush(QColor(208, 208, 255, 255)))
        self.cursor.setPen(QPen(Qt.transparent))
        self.addItem(self.cursor)

        bar_width = 8
        bar_height = int(bar_width * 60.0 / 8.0)

        ascent = QFontMetrics(self.base_font).ascent()
        ascent_big = QFontMetrics(self.base_font_big).ascent()

        post_ops = {}

        # mainlog.debug("reload...2")

        # z = 0
        # for op,order_part,parts in all_operations:
        #     z = op.planned_hours
        #     z = order_part.deadline
        #     z = order_part.qty
        #     z = order_part.human_identifier

        # all_operations = map(lambda i:i[0],all_operations)

        y = 0
        for opdef in all_ops:
            progress.setValue(progress.value() + 1)

            operations = filter(
                lambda op: op.operation_definition_id == opdef.
                operation_definition_id, all_operations)

            # We're only interested in the effort/time that remains
            # to be put on an operation. We're only interested in
            # the future.

            # We want the oeprations that are either
            # - ongoing
            # - ready to start.
            # In all cases we're only interested in operations
            # that are "active"

            if sort == 1:
                operations = sorted(
                    operations, key=lambda op: op.deadline or date(3000, 1, 1))
            elif sort == 2:
                operations = sorted(
                    operations,
                    key=lambda op: op.planned_hours * op.qty - op.done_hours)
            else:
                # Don't sort
                pass

            maximum = 16.0  #float !
            small_hours = 0
            op_ndx = 0
            current_x = 50
            bar_drawn = False

            total_done_hours = total_estimated = 0

            # --------------------------------------------------------------
            # Started operations

            bars_line = BarsLine(16, bar_width, bar_height, current_x, y, self,
                                 order_overview_widget)
            total_hours_to_do = 0

            for op in filter(lambda op: op.done_hours > 0, operations):
                hours_to_do = max(
                    0, op.planned_hours * op.qty -
                    op.done_hours)  # max protects against reporting errors
                total_hours_to_do += hours_to_do

                total_estimated += op.planned_hours * op.qty
                total_done_hours += op.done_hours

                bars_line.add_bar(hours_to_do, QBrush(Qt.green),
                                  self._operation_hoover_description(op),
                                  False,
                                  None)  # op.production_file.order_part)

            # --------------------------------------------------------------
            bars_line_unstarted_operations = BarsLine(16, bar_width,
                                                      bar_height,
                                                      current_x + 30, y, self,
                                                      order_overview_widget)
            total_hours_to_do_on_unstarted_operations = 0
            for op in filter(lambda op: op.done_hours == 0, operations):

                hours_to_do = op.planned_hours * op.qty
                total_hours_to_do_on_unstarted_operations += hours_to_do

                total_estimated += hours_to_do

                bars_line_unstarted_operations.add_bar(
                    hours_to_do, QBrush(Qt.yellow),
                    self._operation_hoover_description(op), False,
                    None)  #op.production_file.order_part)

            y_start = y

            total = total_hours_to_do + total_hours_to_do_on_unstarted_operations

            if total > 0:

                self.drawn_operations_data[
                    opdef.operation_definition_id] = "{}h".format(
                        int(round(total_estimated)))

                gi = QGraphicsSimpleTextItem(
                    _("{} - Estimated to do : {}h; done : {}h").format(
                        opdef.description, int(round(total)),
                        int(round(total_done_hours))))
                gi.setFont(self.base_font_big)
                gi.setPos(0, y - gi.boundingRect().height())
                self.addItem(gi)

                th = gi.boundingRect().height()

                gi = QGraphicsLineItem(-ascent_big, y, 1024 + 2 * ascent_big,
                                       y)
                gi.setPen(QPen(Qt.black))
                self.addItem(gi)

                y += th
            else:
                continue

            y_bars = y

            if total_hours_to_do > 0:
                # There's something to draw

                head = QGraphicsSimpleTextItem(_("Started"))
                head.setFont(self.base_font)
                head.setPos(current_x, y)
                self.addItem(head)
                y += head.boundingRect().height()

                y += bar_height
                bars_line.set_start_pos(current_x, y)
                bars_line.finish_bar()

                foot = QGraphicsSimpleTextItem(
                    _("{}h").format(int(total_hours_to_do + 0.5)))
                foot.setFont(self.base_font)
                foot.setPos(current_x, y)
                self.addItem(foot)
                y += foot.boundingRect().height()

                current_x = max(current_x + bars_line.estimate_width(),
                                head.boundingRect().right(),
                                foot.boundingRect().right())

                bar_drawn = True

            if total_hours_to_do_on_unstarted_operations > 0:

                if bars_line_unstarted_operations.estimate_width(
                ) + current_x > 1200:
                    x = 50
                    y += ascent_big
                else:
                    y = y_bars
                    x = current_x + 50

                head = QGraphicsSimpleTextItem(_("Not started yet"))
                head.setFont(self.base_font)
                head.setPos(x, y)
                self.addItem(head)
                y += head.boundingRect().height()

                y += bar_height
                bars_line_unstarted_operations.set_start_pos(x, y)
                bars_line_unstarted_operations.finish_bar()

                foot = QGraphicsSimpleTextItem(
                    _("{}h").format(
                        int(total_hours_to_do_on_unstarted_operations + 0.5)))
                foot.setFont(self.base_font)
                foot.setPos(x, y)
                self.addItem(foot)
                y += foot.boundingRect().height()

                bar_drawn = True

            y += 3 * ascent_big

            r = self.sceneRect()
            self.posts_offsets[opdef.operation_definition_id] =  \
                QRectF(r.x() - 2*ascent_big, y_start - 1.5*ascent_big,
                       r.width() + 4*ascent_big, (y - ascent_big) - (y_start - 1.5*ascent_big) )
            y += ascent_big

        # mainlog.debug("reload...3")
        import functools
        max_width = functools.reduce(lambda acc, po: max(acc, po.width()),
                                     self.posts_offsets.values(), 0)
        map(lambda po: po.setWidth(max_width), self.posts_offsets.values())

        # for r in self.posts_offsets.values():
        #     gi = QGraphicsLineItem(r.x(),r.y(),r.x()+r.width(),r.y())
        #     gi.setPen(QPen(Qt.lightGray))
        #     self.addItem(gi)

        progress.close()
Exemplo n.º 15
0
class HooverBar(QGraphicsRectItem):
    def __init__(self, x, y, w, h, hoover_text, doubleclick_callback_widget,
                 order_part_id):
        """ doubleclick_callback_widget : we will call the set_on_orderpart method
        of that object if a doubleclik happens here.
        """

        super(HooverBar, self).__init__(x, y, w, h)
        self.setAcceptHoverEvents(True)
        self.gi = None
        self.hoover_text = hoover_text
        self.description = None
        self.doubleclick_callback_widget = doubleclick_callback_widget
        self.order_part_id = order_part_id

        self.base_font = QFont()
        if configuration.font_select:
            self.base_font.setPointSize(self.base_font.pointSize() * 2)

    def hoverEnterEvent(self, event):  # QGraphicsSceneHoverEvent * event )
        # BUG I had a crash running this, I suspect ownership issues regarding
        # graphics items...

        global configuration
        #mainlog.debug("hoverEnterEvent pos={}-{}".format(event.scenePos().x(),event.scenePos().y()))
        # mainlog.debug("hoverEnterEvent data={}".format(self.data))
        super(HooverBar, self).hoverEnterEvent(event)

        if self.gi == None:
            if self.hoover_text:
                self.gi = QGraphicsRectItem(0, 0, 100, 100)
                self.gi.setBrush(QBrush(QColor(0, 64, 0, 192)))
                self.gi.setPen(QPen(Qt.transparent))
                self.gi.setPos(event.scenePos().x() + 20,
                               event.scenePos().y() + 20)

                # txt = [ "" ]

                # txt = [ u"{} {}".format(self.data.production_file.order_part.human_identifier,
                #                        date_to_dmy(self.data.production_file.order_part.deadline)),
                #         nstr(self.data.production_file.order_part.description),
                #         nstr(self.data.description),
                #         _("{}x{}={}h, rest:{}h").format(self.data.production_file.order_part.qty,
                #                                         nice_round(self.data.planned_hours),
                #                                         nice_round(self.data.production_file.order_part.qty*self.data.planned_hours),
                #                                         nice_round(self.data.planned_hours*self.data.production_file.order_part.qty - self.data.done_hours))]

                x = y = 10
                w = 0
                for t in self.hoover_text:
                    description = QGraphicsSimpleTextItem()
                    description.setFont(self.base_font)
                    description.setBrush(QBrush(Qt.white))
                    description.setText(t)
                    description.setParentItem(self.gi)
                    description.setPos(x, y)
                    y += description.boundingRect().height()
                    w = max(w, description.boundingRect().width())
                y += x
                w += 2 * x

                # description.setHtml(u"|{}| <b>{}</b><br/>{}<br>{}x{}={}h".format(
                #         self.data.production_file.order_part.human_identifier,
                #         self.data.production_file.order_part.description,
                #         self.data.description,
                #         self.data.production_file.order_part.qty, self.data.planned_hours, self.data.production_file.order_part.qty*self.data.planned_hours))

                # description.setDefaultTextColor(Qt.white)
                # br = description.boundingRect()

                self.gi.setRect(0, 0, w, y)
                self.scene().addItem(self.gi)
                #mainlog.debug("hoverEnterEvent GI={}".format(self.gi))

        # mainlog.debug("hoverEnterEvent Done")

    def hoverMoveEvent(self, event):
        super(HooverBar, self).hoverMoveEvent(event)

        # if self.gi:
        #     mainlog.debug("hoverMoveEvent GI pos={}-{}".format(self.gi.pos().x(),self.gi.pos().y()))
        # mainlog.debug("hoverMoveEvent pos={}-{}".format(event.scenePos().x(),event.scenePos().y()))
        if self.gi:
            self.gi.setPos(event.scenePos().x() + 20,
                           event.scenePos().y() + 20)

    def hoverLeaveEvent(self, event):
        super(HooverBar, self).hoverLeaveEvent(event)

        if self.gi:
            # mainlog.debug("hoverLeaveEvent GI={}".format(self.gi))
            # self.gi.setActive(False)
            # self.gi.setVisible(False)
            # return

            if self.description:
                # I do this so that I can handle the destruction of description
                # graphics item myself (i.e. description won't be deleted
                # as a children of self.gi)
                self.description.setParentItem(None)
                self.description = None  # and delete...

            # QtDoc : Removes the item item and all its children from the scene.
            #         The ownership of item is passed on to the caller

            self.gi.setParentItem(None)
            # self.scene().removeItem(self.gi)
            self.gi = None
            # mainlog.debug("hoverLeaveEvent -- done")

    # order_part_double_clicked = Signal(int)

    def mouseDoubleClickEvent(self,
                              event):  # QGraphicsSceneHoverEvent * event )
        # mainlog.debug("mouseDoubleClickEvent {}".format(self.data))
        super(HooverBar, self).mouseDoubleClickEvent(event)
        self.doubleclick_callback_widget.set_on_order_part(self.order_part_id)