compose window

This commit is contained in:
Morgan McMillian 2020-11-28 10:00:04 -08:00
parent 7b7c3e637f
commit 77070e5823
2 changed files with 72 additions and 8 deletions

View file

@ -29,7 +29,7 @@ gi.require_version('Handy', '1')
from gi.repository import Handy from gi.repository import Handy
Handy.init() Handy.init()
from .widgets import LoginPage, Timeline, PostItem from .widgets import LoginPage, Timeline, PostItem, ComposeWindow
class Application(Gtk.Application): class Application(Gtk.Application):
@ -58,13 +58,13 @@ class Application(Gtk.Application):
pass pass
def do_activate(self): def do_activate(self):
win = self.props.active_window self.win = self.props.active_window
if not win: if not self.win:
win = Gtk.ApplicationWindow(application=self) self.win = Gtk.ApplicationWindow(application=self)
win.set_default_size(320, 480) self.win.set_default_size(320, 480)
title_bar = Handy.TitleBar() title_bar = Handy.TitleBar()
win.set_titlebar(title_bar) self.win.set_titlebar(title_bar)
self.header = Handy.HeaderBar(show_close_button=True) self.header = Handy.HeaderBar(show_close_button=True)
title_bar.add(self.header) title_bar.add(self.header)
@ -94,8 +94,8 @@ class Application(Gtk.Application):
vbox.pack_start(self.stack, True, True, 0) vbox.pack_start(self.stack, True, True, 0)
vbox.pack_end(stack_switcher_bar, False, False, 0) vbox.pack_end(stack_switcher_bar, False, False, 0)
win.add(vbox) self.win.add(vbox)
win.show_all() self.win.show_all()
def blarp(self, args=None): def blarp(self, args=None):
logging.debug("BLARP") logging.debug("BLARP")
@ -130,6 +130,7 @@ class Application(Gtk.Application):
self.stack.add_titled(global_tl, "global", "Global") self.stack.add_titled(global_tl, "global", "Global")
new_post_button = Gtk.Button.new_from_icon_name('list-add-symbolic', 1) new_post_button = Gtk.Button.new_from_icon_name('list-add-symbolic', 1)
new_post_button.connect('clicked', self.on_new_post)
self.header.pack_start(new_post_button) self.header.pack_start(new_post_button)
reload_button = Gtk.Button.new_from_icon_name('view-refresh-symbolic', 1) reload_button = Gtk.Button.new_from_icon_name('view-refresh-symbolic', 1)
@ -144,6 +145,10 @@ class Application(Gtk.Application):
timeline = self.stack.get_visible_child() timeline = self.stack.get_visible_child()
timeline.emit('refresh') timeline.emit('refresh')
def on_new_post(self, button):
compose = ComposeWindow()
compose.set_transient_for(self.win)
def main(version): def main(version):
logging.basicConfig(level=logging.DEBUG) logging.basicConfig(level=logging.DEBUG)
app = Application() app = Application()

View file

@ -28,6 +28,65 @@ from gi.repository import GObject, Gdk, Gtk, Gio, GLib
gi.require_version('Handy', '1') gi.require_version('Handy', '1')
from gi.repository import Handy from gi.repository import Handy
class ComposeWindow(Handy.Window):
def __init__(self):
super().__init__(modal=True)
self.set_default_size(500, 300)
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
box = Gtk.Box(orientation='vertical')
header = Handy.HeaderBar(show_close_button=False)
cancel_button = Gtk.Button(label='Cancel')
cancel_button.connect('clicked', self.cancel_post)
post_button = Gtk.Button(label='Post')
post_button.connect('clicked', self.send_post)
header.set_title('New Post')
header.pack_start(cancel_button)
header.pack_end(post_button)
scroller = Gtk.ScrolledWindow(halign='fill')
textarea = Gtk.TextView(
left_margin=8,
right_margin=8,
top_margin=8,
bottom_margin=8
)
textarea.set_wrap_mode(Gtk.WrapMode.WORD)
scroller.add(textarea)
self.buffer = textarea.get_buffer()
self.max_length = 256
actionbar = Gtk.ActionBar()
self.counter_label = Gtk.Label()
self.counter_label.set_text(str(self.max_length))
actionbar.pack_end(self.counter_label)
self.buffer.connect('changed', self.validate)
box.pack_start(header, False, False, 0)
box.pack_start(scroller, True, True, 0)
box.pack_end(actionbar, False, False, 0)
self.add(box)
self.show_all()
def validate(self, widget):
self.counter = self.max_length - self.buffer.get_char_count()
self.counter_label.set_text(str(self.counter))
def send_post(self, button):
start = self.buffer.get_start_iter()
end = self.buffer.get_end_iter()
text = self.buffer.get_text(start, end, False)
pnutpy.api.create_post(data={'text': text})
self.close()
def cancel_post(self, button):
self.close()
class LoginPage(Gtk.Box): class LoginPage(Gtk.Box):
__gsignals__ = { __gsignals__ = {