Split signals to class file(s)

This commit is contained in:
Maxim Stewart 2019-07-05 01:08:18 -05:00
parent cdf9dfd379
commit 8ad8e612f5
5 changed files with 102 additions and 96 deletions

View File

@ -5,18 +5,18 @@
# Application imports
from widgets import Grid
from utils import Dragging
from utils import FileHandler
class Controller:
def __init__(self, settings):
self.filehandler = FileHandler()
self.settings = settings
self.builder = self.settings.returnBuilder()
self.desktop = self.builder.get_object("Desktop")
self.webview = self.builder.get_object("webview")
self.desktopPath = self.settings.returnDesktopPath()
self.settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
self.webview.load_uri(self.settings.returnWebHome())
self.desktopPath = self.settings.returnDesktopPath()
self.grid = None
# Add filter to allow only folders to be selected
selectedDirDialog = self.builder.get_object("selectedDirDialog")
@ -24,12 +24,12 @@ class Controller:
selectedDirDialog.add_filter(filefilter)
selectedDirDialog.set_filename(self.desktopPath)
self.grid = None
self.setIconViewDir(selectedDirDialog)
def setIconViewDir(self, widget, data=None):
newPath = widget.get_filename()
Grid(self.desktop, self.settings, newPath)
self.grid = Grid(self.desktop, self.settings)
self.grid.setIconViewDir(newPath)
def getWindowsOnScreen(self):
screen = self.settings.returnScren()
@ -40,19 +40,31 @@ class Controller:
widget.hide()
# File control events
def createFile(self):
def createFile(arg):
pass
def updateFile(self, widget, data=None):
newName = widget.get_text().strip()
if data and data.keyval == 65293: # Enter key event
self.grid.updateFile(newName)
elif data == None: # Save button 'event'
self.grid.updateFile(newName)
def updateFile(self, file):
if len(self.selectedFiles) == 1:
newName = self.currentPath + "/" + file
status = self.filehandler.updateFile(self.selectedFiles[0], newName)
if status == 0:
self.selectedFiles = [newName]
self.setIconViewDir(self.currentPath)
def deleteFiles(self):
if len(self.selectedFiles) == 1:
status = self.filehandler.deleteFile(self.selectedFiles[0])
if status == 0:
self.selectedFiles = []
self.setIconViewDir(self.currentPath)
elif len(self.selectedFiles) > 1:
pass
def deleteFile(self, widget, data=None):
self.grid.deleteFile()
def copyFile(self):
pass
@ -62,21 +74,3 @@ class Controller:
def pasteFile(self):
pass
# Webview events
def showWebview(self, widget):
self.builder.get_object("webViewer").popup()
def loadHome(self, widget):
self.webview.load_uri(self.settings.returnWebHome())
def runSearchWebview(self, widget, data=None):
if data.keyval == 65293:
self.webview.load_uri(widget.get_text().strip())
def refreshPage(self, widget, data=None):
self.webview.load_uri(self.webview.get_uri())
def setUrlBar(self, widget, data=None):
self.builder.get_object("webviewSearch").set_text(widget.get_uri())

View File

@ -11,24 +11,33 @@ from gi.repository import WebKit2 as webkit
from gi.repository import GLib
# Python imports
import inspect
# Application imports
from utils import Settings
from signal_classes import WebviewSignals
from Controller import Controller
class Main:
def __init__(self):
faulthandler.enable()
webkit.WebView() # Needed for glade file to load...
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit)
faulthandler.enable() # For better debug info
webkit.WebView() # Need one initialized for webview to work from glade file
builder = gtk.Builder()
settings = Settings()
settings.attachBuilder(builder)
builder.connect_signals(Controller(settings))
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit)
# Gets the methods from the classes and sets to handler.
# Then, builder connects to any signals it needs.
classes = [WebviewSignals(settings), Controller(settings)]
handlers = {}
for c in classes:
methods = inspect.getmembers(c, predicate=inspect.ismethod)
handlers.update(methods)
builder.connect_signals(handlers)
window = settings.createWindow()
window.fullscreen()
window.show_all()

View File

@ -0,0 +1,37 @@
# Gtk imports
# Python imports
# Application imports
class WebviewSignals:
def __init__(self, settings):
settings = settings
builder = settings.returnBuilder()
self.webview = builder.get_object("webview")
self.webViewer = builder.get_object("webViewer")
self.webviewSearch = builder.get_object("webviewSearch")
self.homePage = settings.returnWebHome()
settings.setDefaultWebviewSettings(self.webview, self.webview.get_settings())
self.webview.load_uri(self.homePage)
# Webview events
def showWebview(self, widget):
self.webViewer.popup()
def loadHome(self, widget):
self.webview.load_uri(self.homePage)
def runSearchWebview(self, widget, data=None):
if data.keyval == 65293:
self.webview.load_uri(widget.get_text().strip())
def refreshPage(self, widget, data=None):
self.webview.load_uri(self.webview.get_uri())
def setUrlBar(self, widget, data=None):
self.webviewSearch.set_text(widget.get_uri())

View File

@ -0,0 +1 @@
from signal_classes.WebviewSignals import WebviewSignals

View File

@ -24,34 +24,32 @@ def threaded(fn):
return wrapper
class Grid:
def __init__(self, desktop, settings, newPath):
self.desktop = desktop
self.settings = settings
self.filehandler = FileHandler()
def __init__(self, desktop, settings):
self.desktop = desktop
self.settings = settings
self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
self.usrHome = settings.returnUserHome()
self.builder = settings.returnBuilder()
self.ColumnSize = settings.returnColumnSize()
self.currentPath = ""
self.selectedFile = ""
self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
self.usrHome = settings.returnUserHome()
self.builder = settings.returnBuilder()
self.ColumnSize = settings.returnColumnSize()
self.vidsList = settings.returnVidsExtensionList()
self.imagesList = settings.returnImagesExtensionList()
self.gtkLock = False # Thread checks for gtkLock
self.threadLock = False # Gtk checks for thread lock
self.helperThread = None # Helper thread object
self.toWorkPool = [] # Thread fills pool and gtk empties it
self.copyCutArry = []
self.selectedFiles = []
self.currentPath = ""
self.desktop.set_model(self.store)
self.desktop.set_pixbuf_column(0)
self.desktop.set_text_column(1)
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
self.desktop.connect("selection-changed", self.setIconSelectionArray, (self.desktop,))
self.vidsList = settings.returnVidsExtensionList()
self.imagesList = settings.returnImagesExtensionList()
self.gtkLock = False # Thread checks for gtkLock
self.threadLock = False # Gtk checks for thread lock
self.helperThread = None # Helper thread object
self.toWorkPool = [] # Thread fills pool and gtk empties it
self.copyCutArry = []
self.setIconViewDir(newPath)
def setIconViewDir(self, path):
self.store.clear()
@ -126,7 +124,7 @@ class Grid:
self.toWorkPool.clear()
return False
# Check again when idle; If nothing else is updating, this function
# gets called immediatly. So, we play hot potato by passing lock to Thread
# gets called immediatly. So, we play hot potato by setting lock to Thread
else:
self.toWorkPool.clear()
self.gtkLock = False
@ -134,13 +132,7 @@ class Grid:
time.sleep(.005) # Fixes refresh and up icon not being added.
return True
def setIconSelectionArray(self, widget, data=None):
pass
# os.system('cls||clear')
# print(data)
def iconLeftClickEventManager(self, widget, item):
print(item)
try:
model = widget.get_model()
fileName = model[item][1]
@ -157,7 +149,7 @@ class Grid:
self.currentPath = file
self.setIconViewDir(self.currentPath)
elif isfile(file):
self.filehandler.openFile(file)
FileHandler().openFile(file)
except Exception as e:
print(e)
@ -168,20 +160,22 @@ class Grid:
controls = self.builder.get_object("iconControlsWindow")
items = widget.get_selected_items()
model = widget.get_model()
self.selectedFiles = []
if len(items) == 1:
fileName = model[items[0]][1]
dir = self.currentPath
file = dir + "/" + fileName
self.selectedFile = file # Used for return to caller
self.selectedFiles.append(file) # Used for return to caller
input.set_text(fileName)
controls.show_all()
if len(items) > 1:
dir = self.currentPath
elif len(items) > 1:
dir = self.currentPath
for item in items:
fileName = model[item][1]
file = dir + "/" + fileName
self.selectedFiles.append(file) # Used for return to caller
print(file)
input.set_text("")
@ -190,32 +184,3 @@ class Grid:
except Exception as e:
print(e)
# Passthrough file control events
def createFile(arg):
pass
def updateFile(self, file):
newName = self.currentPath + "/" + file
status = self.filehandler.updateFile(self.selectedFile, newName)
if status == 0:
self.selectedFile = newName
self.setIconViewDir(self.currentPath)
def deleteFile(self):
status = self.filehandler.deleteFile(self.selectedFile)
if status == 0:
self.selectedFile = ""
self.setIconViewDir(self.currentPath)
def copyFile(self):
pass
def cutFile(self):
pass
def pasteFile(self):
pass