<commit_before>#!/usr/bin/env python2
#
# Copyright (c) 2013, theZacAttacks
#
#
# A simple little twitter client written using the python-twitter
#  module and tcl for a GUI.
#
# Version       Changelog
#-------------------------------------------------------------------------------
# 0.1           original tcl gui code written
#
# 0.2           got the unique api code hardcoded
#
# 0.4           added threads to improve GUI performace
#
# 0.6           changed a lot of the display code to make it more
#                robust and applicable
#
# 0.8           can pull tweets from timeline, can post tweets
#                tweet's author is easily distenguished from tweets
#
# 0.9           tweets displayed accuratly, autoupdating works and 
#                character counting works
#
# 0.9.1         GUI resizes correctly, and took out the hard coded
#                values of my creds and made it check ~/.tcler for
#                the user's key & token. 
#               IDEAS: make links clickable. scan through each tweet
#                that comes in, and make each hyperlink clickable. (DONE)
#
# 0.9.2         Links now clickable, added menu item to open every link
#                Fixed the new tweet display error
#
# 0.9.3         Added some error handling for character for the Tkinter 
#                Text widget
#
# 0.9.4         Added a console option. This prints out the errors/thread
#                info that typically gets printed to the console to a 
#                GUI window for users not running from console. Also
#                https links now work
#               IDEAS: make ERR a list that contains the backlog of errors
#                and/or messages. Make console display the backlog of
#                errors whenever it gets started
#
# 0.9.5         All messages/errors are stored in ERR which is now a global 
#                list. When the console is started the backlog of messages
#                (stored in ERR) is vomited into the console. These backlog
#                messages are greyed out, whereas the new messages are 
#                not greyed.
#
# 0.9.6         Clicking a user's handle (the text in red) will now fill
#                out the 'post' box with their username, allowing easier
#                tweets at a person. Also, incorporated tkHyperLinkManager
#                into the main file.
#               IDEAS: Make the hashtags clickable which opens a Toplevel
#                box that lists the search results. Incorporate a search
#                function into the client itself, accessable via a menu
#                button. 

import twitter
import threading
import webbrowser
import get_access_token

from Tkinter import *
from os import path
from urllib2 import URLError
from time import sleep
from time import localtime
from platform import system

#
# GLOBAL VARIABLE DECLARATION
#

# log of errors
global ERR
ERR = list()

# bool that helps stop the threads
global STREAM_UPDATE
STREAM_UPDATE = True

# the id of the last tweet
global LAST_ID
LAST_ID = None

# Tkinter StringVar (used for updating the character count
global TEXT
TEXT = None

# conDialog reference that is used for checks
global CON
CON = None

# class that helps handle the task of managing the various 'clicky' actions for text
class HyperlinkManager:
        
        def __init__(self, text):
                
                self.text = text
                
                self.text.tag_config("hyper", foreground="blue", underline=1)
                
                self.text.tag_bind("hyper", "<Enter>", self._enter)
                self.text.tag_bind("hyper", "<Leave>", self._leave)
                self.text.tag_bind("hyper", "<Button-1>", lambda x: self._click("hyper"))
                
                self.text.tag_config("handle", foreground="red")
                self.text.tag_bind("handle", "<Button-1>", lambda x: self._click("handle"))
                
                self.reset()
        def reset(self):
                self.links = {}
        def add(self, action, text, thisTag):
                tag = thisTag + "-%d" % len(self.links)
                self.links[tag] = (action,text)
                return thisTag, tag
        def _enter(self, event):
                self.text.config(cursor="hand2")
        def _leave(self, event):
                self.text.config(cursor="")
        def _click(self, thisTag, event = None):
                for tag in self.text.tag_names(CURRENT):
                        if tag[:(len(thisTag) + 1)] == thisTag + "-":
                                self.links[tag][0](self.links[tag][1])
                                return

# a simple class that allows for a Toplevel widget to become active with the console log
class conDialog(Toplevel):
        def __init__(self, parent, title):
                self.top = Toplevel(parent)
                self.top.wm_title(title)
                self.top.wm_minsize(width=200, height=250)
                
                self.parent = parent
                
                self.running = True
                
                self.logger = Text(self.top, width=50, height=15)
                self.logger.pack(fill=BOTH, expand=1)
                self.logger.config(wrap=WORD)
                
                self.close = Button(self.top, text="Close", command=self.closeThisWindow)
                self.close.pack(fill=X,expand=0)
                <commit_msg>added the basis of a search dialog Toplevel widget function<commit_after>#!/usr/bin/env python2
