Esempio n. 1
0
    def draw(cls, window):

        TitleBar.draw(window=window,
                      bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                      title='Subnet')

        TextInput.draw(
            id='subnet',
            window=window,
            caption='SUBNET',
            positionAndSize=(10, 95, 780, 33),
            defaultInput='',
            frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            onEnterCallback=(dg.updateHosts, TextInput.getTextInput, 'subnet'),
            headerColor=cl.GOODSAMARITANBLUE,
        )

        ScrollableTable.draw(id='subnet',
                             window=window,
                             positionAndSize=(10, 140, 780, 450),
                             frameColor=cl.alterColorBrightness(
                                 cl.MIDNIGHTBLUE, 10),
                             headerColor=cl.GOODSAMARITANBLUE,
                             data=tf.getSubnetForTable(),
                             columnWeight=[1, 3])
Esempio n. 2
0
    def draw(cls, window):

        TitleBar.draw(
            window=window,
            bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='Log'
        )

        TextInput.draw(
            id='log',
            window=window,
            caption='FILTER',
            positionAndSize=(10, 95, 780, 33),
            defaultInput='',
            frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            headerColor=cl.GOODSAMARITANBLUE,
        )

        ScrollableTable.draw(
            id='log',
            window=window,
            positionAndSize=(10, 140, 780, 450),
            frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            headerColor=cl.GOODSAMARITANBLUE,
            data=lg.getLog(filter=TextInput.getTextInput('log')),
            columnWeight=[1.1, 1.7, 1.9, 7]
        )
Esempio n. 3
0
    def draw(cls, window):

        TitleBar.draw(
            window = window,
            bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='Disks'
        )

        listExtension = 384
        listLine1 = 95
        listLine2 = 342
        listColumn1 = 10
        listColumn2 = 405
        listCaptionWidth = 110
        listCaptionHeight = 30

        ExpandableList.draw(
            window = window,
            positionAndSize=(listLine1, listColumn1, listCaptionWidth, listCaptionHeight),
            dataBGExtension=listExtension,
            captionBGColor=cl.GOODSAMARITANBLUE,
            valueBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='',
            data={
                'TOTAL': (str(hp.convertBytesToGigabytes(dg.getDiskUsage().total)) + ' GB')
                    if dg.getDiskUsage() != '' else 'Unknown',
                'USED': (str(hp.convertBytesToGigabytes(dg.getDiskUsage().used)) + ' GB')
                    if dg.getDiskUsage() != '' else 'Unknown',
                'FREE': (str(hp.convertBytesToGigabytes(dg.getDiskUsage().free)) + ' GB')
                    if dg.getDiskUsage() != '' else 'Unknown'
            }
        )
    def draw(cls, window):

        TitleBar.draw(window=window,
                      bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                      title='File Browser')

        if dg.isLocal():

            TextInput.draw(
                id='filebrowser',
                window=window,
                caption='PATH',
                positionAndSize=(10, 95, 780, 33),
                defaultInput=dg.getCurrentWorkingDirectory(),
                frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                headerColor=cl.GOODSAMARITANBLUE,
            )

            ScrollableTable.draw(id='filebrowser',
                                 window=window,
                                 positionAndSize=(10, 140, 780, 450),
                                 frameColor=cl.alterColorBrightness(
                                     cl.MIDNIGHTBLUE, 10),
                                 headerColor=cl.GOODSAMARITANBLUE,
                                 data=tf.getFilesAndFoldersForTable(
                                     TextInput.getTextInput('filebrowser')),
                                 columnWeight=[3, 1, 0.65, 1.4, 1.4])

        else:

            PlainText.draw(window=window,
                           position=(10, 95),
                           fontSize=20,
                           content='Current: ' +
                           dg.getCurrentWorkingDirectory())

            TextInput.draw(
                id='filebrowser',
                window=window,
                caption='PATH',
                positionAndSize=(10, 120, 780, 33),
                defaultInput=dg.getCurrentWorkingDirectory(),
                frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                headerColor=cl.GOODSAMARITANBLUE,
            )

            ScrollableTable.draw(id='filebrowser',
                                 window=window,
                                 positionAndSize=(10, 165, 780, 425),
                                 frameColor=cl.alterColorBrightness(
                                     cl.MIDNIGHTBLUE, 10),
                                 headerColor=cl.GOODSAMARITANBLUE,
                                 data=tf.getFilesAndFoldersForTable(
                                     TextInput.getTextInput('filebrowser')),
                                 columnWeight=[3, 1, 0.65, 1.4, 1.4])
Esempio n. 5
0
    def draw(cls, window):

        TitleBar.draw(window=window,
                      bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                      title='Processes')

        ScrollableTable.draw(window=window,
                             id='processes',
                             frameColor=cl.alterColorBrightness(
                                 cl.MIDNIGHTBLUE, 10),
                             headerColor=cl.GOODSAMARITANBLUE,
                             data=tf.getProcessesForTable(),
                             columnWeight=[1, 3, 1, 1, 3, 1])
Esempio n. 6
0
    def draw(cls,
             window,
             height=30,
             menuItems=[],
             fontColor=(0, 0, 0),
             bgColor=(200, 200, 200),
             highlightBrightness=-20
             ):

        
        pointer = cls.__mouseInfo['pointer']

        itemSpacing = 15

        position = pygame.Rect(0, 0, window.get_width(), height)
        pygame.draw.rect(window, bgColor, position)

        logo = pygame.image.load('Resources/images/Orange.png')
        logoMargin = (10, 5)
        window.blit(logo, logoMargin)

        logoOffset = logo.get_rect().width + logoMargin[0] + itemSpacing

        itemOffset = logoOffset

        for x in range(len(menuItems)):
            font = pygame.font.Font(None, 20)
            text = font.render(menuItems[x], 1, fontColor)
            textRect = text.get_rect()
            textRect.topleft = (itemOffset, 9)

            itemHighlightZone = pygame.Rect(itemOffset - int(round(itemSpacing / 2)),
                                            0,
                                            textRect.width + itemSpacing,
                                            height)

            if itemHighlightZone.collidepoint(pointer):
                itemHighlightRect = pygame.Rect(
                    itemOffset - int(round(itemSpacing / 2)),
                    3,
                    textRect.width + itemSpacing,
                    height - 5)
                pygame.draw.rect(window, cl.alterColorBrightness(bgColor, highlightBrightness), itemHighlightRect)

            window.blit(text, textRect)

            if len(cls.__menuItems) < len(menuItems):
                menuItemData = [menuItems[x], itemHighlightZone, False]
                cls.__menuItems.append(menuItemData)
                cls.__menuItems[0][2] = True

            itemOffset += textRect.width + itemSpacing
Esempio n. 7
0
    def draw(cls, window):

        TitleBar.draw(window=window,
                      bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                      title='Network')

        ScrollableTable.draw(window=window,
                             id='network',
                             frameColor=cl.alterColorBrightness(
                                 cl.MIDNIGHTBLUE, 10),
                             headerColor=cl.GOODSAMARITANBLUE,
                             positionAndSize=(10, 95, 780, 240),
                             data=tf.getNetworkForTable(),
                             columnWeight=[1, 3])

        ScrollableTable.draw(window=window,
                             id='processes_network',
                             frameColor=cl.alterColorBrightness(
                                 cl.MIDNIGHTBLUE, 10),
                             headerColor=cl.GOODSAMARITANBLUE,
                             positionAndSize=(10, 348, 780, 240),
                             data=tf.getProcessesNetworkUsageForTable(),
                             columnWeight=[0.2, 0.3, 0.4, 1, 1])
