コード例 #1
0
ファイル: DigiDash.py プロジェクト: mohdkhan95/digidash
    def build(self):
        appLayout = FloatLayout(size=(800, 600))

        bg = Image(source='Images/Metal2.jpg', pos=(0, 0), size=(1500, 840))

        g1 = Gauge()
        g1s = ScatterLayout(scale=0.5, size=g1.size, pos=(30, 80))
        g1s.add_widget(g1)

        g2 = Gauge()
        g2s = ScatterLayout(scale=0.5, size=g1.size, pos=(200, 80))
        g2s.add_widget(g2)

        g3 = Gauge()
        g3s = ScatterLayout(scale=0.5, size=g1.size, pos=(300, 80))
        g3s.add_widget(g3)

        head = Header()
        headscat = Scatter(size=head.size, pos=(0, 530), do_translation=False)
        headscat.add_widget(head)

        foot = Footer()
        Footer.updatedate(foot)
        #Clock.schedule_interval(foot.updatetime, 1)
        Clock.schedule_interval(partial(Footer.updatetime, foot), 1)
        Clock.schedule_interval(partial(Footer.updatedate, foot), 3600)
        #footscat = Scatter(size=foot.size, pos=(0,-10), do_translation=False)
        #footscat.add_widget(foot)

        appLayout.add_widget(bg)
        appLayout.add_widget(g1s)
        appLayout.add_widget(g2s)
        appLayout.add_widget(g3s)
        appLayout.add_widget(headscat)
        appLayout.add_widget(foot)

        Window.size = (800, 600)
        return appLayout
コード例 #2
0
 def testNegativeBoundaries(self):
     """Test passes if trying to create a Footer with the boundarie value negative produces a
     FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, -1, 0)
コード例 #3
0
 def testSetCurrentPage(self):
     """Tests the Footer setCurrentPage method for its expected behavior"""
     footer = Footer(10, 0, 0)
     self.assertEqual(footer.currentPage, 1)
     footer.setCurrentPage(5)
     self.assertEqual(footer.currentPage, 5)
コード例 #4
0
 def testSetCurrentPageNegative(self):
     """Test passes if trying to set a Negative number for the current page produces
     a FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 0, 0).setCurrentPage(-1)
コード例 #5
0
 def testSetCurrentPageHigherTotalPages(self):
     """Test passes if trying to set a number higher than the number of total pages
     for the current page produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 0, 0).setCurrentPage(2)
コード例 #6
0
 def testAroundInvalidTotalPages(self):
     """Test passes if trying to create a Footer with the around value higher than
     (totalPages-1)/2 produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(3, 0, 2)
コード例 #7
0
 def testFloatAround(self):
     """Test passes if trying to create a Footer with a float around value produces a
     FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 0, 1.1)
コード例 #8
0
 def testDefaultPrintB3A1(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 3,
     around = 1, current page = 1"""
     self.assertEqual(Footer(10, 3, 1).print(), "1 2 3 ... 8 9 10")
