Reverted to Iconview and added guards against segfault

This commit is contained in:
Maxim Stewart 2019-06-16 15:12:06 -05:00
parent 8773011925
commit 7a03a3dc6a
15 changed files with 186 additions and 314 deletions

Binary file not shown.

View File

@ -28,6 +28,10 @@ class Main:
window.show_all() window.show_all()
if __name__ == "__main__": if __name__ == "__main__":
main = Main() main = Main()
gtk.main() gtk.main()

View File

@ -28,16 +28,11 @@
</object> </object>
<object class="GtkPopover" id="iconControlsWindow"> <object class="GtkPopover" id="iconControlsWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="position">right</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<object class="GtkEntry" id="iconRenameInput"> <object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</property> <property name="width_request">300</property>
@ -45,30 +40,6 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_stock">gtk-edit</property> <property name="primary_icon_stock">gtk-edit</property>
<signal name="key-release-event" handler="updateFile" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="updateFile" object="iconRenameInput" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -82,14 +53,12 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-delete</property> <property name="label">gtk-copy</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="deleteFile" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -97,9 +66,6 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<placeholder/>
</child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-cut</property> <property name="label">gtk-cut</property>
@ -112,15 +78,19 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">2</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<placeholder/>
</child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-copy</property> <property name="label">gtk-delete</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
</object> </object>
@ -140,12 +110,6 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkImage" id="upImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-go-up</property>
<property name="icon_size">3</property>
</object>
<object class="GtkImage" id="webDropDown"> <object class="GtkImage" id="webDropDown">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -191,7 +155,22 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkSearchEntry" id="searchentry1"> <object class="GtkFileChooserButton" id="selectedDirDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action">select-folder</property>
<property name="filter">Folders</property>
<property name="title" translatable="yes">Directory Chooser</property>
<signal name="file-set" handler="setIconViewDir" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSearchEntry" id="searDir">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property> <property name="primary_icon_name">edit-find-symbolic</property>
@ -201,40 +180,9 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Up</property>
<property name="image">upImage</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="dirUp" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkFileChooserButton" id="selectedDirDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action">select-folder</property>
<property name="filter">Folders</property>
<property name="title" translatable="yes">Directory Chooser</property>
<signal name="selection-changed" handler="setIconViewDir" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -246,7 +194,6 @@
<object class="GtkProgressBar" id="loadProgress"> <object class="GtkProgressBar" id="loadProgress">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="show_text">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -264,17 +211,10 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkTreeView" id="Desktop"> <object class="GtkIconView" id="Desktop">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="headers_visible">False</property> <property name="margin">6</property>
<property name="show_expanders">False</property>
<property name="rubber_banding">True</property>
<property name="enable_grid_lines">both</property>
<signal name="row-activated" handler="iconLeftClickEventManager" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -20,6 +20,17 @@ iconview {
treeview, treeview,
treeview.view { treeview.view {
background: rgba(0, 0, 0, 0.64); background: rgba(0, 0, 0, 0.2);
background-color: rgba(0, 0, 0, 0.64); background-color: rgba(0, 0, 0, 0.2);
}
cell {
margin: 0em;
padding: 0em;
/* float: left; */
}
cell:focus {
outline-style: solid;
outline-color: rgba(0, 232, 255, 0.64);
} }

View File

@ -1,5 +1,8 @@
# Gtk Imports # Gtk Imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
# Python imports # Python imports
from .Grid import Grid from .Grid import Grid
@ -25,18 +28,9 @@ class Events:
self.grid = None 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()
self.grid = Grid(self.desktop, self.settings, newPath) Grid(self.desktop, self.settings, newPath)
def dirUp(self, widget, data=None):
newPath = self.grid.returnParentDir()
self.grid = Grid(self.desktop, self.settings, newPath)
def iconLeftClickEventManager(self, widget, eve, item):
self.grid.iconLeftClickEventManager(widget, eve, item)
def showGridControlMenu(self, widget, data=None): def showGridControlMenu(self, widget, data=None):
popover = self.builder.get_object("gridControlMenu") popover = self.builder.get_object("gridControlMenu")

View File

@ -8,7 +8,7 @@ gi.require_version('Gdk', '3.0')
from gi.repository import Gtk as gtk from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk from gi.repository import Gdk as gdk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
from gi.repository import GLib from gi.repository import GObject as gobject
# Python imports # Python imports
import os, threading import os, threading
@ -18,6 +18,8 @@ from .Icon import Icon
from .FileHandler import FileHandler from .FileHandler import FileHandler
gdk.threads_init()
def threaded(fn): def threaded(fn):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start() threading.Thread(target=fn, args=args, kwargs=kwargs).start()
@ -29,42 +31,27 @@ class Grid:
self.settings = settings self.settings = settings
self.filehandler = FileHandler() self.filehandler = FileHandler()
self.store = gtk.TreeStore(str, GdkPixbuf.Pixbuf) self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
self.usrHome = settings.returnUserHome() self.usrHome = settings.returnUserHome()
self.builder = self.settings.returnBuilder() self.builder = self.settings.returnBuilder()
self.ColumnSize = self.settings.returnColumnSize() self.ColumnSize = self.settings.returnColumnSize()
self.currentPath = "" self.currentPath = ""
self.selectedFile = "" self.selectedFile = ""
self.treeViewCol = None
self.desktop.set_model(self.store)
if len(self.desktop.get_columns()) == 0: self.desktop.set_model(self.store)
self.treeViewCol = gtk.TreeViewColumn("Files") self.desktop.set_pixbuf_column(0)
# Create a column cell to display text self.desktop.set_text_column(1)
colCellText = gtk.CellRendererText() self.desktop.connect("item-activated", self.iconLeftClickEventManager)
# Create a column cell to display an image self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
colCellImg = gtk.CellRendererPixbuf()
# Add the cells to the column
self.treeViewCol.pack_start(colCellImg, False)
self.treeViewCol.pack_start(colCellText, True)
# Bind the text cell to column 0 of the tree's model
self.treeViewCol.add_attribute(colCellText, "text", 0)
# Bind the image cell to column 1 of the tree's model
self.treeViewCol.add_attribute(colCellImg, "pixbuf", 1)
# Append the columns to the TreeView
self.desktop.append_column(self.treeViewCol)
else:
self.treeViewCol = self.desktop.get_column(0)
self.setIconViewDir(newPath) self.setIconViewDir(newPath)
@threaded
def setIconViewDir(self, path): def setIconViewDir(self, path):
# self.treeViewCol.clear()
self.store.clear() self.store.clear()
self.currentPath = path self.currentPath = path
paths = ['.', '..'] dirPaths = ['.', '..']
files = [] files = []
for f in listdir(path): for f in listdir(path):
@ -75,48 +62,41 @@ class Grid:
if isfile(file): if isfile(file):
files.append(f) files.append(f)
else: else:
paths.append(f) dirPaths.append(f)
paths.sort() dirPaths.sort()
files.sort() files.sort()
files = paths + files files = dirPaths + files
self.generateDirectoryGrid(path, files) self.generateDirectoryGrid(path, files)
@threaded def generateDirectoryGrid(self, dirPath, files):
def generateDirectoryGrid(self, path, files):
fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files) fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files)
tickCount = 0.0 tickCount = 0.0
row = 0
col = 0
x = 0
y = 0
loadProgress = self.builder.get_object('loadProgress') loadProgress = self.builder.get_object('loadProgress')
loadProgress.set_text("Loading...") loadProgress.set_text("Loading...")
loadProgress.set_fraction(0.0) loadProgress.set_fraction(0.0)
for file in files: for file in files:
imgBuffer = self.getImgBuffer(path, file) imgBuffer = Icon(self.settings).createIcon(dirPath, file)
GLib.idle_add(self.addToGrid, (imgBuffer, file,)) gobject.idle_add(self.addToGrid, (imgBuffer, file,))
# tickCount += fractionTick # tickCount += fractionTick
loadProgress.set_fraction(tickCount) # loadProgress.set_fraction(tickCount)
loadProgress.set_text("Finished...") loadProgress.set_text("Finished...")
def getImgBuffer(self, path, file): def addToGrid(self, args):
return Icon(self.settings).createIcon(path, file) self.store.append([args[0], args[1]])
def addToGrid(self, args, parent=None):
# NOTE: Converting to pixbuf after retreval to keep Icon.py more universal.
# We can just remove get_pixbuf to get a gtk image.
# We probably need a settings check to chose a set type...
self.store.append(parent, [args[1], args[0].get_pixbuf()])
def iconLeftClickEventManager(self, widget, eve, item):
tree_selection = self.desktop.get_selection()
(model, pathlist) = tree_selection.get_selected_rows()
fileName = None
dir = self.currentPath
for path in pathlist :
tree_iter = model.get_iter(path)
fileName = model.get_value(tree_iter,0)
def iconLeftClickEventManager(self, widget, item):
try: try:
model = widget.get_model()
fileName = model[item][1]
dir = self.currentPath
file = dir + "/" + fileName file = dir + "/" + fileName
if fileName == ".": if fileName == ".":
@ -155,9 +135,6 @@ class Grid:
print(e) print(e)
def returnParentDir(self):
return os.path.abspath(os.path.join(self.currentPath, os.pardir))
# Passthrough file control events # Passthrough file control events
def createFile(arg): def createFile(arg):
pass pass