Esempio n. 8
0
    def draw(cls, window):

        TitleBar.draw(
            window = window,
            bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='Dashboard'
        )

        listExtension = 384
        listLine1 = 128
        listLine2 = 342
        listColumn1 = 10
        listColumn2 = 405
        listCaptionWidth = 110
        listCaptionHeight = 30

        ExpandableList.draw(
            window = window,
            positionAndSize=(listLine1, listColumn1, listCaptionWidth, listCaptionHeight),
            dataBGExtension=listExtension,
            captionBGColor=cl.GOODSAMARITANBLUE,
            valueBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='CPU',
            data={
                'BRAND': dg.getProcessorBrand()
                    if dg.getProcessorBrand() != '' else 'Unknown',
                'ARCHITECTURE': dg.getProcessorArchitecture()
                    if dg.getProcessorArchitecture() != '' else 'Unknown',
                'WORDLENGTH': (str(dg.getProcessorWordLength()) + ' bits')
                    if dg.getProcessorWordLength() != '' else 'Unknown',
                'FREQUENCY': (str(dg.getCpuFreq().current) + ' Hz') if dg.getCpuFreq() != '' else 'Unknown',
                'CORES': str(dg.getCores()) + ' (' + str(dg.getPhysicalCores()) + ' physical)',
            }
        )

        ExpandableList.draw(
            window = window,
            positionAndSize=(listLine1, listColumn2, listCaptionWidth, listCaptionHeight),
            dataBGExtension=listExtension,
            captionBGColor=cl.GOODSAMARITANBLUE,
            valueBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='Memory',
            data={
                'TOTAL': (str(hp.convertBytesToGigabytes(dg.getVirtualMemory().total)) + ' GB')
                    if dg.getVirtualMemory() != '' else 'Unknown',
                'AVAILABLE': (str(hp.convertBytesToGigabytes(dg.getVirtualMemory().available)) + ' GB')
                    if dg.getVirtualMemory() != '' else 'Unknown',
                'PERCENT': (str(dg.getVirtualMemory().percent) + ' %')
                    if dg.getVirtualMemory() != '' else 'Unknown',
                'USED': (str(hp.convertBytesToGigabytes(dg.getVirtualMemory().used)) + ' GB')
                    if dg.getVirtualMemory() != '' else 'Unknown',
                'FREE': (str(hp.convertBytesToGigabytes(dg.getVirtualMemory().free)) + ' GB')
                    if dg.getVirtualMemory() != '' else 'Unknown',
            }
        )

        ExpandableList.draw(
            window = window,
            positionAndSize=(listLine2, listColumn1, listCaptionWidth, listCaptionHeight),
            dataBGExtension=listExtension,
            captionBGColor=cl.GOODSAMARITANBLUE,
            valueBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='Disks',
            data={
                'TOTAL': (str(hp.convertBytesToGigabytes(dg.getDiskUsage().total)) + ' GB')
                    if dg.getDiskUsage() != '' else 'Unknown',
                'USED': (str(hp.convertBytesToGigabytes(dg.getDiskUsage().used)) + ' GB')
                    if dg.getDiskUsage() != '' else 'Unknown',
                'FREE': (str(hp.convertBytesToGigabytes(dg.getDiskUsage().free)) + ' GB')
                    if dg.getDiskUsage() != '' else 'Unknown',
                ' - ': '',
                '  -  ': '',
            }
        )

        ExpandableList.draw(
            window = window,
            positionAndSize=(listLine2, listColumn2, listCaptionWidth, listCaptionHeight),
            dataBGExtension=listExtension,
            captionBGColor=cl.GOODSAMARITANBLUE,
            valueBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            title='Network',
            data={
                'HOST': dg.getDomainName() if dg.getDomainName() != '' else 'Unknown',
                'IP': dg.getIp() if dg.getIp() != '' else 'Unknown',
                'NETMASK': dg.getNetmask() if dg.getNetmask() != '' else 'Unknown',
                '-': '',
                ' - ': '',
            }
        )

        horizontalBarWidth = 250
        horizontalBarHeight = 30
        horizontalBarY = 558
        amountColor = cl.PURPLECORALLITE

        HorizontalBar.draw(
            window = window,
            caption='Memory Usage',
            unit='GB',
            totalValue=dg.getVirtualMemory().total if dg.getVirtualMemory() != '' else 100,
            currentValue=dg.getVirtualMemory().used if dg.getVirtualMemory() != '' else 0,
            positionAndSize=(10, horizontalBarY, horizontalBarWidth, horizontalBarHeight),
            barColor=cl.GRAY1,
            amountColor=amountColor
        )

        HorizontalBar.draw(
            window = window,
            caption='CPU Usage',
            unit='Hz',
            totalValue=dg.getCpuFreq().max if dg.getCpuFreq() != '' else 100,
            currentValue=(dg.getCpuPercentage() / 100 * dg.getCpuFreq().max) if dg.getCpuFreq() != '' else 0,
            positionAndSize=(274, horizontalBarY, horizontalBarWidth, horizontalBarHeight),
            barColor=cl.GRAY1,
            amountColor=amountColor
        )

        HorizontalBar.draw(
            window = window,
            caption='Disk Usage',
            unit='GB',
            totalValue=dg.getDiskUsage().total if dg.getDiskUsage() != '' else 1,
            currentValue=dg.getDiskUsage().used if dg.getDiskUsage() != '' else 0,
            positionAndSize=(538, horizontalBarY, horizontalBarWidth, horizontalBarHeight),
            barColor=cl.GRAY1,
            amountColor=amountColor
        )
