示例#1
0
文件: langctrl.py 项目: boothj5/pyloc
    def __init__(self, parent, lang_stats):
        PieCtrl.__init__(self, parent, -1, wx.DefaultPosition)
        self.SetAngle(radians(25))
        self.GetLegend().SetTransparent(True)
        self.GetLegend().SetHorizontalBorder(10)
        self.GetLegend().SetWindowStyle(wx.STATIC_BORDER)
        self.GetLegend().SetLabelFont(wx.Font(10, wx.FONTFAMILY_DEFAULT,
                                                  wx.FONTSTYLE_NORMAL,
                                                  wx.FONTWEIGHT_NORMAL,
                                                  False, "Courier New"))
        self.GetLegend().SetLabelColour(wx.Colour(0, 0, 127))

        colours = [ wx.Colour(200, 50, 50) ,
                    wx.Colour(50, 200, 50) ,
                    wx.Colour(50, 50, 200) ,
                    wx.Colour(100, 0, 200) ,
                    wx.Colour(200, 200, 0) ,
                    wx.Colour(0, 0, 200) ,
                    wx.Colour(200, 0, 200) ,
                    wx.Colour(0, 200, 200) ,
                    wx.Colour(0, 0, 50) ,
                    wx.Colour(0, 25, 50) ,
                    wx.Colour(25, 0, 50) ,
                    wx.Colour(0, 100, 50) ,
                    wx.Colour(175, 175, 50) ,
                    wx.Colour(50, 100, 175) ,
                    wx.Colour(175, 100, 175) ,
                    wx.Colour(0, 50, 0) ]

        colour = 0
        counts = []
        for lang in lang_stats:
            name = lang
            total = lang_stats[lang][pylocstats.TOTAL_LINES]
            counts.append((name, total))

        sorted_counts = reversed(sorted(counts, key=lambda l: l[1]))

        for lang, count in sorted_counts:
            part = PiePart()
            lines = pylocstats.format_thousands(count)
            part.SetLabel(lang + " (" + str(lines) + ")")
            part.SetValue(count)
            part.SetColour(colours[colour])
            colour = colour + 1
            self._series.append(part)
示例#2
0
文件: pyloc.py 项目: boothj5/pyloc
    def on_open_dir(self, event):

        # show dialog to choose directory
        dialog = wx.DirDialog(self, "Choose a directory", self.dirname)
        action = dialog.ShowModal() 

        # if directory chosen
        if action == wx.ID_OK:
            self.SetStatusText("Preparing...")
            self.dirname = dialog.GetPath()
            dialog.Destroy()

            # clear the main sizer
            self.sizer.DeleteWindows()

            # get lang stats showing progress
            lang_stats = {}
            num_files = sum((len(f) for _, _, f in os.walk(self.dirname)))
            self.SetStatusText("Scanning...")
            progressDlg = StatsProgressDialog(self, self.dirname, lang_stats, num_files)

            for count in init_stats(self.dirname, lang_stats):
                progressDlg.Update(count)

            progressDlg.Destroy()
            self.SetStatusText("Done.")

            # calculate total PhyLOC
            total = calc_total(lang_stats)
            formatted_total = format_thousands(total)

            # set up controls
            self.langpie = LangPieCtrl(self, lang_stats)            
            self.rightpanel = wx.Panel(self, -1, style=wx.SIMPLE_BORDER)

            # right panel controls
            self.summarypanel = wx.Panel(self.rightpanel, -1, style=wx.NO_BORDER)
            self.langchooserpanel = wx.Panel(self.rightpanel, -1, style=wx.NO_BORDER)
            self.stats = LangStatsCtrl(self.rightpanel, self.dirname, lang_stats)

            # summary panel text controls
            self.dirlabel = wx.StaticText(self.summarypanel, -1, 
                                          "Directory: ", style=wx.ALIGN_CENTRE)
            self.dirvalue = wx.StaticText(self.summarypanel, -1,
                                          self.dirname, style=wx.ALIGN_CENTRE)
            self.totallabel = wx.StaticText(self.summarypanel, -1, 
                                            "Total Physical LOC: ", style=wx.ALIGN_CENTRE)
            self.totalvalue = wx.StaticText(self.summarypanel, -1, 
                                            formatted_total, style=wx.ALIGN_CENTRE)


            # set up and layout summary panel sizer
            summarysizer = wx.GridSizer(2,2, 5, 5)
            summarysizer.Add(self.dirlabel, 1, wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
            summarysizer.Add(self.dirvalue, 1, wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
            summarysizer.Add(self.totallabel, 1, wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
            summarysizer.Add(self.totalvalue, 1, wx.ALIGN_CENTRE_VERTICAL | wx.ALIGN_LEFT)
            self.summarypanel.SetAutoLayout(True)
            self.summarypanel.SetSizer(summarysizer)
            self.summarypanel.Layout()

            # set up and layout right panel sizer
            rightsizer = wx.BoxSizer(wx.VERTICAL)
            rightsizer.Add(self.summarypanel, 1, wx.CENTRE)
            rightsizer.Add(self.langchooserpanel, 1, wx.EXPAND)
            rightsizer.Add(self.stats, 10, wx.EXPAND)
            self.rightpanel.SetAutoLayout(True)
            self.rightpanel.SetSizer(rightsizer)
            self.rightpanel.Layout()

            # set up and layout main sizer
            self.sizer.Add(self.langpie, 1, wx.EXPAND)
            self.sizer.Add(self.rightpanel, 1, wx.EXPAND)
            self.SetAutoLayout(True) 
            self.SetSizer(self.sizer)
            self.Layout()

        # if cancel chosen
        else:
            dialog.Destroy()