View File

@ -64,7 +64,9 @@ class Icon:
print(e) print(e)
thumbnl = gtk.Image(stock = gtk.STOCK_DIALOG_ERROR) thumbnl = gtk.Image(stock = gtk.STOCK_DIALOG_ERROR)
return thumbnl # NOTE: Returning pixbuf through retreval to keep this file more universaly usable.
# We can just remove get_pixbuf to get a gtk image
return thumbnl.get_pixbuf()
def createIconImageBuffer(self, path, wxh): def createIconImageBuffer(self, path, wxh):
pixbuf = None pixbuf = None
@ -73,6 +75,7 @@ class Icon:
filename = path, filename = path,
width = wxh[0], width = wxh[0],
height = wxh[1], height = wxh[1],
# preserve_aspect_ratio = False)
preserve_aspect_ratio = True) preserve_aspect_ratio = True)
return gtk.Image.new_from_pixbuf(pixbuf) return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e: except Exception as e:

View File

@ -44,6 +44,13 @@ class Settings:
if visual != None and screen.is_composited(): if visual != None and screen.is_composited():
window.set_visual(visual) window.set_visual(visual)
# bind css file
cssProvider = gtk.CssProvider()
cssProvider.load_from_path('resources/stylesheet.css')
screen = gdk.Screen.get_default()
styleContext = gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, gtk.STYLE_PROVIDER_PRIORITY_USER)
window.set_app_paintable(True) window.set_app_paintable(True)
window.connect("draw", self.area_draw) window.connect("draw", self.area_draw)
monitors = self.getMonitorData(screen) monitors = self.getMonitorData(screen)

View File

@ -28,6 +28,10 @@ class Main:
window.show_all() window.show_all()
if __name__ == "__main__": if __name__ == "__main__":
main = Main() main = Main()
gtk.main() gtk.main()

View File

@ -28,16 +28,11 @@
</object> </object>
<object class="GtkPopover" id="iconControlsWindow"> <object class="GtkPopover" id="iconControlsWindow">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="position">right</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="orientation">vertical</property> <property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child> <child>
<object class="GtkEntry" id="iconRenameInput"> <object class="GtkEntry" id="iconRenameInput">
<property name="width_request">300</property> <property name="width_request">300</property>
@ -45,30 +40,6 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_stock">gtk-edit</property> <property name="primary_icon_stock">gtk-edit</property>
<signal name="key-release-event" handler="updateFile" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="updateFile" object="iconRenameInput" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -82,14 +53,12 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-delete</property> <property name="label">gtk-copy</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
<signal name="clicked" handler="deleteFile" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -97,9 +66,6 @@
<property name="position">0</property> <property name="position">0</property>
</packing> </packing>
</child> </child>
<child>
<placeholder/>
</child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-cut</property> <property name="label">gtk-cut</property>
@ -112,15 +78,19 @@
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">2</property> <property name="position">1</property>
</packing> </packing>
</child> </child>
<child>
<placeholder/>
</child>
<child> <child>
<object class="GtkButton"> <object class="GtkButton">
<property name="label">gtk-copy</property> <property name="label">gtk-delete</property>
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="margin_left">65</property>
<property name="use_stock">True</property> <property name="use_stock">True</property>
<property name="always_show_image">True</property> <property name="always_show_image">True</property>
</object> </object>
@ -140,12 +110,6 @@
</object> </object>
</child> </child>
</object> </object>
<object class="GtkImage" id="upImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-go-up</property>
<property name="icon_size">3</property>
</object>
<object class="GtkImage" id="webDropDown"> <object class="GtkImage" id="webDropDown">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
@ -191,7 +155,22 @@
</packing> </packing>
</child> </child>
<child> <child>
<object class="GtkSearchEntry" id="searchentry1"> <object class="GtkFileChooserButton" id="selectedDirDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action">select-folder</property>
<property name="filter">Folders</property>
<property name="title" translatable="yes">Directory Chooser</property>
<signal name="file-set" handler="setIconViewDir" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkSearchEntry" id="searDir">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property> <property name="primary_icon_name">edit-find-symbolic</property>
@ -201,40 +180,9 @@
<packing> <packing>
<property name="expand">True</property> <property name="expand">True</property>
<property name="fill">True</property> <property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Up</property>
<property name="image">upImage</property>
<property name="always_show_image">True</property>
<signal name="clicked" handler="dirUp" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property> <property name="position">2</property>
</packing> </packing>
</child> </child>
<child>
<object class="GtkFileChooserButton" id="selectedDirDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="action">select-folder</property>
<property name="filter">Folders</property>
<property name="title" translatable="yes">Directory Chooser</property>
<signal name="selection-changed" handler="setIconViewDir" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -246,7 +194,6 @@
<object class="GtkProgressBar" id="loadProgress"> <object class="GtkProgressBar" id="loadProgress">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="show_text">True</property>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -264,17 +211,10 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkTreeView" id="Desktop"> <object class="GtkIconView" id="Desktop">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="headers_visible">False</property> <property name="margin">6</property>
<property name="show_expanders">False</property>
<property name="rubber_banding">True</property>
<property name="enable_grid_lines">both</property>
<signal name="row-activated" handler="iconLeftClickEventManager" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection"/>
</child>
</object> </object>
</child> </child>
</object> </object>

View File

@ -20,6 +20,17 @@ iconview {
treeview, treeview,
treeview.view { treeview.view {
background: rgba(0, 0, 0, 0.64); background: rgba(0, 0, 0, 0.2);
background-color: rgba(0, 0, 0, 0.64); background-color: rgba(0, 0, 0, 0.2);
}
cell {
margin: 0em;
padding: 0em;
/* float: left; */
}
cell:focus {
outline-style: solid;
outline-color: rgba(0, 232, 255, 0.64);
} }

View File

@ -1,5 +1,8 @@
# Gtk Imports # Gtk Imports
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
# Python imports # Python imports
from .Grid import Grid from .Grid import Grid
@ -25,18 +28,9 @@ class Events:
self.grid = None 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()
self.grid = Grid(self.desktop, self.settings, newPath) Grid(self.desktop, self.settings, newPath)
def dirUp(self, widget, data=None):
newPath = self.grid.returnParentDir()
self.grid = Grid(self.desktop, self.settings, newPath)
def iconLeftClickEventManager(self, widget, eve, item):
self.grid.iconLeftClickEventManager(widget, eve, item)
def showGridControlMenu(self, widget, data=None): def showGridControlMenu(self, widget, data=None):
popover = self.builder.get_object("gridControlMenu") popover = self.builder.get_object("gridControlMenu")

View File

@ -8,7 +8,7 @@ gi.require_version('Gdk', '3.0')
from gi.repository import Gtk as gtk from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk from gi.repository import Gdk as gdk
from gi.repository import GdkPixbuf from gi.repository import GdkPixbuf
from gi.repository import GLib from gi.repository import GObject as gobject
# Python imports # Python imports
import os, threading import os, threading
@ -18,6 +18,8 @@ from .Icon import Icon
from .FileHandler import FileHandler from .FileHandler import FileHandler
gdk.threads_init()
def threaded(fn): def threaded(fn):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
threading.Thread(target=fn, args=args, kwargs=kwargs).start() threading.Thread(target=fn, args=args, kwargs=kwargs).start()
@ -29,42 +31,27 @@ class Grid:
self.settings = settings self.settings = settings
self.filehandler = FileHandler() self.filehandler = FileHandler()
self.store = gtk.TreeStore(str, GdkPixbuf.Pixbuf) self.store = gtk.ListStore(GdkPixbuf.Pixbuf, str)
self.usrHome = settings.returnUserHome() self.usrHome = settings.returnUserHome()
self.builder = self.settings.returnBuilder() self.builder = self.settings.returnBuilder()
self.ColumnSize = self.settings.returnColumnSize() self.ColumnSize = self.settings.returnColumnSize()
self.currentPath = "" self.currentPath = ""
self.selectedFile = "" self.selectedFile = ""
self.treeViewCol = None
self.desktop.set_model(self.store)
if len(self.desktop.get_columns()) == 0: self.desktop.set_model(self.store)
self.treeViewCol = gtk.TreeViewColumn("Files") self.desktop.set_pixbuf_column(0)
# Create a column cell to display text self.desktop.set_text_column(1)
colCellText = gtk.CellRendererText() self.desktop.connect("item-activated", self.iconLeftClickEventManager)
# Create a column cell to display an image self.desktop.connect("button_press_event", self.iconRightClickEventManager, (self.desktop,))
colCellImg = gtk.CellRendererPixbuf()
# Add the cells to the column
self.treeViewCol.pack_start(colCellImg, False)
self.treeViewCol.pack_start(colCellText, True)
# Bind the text cell to column 0 of the tree's model
self.treeViewCol.add_attribute(colCellText, "text", 0)
# Bind the image cell to column 1 of the tree's model
self.treeViewCol.add_attribute(colCellImg, "pixbuf", 1)
# Append the columns to the TreeView
self.desktop.append_column(self.treeViewCol)
else:
self.treeViewCol = self.desktop.get_column(0)
self.setIconViewDir(newPath) self.setIconViewDir(newPath)
@threaded
def setIconViewDir(self, path): def setIconViewDir(self, path):
# self.treeViewCol.clear()
self.store.clear() self.store.clear()
self.currentPath = path self.currentPath = path
paths = ['.', '..'] dirPaths = ['.', '..']
files = [] files = []
for f in listdir(path): for f in listdir(path):
@ -75,48 +62,41 @@ class Grid:
if isfile(file): if isfile(file):
files.append(f) files.append(f)
else: else:
paths.append(f) dirPaths.append(f)
paths.sort() dirPaths.sort()
files.sort() files.sort()
files = paths + files files = dirPaths + files
self.generateDirectoryGrid(path, files) self.generateDirectoryGrid(path, files)
@threaded def generateDirectoryGrid(self, dirPath, files):
def generateDirectoryGrid(self, path, files):
fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files) fractionTick = 1.0 / 1.0 if len(files) == 0 else len(files)
tickCount = 0.0 tickCount = 0.0
row = 0
col = 0
x = 0
y = 0
loadProgress = self.builder.get_object('loadProgress') loadProgress = self.builder.get_object('loadProgress')
loadProgress.set_text("Loading...") loadProgress.set_text("Loading...")
loadProgress.set_fraction(0.0) loadProgress.set_fraction(0.0)
for file in files: for file in files:
imgBuffer = self.getImgBuffer(path, file) imgBuffer = Icon(self.settings).createIcon(dirPath, file)
GLib.idle_add(self.addToGrid, (imgBuffer, file,)) gobject.idle_add(self.addToGrid, (imgBuffer, file,))
# tickCount += fractionTick # tickCount += fractionTick
loadProgress.set_fraction(tickCount) # loadProgress.set_fraction(tickCount)
loadProgress.set_text("Finished...") loadProgress.set_text("Finished...")
def getImgBuffer(self, path, file): def addToGrid(self, args):
return Icon(self.settings).createIcon(path, file) self.store.append([args[0], args[1]])
def addToGrid(self, args, parent=None):
# NOTE: Converting to pixbuf after retreval to keep Icon.py more universal.
# We can just remove get_pixbuf to get a gtk image.
# We probably need a settings check to chose a set type...
self.store.append(parent, [args[1], args[0].get_pixbuf()])
def iconLeftClickEventManager(self, widget, eve, item):
tree_selection = self.desktop.get_selection()
(model, pathlist) = tree_selection.get_selected_rows()
fileName = None
dir = self.currentPath
for path in pathlist :
tree_iter = model.get_iter(path)
fileName = model.get_value(tree_iter,0)
def iconLeftClickEventManager(self, widget, item):
try: try:
model = widget.get_model()
fileName = model[item][1]
dir = self.currentPath
file = dir + "/" + fileName file = dir + "/" + fileName
if fileName == ".": if fileName == ".":
@ -155,9 +135,6 @@ class Grid:
print(e) print(e)
def returnParentDir(self):
return os.path.abspath(os.path.join(self.currentPath, os.pardir))
# Passthrough file control events # Passthrough file control events
def createFile(arg): def createFile(arg):
pass pass

