-
Notifications
You must be signed in to change notification settings - Fork 0
Review #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vsubhuman
wants to merge
27
commits into
empty
Choose a base branch
from
review
base: empty
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Review #1
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
c9bd900
Initial commit
Nebyt fa1629d
Text field fills all space of a tab.
Nebyt 75baaf9
Change app icon
Nebyt 2037864
Change app icon
Nebyt d85a680
Change size for Linux and Windows
Nebyt 46e8dea
Path to icon.
Nebyt 2b39445
Change app icon
Nebyt 0f64442
Change app icon
Nebyt d93535f
Bind the button for start and stop watch the tail of file.
Nebyt bb39283
Move class Tab to another file.
Nebyt df139ef
Added modal window.
Nebyt 58f443a
added recognize_codec function
Nebyt ee3b89d
Added recognition file format. Thanks http://patttern.blogspot.ru/201…
Nebyt c0932f4
Little visual change
Nebyt 872589c
Added skeleton of the save module.
Nebyt 9f0652e
Added save module.
Nebyt 9ad9dc4
Little visual change
Nebyt dd61773
Changed save module
Nebyt 4114f76
Organized files by folders
Nebyt 9245c1a
Organized files by folders
Nebyt 351286f
Fix the save module. Now then tab is closed, it delete from list of t…
Nebyt 95c9fbd
Added random choice from file 'dict.txt'.
Nebyt f6c4b34
Merge branch 'master' into review
fef17e7
If the file was not changed , the programm does not read the file
Nebyt d923a43
Highlight the word 'error'.
Nebyt fe08d79
Menu bar changed.
Nebyt aad4e3f
Merge remote-tracking branch 'origin/master' into review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import tkinter | ||
from tkinter import ttk | ||
from modules.list_of_tab import list_of_tab | ||
|
||
|
||
class CustomNotebook(ttk.Notebook): | ||
"""A ttk Notebook with close buttons on each tab""" | ||
|
||
__initialized = False | ||
|
||
def __init__(self, *args, **kwargs): | ||
if not self.__initialized: | ||
self.__initialize_custom_style() | ||
self.__initialized = True | ||
|
||
kwargs["style"] = "CustomNotebook" | ||
ttk.Notebook.__init__(self, *args, **kwargs) | ||
|
||
self._active = None | ||
|
||
self.bind("<ButtonPress-1>", self.on_close_press, True) | ||
self.bind("<ButtonRelease-1>", self.on_close_release) | ||
|
||
def on_close_press(self, event): | ||
"""Called when the button is pressed over the close button""" | ||
|
||
element = self.identify(event.x, event.y) | ||
|
||
if "close" in element: | ||
index = self.index("@%d,%d" % (event.x, event.y)) | ||
self.state(['pressed']) | ||
self._active = index | ||
|
||
def on_close_release(self, event): | ||
"""Called when the button is released over the close button""" | ||
if not self.instate(['pressed']): | ||
return | ||
|
||
element = self.identify(event.x, event.y) | ||
index = self.index("@%d,%d" % (event.x, event.y)) | ||
tab_name_for_delete = self.tab(index, "text") # get name of closed tab | ||
|
||
if "close" in element and self._active == index: | ||
self.forget(index) | ||
self.event_generate("<<NotebookTabClosed>>") | ||
|
||
self.state(["!pressed"]) | ||
self._active = None | ||
|
||
for tab in list_of_tab.get_all_tab(): | ||
if tab.tab_name == tab_name_for_delete: | ||
list_of_tab.remove_tab(tab) | ||
break | ||
|
||
def __initialize_custom_style(self): | ||
style = ttk.Style() | ||
self.images = ( | ||
tkinter.PhotoImage("img_close", data=''' | ||
R0lGODlhCAAIAMIBAAAAADs7O4+Pj9nZ2Ts7Ozs7Ozs7Ozs7OyH+EUNyZWF0ZWQg | ||
d2l0aCBHSU1QACH5BAEKAAQALAAAAAAIAAgAAAMVGDBEA0qNJyGw7AmxmuaZhWEU | ||
5kEJADs= | ||
'''), | ||
tkinter.PhotoImage("img_closeactive", data=''' | ||
R0lGODlhCAAIAMIEAAAAAP/SAP/bNNnZ2cbGxsbGxsbGxsbGxiH5BAEKAAQALAAA | ||
AAAIAAgAAAMVGDBEA0qNJyGw7AmxmuaZhWEU5kEJADs= | ||
'''), | ||
tkinter.PhotoImage("img_closepressed", data=''' | ||
R0lGODlhCAAIAMIEAAAAAOUqKv9mZtnZ2Ts7Ozs7Ozs7Ozs7OyH+EUNyZWF0ZWQg | ||
d2l0aCBHSU1QACH5BAEKAAQALAAAAAAIAAgAAAMVGDBEA0qNJyGw7AmxmuaZhWEU | ||
5kEJADs= | ||
''') | ||
) | ||
|
||
style.element_create("close", "image", "img_close", | ||
("active", "pressed", "!disabled", "img_closepressed"), | ||
("active", "!disabled", "img_closeactive"), border=8, sticky='') | ||
style.layout("CustomNotebook", [("CustomNotebook.client", {"sticky": "nswe"})]) | ||
style.layout("CustomNotebook.Tab", [ | ||
("CustomNotebook.tab", { | ||
"sticky": "nswe", | ||
"children": [ | ||
("CustomNotebook.padding", { | ||
"side": "top", | ||
"sticky": "nswe", | ||
"children": [ | ||
("CustomNotebook.focus", { | ||
"side": "top", | ||
"sticky": "nswe", | ||
"children": [ | ||
("CustomNotebook.label", {"side": "left", "sticky": ''}), | ||
("CustomNotebook.close", {"side": "left", "sticky": ''}), | ||
] | ||
}) | ||
] | ||
}) | ||
] | ||
}) | ||
]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
from modules.loader import Tail | ||
import tkinter | ||
from tkinter import ttk | ||
import threading | ||
import time | ||
from modules.list_of_tab import list_of_tab | ||
|
||
|
||
class Tab: | ||
def __init__(self, main_space, file_path=''): | ||
self.path_to_file = file_path | ||
self.__end = 0 | ||
self.search_index = '1.0' | ||
self.all_visible_text = '' | ||
self.document = Tail(file_path) # создаем на вкладке объект документа, который читаем | ||
self.page = ttk.Frame(main_space) # объект вкладка | ||
self.__tab_name_expect = file_path.split('/')[-1] # имя вкладки, берем последнее значение после разделения по символу / | ||
|
||
self.tab_name = self.__set_tab_name(self.__tab_name_expect) | ||
self.txt = tkinter.Text(self.page, font="TextFont", spacing3=2) # объект текстовое поле | ||
self.scroll = tkinter.Scrollbar(self.txt) # объект скролбарр на вкладку | ||
|
||
self.txt.config(yscrollcommand=self.scroll.set) | ||
self.scroll.config(command=self.txt.yview) # прикрепляем скроллбар к текстовому полю | ||
|
||
self.txt.pack(side='top', fill='both', expand=True) # задаем размещение текстового поле | ||
self.scroll.pack(side='right', fill=tkinter.Y) # задаем размещение скроллбара | ||
|
||
self.txt.tag_config("red", background="red", foreground="white") | ||
|
||
main_space.add(self.page, text='{}'.format(self.tab_name)) # добавляем вкладку | ||
|
||
self.txt.bind('<End>', self.__watch_tail) # при нажатии на кнопку END начинается просмотр последних данных | ||
self.txt.bind('<Double-Button-1>', self.__stop_watch_tail) # при 2-м клике останавливаем просмотр | ||
|
||
self.txt.insert(tkinter.END, self.document.get_lines()) # вставляем текст из нашего документа | ||
self.txt.config(state='disabled') # закрываем возможность редактировать | ||
self.thread_highlight = threading.Thread(target=self.__highlight_word, | ||
args=['error', self.search_index], | ||
daemon=True, | ||
name='__highlight_red') # поток для выделения текста | ||
self.thread_show_last_string = threading.Thread(target=self.__shows_the_last_string, | ||
daemon=True, | ||
name='__watch_tail') # поток для просмотра последней строки | ||
self.thread_highlight.start() | ||
|
||
def __set_tab_name(self, tab_name_expect): | ||
self.__name, self.__file_fmt = tab_name_expect.split('.') | ||
self.__all_tabs = list_of_tab.get_all_tab() | ||
self.__count = 1 | ||
for tab in self.__all_tabs: | ||
if tab.tab_name == tab_name_expect: | ||
tab_name_expect = '{0}({1}).{2}'.format(self.__name, self.__count, self.__file_fmt) | ||
self.__count += 1 | ||
return tab_name_expect | ||
|
||
def update_text(self): | ||
"""Эта функция должна была обновлять текст на вкладке""" | ||
self.txt.config(state='normal') | ||
self.txt.insert(tkinter.END, self.document.get_lines()) | ||
self.txt.config(state='disabled') | ||
|
||
def __shows_the_last_string(self): | ||
"""На постоянке крутиться проверка для перехода к концу""" | ||
while True: | ||
while self.__end: | ||
self.txt.see(tkinter.END) | ||
time.sleep(1) | ||
time.sleep(1) | ||
|
||
def __watch_tail(self, event): | ||
"""запуск потока для постоянного просмотра последнего файла""" | ||
self.__end = 1 | ||
if not self.thread_show_last_string.isAlive(): | ||
self.thread_show_last_string.start() | ||
|
||
def __stop_watch_tail(self, event): | ||
"""останавливаем цикл, который постоянно мониторит последнюю строку""" | ||
self.__end = 0 | ||
|
||
def __search_word(self, word, start_index): | ||
"""Find first position of the word, from start position""" | ||
pos = self.txt.search(word, start_index, tkinter.END) | ||
if pos: | ||
string, sym = pos.split('.') | ||
new_sym = str(int(sym) + len(word)) | ||
next_start_index = '{0}.{1}'.format(string, new_sym) | ||
self.search_index = next_start_index | ||
return pos, next_start_index | ||
else: | ||
next_start_index = '' | ||
return pos, next_start_index | ||
|
||
def __highlight_word(self, word, start_index): | ||
next_index = start_index | ||
while True: | ||
first_sym, last_sym = self.__search_word(word, start_index=next_index) | ||
if last_sym: | ||
next_index = last_sym | ||
self.txt.tag_add('red', first_sym, last_sym) | ||
time.sleep(0.2) | ||
else: | ||
time.sleep(0.7) | ||
|
||
def get_all_text(self): | ||
self.all_visible_text = self.txt.get(1.0, tkinter.END) | ||
return self.all_visible_text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import tkinter | ||
import os | ||
|
||
|
||
class ModalWindow: | ||
def __init__(self, file_name): | ||
self.__file_name = file_name | ||
self.width = 200 | ||
self.height = 100 | ||
self.top = tkinter.Toplevel(padx=1, pady=1) | ||
self.start_pos_x = int((self.top.winfo_screenwidth() / 2) - (self.width / 2)) | ||
self.start_pos_y = int((self.top.winfo_screenheight() / 2.5) - (self.height / 2)) | ||
self.top.title("Warning!") | ||
self.top.geometry('{0}x{1}+{2}+{3}'.format(self.width, self.height, | ||
self.start_pos_x, self.start_pos_y)) | ||
self.top.maxsize(self.width, self.height) | ||
self.top.resizable(0, 0) | ||
if os.name == 'nt': | ||
self.top.attributes('-toolwindow', 1) | ||
|
||
self.msg = tkinter.Message(self.top, text="{0}\n is not a text file!".format(self.__file_name), | ||
justify='left', width=190, font='Arial 12') | ||
self.msg.pack(side='top', fill='both', expand=True) | ||
|
||
self.button = tkinter.Button(self.top, text="Close", command=self.top.destroy) | ||
self.button.pack(side='top', expand=True) | ||
|
||
def show(self): | ||
self.top.focus_set() | ||
self.top.mainloop() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error | ||
Error | ||
warn | ||
Warning | ||
INFO | ||
info | ||
Info | ||
DEBUG | ||
Debug | ||
Left | ||
Right | ||
Up | ||
AND | ||
Down |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import time | ||
import sys | ||
import msvcrt | ||
import threading | ||
import os | ||
import random | ||
|
||
pressed_key = '' | ||
|
||
|
||
def press_key(): | ||
while True: | ||
pressed_key = msvcrt.getwch() | ||
if pressed_key == 'q': | ||
sys.exit() | ||
time.sleep(0.5) | ||
|
||
|
||
th = threading.Thread(target=press_key,name=2) | ||
|
||
|
||
def fill_file(): | ||
k = 1 | ||
words: list | ||
with open('dict.txt', 'r') as dictionary: | ||
words = dictionary.read().split('\n') | ||
for count in range(11): | ||
file_path = '{0}{1}{2}'.format(os.getcwd(), os.sep, 'test_{0}.log'.format(count)) | ||
if not os.path.exists(r'{0}'.format(file_path)): | ||
while True: | ||
if pressed_key == 'q': | ||
print('Stop the script') | ||
sys.exit(0) | ||
else: | ||
with open('test_{0}.log'.format(count), 'a') as file: | ||
file.writelines('New string {0} {1} Новая строка {0} {2}\n'.format(k, | ||
random.choice(words), | ||
random.choice(words))) | ||
print('New string {0} {1} Новая строка {0} {2}\n'.format(k, | ||
random.choice(words), | ||
random.choice(words))) | ||
k += 1 | ||
time.sleep(1) | ||
else: | ||
pass | ||
|
||
|
||
def starter(): | ||
th.start() | ||
fill_file() | ||
|
||
|
||
starter() |
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Стоит проверять, что документ чота вернул, прежде чем пытаться обновлять табу: