-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
173 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import typing | ||
from gi.repository import Gtk | ||
from .utils import SimpleButton, LabeledTextbox | ||
from .. import threadpool | ||
import praw.models | ||
|
||
ID_SEND = 100 | ||
ID_CANCEL = 101 | ||
|
||
|
||
class ReplyDialog(Gtk.Dialog): | ||
def __init__( | ||
self, | ||
parent_window: Gtk.Widget, | ||
title: str, | ||
parent: typing.Union[praw.models.Comment, praw.models.Submission], | ||
): | ||
super().__init__(title) | ||
self.set_transient_for(parent_window) | ||
self.parent = parent | ||
self.box = self.get_content_area() | ||
self.parent_text = ( | ||
parent.body | ||
if isinstance(parent, praw.models.Comment) | ||
else (parent.selftext or parent.url or "") | ||
) | ||
self.parent_body = LabeledTextbox("Replying to", self.parent_text, False, True) | ||
self.box.add(self.parent_body) | ||
self.reply_body = LabeledTextbox("Your reply", "", True, True) | ||
self.box.add(self.reply_body) | ||
self.add_button("Send", ID_SEND) | ||
self.add_button("Cancel", ID_CANCEL) | ||
|
||
def run(self): | ||
self.show_all() | ||
response = super().run() | ||
if response == ID_SEND: | ||
try: | ||
comment = self.parent.reply(body=self.reply_body.get_text()) | ||
if isinstance(self.parent, praw.models.Submission): | ||
self.parent._fetch() | ||
else: | ||
self.parent.refresh() | ||
self.destroy() | ||
return comment | ||
except Exception as e: | ||
print(e) | ||
self.destroy() | ||
return None | ||
self.destroy() | ||
return None |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
from .labeled_text_ctrl import * | ||
from .labeled_lisst_ctrl import * | ||
from .simple_button import SimpleButton | ||
from .input_dialog import InputDialog |
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,21 @@ | ||
from gi.repository import Gtk | ||
from . import LabeledTextbox | ||
|
||
|
||
class InputDialog(Gtk.Dialog): | ||
def __init__(self, title: str, question: str): | ||
super().__init__(title) | ||
self.box = self.get_content_area() | ||
self.input = LabeledTextbox(question, "") | ||
self.input.textbox.set_activates_default(True) | ||
self.box.add(self.input) | ||
button = self.add_button("Done", Gtk.ResponseType.OK) | ||
button.set_can_default(True) | ||
button.grab_default() | ||
|
||
def run(self): | ||
self.show_all() | ||
response = super().run() | ||
text = self.input.get_text() | ||
self.destroy() | ||
return text if response == Gtk.ResponseType.OK else None |
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,17 @@ | ||
import typing | ||
from gi.repository import Gtk | ||
|
||
|
||
class SimpleButton(Gtk.Button): | ||
def __init__( | ||
self, label: str, callback: typing.Optional[typing.Callable[[], None]] | ||
): | ||
super().__init__(label) | ||
self.set_use_underline(True) | ||
self.callback = callback | ||
if callback: | ||
self.connect("clicked", self.on_clicked) | ||
|
||
def on_clicked(self, *args): | ||
self.stop_emission_by_name("clicked") | ||
self.callback() |
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