From df8ba1d495c9e9d046fac95787770b374d40b4aa Mon Sep 17 00:00:00 2001 From: Theo Kroening Date: Tue, 16 Apr 2024 11:59:28 -0400 Subject: [PATCH 1/4] Fixed icon-related crashes on Linux --- Main.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Main.py b/Main.py index 604ebae..a1f9146 100644 --- a/Main.py +++ b/Main.py @@ -8,10 +8,20 @@ from os.path import exists from os import listdir from tkcalendar import DateEntry +from PIL import Image, ImageTk # safeguard for the treeview automated string conversion problem PREFIX = '<@!PREFIX>' +def setIcon(object): + """ + This function sets the icon of a tkinter window (passed in as `object`) to + the CFM icon. + """ + im = Image.open('assets/CFM.ico') + photo = ImageTk.PhotoImage(im) + object.wm_iconphoto(True, photo) + # change to desired resolution def set_resolution(window, width, height): @@ -287,7 +297,7 @@ def __init__(self, *args, **kwargs): # global window customization self.title('Counter for Messenger') - self.iconbitmap('assets/CFM.ico') + setIcon(self) # frame container setup self.container = tk.Frame(self) @@ -447,7 +457,7 @@ def __init__(self, controller): # profile window customization self.title(self.module.TITLE_PROFILE) - self.iconbitmap('assets/CFM.ico') + setIcon(self) self.focus_set() self.grab_set() @@ -501,7 +511,7 @@ def __init__(self, controller): # settings window customization self.title(self.module.TITLE_SETTINGS) - self.iconbitmap('assets/CFM.ico') + setIcon(self) self.focus_set() self.grab_set() @@ -607,7 +617,7 @@ def __init__(self, controller, chat_total, treeview): # loading window customization self.title(f'{self.module.TITLE_LOADING}...') - self.iconbitmap('assets/CFM.ico') + setIcon(self) self.resizable(False, False) self.focus_set() self.grab_set() @@ -678,7 +688,7 @@ def __init__(self, controller, selection): # statistics window customization self.title(self.module.TITLE_STATISTICS) - self.iconbitmap('assets/CFM.ico') + setIcon(self) self.focus_set() self.grab_set() From aa27ec67ca8ee5aa9bddd11274f1eb377e7c53dc Mon Sep 17 00:00:00 2001 From: Chen3018 Date: Tue, 23 Apr 2024 00:02:51 -0400 Subject: [PATCH 2/4] Backend function to filter the rows --- Main.py | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/Main.py b/Main.py index a1f9146..fcf1504 100644 --- a/Main.py +++ b/Main.py @@ -148,6 +148,32 @@ def __init__(self, parent, controller): self.treeview.bind('', lambda event: self.deselect()) self.treeview.bind('', lambda event: self.show_statistics()) + # *Ordered* list of columns (so we can display them in a fixed order) + self.columns = [ + 'name', + 'pep', + 'type', + 'msg', + 'call', + 'photos', + 'gifs', + 'videos', + 'files' + ] + self.column_titles = columns + + # filter columns + self.filter_columns = { + 'name': '', + 'pep': set(), + 'msg': -1, + 'call': -1, + 'photos': -1, + 'gifs': -1, + 'videos': -1, + 'files': -1 + } + # show frame title ttk.Label( self.main, text=f'{self.module.TITLE_NUMBER_OF_MSGS}: ', foreground='#ffffff', background='#232323', @@ -251,6 +277,39 @@ def sort_treeview(self, column, order, bias): # Reverse the order for the next sort self.treeview.heading(column, command=lambda: self.sort_treeview(column, not order, bias)) + def filter_treeview(self): + """ + This function filters out rows based on criterias selected by the user. + Example: Show messages with more than 10 photos, but less than 50. + """ + + # Retrieve all the rows in the treeview + children = self.treeview.get_children('') + + filtered = [] + + for child in children: + # Check if user wants to filter by name + if self.filter_columns['name'] != '': + if child['name'] != self.filter_columns['name']: + filtered.append(child) + + # Check if user wants to filter by participants + if self.filter_columns['pep'] != {}: + # only append if no participants are in the list + if self.filter_columns['pep'].isdisjoint(child['pep']): + filtered.append(child) + + for column_name in ['msg', 'call', 'photos', 'gifs', 'videos', 'files']: + # Check if user wants to filter by messages + if self.filter_columns[column_name] != -1: + min, max = self.filter_columns[column_name] + if min <= child[column_name] <= max: + filtered.append(child) + + # Set the selection to the filtered list + self.treeview.selection_set(filtered) + # invoked on double left click on any treeview listing def show_statistics(self): try: From a65c22b0f3fbdfccd60eb96c13af9b8b42b45952 Mon Sep 17 00:00:00 2001 From: Chen3018 Date: Sat, 27 Apr 2024 15:57:59 -0400 Subject: [PATCH 3/4] Fixes bug that adds rows multiple times --- Main.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Main.py b/Main.py index fcf1504..d3d1101 100644 --- a/Main.py +++ b/Main.py @@ -286,27 +286,38 @@ def filter_treeview(self): # Retrieve all the rows in the treeview children = self.treeview.get_children('') - filtered = [] + to_remove = [] for child in children: + remove = False + # Check if user wants to filter by name if self.filter_columns['name'] != '': if child['name'] != self.filter_columns['name']: - filtered.append(child) + remove = True # Check if user wants to filter by participants if self.filter_columns['pep'] != {}: # only append if no participants are in the list if self.filter_columns['pep'].isdisjoint(child['pep']): - filtered.append(child) + remove = True for column_name in ['msg', 'call', 'photos', 'gifs', 'videos', 'files']: # Check if user wants to filter by messages if self.filter_columns[column_name] != -1: min, max = self.filter_columns[column_name] if min <= child[column_name] <= max: - filtered.append(child) + remove = True + + if remove: + to_remove.append(child) + filtered = [] + + for child in children: + if child not in to_remove: + filtered.append(child) + # Set the selection to the filtered list self.treeview.selection_set(filtered) From 895a058486b7e259e5023dc1e552cb502ca974ed Mon Sep 17 00:00:00 2001 From: Chen3018 Date: Sat, 27 Apr 2024 16:09:30 -0400 Subject: [PATCH 4/4] Fixes bug that filters number columns incorrectly --- Main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Main.py b/Main.py index d3d1101..c960b9e 100644 --- a/Main.py +++ b/Main.py @@ -303,10 +303,10 @@ def filter_treeview(self): remove = True for column_name in ['msg', 'call', 'photos', 'gifs', 'videos', 'files']: - # Check if user wants to filter by messages + # Check if user wants to filter by other columns if self.filter_columns[column_name] != -1: min, max = self.filter_columns[column_name] - if min <= child[column_name] <= max: + if min > child[column_name] or child[column_name] > max: remove = True if remove: