generated from itdominator/Python-With-Gtk-Template
WIP File widget
This commit is contained in:
parent
b32eafcabe
commit
b3ba472dcc
@ -79,32 +79,33 @@ class DragArea(Gtk.Fixed):
|
||||
|
||||
def _on_drag_data_received(self, widget, drag_context, _x, _y, data, info, time):
|
||||
if info == 70:
|
||||
event_system.emit("set_widget_type", "TextAreaWidget")
|
||||
dynamic_widget = self.add_or_select_widget(x = _x, y = _y)
|
||||
body = dynamic_widget.get_body()
|
||||
|
||||
body.buffer.set_text(data.get_text())
|
||||
dynamic_widget.save()
|
||||
|
||||
self._load_dnd_text(data, _x, _y)
|
||||
return
|
||||
|
||||
if info == 80:
|
||||
uris = data.get_uris()
|
||||
|
||||
if len(uris) == 0:
|
||||
uris = data.get_text().split("\n")
|
||||
|
||||
for uri in uris:
|
||||
gfile = None
|
||||
try:
|
||||
gfile = Gio.File.new_for_uri(uri)
|
||||
except Exception as e:
|
||||
gfile = Gio.File.new_for_path(uri)
|
||||
|
||||
# event_system.emit('create_view', (None, None, gfile,))
|
||||
|
||||
self._load_dnd_files(data, _x, _y)
|
||||
return
|
||||
|
||||
def _load_dnd_text(self, data, _x, _y):
|
||||
event_system.emit("set_widget_type", "TextAreaWidget")
|
||||
dynamic_widget = self.add_or_select_widget(x = _x, y = _y)
|
||||
body = dynamic_widget.get_body()
|
||||
|
||||
body.buffer.set_text(data.get_text())
|
||||
dynamic_widget.save()
|
||||
|
||||
def _load_dnd_files(self, data, _x, _y):
|
||||
uris = data.get_uris()
|
||||
|
||||
if len(uris) == 0:
|
||||
uris = data.get_text().split("\n")
|
||||
|
||||
for uri in uris:
|
||||
event_system.emit("set_widget_type", "FileWidget")
|
||||
dynamic_widget = self.add_or_select_widget(x = _x, y = _y)
|
||||
dynamic_widget.set_file(uri)
|
||||
|
||||
|
||||
def _move_callback(self, widget = None, x = None, y = None):
|
||||
self.move(widget.get_parent(), x, y)
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
"""
|
||||
Widgets Selector Widgets
|
||||
"""
|
||||
from .file import FileWidget
|
||||
from .text_area import TextAreaWidget
|
||||
|
85
src/core/widgets/widget_selector/widgets/file.py
Normal file
85
src/core/widgets/widget_selector/widgets/file.py
Normal file
@ -0,0 +1,85 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
from utils.widget_save_load_controller import WidgetSaveLoadController
|
||||
|
||||
|
||||
class FileWidget(WidgetSaveLoadController, Gtk.Box):
|
||||
def __init__(self):
|
||||
super(FileWidget, self).__init__()
|
||||
|
||||
self._file_path = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
event_system.emit("register_to_query_controller", (self, self.get_query_data))
|
||||
self.show_all()
|
||||
|
||||
|
||||
def new(self):
|
||||
widget = FileWidget()
|
||||
return widget
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_orientation(0)
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("key-release-event", self._key_released)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
image = Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY )
|
||||
self.add(image)
|
||||
|
||||
def _key_released(self, widget = None, eve = None):
|
||||
if eve.type == 9:
|
||||
# if enter or spacebar:
|
||||
# pass
|
||||
...
|
||||
|
||||
def get_query_data(self):
|
||||
return self.get_file_name()
|
||||
|
||||
def get_saveable_data(self):
|
||||
self.save_collection["data"] = self.get_file_path()
|
||||
self.save_collection["widget_type"] = str(type(self).__name__)
|
||||
return self.save_collection
|
||||
|
||||
def set_saveable_data(self, data):
|
||||
self.save_collection = data
|
||||
self.load_saveable_data()
|
||||
|
||||
def load_saveable_data(self):
|
||||
self.set_file_path( self.save_collection["data"] )
|
||||
|
||||
|
||||
def set_file_path(self, path):
|
||||
try:
|
||||
self._file_path = Gio.File.new_for_uri(path)
|
||||
except Exception as e:
|
||||
self._file_path = Gio.File.new_for_path(path)
|
||||
|
||||
def get_file(self):
|
||||
return self._file_path
|
||||
|
||||
def get_file_path(self):
|
||||
path = self._file_path.get_path()
|
||||
if not path:
|
||||
path = self._file_path.get_uri()
|
||||
|
||||
return path
|
||||
|
||||
def get_file_name(self):
|
||||
info = self._file_path.query_info("standard::*", 0, cancellable = None)
|
||||
return info.get_display_name()
|
@ -28,6 +28,11 @@ class TextAreaWidget(WidgetSaveLoadController, GtkSource.View):
|
||||
self.show()
|
||||
|
||||
|
||||
def new(self):
|
||||
widget = TextAreaWidget()
|
||||
widget.buffer.set_text("Lorem ipsum dolor")
|
||||
return widget
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
@ -50,11 +55,6 @@ class TextAreaWidget(WidgetSaveLoadController, GtkSource.View):
|
||||
self.get_parent().save_needed = True
|
||||
self._buffer_hash = _hash
|
||||
|
||||
|
||||
def get_buffer_text(self):
|
||||
start, end = self.buffer.get_start_iter(), self.buffer.get_end_iter()
|
||||
return self.buffer.get_slice(start, end, True)
|
||||
|
||||
def get_query_data(self):
|
||||
return self.get_buffer_text()
|
||||
|
||||
@ -73,11 +73,13 @@ class TextAreaWidget(WidgetSaveLoadController, GtkSource.View):
|
||||
|
||||
self.buffer.set_text(text)
|
||||
|
||||
|
||||
|
||||
|
||||
def get_buffer_text(self):
|
||||
start, end = self.buffer.get_start_iter(), self.buffer.get_end_iter()
|
||||
return self.buffer.get_slice(start, end, True)
|
||||
|
||||
def get_hash(self, text):
|
||||
sha = hashlib.sha1(text.encode("utf-8"))
|
||||
return sha.hexdigest()
|
||||
|
||||
def new(self):
|
||||
widget = TextAreaWidget()
|
||||
widget.buffer.set_text("Lorem ipsum dolor")
|
||||
return widget
|
||||
|
Loading…
Reference in New Issue
Block a user