Changed threadding setup

This commit is contained in:
Maxim Stewart 2019-06-20 23:07:30 -05:00
parent ccd29988ff
commit fbf6b24389
3 changed files with 42 additions and 28 deletions

View File

@ -11,7 +11,7 @@ from gi.repository import GLib as glib
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
# Python imports # Python imports
import os, threading import os, threading, time
from os.path import isdir, isfile, join from os.path import isdir, isfile, join
from os import listdir from os import listdir
from .Icon import Icon from .Icon import Icon
@ -48,9 +48,10 @@ class Grid:
self.copyCutArry = [] self.copyCutArry = []
self.gtkLock = False # Thread checks for gtkLock self.gtkLock = False # Thread checks for gtkLock
self.threadLock = False # Gtk checks for thread lock self.threadLock = False # Gtk checks for thread lock
self.toWorkPool = [] # Thread fills pool and gtk empties it self.helperThread = None # Helper thread object
self.toWorkPool = [] # Thread fills pool and gtk empties it
self.setIconViewDir(newPath) self.setIconViewDir(newPath)
@ -86,26 +87,30 @@ class Grid:
images.sort() images.sort()
desktop.sort() desktop.sort()
files.sort() files.sort()
files = dirPaths + vids + images + desktop + files files = dirPaths + vids + images + desktop + files
self.generateDirectoryGrid(path, files) # Run helper thread...
if self.helperThread:
self.helperThread.terminate()
self.helperThread = None
# Run helper thread...
self.threadLock = True
self.helperThread = threading.Thread(target=self.generateDirectoryGridIcon, args=(path, files)).start()
glib.idle_add(self.addToGrid, (file,)) # This must stay in the main thread b/c glib.idle_add(self.addToGrid, (file,)) # This must stay in the main thread b/c
# gtk isn't thread safe/aware So, we # gtk isn't thread safe/aware So, we
# make a sad lil thread hot potato 'game' # make a sad lil thread hot potato 'game'
# out of this process. # out of this process.
@threaded # @threaded
def generateDirectoryGrid(self, dirPath, files): def generateDirectoryGridIcon(self, dirPath, files):
# NOTE: We'll be passing pixbuf after retreval to keep Icon.py file more # NOTE: We'll be passing pixbuf after retreval to keep Icon.py file more
# universaly usable. We can just remove get_pixbuf to get a gtk.Image type # universaly usable. We can just remove get_pixbuf to get a gtk.Image type
for file in files: for file in files:
image = Icon(self.settings).createIcon(dirPath, file) image = Icon(self.settings).createIcon(dirPath, file)
self.toWorkPool.append([image.get_pixbuf(), file]) self.toWorkPool.append([image.get_pixbuf(), file])
self.threadLock = False self.threadLock = False
self.gtkLock = True self.gtkLock = True
storageQue.clear()
def addToGrid(self, args): def addToGrid(self, args):
@ -128,11 +133,13 @@ class Grid:
self.toWorkPool.clear() self.toWorkPool.clear()
self.gtkLock = False self.gtkLock = False
self.threadLock = True self.threadLock = True
time.sleep(.005) # Fixes refresh and up icon not being added.
return True return True
def setIconSelectionArray(self, widget, data=None): def setIconSelectionArray(self, widget, data=None):
os.system('cls||clear') pass
print(data) # os.system('cls||clear')
# print(data)
def iconLeftClickEventManager(self, widget, item): def iconLeftClickEventManager(self, widget, item):
try: try:
@ -190,14 +197,14 @@ class Grid:
if status == 0: if status == 0:
self.selectedFile = newName self.selectedFile = newName
self.generateDirectoryGrid(self.currentPath) self.setIconViewDir(self.currentPath)
def deleteFile(self): def deleteFile(self):
status = self.filehandler.deleteFile(self.selectedFile) status = self.filehandler.deleteFile(self.selectedFile)
if status == 0: if status == 0:
self.selectedFile = "" self.selectedFile = ""
self.generateDirectoryGrid(self.currentPath) self.setIconViewDir(self.currentPath)
def copyFile(self): def copyFile(self):
pass pass

View File

@ -11,7 +11,7 @@ from gi.repository import GLib as glib
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
# Python imports # Python imports
import os, threading import os, threading, time
from os.path import isdir, isfile, join from os.path import isdir, isfile, join
from os import listdir from os import listdir
from .Icon import Icon from .Icon import Icon
@ -48,9 +48,10 @@ class Grid:
self.copyCutArry = [] self.copyCutArry = []
self.gtkLock = False # Thread checks for gtkLock self.gtkLock = False # Thread checks for gtkLock
self.threadLock = False # Gtk checks for thread lock self.threadLock = False # Gtk checks for thread lock
self.toWorkPool = [] # Thread fills pool and gtk empties it self.helperThread = None # Helper thread object
self.toWorkPool = [] # Thread fills pool and gtk empties it
self.setIconViewDir(newPath) self.setIconViewDir(newPath)
@ -86,26 +87,30 @@ class Grid:
images.sort() images.sort()
desktop.sort() desktop.sort()
files.sort() files.sort()
files = dirPaths + vids + images + desktop + files files = dirPaths + vids + images + desktop + files
self.generateDirectoryGrid(path, files) # Run helper thread...
if self.helperThread:
self.helperThread.terminate()
self.helperThread = None
# Run helper thread...
self.threadLock = True
self.helperThread = threading.Thread(target=self.generateDirectoryGridIcon, args=(path, files)).start()
glib.idle_add(self.addToGrid, (file,)) # This must stay in the main thread b/c glib.idle_add(self.addToGrid, (file,)) # This must stay in the main thread b/c
# gtk isn't thread safe/aware So, we # gtk isn't thread safe/aware So, we
# make a sad lil thread hot potato 'game' # make a sad lil thread hot potato 'game'
# out of this process. # out of this process.
@threaded # @threaded
def generateDirectoryGrid(self, dirPath, files): def generateDirectoryGridIcon(self, dirPath, files):
# NOTE: We'll be passing pixbuf after retreval to keep Icon.py file more # NOTE: We'll be passing pixbuf after retreval to keep Icon.py file more
# universaly usable. We can just remove get_pixbuf to get a gtk.Image type # universaly usable. We can just remove get_pixbuf to get a gtk.Image type
for file in files: for file in files:
image = Icon(self.settings).createIcon(dirPath, file) image = Icon(self.settings).createIcon(dirPath, file)
self.toWorkPool.append([image.get_pixbuf(), file]) self.toWorkPool.append([image.get_pixbuf(), file])
self.threadLock = False self.threadLock = False
self.gtkLock = True self.gtkLock = True
storageQue.clear()
def addToGrid(self, args): def addToGrid(self, args):
@ -128,11 +133,13 @@ class Grid:
self.toWorkPool.clear() self.toWorkPool.clear()
self.gtkLock = False self.gtkLock = False
self.threadLock = True self.threadLock = True
time.sleep(.005) # Fixes refresh and up icon not being added.
return True return True
def setIconSelectionArray(self, widget, data=None): def setIconSelectionArray(self, widget, data=None):
os.system('cls||clear') pass
print(data) # os.system('cls||clear')
# print(data)
def iconLeftClickEventManager(self, widget, item): def iconLeftClickEventManager(self, widget, item):
try: try:
@ -190,14 +197,14 @@ class Grid:
if status == 0: if status == 0:
self.selectedFile = newName self.selectedFile = newName
self.generateDirectoryGrid(self.currentPath) self.setIconViewDir(self.currentPath)
def deleteFile(self): def deleteFile(self):
status = self.filehandler.deleteFile(self.selectedFile) status = self.filehandler.deleteFile(self.selectedFile)
if status == 0: if status == 0:
self.selectedFile = "" self.selectedFile = ""
self.generateDirectoryGrid(self.currentPath) self.setIconViewDir(self.currentPath)
def copyFile(self): def copyFile(self):
pass pass

BIN
src/versions/pytop-0.0.1/pytop Executable file

Binary file not shown.