DnD updates, window title updates, cleanup, etc

This commit is contained in:
itdominator 2021-11-16 01:28:08 -06:00
parent 771845d301
commit 00c207a153
7 changed files with 90 additions and 62 deletions

View File

@ -10,10 +10,9 @@ tracemalloc.start()
# Gtk imports
import gi, faulthandler, traceback, signal
import gi, faulthandler, traceback
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
from gi.repository import GLib
# Application imports
from __init__ import Main
@ -22,7 +21,6 @@ from __init__ import Main
if __name__ == "__main__":
try:
setproctitle('PyFM')
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit)
faulthandler.enable() # For better debug info
parser = argparse.ArgumentParser()
# Add long and short arguments

View File

@ -31,8 +31,8 @@
<property name="height-request">600</property>
<property name="can-focus">False</property>
<property name="window-position">center</property>
<property name="default-width">1200</property>
<property name="default-height">720</property>
<property name="default-width">1670</property>
<property name="default-height">830</property>
<property name="icon">pyfm.png</property>
<property name="gravity">center</property>
<child>

View File

@ -46,7 +46,7 @@ class View(Settings, FileHandler, Launcher, Icon, Path):
def load_directory(self):
path = self.get_path()
self.dirs = [".", ".."]
self.dirs = []
self.vids = []
self.images = []
self.desktop = []

View File

@ -1,10 +1,11 @@
# Python imports
import threading, subprocess, os, time
import threading, subprocess, signal, inspect, os, time
# Gtk imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
from gi.repository import GLib
# Application imports
from .mixins import *
@ -39,11 +40,13 @@ class Signals(WindowMixin, PaneMixin):
self.is_pane2_hidden = False
self.is_pane3_hidden = False
self.is_pane4_hidden = False
self.refresh_lock = False
self.window.show()
self.generate_windows(self.state)
self.window.connect("delete-event", self.tear_down)
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.tear_down)
self.gui_event_observer()
@ -53,10 +56,26 @@ class Signals(WindowMixin, PaneMixin):
time.sleep(event_sleep_time)
event = event_system.consume_gui_event()
if event:
type, target, data = event
try:
type, target, data = event
method = getattr(self.__class__, type)
GLib.idle_add(method, (self, data,))
except Exception as e:
print(repr(e))
def refresh_tab(data=None):
self, ids = data
wid, tid = ids.split("|")
notebook = self.builder.get_object(f"window_{wid}")
icon_view, tab_label = self.get_icon_view_and_label_from_notebook(notebook, f"{wid}|{tid}")
view = self.get_fm_window(wid).get_view_by_id(tid)
store = icon_view.get_model()
view.load_directory()
self.load_store(view, store)
def tear_down(self, widget, eve):
def tear_down(self, widget=None, eve=None):
self.window_controller.save_state()
event_system.monitor_events = False
time.sleep(event_sleep_time)
gtk.main_quit()
@ -72,7 +91,7 @@ class Signals(WindowMixin, PaneMixin):
object.set_active(True)
for view in views:
self.create_new_view_notebook(None, view, i)
self.create_new_view_notebook(None, i, view)
if isHidden:
self.toggle_notebook_pane(object)
@ -80,7 +99,7 @@ class Signals(WindowMixin, PaneMixin):
for j in range(0, 4):
i = j + 1
self.window_controller.create_window()
self.create_new_view_notebook(None, None, i)
self.create_new_view_notebook(None, i, None)
def getClipboardData(self):

View File