#
# Copyright (c) 2013, theZacAttacks
#
#
# A simple little twitter client written using the python-twitter
#  module and tcl for a GUI.
#
# Version       Changelog
#-------------------------------------------------------------------------------
# 0.1           original tcl gui code written
#
# 0.2           got the unique api code hardcoded
#
# 0.4           added threads to improve GUI performace
#
# 0.6           changed a lot of the display code to make it more
#                robust and applicable
#
# 0.8           can pull tweets from timeline, can post tweets
#                tweet's author is easily distenguished from tweets
#
# 0.9           tweets displayed accuratly, autoupdating works and 
#                character counting works
#
# 0.9.1         GUI resizes correctly, and took out the hard coded
#                values of my creds and made it check ~/.tcler for
#                the user's key & token. 
#               IDEAS: make links clickable. scan through each tweet
#                that comes in, and make each hyperlink clickable. (DONE)
#
# 0.9.2         Links now clickable, added menu item to open every link
#                Fixed the new tweet display error
#
# 0.9.3         Added some error handling for character for the Tkinter 
#                Text widget
#
# 0.9.4         Added a console option. This prints out the errors/thread
#                info that typically gets printed to the console to a 
#                GUI window for users not running from console. Also
#                https links now work
#               IDEAS: make ERR a list that contains the backlog of errors
#                and/or messages. Make console display the backlog of
#                errors whenever it gets started
#
# 0.9.5         All messages/errors are stored in ERR which is now a global 
#                list. When the console is started the backlog of messages
#                (stored in ERR) is vomited into the console. These backlog
#                messages are greyed out, whereas the new messages are 
#                not greyed.
#
# 0.9.6         Clicking a user's handle (the text in red) will now fill
#                out the 'post' box with their username, allowing easier
#                tweets at a person. Also, incorporated tkHyperLinkManager
#                into the main file.
#               IDEAS: Make the hashtags clickable which opens a Toplevel
#                box that lists the search results. Incorporate a search
#                function into the client itself, accessable via a menu
#                button. 

import twitter
import threading
import webbrowser
import get_access_token

from Tkinter import *
from os import path
from urllib2 import URLError
from time import sleep
from time import localtime
from platform import system

#
# GLOBAL VARIABLE DECLARATION
#

# log of errors
global ERR
ERR = list()

# bool that helps stop the threads
global STREAM_UPDATE
STREAM_UPDATE = True

# the id of the last tweet
global LAST_ID
LAST_ID = None

# Tkinter StringVar (used for updating the character count
global TEXT
TEXT = None

# conDialog reference that is used for checks
global CON
CON = None

# class that helps handle the task of managing the various 'clicky' actions for text
class HyperlinkManager:
        
        def __init__(self, text):
                
                self.text = text
                
                self.text.tag_config("hyper", foreground="blue", underline=1)
                
                self.text.tag_bind("hyper", "<Enter>", self._enter)
                self.text.tag_bind("hyper", "<Leave>", self._leave)
                self.text.tag_bind("hyper", "<Button-1>", lambda x: self._click("hyper"))
                
                self.text.tag_config("handle", foreground="red")
                self.text.tag_bind("handle", "<Button-1>", lambda x: self._click("handle"))
                
                self.reset()
        def reset(self):
                self.links = {}
        def add(self, action, text, thisTag):
                tag = thisTag + "-%d" % len(self.links)
                self.links[tag] = (action,text)
                return thisTag, tag
        def _enter(self, event):
                self.text.config(cursor="hand2")
        def _leave(self, event):
                self.text.config(cursor="")
        def _click(self, thisTag, event = None):
                for tag in self.text.tag_names(CURRENT):
                        if tag[:(len(thisTag) + 1)] == thisTag + "-":
                                self.links[tag][0](self.links[tag][1])
                                return

class searchDialog(Toplevel):
        def __init__(self, parent, title):
                self.top = Toplevel(parent)
                self.top.wm_title(title)
                
                self.searchy = Text(self.top)
                

# a small class that allows for a Toplevel widget to become active with the console log
class conDialog(Toplevel):
        def __init__(self, parent, title):
                self.top = Toplevel(parent)
                self.top.wm_title(title)
                self.top.wm_minsize(width=200, height=250)
                
                self.parent = parent
                
                self.logger = Text(self.top, width=50, height=15)
                self.logger.pack(fill=BOTH, expand=1)
                self.logger.config(wrap=WORD)
                
                self.close = Button(self.top, text="Close", command=self.closeThisWindow)
                self.close.pack(fill=X,expand=0)
                
{'fraction_non_alphanumeric': 0.08914275434019969, 'fraction_numerical': 0.009894755779436899, 'mean_word_length': 1.6868052199130015, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3570524', 'n_tokens_mistral': 3041, 'n_tokens_neox': 2823, 'n_words': 1066}