コード例 #9
0
 def testPrintCP5B1A1(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 1,
     around = 1, current page = 5"""
     footer = Footer(10, 1, 1)
     footer.setCurrentPage(5)
     self.assertEqual(footer.print(), "1 ... 4 5 6 ... 10")
コード例 #10
0
 def testDefaultPrintB1A2(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 1,
     around = 2, current page = 1"""
     self.assertEqual(Footer(10, 1, 2).print(), "1 2 3 ... 10")
コード例 #11
0
 def testZeroTotalPages(self):
     """Test passes if trying to create a Footer with no total pages produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(0, 0, 0)
コード例 #12
0
 def testDefaulPrintB0A1(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 0,
     around = 1, current page = 1"""
     self.assertEqual(Footer(10, 0, 1).print(), "1 2 ...")
コード例 #13
0
    def build(self):
        self.log = logging.getLogger('digilogger')

        Config = ConfigParser.ConfigParser()
        Config.read("Settings.ini")
        GaugeList = Config.sections()[1:]

        self.ActiveGauges = []

        bright = Config.get('Application_Settings', 'Brightness')
        subprocess.call(['sudo', './brightness.sh', str(bright)])
        self.log.debug(''.join(("System brightness changed to ", bright)))

        #Initialize all Gauges from INI config file
        for g in GaugeList:
            gtype = Config.get(g, 'type')
            gstyle = int(Config.get(g, 'style'))
            gposx = float(Config.get(g, 'posx'))
            gposy = float(Config.get(g, 'posy'))
            gscale = float(Config.get(g, 'scale'))
            gmeasure = Config.get(g, 'measure')
            gunits = Config.get(g, 'units')
            gmin = float(Config.get(g, 'min'))
            gmax = float(Config.get(g, 'max'))
            PID = str(Config.get(g, 'pid'))

            bg = Config.get(g, 'background')
            tc = ast.literal_eval(str(Config.get(g, 'textcolor')))
            dl = Config.get(g, 'dialcolor')

            if (gtype == 'analog'):
                curG = Gauge()
                curGS = Scatter(scale=gscale,
                                scale_min=0.25,
                                scale_max=1.5,
                                size_hint=(None, None),
                                size=(400, 400),
                                pos=(gposx, gposy))
                curGS.add_widget(curG)
                Gauge.setParents(curG, self, curGS)
                Gauge.setGaugeParameters(curG, gmeasure, gmin, gmax, gunits)
                self.ActiveGauges.append(curGS)
                curG.gauge.source = bg
                curG.dial.source = dl

                for l in curG.UnitScaleLabels:
                    l.color = tc

                curG.MTitle.color = tc
                curG.MUnits.color = tc

                curG.PID = PID

                Clock.schedule_interval(partial(Gauge.setVALUE, curG), 0.005)
                canbus.subscribe(PID)
                self.log.debug(''.join(
                    ("Created new analog gauge: ", gmeasure)))

            else:
                curG = GaugeDigital()
                curGS = Scatter(scale=gscale,
                                scale_min=0.25,
                                scale_max=1.5,
                                size_hint=(None, None),
                                size=(400, 400),
                                pos=(gposx, gposy))
                curGS.add_widget(curG)
                GaugeDigital.setParents(curG, self, curGS)
                GaugeDigital.setGaugeParameters(curG, gmeasure, gmin, gmax,
                                                gunits)
                self.ActiveGauges.append(curGS)
                curG.gauge.source = bg

                curG.MTitle.color = tc
                curG.MUnits.color = tc
                curG.VALUE.color = tc

                curG.PID = PID

                Clock.schedule_interval(partial(GaugeDigital.setVALUE, curG),
                                        0.005)
                canbus.subscribe(PID)
                self.log.debug(''.join(
                    ("Created new digital gauge: ", gmeasure)))

    #Define application layout
        self.appLayout = FloatLayout(size=(800, 600))
        self.log.debug("System resolution set to 800x600.")

        #Background loaded from ini file
        bg_path = Config.get('Application_Settings', 'Background')
        self.bg = Image(source=bg_path,
                        pos=(0, 0),
                        size=(Window.size[0], Window.size[1]))

        #Create header
        #head = Header()
        #win_w = Window.size[0]
        #win_h = Window.size[1]
        #head = Image(source='Images/StatusBar.png', size=(win_w,win_h/12), pos=(0,win_h-60))

        #Create footer and schedule clock and date functions
        foot = Footer()
        Footer.updatedate(foot)
        Clock.schedule_interval(partial(Footer.updatetime, foot), 1)
        Clock.schedule_interval(partial(Footer.updatedate, foot), 3600)

        #Add Background Header and Footer
        #self.appLayout.add_widget(head)
        self.appLayout.add_widget(self.bg)
        self.appLayout.add_widget(foot)

        #Add Menus
        self.settingMenu = Settings(size_hint=(.3, .01))
        Settings.set_parent(self.settingMenu, self)
        self.gaugeMenu = AddGauge()
        AddGauge.set_parent(self.gaugeMenu, self)
        self.appLayout.add_widget(self.settingMenu)
        self.appLayout.add_widget(self.gaugeMenu)  #DONT MOVE

        #Add Gauges
        for ag in self.ActiveGauges:
            self.appLayout.add_widget(ag)

        self.log.debug("DigiDash home screen started.")
        self.Config = Config  #Create a class reff to Config Parser used in startup

        return self.appLayout
コード例 #14
0
 def __resize__(instance, val):
     print('RESIZE TRIGGERED: ' + str(Window.size))
     Settings.__resize__(self.settingMenu)
     AddGauge.__resize__(self.gaugeMenu)
     Header.__resize__(self.head)
     Footer.__resize__(self.foot)
コード例 #15
0
 def testFloatBoundaries(self):
     """Test passes if trying to create a Footer with the boundarie value a float produces a
     FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 1.1, 0)
コード例 #16
0
 def testFloatTotalPages(self):
     """Test passes if trying to create a Footer with a float for the total number of pages
     produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(1.1, 0, 0)
コード例 #17
0
 def testAroundHigherThanTotalPages(self):
     """Test passes if trying to create a Footer with the around value higher than the total
     number of pages produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 0, 2)
コード例 #18
0
 def testPrintCP5B4A4(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 4,
     around = 4, current page = 5"""
     footer = Footer(10, 4, 4)
     footer.setCurrentPage(5)
     self.assertEqual(footer.print(), "1 2 3 4 5 6 7 8 9 10")
コード例 #19
0
 def testNegativeAround(self):
     """Test passes if trying to create a Footer with a negative around value produces a
     FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 0, -1)
コード例 #20
0
 def testPrintCP10B0A0(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 0,
     around = 0, current page = 10"""
     footer = Footer(10, 0, 0)
     footer.setCurrentPage(10)
     self.assertEqual(footer.print(), "... 10")
コード例 #21
0
 def testNegativeTotalPages(self):
     """Test passes if trying to create a Footer with a number of total pages equal to a
     negative ammount produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(-1, 0, 0)
コード例 #22
0
 def testPrintCP10B1A2(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 2,
     around = 1, current page = 10"""
     footer = Footer(10, 1, 2)
     footer.setCurrentPage(10)
     self.assertEqual(footer.print(), "1 ... 8 9 10")
コード例 #23
0
 def testSetCurrentPageFloat(self):
     """Test passes if trying to set a float for the current page produces a
     FooterError"""
     with self.assertRaises(FooterError):
         Footer(2, 0, 0).setCurrentPage(1.1)
コード例 #24
0
 def testPrintCP8B3A1(self):
     """Tests the Footer print method for an instance with total 10 pages, boundaries = 3,
     around = 1, current page = 8"""
     footer = Footer(10, 3, 1)
     footer.setCurrentPage(8)
     self.assertEqual(footer.print(), "1 2 3 ... 7 8 9 10")
コード例 #25
0
 def testSetCurrentPageZero(self):
     """Test passes if trying to set zero for the current page produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(1, 0, 0).setCurrentPage(0)
コード例 #26
0
 def testBoundariesInvalidTotalPages(self):
     """Test passes if trying to create a Footer with the boundarie value higher than
     (totalPages-1)/2 produces a FooterError"""
     with self.assertRaises(FooterError):
         Footer(3, 2, 0)
コード例 #27
0
    def readStat(self):
        """
            Returns list of CPU info
        """
        return [
            i.split() for i in [line.strip() for line in open('/proc/stat')]
        ]


# Testing
if __name__ == '__main__':
    from sys import argv
    from timeit import Timer

    cm = CPUMeter(1)
    frame = Frame(ListBox([cm]), header=None, footer=Footer())

    def exit(key):
        if key in ('q', 'Q'):
            raise ExitMainLoop()

    def refresh(loop, data):
        cm.update()
        loop.set_alarm_in(1, refresh)

    if argv[1] == 'perf':
        t = Timer(lambda: cm.update())
        print 'CPUMeter: ', t.timeit(number=10000)
    else:
        main_loop = MainLoop(frame,
                             palette,
コード例 #28
0
    def readStat(self):
        """
            Returns list of CPU info
        """
        return [
            i.split() for i in [line.strip() for line in open('/proc/stat')]
        ]


# Testing
if __name__ == '__main__':
    sd = ResourceManager()
    lb = sd

    frame = Frame(lb, header=None, footer=Footer())

    def keyPress(key):
        if key in ('q', 'Q'):
            raise ExitMainLoop()

    def refresh(loop, data):
        sd.update()
        loop.set_alarm_in(1.5, refresh)

    main_loop = MainLoop(frame,
                         palette,
                         unhandled_input=keyPress,
                         pop_ups=True)
    main_loop.set_alarm_in(1.5, refresh)
    main_loop.run()