@ -17,7 +17,7 @@ class TabMixin(WidgetMixin):
def get_fm_window(self, wid):
return self.window_controller.get_window_by_nickname(f"window_{wid}")
def create_tab(self, wid, path=None, save_state=True):
def create_tab(self, wid, path=None):
notebook = self.builder.get_object(f"window_{wid}")
path_entry = self.builder.get_object(f"path_entry")
view = self.window_controller.add_view_for_window_by_nickname(f"window_{wid}")
@ -36,51 +36,25 @@ class TabMixin(WidgetMixin):
notebook.set_current_page(index)
notebook.set_tab_reorderable(scroll, True)
self.load_store(view, store, save_state)
self.load_store(view, store)
self.set_window_title()
def close_tab(self, widget, eve):
notebook = widget.get_parent().get_parent()
page = notebook.get_current_page()
tid = self.get_tab_id_from_widget(widget.get_parent())
wid = int(notebook.get_name()[-1])
notebook = widget.get_parent().get_parent()
page = notebook.get_current_page()
tid = self.get_tab_id_from_widget(widget.get_parent())
wid = int(notebook.get_name()[-1])
self.get_fm_window(wid).delete_view_by_id(tid)
notebook.remove_page(page)
self.window_controller.save_state()
self.set_window_title()
def grid_icon_double_left_click(self, widget, item):
try:
wid, tid = self.window_controller.get_active_data()
notebook = self.builder.get_object(f"window_{wid}")
path_entry = self.builder.get_object(f"path_entry")
tab_label = self.get_tab_label_widget_from_widget(notebook, widget)
view = self.get_fm_window(wid).get_view_by_id(tid)
model = widget.get_model()
fileName = model[item][1]
dir = view.get_current_directory()
file = dir + "/" + fileName
refresh = True
if fileName == ".":
view.load_directory()
elif fileName == "..":
view.pop_from_path()
elif isdir(file):
view.set_path(file)
elif isfile(file):
refresh = False
view.open_file_locally(file)
if refresh == True:
self.load_store(view, model)
tab_label.set_label(view.get_end_of_path())
path_entry.set_text(view.get_current_directory())
except Exception as e:
print(repr(e))
def set_window_title(self):
wid, tid = self.window_controller.get_active_data()
view = self.get_fm_window(wid).get_view_by_id(tid)
dir = view.get_current_directory()
self.window.set_title(dir)
def grid_icon_single_click(self, widget, eve):
try:
@ -89,6 +63,7 @@ class TabMixin(WidgetMixin):
if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1: # l-click
self.set_path_text(wid, tid)
self.set_window_title()
if self.single_click_open: # FIXME: need to find a way to pass the model index
self.icon_double_left_click(widget)
@ -123,6 +98,33 @@ class TabMixin(WidgetMixin):
except Exception as e:
print(repr(e))
def grid_icon_double_left_click(self, widget, item):
try:
wid, tid = self.window_controller.get_active_data()
notebook = self.builder.get_object(f"window_{wid}")
path_entry = self.builder.get_object(f"path_entry")
tab_label = self.get_tab_label_widget_from_widget(notebook, widget)
view = self.get_fm_window(wid).get_view_by_id(tid)
model = widget.get_model()
fileName = model[item][1]
dir = view.get_current_directory()
file = dir + "/" + fileName
refresh = True
if isdir(file):
view.set_path(file)
elif isfile(file):
refresh = False
view.open_file_locally(file)
if refresh == True:
self.load_store(view, model)
tab_label.set_label(view.get_end_of_path())
path_entry.set_text(view.get_current_directory())
except Exception as e:
print(repr(e))
def grid_on_drag_set(self, widget, drag_context, data, info, time):
action = widget.get_name()
@ -140,7 +142,7 @@ class TabMixin(WidgetMixin):
uris.append(fpath)
data.set_uris(uris)
event_system.push_gui_event(["refresh_tab", None, action])
def grid_on_drag_motion(self, widget, drag_context, x, y, data):
wid, tid = widget.get_name().split("|")
@ -157,14 +159,18 @@ class TabMixin(WidgetMixin):
uris = data.get_uris()
dest = view.get_current_directory()
print(f"Target Move Path: {dest}")
print(f"{wid}|{tid}")
if len(uris) > 0:
print(f"Target Move Path: {dest}")
self.refresh_lock = True
for uri in uris:
print(f"URI: {uri}")
self.move_file(view, uri, dest)
# Reloads new directory
view.load_directory()
self.load_store(view, store, False)
self.load_store(view, store)
self.refresh_lock = False
def do_action_from_bar_controls(self, widget, eve=None):
action = widget.get_name()
@ -181,7 +187,7 @@ class TabMixin(WidgetMixin):
view.set_to_home()
if action == "refresh_view":
view.load_directory()
if action == "create_tab" :
if action == "create_tab":
dir = view.get_current_directory()
self.create_tab(wid, dir)
return
@ -191,11 +197,10 @@ class TabMixin(WidgetMixin):
if not traversed:
return
self.load_store(view, store, True)
self.load_store(view, store)
self.set_path_text(wid, tid)
tab_label.set_label(view.get_end_of_path())
self.set_window_title()
# File control events

View File

@ -23,7 +23,7 @@ def threaded(fn):
class WidgetMixin:
def load_store(self, view, store, save_state=True):
def load_store(self, view, store, save_state=False):
store.clear()
dir = view.get_current_directory()
files = view.get_files()
@ -32,16 +32,18 @@ class WidgetMixin:
store.append([generic_icon, file[0]])
self.create_icon(i, view, store, dir, file[0])
# Not likely called often here but could be useful
if save_state:
self.window_controller.save_state()
@threaded
def create_icon(self, i, view, store, dir, file):
icon = None
try:
icon = view.create_icon(dir, file).get_pixbuf()
GLib.idle_add(self.update_store, (i, store, icon,))
except Exception as e:
return
GLib.idle_add(self.update_store, (i, store, icon,))
def update_store(self, item):
i, store, icon = item
@ -59,6 +61,9 @@ class WidgetMixin:
icon = Gtk.Image(stock=Gtk.STOCK_CLOSE)
label.set_label(f"{view.get_end_of_path()}")
label.set_width_chars(25)
label.set_max_width_chars(64)
label.set_ellipsize(2) #PANGO_ELLIPSIZE_MIDDLE
tid.set_label(f"{view.id}")
close.add(icon)
@ -80,7 +85,7 @@ class WidgetMixin:
grid.set_pixbuf_column(0)
grid.set_text_column(1)
grid.set_item_orientation(0)
grid.set_item_orientation(1)
grid.set_selection_mode(3)
grid.set_item_width(152)
grid.set_item_padding(2)
@ -149,6 +154,7 @@ class WidgetMixin:
wid, tid = content.get_children()[0].get_name().split("|")
self.window_controller.set_active_data(wid, tid)
self.set_path_text(wid, tid)
self.set_window_title()
def set_path_text(self, wid, tid):
path_entry = self.builder.get_object("path_entry")

View File

@ -4,5 +4,5 @@ from . import TabMixin
class WindowMixin(TabMixin):
"""docstring for WindowMixin"""
def create_new_view_notebook(self, widget=None, path=None, wid=None):
self.create_tab(wid, path, save_state=False)
def create_new_view_notebook(self, widget=None, wid=None, path=None):
self.create_tab(wid, path)