-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Spasov
authored and
Martin Spasov
committed
Sep 24, 2017
1 parent
2146ad0
commit 8fe309a
Showing
10 changed files
with
116 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -4,11 +4,15 @@ | |
from gi.repository import Gtk, Gdk, Pango, GdkPixbuf | ||
import format_toolbar as ft | ||
import subprocess | ||
from logger import logger as lg | ||
|
||
WHITESPACE = ('\r', '\n', '\t', ' ') | ||
|
||
class UndoableInsert(object): | ||
|
||
logger = lg.Logger() | ||
|
||
@lg.logging_decorator(logger) | ||
def __init__(self,text_iter,text,text_len): | ||
|
||
self.offset = text_iter.get_offset() | ||
|
@@ -22,6 +26,9 @@ def __init__(self,text_iter,text,text_len): | |
|
||
class UndoableDelete(object): | ||
|
||
logger = lg.Logger() | ||
|
||
@lg.logging_decorator(logger) | ||
def __init__(self,buf, start_iter,end_iter): | ||
|
||
self.text = buf.get_text(start_iter, end_iter,False) | ||
|
@@ -39,7 +46,10 @@ def __init__(self,buf, start_iter,end_iter): | |
self.mergeable = True | ||
|
||
class UndoableInsertTag(object): | ||
|
||
logger = lg.Logger() | ||
|
||
@lg.logging_decorator(logger) | ||
def __init__(self, tag, start, end): | ||
self.tag = tag | ||
self.start = start.get_offset() | ||
|
@@ -48,6 +58,9 @@ def __init__(self, tag, start, end): | |
|
||
class UndoableDeleteTag(object): | ||
|
||
logger = lg.Logger() | ||
|
||
@lg.logging_decorator(logger) | ||
def __init__(self,tag,start,end): | ||
self.tag = tag | ||
self.start = start.get_offset() | ||
|
@@ -57,6 +70,9 @@ def __init__(self,tag,start,end): | |
|
||
class Editor(Gtk.Grid): | ||
|
||
logger = lg.Logger() | ||
|
||
@lg.logging_decorator(logger) | ||
def __init__(self,parent): | ||
|
||
Gtk.Grid.__init__(self, row_spacing=5, column_spacing=2) | ||
|
@@ -169,6 +185,7 @@ def __init__(self,parent): | |
self.attach(self.scrolled_window, 0, 0, 2, 1) | ||
self.attach(self.format_toolbar, 0, 1, 2, 1) | ||
|
||
@lg.logging_decorator(logger) | ||
def get_text(self,start=None,end=None): | ||
if not start: | ||
start = self.textbuffer.get_start_iter() | ||
|
@@ -179,11 +196,13 @@ def get_text(self,start=None,end=None): | |
start, | ||
end) | ||
|
||
@lg.logging_decorator(logger) | ||
def get_clean_text(self): | ||
|
||
return self.textbuffer.get_text(self.textbuffer.get_start_iter(), | ||
self.textbuffer.get_end_iter(), False) | ||
|
||
@lg.logging_decorator(logger) | ||
def set_text(self, content): | ||
self.textbuffer.set_text("") | ||
if content != "": | ||
|
@@ -197,6 +216,7 @@ def set_text(self, content): | |
else: | ||
pass | ||
|
||
@lg.logging_decorator(logger) | ||
def toggle_tag(self, widget, tag): | ||
# | ||
# Toggles tag on selection, it does not do anything if there is no selection | ||
|
@@ -230,6 +250,7 @@ def toggle_tag(self, widget, tag): | |
self.undo_stack.append(undo_action) | ||
self.textview.grab_focus() | ||
|
||
@lg.logging_decorator(logger) | ||
def apply_tag(self, widget, tag): | ||
# | ||
# Applyes tag on selection, this is currently used | ||
|
@@ -255,6 +276,7 @@ def apply_tag(self, widget, tag): | |
self.undo_stack.append(undo_action) | ||
self.textview.grab_focus() | ||
|
||
@lg.logging_decorator(logger) | ||
def apply_just(self,widget,tag): | ||
# gets an itter at the current offset and then gets the current line from it. | ||
# if there is only one char,then the start iter and the end iter are the same. | ||
|
@@ -277,7 +299,7 @@ def apply_just(self,widget,tag): | |
self.textbuffer.apply_tag(self.tags[tag],start_iter,end_iter) | ||
self.textview.grab_focus() | ||
|
||
|
||
@lg.logging_decorator(logger) | ||
def insert_with_tags(self, buf, start_iter, data, data_len): | ||
end = self.textbuffer.props.cursor_position | ||
#creating new start iter because the provided one | ||
|
@@ -369,6 +391,7 @@ def can_be_merged(prev,cur): | |
self.current_indent_level += 1 | ||
self.textview.grab_focus() | ||
|
||
@lg.logging_decorator(logger) | ||
def delete(self,buff, start,end): | ||
if buff.get_text(start,end,False) == '\t' and \ | ||
start.get_line_offset() <= self.current_indent_level and \ | ||
|
@@ -419,12 +442,14 @@ def can_be_merged(prev,cur): | |
self.undo_stack.append(prev_delete) | ||
self.undo_stack.append(undo_action) | ||
|
||
@lg.logging_decorator(logger) | ||
def delete_after(self,buff,start,end): | ||
if self.offset_after_tab_deletion: | ||
self.textbuffer.insert(buff.get_iter_at_offset(self.offset_after_tab_deletion),'-',1) | ||
self.textbuffer.insert(buff.get_iter_at_offset(self.offset_after_tab_deletion+1),' ',1) | ||
self.offset_after_tab_deletion = None | ||
|
||
|
||
@lg.logging_decorator(logger) | ||
def undo(self,widget): | ||
if not self.undo_stack: | ||
return | ||
|
@@ -458,7 +483,8 @@ def undo(self,widget): | |
self.textview.grab_focus() | ||
self.not_undoable_action = False | ||
self.undo_in_progress = False | ||
|
||
|
||
@lg.logging_decorator(logger) | ||
def redo(self,widget): | ||
if not self.redo_stack: | ||
return | ||
|
@@ -492,6 +518,7 @@ def redo(self,widget): | |
self.not_undoable_action = False | ||
self.undo_in_progress = False | ||
|
||
@lg.logging_decorator(logger) | ||
def add_image(self, widget): | ||
dialog = Gtk.FileChooserDialog("Pick a file", | ||
None, | ||
|
@@ -525,20 +552,23 @@ def add_image(self, widget): | |
|
||
dialog.destroy() | ||
|
||
@lg.logging_decorator(logger) | ||
def add_list(self,widget): | ||
if self.format_toolbar.list.get_active(): | ||
current_position = self.textbuffer.get_iter_at_offset(self.textbuffer.props.cursor_position) | ||
self.textbuffer.insert(current_position, '\n\t- ') | ||
else: | ||
self.current_indent_level = 1 | ||
|
||
@lg.logging_decorator(logger) | ||
def send_feedback(self, widget): | ||
try: | ||
result = subprocess.call( | ||
["pantheon-mail", "mailto:[email protected]"]) | ||
except OSError: | ||
pass | ||
|
||
|
||
@lg.logging_decorator(logger) | ||
def activate_shortcuts(self,widget,event): | ||
keyval = event.keyval | ||
keyval_name = Gdk.keyval_name(keyval) | ||
|
Empty file.
This file contains 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,28 @@ | ||
import logging | ||
from gi.repository import GLib | ||
|
||
class Logger(object): | ||
|
||
def __init__(self): | ||
self.logger = logging.getLogger('Main') | ||
self.logger.setLevel(logging.DEBUG) | ||
logging_path = "{}/Noted/Main".format(GLib.get_user_data_dir()) | ||
self.handler = logging.FileHandler(logging_path) | ||
formatter = logging.Formatter('%(asctime)s - %(name)s - %(message)s') | ||
self.handler.setFormatter(formatter) | ||
self.logger.addHandler(self.handler) | ||
|
||
|
||
def logging_decorator(logger): | ||
def decorator(function): | ||
def wrapper(*args,**kwargs): | ||
try: | ||
result = function(*args,**kwargs) | ||
logger.logger.debug('Succesfully completed {}'.format(function.__name__)) | ||
return result | ||
except Exception as e: | ||
logger.logger.debug('There was a problem running the function {} ; ERROR MESSAGE > {}'.format(function.__name__,e)) | ||
#NOTE figure out how to close on exception | ||
raise e | ||
return wrapper | ||
return decorator |
Oops, something went wrong.