Split signals to class file(s)
This commit is contained in:
parent
cdf9dfd379
commit
8ad8e612f5
@ -5,18 +5,18 @@
|
|||||||
# Application imports
|
# Application imports
|
||||||
from widgets import Grid
|
from widgets import Grid
|
||||||
from utils import Dragging
|
from utils import Dragging
|
||||||
|
from utils import FileHandler
|
||||||
|
|
||||||
|
|
||||||
class Controller:
|
class Controller:
|
||||||
def __init__(self, settings):
|
def __init__(self, settings):
|
||||||
|
self.filehandler = FileHandler()
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.builder = self.settings.returnBuilder()
|
self.builder = self.settings.returnBuilder()
|
||||||
self.desktop = self.builder.get_object("Desktop")
|
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.desktopPath = self.settings.returnDesktopPath()
|
||||||
self.webview.load_uri(self.settings.returnWebHome())
|
self.grid = None
|
||||||
|
|
||||||
# Add filter to allow only folders to be selected
|
# Add filter to allow only folders to be selected
|
||||||
selectedDirDialog = self.builder.get_object("selectedDirDialog")
|
selectedDirDialog = self.builder.get_object("selectedDirDialog")
|
||||||
@ -24,12 +24,12 @@ class Controller:
|
|||||||
selectedDirDialog.add_filter(filefilter)
|
selectedDirDialog.add_filter(filefilter)
|
||||||
selectedDirDialog.set_filename(self.desktopPath)
|
selectedDirDialog.set_filename(self.desktopPath)
|
||||||
|
|
||||||
self.grid = None
|
|
||||||
self.setIconViewDir(selectedDirDialog)
|
self.setIconViewDir(selectedDirDialog)
|
||||||
|
|
||||||
def setIconViewDir(self, widget, data=None):
|
def setIconViewDir(self, widget, data=None):
|
||||||
newPath = widget.get_filename()
|
newPath = widget.get_filename()
|
||||||
Grid(self.desktop, self.settings, newPath)
|
self.grid = Grid(self.desktop, self.settings)
|
||||||
|
self.grid.setIconViewDir(newPath)
|
||||||
|
|
||||||
def getWindowsOnScreen(self):
|
def getWindowsOnScreen(self):
|
||||||
screen = self.settings.returnScren()
|
screen = self.settings.returnScren()
|
||||||
@ -40,19 +40,31 @@ class Controller:
|
|||||||
widget.hide()
|
widget.hide()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# File control events
|
# File control events
|
||||||
def createFile(self):
|
def createFile(arg):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def updateFile(self, widget, data=None):
|
def updateFile(self, file):
|
||||||
newName = widget.get_text().strip()
|
if len(self.selectedFiles) == 1:
|
||||||
if data and data.keyval == 65293: # Enter key event
|
newName = self.currentPath + "/" + file
|
||||||
self.grid.updateFile(newName)
|
status = self.filehandler.updateFile(self.selectedFiles[0], newName)
|
||||||
elif data == None: # Save button 'event'
|
|
||||||
self.grid.updateFile(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):
|
def copyFile(self):
|
||||||
pass
|
pass
|
||||||
@ -62,21 +74,3 @@ class Controller:
|
|||||||
|
|
||||||
def pasteFile(self):
|
def pasteFile(self):
|
||||||
pass
|
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())
|
|
||||||
|
@ -11,24 +11,33 @@ from gi.repository import WebKit2 as webkit
|
|||||||
from gi.repository import GLib
|
from gi.repository import GLib
|
||||||
|
|
||||||
# Python imports
|
# Python imports
|
||||||
|
import inspect
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from utils import Settings
|
from utils import Settings
|
||||||
|
from signal_classes import WebviewSignals
|
||||||
from Controller import Controller
|
from Controller import Controller
|
||||||
|
|
||||||
|
|
||||||
class Main:
|
class Main:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
faulthandler.enable()
|
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit)
|
||||||
webkit.WebView() # Needed for glade file to load...
|
faulthandler.enable() # For better debug info
|
||||||
|
webkit.WebView() # Need one initialized for webview to work from glade file
|
||||||
|
|
||||||
builder = gtk.Builder()
|
builder = gtk.Builder()
|
||||||
settings = Settings()
|
settings = Settings()
|
||||||
settings.attachBuilder(builder)
|
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 = settings.createWindow()
|
||||||
window.fullscreen()
|
window.fullscreen()
|
||||||
window.show_all()
|
window.show_all()
|
||||||
|
37
src/pytop-0.0.1/Pytop/signal_classes/WebviewSignals.py
Normal file
37
src/pytop-0.0.1/Pytop/signal_classes/WebviewSignals.py
Normal 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())
|
1
src/pytop-0.0.1/Pytop/signal_classes/__init__.py
Normal file
1
src/pytop-0.0.1/Pytop/signal_classes/__init__.py
Normal file
@ -0,0 +1 @@
|
|||||||
|
from signal_classes.WebviewSignals import WebviewSignals
|
@ -24,34 +24,32 @@ def threaded(fn):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
class Grid:
|
class Grid:
|
||||||
def __init__(self, desktop, settings, newPath):
|
def __init__(self, desktop, settings):
|
||||||
self.desktop = desktop
|
self.desktop = desktop
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.filehandler = FileHandler()
|
|
||||||
|
|
||||||
self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
|
self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
|
||||||
self.usrHome = settings.returnUserHome()
|
self.usrHome = settings.returnUserHome()
|
||||||
self.builder = settings.returnBuilder()
|
self.builder = settings.returnBuilder()
|
||||||
self.ColumnSize = settings.returnColumnSize()
|
self.ColumnSize = settings.returnColumnSize()
|
||||||
self.currentPath = ""
|
self.vidsList = settings.returnVidsExtensionList()
|
||||||
self.selectedFile = ""
|
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_model(self.store)
|
||||||
self.desktop.set_pixbuf_column(0)
|
self.desktop.set_pixbuf_column(0)
|
||||||
self.desktop.set_text_column(1)
|
self.desktop.set_text_column(1)
|
||||||
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
self.desktop.connect("item-activated", self.iconLeftClickEventManager)
|
||||||
self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
|
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):
|
def setIconViewDir(self, path):
|
||||||
self.store.clear()
|
self.store.clear()
|
||||||
@ -126,7 +124,7 @@ class Grid:
|
|||||||
self.toWorkPool.clear()
|
self.toWorkPool.clear()
|
||||||
return False
|
return False
|
||||||
# Check again when idle; If nothing else is updating, this function
|
# 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:
|
else:
|
||||||
self.toWorkPool.clear()
|
self.toWorkPool.clear()
|
||||||
self.gtkLock = False
|
self.gtkLock = False
|
||||||
@ -134,13 +132,7 @@ class Grid:
|
|||||||
time.sleep(.005) # Fixes refresh and up icon not being added.
|
time.sleep(.005) # Fixes refresh and up icon not being added.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def setIconSelectionArray(self, widget, data=None):
|
|
||||||
pass
|
|
||||||
# os.system('cls||clear')
|
|
||||||
# print(data)
|
|
||||||
|
|
||||||
def iconLeftClickEventManager(self, widget, item):
|
def iconLeftClickEventManager(self, widget, item):
|
||||||
print(item)
|
|
||||||
try:
|
try:
|
||||||
model = widget.get_model()
|
model = widget.get_model()
|
||||||
fileName = model[item][1]
|
fileName = model[item][1]
|
||||||
@ -157,7 +149,7 @@ class Grid:
|
|||||||
self.currentPath = file
|
self.currentPath = file
|
||||||
self.setIconViewDir(self.currentPath)
|
self.setIconViewDir(self.currentPath)
|
||||||
elif isfile(file):
|
elif isfile(file):
|
||||||
self.filehandler.openFile(file)
|
FileHandler().openFile(file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
@ -168,20 +160,22 @@ class Grid:
|
|||||||
controls = self.builder.get_object("iconControlsWindow")
|
controls = self.builder.get_object("iconControlsWindow")
|
||||||
items = widget.get_selected_items()
|
items = widget.get_selected_items()
|
||||||
model = widget.get_model()
|
model = widget.get_model()
|
||||||
|
self.selectedFiles = []
|
||||||
|
|
||||||
if len(items) == 1:
|
if len(items) == 1:
|
||||||
fileName = model[items[0]][1]
|
fileName = model[items[0]][1]
|
||||||
dir = self.currentPath
|
dir = self.currentPath
|
||||||
file = dir + "/" + fileName
|
file = dir + "/" + fileName
|
||||||
|
|
||||||
self.selectedFile = file # Used for return to caller
|
self.selectedFiles.append(file) # Used for return to caller
|
||||||
input.set_text(fileName)
|
input.set_text(fileName)
|
||||||
controls.show_all()
|
controls.show_all()
|
||||||
if len(items) > 1:
|
elif len(items) > 1:
|
||||||
dir = self.currentPath
|
dir = self.currentPath
|
||||||
for item in items:
|
for item in items:
|
||||||
fileName = model[item][1]
|
fileName = model[item][1]
|
||||||
file = dir + "/" + fileName
|
file = dir + "/" + fileName
|
||||||
|
self.selectedFiles.append(file) # Used for return to caller
|
||||||
print(file)
|
print(file)
|
||||||
|
|
||||||
input.set_text("")
|
input.set_text("")
|
||||||
@ -190,32 +184,3 @@ class Grid:
|
|||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user