-
Notifications
You must be signed in to change notification settings - Fork 64
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
Adding hook feature #40
Open
ghost
wants to merge
4
commits into
seanh:master
Choose a base branch
from
unknown repository
base: master
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7c7ca7
Adding hook feature to execute external scripts when special events
75dcdb4
Replacing JSON parameter style by a --*-hook parameter style
040609c
Adding try except when launching hook.
e2e35df
Merge branch 'master' of https://github.com/seanh/terminal_velocity
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
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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
""" | ||
import subprocess | ||
import logging | ||
import os | ||
logger = logging.getLogger(__name__) | ||
|
||
import urwid | ||
|
@@ -238,8 +239,7 @@ def mouse_event(self, size, event, button, col, row, focus): | |
class MainFrame(urwid.Frame): | ||
"""The topmost urwid widget.""" | ||
|
||
def __init__(self, notes_dir, editor, extension, extensions): | ||
|
||
def __init__(self, notes_dir, editor, extension, extensions, hooks): | ||
self.editor = editor | ||
self.notebook = notebook.PlainTextNoteBook(notes_dir, extension, | ||
extensions) | ||
|
@@ -253,6 +253,8 @@ def __init__(self, notes_dir, editor, extension, extensions): | |
|
||
self._selected_note = None | ||
|
||
self.hooks = hooks | ||
|
||
self.search_box = AutocompleteWidget(wrap="clip") | ||
self.list_box = NoteFilterListBox(on_changed=self.on_list_box_changed) | ||
|
||
|
@@ -306,6 +308,15 @@ def quit(self): | |
|
||
raise urwid.ExitMainLoop() | ||
|
||
def execute_hook(self, hook, param): | ||
"""Execute the defined hook | ||
|
||
For the time being only the post hook has been tested | ||
|
||
""" | ||
if hook in self.hooks != "" and os.path.isfile(self.hooks[hook]): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit odd. I think this might do what you wanted: |
||
subprocess.call([self.hooks[hook], param]) | ||
|
||
def keypress(self, size, key): | ||
|
||
maxcol, maxrow = size | ||
|
@@ -325,17 +336,20 @@ def keypress(self, size, key): | |
elif key in ["enter"]: | ||
if self.selected_note: | ||
system(self.editor, [self.selected_note.abspath], self.loop) | ||
self.execute_hook("post", self.selected_note.abspath) | ||
else: | ||
if self.search_box.edit_text: | ||
try: | ||
note = self.notebook.add_new(self.search_box.edit_text) | ||
system(self.editor, [note.abspath], self.loop) | ||
self.execute_hook("post", note.abspath) | ||
except notebook.NoteAlreadyExistsError: | ||
# Try to open the existing note instead. | ||
system(self.editor, | ||
[self.search_box.edit_text + | ||
system(self.editor, [self.search_box.edit_text + | ||
self.notebook.extension], | ||
self.loop) | ||
self.execute_hook("post", self.search_box.edit_text + | ||
self.notebook.extension) | ||
except notebook.InvalidNoteTitleError: | ||
# TODO: Display error message to user. | ||
pass | ||
|
@@ -435,10 +449,10 @@ def on_list_box_changed(self, note): | |
self.selected_note = note | ||
|
||
|
||
def launch(notes_dir, editor, extension, extensions): | ||
def launch(notes_dir, editor, extension, extensions, hooks): | ||
"""Launch the user interface.""" | ||
|
||
frame = MainFrame(notes_dir, editor, extension, extensions) | ||
frame = MainFrame(notes_dir, editor, extension, extensions, hooks) | ||
loop = urwid.MainLoop(frame, palette) | ||
frame.loop = loop | ||
loop.run() |
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.
Typos:
occure -> occur
such has -> such as
Also I don't think the
\
is necessary because Python has implied line continuation inside parentheses, so you can do: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.
I get an error on python 2.7.9 when trying:
print("test test")
... Sorry can't get markdown to work but both test are on different line