Esempio n. 9
0
    def draw(cls,
             window,                           # Reference surface
             positionAndSize = (0, 0, 0, 0),   # Position and size tuple
             dataBGExtension = 100,            # Value data display size
             margins = (7, 5),                 # Margins between cells
             title = '',                       # Title
             titleAlignment = 'center',        # Title alignment
             data = {},                        # Data to be displayed
             captionBGColor = (60, 60, 60),    # Keys (or 'caption') background color
             valueBGColor = (200, 200, 200),   # Value background color
             textBrightness = (100, 100),      # Color contrast text/background
             fontSize = 18):                   # Font size

        position = pygame.Rect(positionAndSize)

        for x, key in enumerate(data):

            marginBetweenLines = 0 if x is 0 else margins[1]

            # ---> Draw value BG
            position = pygame.Rect(positionAndSize)
            position.topleft = (position.top,
                                position.left + (positionAndSize[3] + marginBetweenLines) * x)
            position.width = dataBGExtension
            pygame.draw.rect(window, valueBGColor, position)

            # ---> Draw caption
            position = pygame.Rect(positionAndSize)
            font = pygame.font.Font(None, fontSize)
            text = font.render(str(data[key]), 1, cl.alterColorBrightness(valueBGColor, textBrightness[1]))
            textRect = text.get_rect()
            textRect.topleft = (position.top + position.width+5,
                                position.left + (positionAndSize[3] + marginBetweenLines) * x +
                                positionAndSize[3] / 2 - textRect.height / 2 + 1)
            window.blit(text, textRect)

            # ---> Draw caption BG
            position = pygame.Rect(positionAndSize)
            position.topleft = (position.top+1,
                                         position.left+(positionAndSize[3]+marginBetweenLines)*x+1)
            position.width -= 2
            position.height -= 2
            pygame.draw.rect(window, captionBGColor, position)

            # ---> Draw caption
            position = pygame.Rect(positionAndSize)
            font = pygame.font.Font(None, fontSize)
            text = font.render(key, 1, cl.alterColorBrightness(captionBGColor, textBrightness[0]))
            textRect = text.get_rect()
            textRect.topleft = (position.top+positionAndSize[2]/2-textRect.width/2,
                                position.left+(positionAndSize[3]+marginBetweenLines)*x+
                                positionAndSize[3]/2-textRect.height/2+1)
            window.blit(text, textRect)

        # ---> Draws list title
        font = pygame.font.Font(None, 25)
        text = font.render(title, 1, (220, 220, 220))
        textRect = text.get_rect()

        if titleAlignment is 'left':
            textRect.topleft = (position.top,
                                position.left-position.height+5)

        elif titleAlignment is 'center':
            textRect.topleft = (position.top+dataBGExtension/2-textRect.width/2,
                                position.left - position.height + 5)

        window.blit(text, textRect)
Esempio n. 10
0
    def draw(cls, window):

        v0ff = 30

        TitleBar.draw(window=window,
                      bgColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
                      title='Sharing')

        SelectorButton.draw(
            id='local',
            window=window,
            selectedCaption='LOCAL DATA',
            unselectedCaption='LOCAL DATA',
            fontSize=25,
            selectedBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 20),
            unselectedBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 5),
            positionAndSize=(10, 100 + v0ff, 780, 80),
            initialState=True,
            deactivatable=False,
            onActivate=((SelectorButton.deactivate, 'remote'),
                        dg.setLocalData),
        )

        host = TextInput.getTextInput('remote_host')
        port = TextInput.getTextInput('remote_port')

        SelectorButton.draw(
            id='remote',
            window=window,
            selectedCaption='REMOTE DATA',
            unselectedCaption='REMOTE DATA',
            fontSize=25,
            selectedBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 20),
            unselectedBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 5),
            deactivatable=False,
            positionAndSize=(10, 200 + v0ff, 780, 80),
            onActivate=((SelectorButton.deactivate, 'local'),
                        (dg.setRemoteData, [host, port])),
        )

        TextInput.draw(
            id='remote_host',
            window=window,
            caption='HOST',
            positionAndSize=(10, 285 + v0ff, 387, 33),
            defaultInput='',
            frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            headerColor=cl.GOODSAMARITANBLUE,
        )

        TextInput.draw(
            id='remote_port',
            window=window,
            caption='PORT',
            positionAndSize=(403, 285 + v0ff, 387, 33),
            defaultInput='',
            frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            headerColor=cl.GOODSAMARITANBLUE,
        )

        ExpandableList.draw(window=window,
                            positionAndSize=(323 + v0ff, 10, 82, 30),
                            dataBGExtension=780,
                            captionBGColor=cl.GOODSAMARITANBLUE,
                            valueBGColor=cl.alterColorBrightness(
                                cl.MIDNIGHTBLUE, 10),
                            title='',
                            data={
                                'STATUS': rd.getMessage(),
                            })

        SelectorButton.draw(
            id='broadcast',
            window=window,
            unselectedCaption='BROADCAST',
            selectedCaption='BROADCASTING ...',
            fontSize=25,
            selectedBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 20),
            unselectedBGColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 5),
            positionAndSize=(10, 375 + v0ff, 780, 80),
            onActivate=((bc.startBroadcasting,
                         TextInput.getTextInput('broadcast_port')), ),
            onDeactivate=(bc.stopBroadcasting, ))

        TextInput.draw(
            id='broadcast_port',
            window=window,
            caption='PORT',
            positionAndSize=(10, 460 + v0ff, 780, 33),
            defaultInput='',
            frameColor=cl.alterColorBrightness(cl.MIDNIGHTBLUE, 10),
            headerColor=cl.GOODSAMARITANBLUE,
        )

        ExpandableList.draw(window=window,
                            positionAndSize=(498 + v0ff, 10, 82, 30),
                            dataBGExtension=780,
                            captionBGColor=cl.GOODSAMARITANBLUE,
                            valueBGColor=cl.alterColorBrightness(
                                cl.MIDNIGHTBLUE, 10),
                            title='',
                            data={
                                'STATUS': bc.getMessage(),
                            })

        if SelectorButton.isSelected('broadcast'):

            ExpandableList.draw(window=window,
                                positionAndSize=(388 + v0ff, 580, 45, 25),
                                fontSize=17,
                                dataBGExtension=200,
                                captionBGColor=cl.GOODSAMARITANBLUE,
                                valueBGColor=cl.alterColorBrightness(
                                    cl.MIDNIGHTBLUE, 10),
                                title='',
                                data={
                                    'IP': bc.getBroadcastAddress()[2],
                                    'PORT': bc.getBroadcastAddress()[1]
                                })
