示例#1
0
def new_rpc(name='Client'):
    s = GUIClient(9367)
    s.connect()
    out.set_output(name, s)
    return s
示例#2
0
文件: gui.py 项目: pjurik2/pykarma
    def __init__(self):
        reddit.reload_filters()
        self.check_cache = {}
        self.links_queued = pickle_load('linksqueued', {})
        self.links_checked = pickle_load('linkschecked', {})
        
        self.menu_idx = 0
        self.links_lock = threading.Lock()
        self.check_lock = threading.Lock()
        self.url_next = None
        
        self.title_stats = reddit_titles.TitleStats()
        threading.Thread(target=self.title_stats.crawl).start()
        
        self.server = GUIServer(self, HOST, PORT)
        self.server.serve()

        self.app = wx.App()
        self.frame = wx.Frame(None, -1, 'PyKarma')

        self.sizer = wx.GridBagSizer()
        self.sizer.AddGrowableCol(0, 10)
        self.sizer.AddGrowableRow(1, 10)
        self.sizer.AddGrowableRow(2, 15)
        

        self.karma = wx.StaticText(self.frame,
                                   style=wx.ALIGN_CENTRE)
        self.karma.SetLabel('Link Karma: Unknown')

        self.karma_font = wx.Font(24, wx.FONTFAMILY_DEFAULT,
                                  wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)

        self.karma.SetFont(self.karma_font)
        self.karma.SetBackgroundColour('white')
        self.karma.SetForegroundColour('red')
        
        self.sizer.Add(self.karma, pos=(0, 0), flag=wx.EXPAND)

        self.out = wx.TextCtrl(self.frame, size=(1200, 200),
                               style=(wx.TE_READONLY | wx.TE_MULTILINE | wx.TE_AUTO_URL | wx.TE_RICH2 | wx.TE_NOHIDESEL))
        self.out.Bind(wx.EVT_TEXT_URL, self.url_open)
        self.out.Bind(wx.EVT_LEFT_UP, self.url_open2)

        self.sizer.Add(self.out, pos=(1, 0), flag=wx.EXPAND)

        self.links = wx.ListCtrl(self.frame, size=(1200, 200),
                                style=wx.LC_REPORT)
        
        self.links.InsertColumn(0, 'Source', width=75)
        self.links.InsertColumn(1, 'Title', width=375)
        self.links.InsertColumn(2, 'URL', width=200)
        self.links.InsertColumn(3, 'Subreddit', width=97)
        self.links.InsertColumn(4, 'Match Strength', width=97)
        self.links.InsertColumn(5, 'Relative Certainty', width=97)
        self.links.InsertColumn(6, 'Staleness', width=80)
        self.links.InsertColumn(7, 'Keywords', width=325)

        self.links.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.links_activate)
        self.links.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.links_right)
        self.links.Bind(wx.EVT_LIST_KEY_DOWN, self.link_keypress)

        for url, link in self.links_queued.iteritems():
            self.links_append(*link, force=True)
        
        self.sizer.Add(self.links, pos=(2, 0), flag=wx.EXPAND)

        self.fout = FileOutput(self)
        out.set_output('Main', self.fout)

        self.frame.SetSizerAndFit(self.sizer)
        self.frame.Show()
        self.app.MainLoop()