<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals
import Tkinter

from collections import deque
from PIL import Image, ImageTk
import random
import sys
from base.graph_fetch.fetcher import GraphFetcher, DELETE, DISCARD, INC_RANK, DEC_RANK
from base.graph_fetch.fetcher import ImageSlot  # to let pickle can recognize ImageSlot
from base.dir_handle.dir_handler import GraphDirHandler
from base.setting.utility import RankArbitrator as Arbitrator
from base.setting.image import Image as ImageObj
from util.color import get_random_color
from util.global_def import show, info, error, get_msg
from util.global_def import NA, get_slideshow_frequency, get_phrase_appear_ratio, get_fullscreen_mode2
from util.message import Msg

__BG__ = 'black'


def user_quit(*unused):
    sys.exit()


class GraphViewer(object):
    """'randomly' show the crawled picture"""
    IMAGE_HISTORY_SIZE = 10

    def __init__(self):
        self.__root = Tkinter.Tk()
        self.__root.configure(background=__BG__)
        self.__root.title("reminder")
        w, h = self.__root.winfo_screenwidth(), self.__root.winfo_screenheight()
        self.__full_geom = "%dx%d+0+0" % (w, h)
        self.__root.geometry(self.__full_geom)
        self.__old_label_image = None
        self.__pending_jobs = []
        self.__tk_obj_ref = None  # need keep ref to prevent GC (garbage collection)
        self.__onscreen_help = False
        self.__onscreen_info = False
        self.__pause_slideshow = False
        self.__fullscreen_mode = True
        if get_fullscreen_mode2():
            self.__root.overrideredirect(self.__fullscreen_mode)  # do this b4 ...'-fullscreen'
        self.__root.attributes("-fullscreen", self.__fullscreen_mode)
        self.__root.bind("<Escape>", self.toggle_display_mode)
        self.__root.bind("<BackSpace>", self.delete_image)
        self.__root.bind("<Button>", lambda e: e.widget.quit())
        self.__root.bind("<Right>", lambda e: e.widget.quit())
        self.__root.bind("<Left>", self.show_previous_image)
        self.__root.bind("<h>", self.toggle_onscreen_help)
        self.__root.bind("<i>", self.toggle_onscreen_info)
        self.__root.bind("<p>", self.toggle_pause_slideshow)
        self.__root.bind("<q>", user_quit)
        self.__root.bind("<equal>", self.increment_rank)
        self.__root.bind("<minus>", self.decrement_rank)
        self.__cur_image_obj = None
        self.__cur_image_obj_list = []  # image_obj in list
        self.__cur_image_obj_dict = {}  # image_obj in dict (same content as above)
        self.__phrase_binding = {}  # key: pattern, value: list of PhraseGroup
        self.__cur_phrase_obj_dict = {}  # key: phrase group name, value: PhraseGroup
        self.__cur_graph_file = None
        self.__graph_history = deque(maxlen=GraphViewer.IMAGE_HISTORY_SIZE)
        self.__cur_digest = ""
        self.__arbitrator = None
        self.__canvas = Tkinter.Canvas(self.__root, bg=__BG__, bd=0, highlightthickness=0)
        self.__canvas.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
        self.__help = self.help_text()
        self.__info = self.info_text()
        self.__phrase_var = Tkinter.StringVar()
        self.__phrase = self.phrase_text()

    def get_full_geom(self):
        w, h = self.__root.winfo_screenwidth(), self.__root.winfo_screenheight()
        return "%dx%d+0+0" % (w, h)

    def toggle_display_mode(self, *unused):
        self.__fullscreen_mode = not self.__fullscreen_mode
        self.__root.attributes("-fullscreen", self.__fullscreen_mode)
        if get_fullscreen_mode2():
            self.__root.overrideredirect(self.__fullscreen_mode)
        self.set_graph_content(self.__cur_graph_file)

    def delete_image(self, *unused):
        if self.__cur_image_obj.location:
            return  # spec.: not support remove image that user 'specified'
        info(get_msg(Msg.remove_image), self.__cur_graph_file)
        self.__graph_history.remove([self.__cur_image_obj, self.__cur_graph_file])
        GraphFetcher.handle_image(self.__cur_graph_file, DELETE)
        self.cancel_pending_jobs()
        self.timer_action()

    def show_previous_image(self, *unused):
        last_graph = self.__graph_history.pop()
        self.__graph_history.appendleft(last_graph)
        self.set_graph(*self.__graph_history.pop())
        self.cancel_pending_jobs()
        self.prepare_for_next_view(get_slideshow_frequency() * 1000)

    def increment_rank(self, *unused):
        info(get_msg(Msg.increase_rank), self.__cur_graph_file)
        if self.__cur_image_obj.location:<commit_msg>fix issue upon 'pause', deletion will not trigger image update<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function, unicode_literals
import Tkinter

