generated from itdominator/Python-With-Gtk-Template
86 lines
2.1 KiB
Python
86 lines
2.1 KiB
Python
# 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()
|