Files
DemonEditor/app/ui/picons_dialog.py

71 lines
2.2 KiB
Python
Raw Normal View History

2018-01-10 12:15:41 +03:00
import subprocess
import time
from gi.repository import GLib
from app.commons import run_idle, run_task
from . import Gtk, UI_RESOURCES_PATH
2018-01-08 22:00:48 +03:00
class PiconsDialog:
2018-01-10 18:09:44 +03:00
def __init__(self, transient, options):
2018-01-10 12:15:41 +03:00
self._current_process = None
2018-01-10 18:09:44 +03:00
self._picons_path = options.get("picons_dir_path", "")
2018-01-10 12:15:41 +03:00
handlers = {"on_receive": self.on_receive,
"on_cancel": self.on_cancel,
"on_close": self.on_close,
"on_send": self.on_send}
2018-01-08 22:00:48 +03:00
builder = Gtk.Builder()
2018-01-10 18:09:44 +03:00
builder.add_objects_from_file(UI_RESOURCES_PATH + "picons_dialog.glade", ("picons_dialog", "receive_image"))
2018-01-08 22:00:48 +03:00
builder.connect_signals(handlers)
self._dialog = builder.get_object("picons_dialog")
self._dialog.set_transient_for(transient)
2018-01-10 12:15:41 +03:00
self._expander = builder.get_object("expander")
self._text_view = builder.get_object("text_view")
self._info_bar = builder.get_object("info_bar")
2018-01-10 18:09:44 +03:00
self._ip_entry = builder.get_object("ip_entry")
self._picons_entry = builder.get_object("picons_entry")
self._url_entry = builder.get_object("url_entry")
self._picons_dir_entry = builder.get_object("picons_dir_entry")
self._ip_entry.set_text(options.get("host", ""))
self._picons_entry.set_text(options.get("picons_path", ""))
self._picons_dir_entry.set_text(self._picons_path)
2018-01-08 22:00:48 +03:00
def show(self):
self._dialog.run()
self._dialog.destroy()
2018-01-10 12:15:41 +03:00
def on_receive(self, item):
self._current_process = subprocess.Popen("ls", stdout=subprocess.PIPE)
2018-01-10 18:09:44 +03:00
GLib.io_add_watch(self._current_process.stdout, GLib.IO_IN, self.write_to_buffer)
2018-01-10 12:15:41 +03:00
def write_to_buffer(self, fd, condition):
if condition == GLib.IO_IN:
2018-01-10 18:09:44 +03:00
char = fd.read(1)
2018-01-10 12:15:41 +03:00
buf = self._text_view.get_buffer()
buf.insert_at_cursor(str(char))
return True
else:
return False
@run_task
def on_cancel(self, item):
if self._current_process:
self._current_process.kill()
time.sleep(1)
@run_idle
def on_close(self, item):
self.on_cancel(item)
self._dialog.destroy()
2018-01-10 18:09:44 +03:00
2018-01-10 12:15:41 +03:00
def on_send(self, item):
pass
2018-01-08 22:00:48 +03:00
if __name__ == "__main__":
pass