from collections import deque
from PIL import Image, ImageTk
import random
import sys
from base.graph_fetch.fetcher import GraphFetcher, DELETE, DISCARD, INC_RANK, DEC_RANK
from base.graph_fetch.fetcher import ImageSlot  # to let pickle can recognize ImageSlot
from base.dir_handle.dir_handler import GraphDirHandler
from base.setting.utility import RankArbitrator as Arbitrator
from base.setting.image import Image as ImageObj
from util.color import get_random_color
from util.global_def import show, info, error, get_msg
from util.global_def import NA, get_slideshow_frequency, get_phrase_appear_ratio, get_fullscreen_mode2
from util.message import Msg

__BG__ = 'black'


def user_quit(*unused):
    sys.exit()


class GraphViewer(object):
    """'randomly' show the crawled picture"""
    IMAGE_HISTORY_SIZE = 10

    def __init__(self):
        self.__root = Tkinter.Tk()
        self.__root.configure(background=__BG__)
        self.__root.title("reminder")
        w, h = self.__root.winfo_screenwidth(), self.__root.winfo_screenheight()
        self.__full_geom = "%dx%d+0+0" % (w, h)
        self.__root.geometry(self.__full_geom)
        self.__old_label_image = None
        self.__pending_jobs = []
        self.__tk_obj_ref = None  # need keep ref to prevent GC (garbage collection)
        self.__onscreen_help = False
        self.__onscreen_info = False
        self.__pause_slideshow = False
        self.__fullscreen_mode = True
        if get_fullscreen_mode2():
            self.__root.overrideredirect(self.__fullscreen_mode)  # do this b4 ...'-fullscreen'
        self.__root.attributes("-fullscreen", self.__fullscreen_mode)
        self.__root.bind("<Escape>", self.toggle_display_mode)
        self.__root.bind("<BackSpace>", self.delete_image)
        self.__root.bind("<Button>", lambda e: e.widget.quit())
        self.__root.bind("<Right>", lambda e: e.widget.quit())
        self.__root.bind("<Left>", self.show_previous_image)
        self.__root.bind("<h>", self.toggle_onscreen_help)
        self.__root.bind("<i>", self.toggle_onscreen_info)
        self.__root.bind("<p>", self.toggle_pause_slideshow)
        self.__root.bind("<q>", user_quit)
        self.__root.bind("<equal>", self.increment_rank)
        self.__root.bind("<minus>", self.decrement_rank)
        self.__cur_image_obj = None
        self.__cur_image_obj_list = []  # image_obj in list
        self.__cur_image_obj_dict = {}  # image_obj in dict (same content as above)
        self.__phrase_binding = {}  # key: pattern, value: list of PhraseGroup
        self.__cur_phrase_obj_dict = {}  # key: phrase group name, value: PhraseGroup
        self.__cur_graph_file = None
        self.__graph_history = deque(maxlen=GraphViewer.IMAGE_HISTORY_SIZE)
        self.__cur_digest = ""
        self.__arbitrator = None
        self.__canvas = Tkinter.Canvas(self.__root, bg=__BG__, bd=0, highlightthickness=0)
        self.__canvas.pack(expand=Tkinter.YES, fill=Tkinter.BOTH)
        self.__help = self.help_text()
        self.__info = self.info_text()
        self.__phrase_var = Tkinter.StringVar()
        self.__phrase = self.phrase_text()

    def get_full_geom(self):
        w, h = self.__root.winfo_screenwidth(), self.__root.winfo_screenheight()
        return "%dx%d+0+0" % (w, h)

    def toggle_display_mode(self, *unused):
        self.__fullscreen_mode = not self.__fullscreen_mode
        self.__root.attributes("-fullscreen", self.__fullscreen_mode)
        if get_fullscreen_mode2():
            self.__root.overrideredirect(self.__fullscreen_mode)
        self.set_graph_content(self.__cur_graph_file)

    def delete_image(self, *unused):
        if self.__cur_image_obj.location:
            return  # spec.: not support remove image that user 'specified'
        info(get_msg(Msg.remove_image), self.__cur_graph_file)
        self.__graph_history.remove([self.__cur_image_obj, self.__cur_graph_file])
        GraphFetcher.handle_image(self.__cur_graph_file, DELETE)
        self.cancel_pending_jobs()
        self.timer_action(True)

    def show_previous_image(self, *unused):
        last_graph = self.__graph_history.pop()
        self.__graph_history.appendleft(last_graph)
        self.set_graph(*self.__graph_history.pop())
        self.cancel_pending_jobs()
        self.prepare_for_next_view(get_slideshow_frequency() * 1000)

    def increment_rank(self, *unused):
        info(get_msg(Msg.increase_rank), self.__cur_graph_file)
        if self.__cur_image_obj.location:
{'fraction_non_alphanumeric': 0.10682524375870567, 'fraction_numerical': 0.0036429872495446266, 'mean_word_length': 3.415326395458846, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '7186819', 'n_tokens_mistral': 2945, 'n_tokens_neox': 2889, 'n_words': 560}