View File

@ -64,7 +64,9 @@ class Icon:
print(e) print(e)
thumbnl = gtk.Image(stock = gtk.STOCK_DIALOG_ERROR) thumbnl = gtk.Image(stock = gtk.STOCK_DIALOG_ERROR)
return thumbnl # NOTE: Returning pixbuf through retreval to keep this file more universaly usable.
# We can just remove get_pixbuf to get a gtk image
return thumbnl.get_pixbuf()
def createIconImageBuffer(self, path, wxh): def createIconImageBuffer(self, path, wxh):
pixbuf = None pixbuf = None
@ -73,6 +75,7 @@ class Icon:
filename = path, filename = path,
width = wxh[0], width = wxh[0],
height = wxh[1], height = wxh[1],
# preserve_aspect_ratio = False)
preserve_aspect_ratio = True) preserve_aspect_ratio = True)
return gtk.Image.new_from_pixbuf(pixbuf) return gtk.Image.new_from_pixbuf(pixbuf)
except Exception as e: except Exception as e:

View File

@ -44,6 +44,13 @@ class Settings:
if visual != None and screen.is_composited(): if visual != None and screen.is_composited():
window.set_visual(visual) window.set_visual(visual)
# bind css file
cssProvider = gtk.CssProvider()
cssProvider.load_from_path('resources/stylesheet.css')
screen = gdk.Screen.get_default()
styleContext = gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, gtk.STYLE_PROVIDER_PRIORITY_USER)
window.set_app_paintable(True) window.set_app_paintable(True)
window.connect("draw", self.area_draw) window.connect("draw", self.area_draw)
monitors = self.getMonitorData(screen) monitors = self.getMonitorData(screen)