Esempio n. 11
0
    def draw(cls,
             id,
             window,
             positionAndSize=(10, 95, 780, 495),
             frameColor=(255, 255, 255),
             headerColor=(255, 255, 255),
             data=[],
             columnWeight=[],
             padding=5):

        if len(columnWeight) is not len(data[0]):
            columnWeight = [1 for x in list(range(len(data[0])))]

        if id not in cls.__tableInfo or cls.__tableInfo[id][
                'rect'] != pygame.Rect(positionAndSize):
            cls.__tableInfo[id] = {
                'scrollBarY': None,
                'dataPositionModifier': 0,
                'rect': pygame.Rect((positionAndSize))
            }

        pygame.draw.rect(window, frameColor, positionAndSize)

        # ---> General variable definitions
        dataLineHeight = 20
        totalDataHeight = dataLineHeight * len(data) - 1
        headerHeight = 30
        headerMarginBottom = 5
        dataFrameHeight = positionAndSize[
            3] - padding * 2 - headerHeight - headerMarginBottom
        navigationRectHeight = 28
        navigationRectMargin = 2
        innerFrameHeight = positionAndSize[3] - padding * 2
        scrollBarFrameScrollableAreaHeight = innerFrameHeight - navigationRectHeight * 2 - navigationRectMargin * 4
        noOfColumns = len(data[0])

        scrollBarHeight = int(
            round((dataFrameHeight / totalDataHeight) *
                  scrollBarFrameScrollableAreaHeight))
        scrollBarHeight = scrollBarHeight if scrollBarHeight <= scrollBarFrameScrollableAreaHeight else scrollBarFrameScrollableAreaHeight

        # ---> Inner Frame
        innerFrameRect = pygame.Rect(positionAndSize)
        innerFrameRect.topleft = (innerFrameRect.left + padding,
                                  innerFrameRect.top + padding)
        innerFrameRect.width -= padding * 2
        innerFrameRect.height = innerFrameHeight
        # pygame.draw.rect(window, Helpers.alterColorBrightness(frameColor, 10), innerFrameRect)

        # ---> Scrollbar frame
        scrollBarFrameRect = copy.deepcopy(innerFrameRect)
        scrollBarFrameRect.width = 20
        scrollBarFrameRect.topleft = (scrollBarFrameRect.left +
                                      innerFrameRect.width -
                                      scrollBarFrameRect.width,
                                      scrollBarFrameRect.top)
        pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 20),
                         scrollBarFrameRect)

        # ---> Scrollbar navigation arrow top
        navigationTopRect = copy.deepcopy(scrollBarFrameRect)
        navigationTopRect.height = navigationRectHeight
        navigationTopRect.width -= navigationRectMargin * 2
        navigationTopRect.topleft = (navigationTopRect.left +
                                     navigationRectMargin,
                                     navigationTopRect.top +
                                     navigationRectMargin)
        pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 30),
                         navigationTopRect)
        pygame.draw.polygon(window, cl.alterColorBrightness(frameColor, 50), (
            (navigationTopRect.left + 3, navigationTopRect.bottom - 8),
            (navigationTopRect.right - 3, navigationTopRect.bottom - 8),
            (navigationTopRect.left + navigationTopRect.width / 2,
             navigationTopRect.top + 8),
        ), 0)

        if cls.__mouseInfo['isLeftButtonPressed']:

            if navigationTopRect.collidepoint(cls.__mouseInfo['pointer']):

                cls.__tableInfo[id]['dataPositionModifier'] -= int(
                    round(totalDataHeight / len(data)))
                cls.__tableInfo[id]['scrollBarY'] -= int(
                    round(scrollBarFrameScrollableAreaHeight / len(data)))

                if cls.__tableInfo[id][
                        'scrollBarY'] <= navigationTopRect.bottom + 3:
                    cls.__tableInfo[id]['dataPositionModifier'] = 0
                    cls.__tableInfo[id][
                        'scrollBarY'] = navigationTopRect.bottom + 3

        # ---> Scrollbar navigation arrow bottom
        navigationBottomRect = copy.deepcopy(navigationTopRect)
        navigationBottomRect.topleft = (navigationBottomRect.left,
                                        scrollBarFrameRect.bottom - 2 -
                                        navigationBottomRect.height)
        pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 30),
                         navigationBottomRect)
        pygame.draw.polygon(window, cl.alterColorBrightness(frameColor, 50), (
            (navigationBottomRect.left + 3, navigationBottomRect.top + 8),
            (navigationBottomRect.right - 3, navigationBottomRect.top + 8),
            (navigationBottomRect.left + navigationBottomRect.width / 2,
             navigationBottomRect.bottom - 8),
        ), 0)

        if cls.__mouseInfo['isLeftButtonPressed']:

            if navigationBottomRect.collidepoint(cls.__mouseInfo['pointer']):

                cls.__tableInfo[id]['dataPositionModifier'] += int(
                    round(totalDataHeight / len(data)))
                cls.__tableInfo[id]['scrollBarY'] += int(
                    round(scrollBarFrameScrollableAreaHeight / len(data)))

                if cls.__tableInfo[id]['scrollBarY'] + scrollBarHeight >= \
                        navigationTopRect.bottom + 3 + scrollBarFrameScrollableAreaHeight:

                    cls.__tableInfo[id]['dataPositionModifier'] = int(
                        round(((scrollBarFrameScrollableAreaHeight -
                                scrollBarHeight) /
                               scrollBarFrameScrollableAreaHeight) *
                              totalDataHeight))
                    cls.__tableInfo[id][
                        'scrollBarY'] = navigationTopRect.bottom + 3 + scrollBarFrameScrollableAreaHeight - scrollBarHeight

        # ---> Table frame
        tableRect = copy.deepcopy(innerFrameRect)
        tableRect.width -= scrollBarFrameRect.width + 3
        # pygame.draw.rect(window, Helpers.alterColorBrightness(frameColor, -30), tableRect)

        # ---> Scrollbar
        scrollBarRect = copy.deepcopy(navigationTopRect)
        scrollBarRect.height = scrollBarHeight

        if cls.__tableInfo[id]['scrollBarY'] is None:
            scrollBarRect.topleft = (navigationTopRect.left,
                                     navigationTopRect.bottom + 3)
            cls.__tableInfo[id]['scrollBarY'] = navigationTopRect.bottom + 3

        else:
            scrollBarRect.topleft = (navigationTopRect.left,
                                     cls.__tableInfo[id]['scrollBarY'])

        if cls.__mouseInfo['isLeftButtonPressed']:
            pointer = cls.__mouseInfo['pointer']

            scrollBarPosition = pointer[1] - scrollBarRect.height / 2

            scrollBarClickableRect = pygame.Rect(
                scrollBarFrameRect.left,
                scrollBarFrameRect.top + navigationTopRect.height + 3,
                scrollBarFrameRect.width, scrollBarFrameRect.height -
                navigationBottomRect.height - 6 - navigationTopRect.height - 6)

            if scrollBarClickableRect.collidepoint(pointer):

                if scrollBarPosition > navigationTopRect.bottom and \
                        scrollBarPosition+scrollBarRect.height < navigationBottomRect.top:

                    cls.__tableInfo[id][
                        'scrollBarY'] = pointer[1] - scrollBarRect.height / 2
                    cls.__tableInfo[id]['dataPositionModifier'] = \
                        int(round(((cls.__tableInfo[id]['scrollBarY']-navigationTopRect.bottom+3)/scrollBarFrameScrollableAreaHeight)*totalDataHeight))

                elif scrollBarPosition < navigationTopRect.bottom:
                    cls.__tableInfo[id][
                        'scrollBarY'] = navigationTopRect.bottom + 3
                    cls.__tableInfo[id]['dataPositionModifier'] = 0

                elif scrollBarPosition + scrollBarRect.height > navigationBottomRect.top:
                    cls.__tableInfo[id][
                        'scrollBarY'] = navigationBottomRect.top - scrollBarRect.height - 3
                    cls.__tableInfo[id]['dataPositionModifier'] = \
                        int(round(((cls.__tableInfo[id][
                                        'scrollBarY'] - navigationTopRect.bottom + 3) / scrollBarFrameScrollableAreaHeight) * totalDataHeight))

        scrollBarRect.topleft = (scrollBarRect.left,
                                 cls.__tableInfo[id]['scrollBarY'])
        pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 40),
                         scrollBarRect)

        # ---> Headers
        font = pygame.font.Font(None, 20)
        columnsWidth = []
        columnsLeft = []

        for x in range(noOfColumns):

            columnsLeft.append(innerFrameRect.left + sum(columnsWidth))
            columnsWidth.append(tableRect.width * columnWeight[x] /
                                sum(columnWeight))

            # ---> Header box
            headerRect = pygame.Rect(0, 0, 0, 0)
            headerRect.width = (columnsWidth[x] -
                                2) if x < noOfColumns - 1 else columnsWidth[x]
            headerRect.height = headerHeight
            headerRect.topleft = (columnsLeft[x], innerFrameRect.top)
            pygame.draw.rect(window, headerColor, headerRect)

            # ---> Header title
            text = font.render(data[0][x], 1, (255, 255, 255))
            textRect = text.get_rect()
            textRect.topleft = (headerRect.left + headerRect.width / 2 -
                                textRect.width / 2, headerRect.top +
                                headerRect.height / 2 - textRect.height / 2)
            window.blit(text, textRect)

        # ---> Display data
        dataFrameRect = pygame.Rect(
            tableRect.left,
            tableRect.top + headerRect.height + headerMarginBottom,
            tableRect.width,
            tableRect.height - headerRect.height - headerMarginBottom)

        for x in range(1, len(data)):

            for y in range(noOfColumns):

                text = font.render(str(data[x][y]), 1, (255, 255, 255))
                textRect = text.get_rect()
                textRect.topleft = (columnsLeft[y] + 3, innerFrameRect.top +
                                    (dataLineHeight *
                                     (x - 1) + headerRect.height + 5))
                textRect.top -= cls.__tableInfo[id]['dataPositionModifier']
                if dataFrameRect.contains(textRect):
                    window.blit(text, textRect)
                else:
                    break
    def draw(cls,
             id,
             window,
             averaging = 60,
             positionAndSize = (0, 0, 0, 0),
             frameColor = (0, 0, 0),
             padding = 5,
             percentageList = [],
             caption = 'Core '
             ):

        noOfElements = len(percentageList)

        # ---> Initiate and update multiVerticalBarsHistory under provided ID
        if not id in cls.__multiVerticalBarsHistory:
            cls.__multiVerticalBarsHistory[id] = []

        elif len(cls.__multiVerticalBarsHistory[id])>=averaging:
            del cls.__multiVerticalBarsHistory[id][0]

        if percentageList != '':
            cls.__multiVerticalBarsHistory[id].append(percentageList)

        # ---> Calculate averages and reassign percentageList
        percentageList = []

        for x in range(noOfElements):
            averagesList = [(z[x]) for z in cls.__multiVerticalBarsHistory[id]]
            percentageList.append(round(mean(averagesList), 1))

        pygame.draw.rect(window, frameColor, positionAndSize)

        # ---> Inner Frame
        innerFrameRect = pygame.Rect(positionAndSize)
        innerFrameRect.topleft = (innerFrameRect.left+padding, innerFrameRect.top+padding)
        innerFrameRect.width -= padding*2
        innerFrameRect.height -= padding*2
        pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 10), innerFrameRect)

        zoneRect = copy.deepcopy(innerFrameRect)

        for x in range(noOfElements):

            # ---> Zones
            zoneRect.topleft = (int(round(innerFrameRect.left+(innerFrameRect.width/noOfElements)*x)), innerFrameRect.top)
            zoneRect.width = int(round((innerFrameRect.width/noOfElements)))
            pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 15), zoneRect, 1)

            # ---> Bar Labels
            font = pygame.font.Font(None, 20)
            text = font.render(caption + str(x+1), 1, (255,255,255))
            textRect = text.get_rect()
            textRect.topleft = (zoneRect.left+zoneRect.width/2-textRect.width/2, zoneRect.top+zoneRect.height-textRect.height-8)
            window.blit(text, textRect)

            # ---> Dividers
            marginFromZone = 10
            dividerRect = pygame.Rect(0, 0, 0, 0)
            dividerRect.topleft = (zoneRect.left+marginFromZone, zoneRect.top+zoneRect.height-textRect.height-20)
            dividerRect.height = 5
            dividerRect.width = zoneRect.width-marginFromZone*2
            pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 30), dividerRect)

            # ---> Full Bars
            marginFromZoneTop = 15
            fullBarRect = pygame.Rect(0, 0, 0, 0)
            fullBarRect.height = zoneRect.height-textRect.height-20-marginFromZoneTop
            fullBarRect.width = int(round((zoneRect.width-marginFromZone*2)*0.8))
            fullBarRect.topleft = (zoneRect.left+zoneRect.width/2-fullBarRect.width/2, zoneRect.top+marginFromZoneTop)
            pygame.draw.rect(window, cl.alterColorBrightness(frameColor, 30), fullBarRect)

            # ---> Percentage Bars
            marginFromZoneTop = 20
            marginFromFullBarRect = 5
            percentBarRect = pygame.Rect(0, 0, 0, 0)
            percentBarRect.height = (zoneRect.height - textRect.height - 20 - marginFromZoneTop)
            percentBarRect.height = int(round(percentBarRect.height*percentageList[x]/100))
            percentBarRect.width = int(round((zoneRect.width - marginFromZone * 2) * 0.8)) - marginFromFullBarRect*2
            percentBarRect.topleft = ((zoneRect.left + zoneRect.width / 2 - fullBarRect.width / 2)+marginFromFullBarRect,
                                      zoneRect.top + marginFromZoneTop+(fullBarRect.height-percentBarRect.height)-marginFromFullBarRect)
            pygame.draw.rect(window, cl.alterColorBrightness(frameColor, -30), percentBarRect)

            # ---> Percentage index
            marginFromPercentBarTop = 5
            font = pygame.font.Font(None, 13)
            text = font.render(str(percentageList[x]) + '%', 1, (255, 255, 255))
            textRect = text.get_rect()
            textRect.topleft = (percentBarRect.left + percentBarRect.width/2 - textRect.width/2, percentBarRect.top+marginFromPercentBarTop)
            if textRect.top+textRect.height+3>fullBarRect.top+fullBarRect.height:
                textRect.top = fullBarRect.top+fullBarRect.height-textRect.height-3
            window.blit(text, textRect)
Esempio n. 13
0
    def draw(cls,
             id,
             window,
             positionAndSize=(10, 95, 780, 495),
             frameColor=(255, 255, 255),
             headerColor=(255, 255, 255),
             caption='',
             defaultInput='',
             padding=5,
             onEnterCallback=None):

        if id not in cls.__txiContent:
            cls.__txiContent[id] = {
                'data': defaultInput,
                'isSelected': False,
                'rect': pygame.Rect(positionAndSize),
                'onEnterCallback': onEnterCallback
            }

        cls.__txiContent[id]['rect'] = pygame.Rect(positionAndSize)
        cls.__txiContent[id]['onEnterCallback'] = onEnterCallback

        pygame.draw.rect(window, frameColor, positionAndSize)

        # ---> Variables Definition
        textAreaMargin = 5
        captionHorizontalMargin = 15

        # ---> Inner Frame
        innerFrameRect = pygame.Rect(positionAndSize)
        innerFrameRect.topleft = (innerFrameRect.left + padding,
                                  innerFrameRect.top + padding)
        innerFrameRect.width -= padding * 2
        innerFrameRect.height -= padding * 2
        brightness = 10 if not cls.__txiContent[id]['isSelected'] else 60
        pygame.draw.rect(window,
                         cl.alterColorBrightness(frameColor, brightness),
                         innerFrameRect, 1)

        # ---> Caption Text
        fontSize = int(
            round((innerFrameRect.height - (2 * textAreaMargin)) * 1.5))
        font = pygame.font.Font(None, fontSize)
        text = font.render(caption, 1, (255, 255, 255))
        textRect = text.get_rect()
        textRect.topleft = (innerFrameRect.left + textAreaMargin +
                            captionHorizontalMargin,
                            innerFrameRect.top + textAreaMargin)

        # ---> Caption Area
        captionAreaRect = pygame.Rect(0, 0, 0, 0)
        captionAreaRect.topleft = (innerFrameRect.left, innerFrameRect.top)
        captionAreaRect.width = textRect.width + textAreaMargin * 2 + captionHorizontalMargin * 2
        captionAreaRect.height = innerFrameRect.height
        brightness = cl.alterColorBrightness(frameColor, 20) if not cls.__txiContent[id]['isSelected'] else \
            cl.alterColorBrightness(frameColor, 50)
        pygame.draw.rect(window, brightness, captionAreaRect)
        window.blit(text, textRect)

        # ---> Text Area
        textAreaRect = pygame.Rect(innerFrameRect)
        textAreaRect.topleft = (innerFrameRect.left + textAreaMargin +
                                captionAreaRect.width,
                                innerFrameRect.top + textAreaMargin)
        textAreaRect.width -= textAreaMargin * 2 + captionAreaRect.width
        textAreaRect.height -= textAreaMargin * 2
        # pygame.draw.rect(window, Helpers.alterColorBrightness(frameColor, 30), textAreaRect, 1)

        # ---> Data Display
        displayText = cls.__txiContent[id]['data']
        fontSize = int(round(textAreaRect.height * 1.5))
        font = pygame.font.Font(None, fontSize)
        text = font.render(displayText, 1, (255, 255, 255))
        textRect = text.get_rect()
        textRect.topleft = (textAreaRect.left, textAreaRect.top)

        while textAreaRect.right < textRect.right:

            displayText = displayText[1:]
            text = font.render(displayText, 1, (255, 255, 255))
            rect = text.get_rect()
            textRect.width = rect.width

        window.blit(text, textRect)