Changed load setup, added logger class, +more

This commit is contained in:
Maxim Stewart 2020-05-08 21:02:13 -05:00
parent 2f4e480265
commit 88d836ac06
14 changed files with 221 additions and 112 deletions

Binary file not shown.

View File

@ -1,12 +0,0 @@
#!/bin/bash
# set -o xtrace ## To debug scripts
# set -o errexit ## To exit on error
# set -o errunset ## To exit if a variable is referenced but not set
function main() {
# GTK_DEBUG=interactive python3 ./PyTop.py
python3 ./PyTop.py
}
main $@;

4
src/Pytop/PyTop.py → src/Pytop/__init__.py Normal file → Executable file
View File

@ -19,7 +19,7 @@ from signal_classes import CrossClassSignals, GridSignals, TaskbarSignals, DrawS
class Main:
def __init__(self):
def __init__(self, args):
setproctitle('Pytop')
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit)
faulthandler.enable() # For better debug info
@ -74,4 +74,4 @@ if __name__ == "__main__":
main = Main()
gtk.main()
except Exception as e:
print(e)
print( repr(e) )

35
src/Pytop/__main__.py Normal file
View File

@ -0,0 +1,35 @@
#!/usr/bin/python3
# Python imports
import argparse
import pdb # For trace debugging
from setproctitle import setproctitle
# Gtk imports
import gi, faulthandler, signal
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk as gtk
from gi.repository import GLib
# Application imports
from __init__ import Main
if __name__ == "__main__":
try:
# pdb.set_trace()
setproctitle('Pytop')
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
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")
# Read arguments (If any...)
args = parser.parse_args()
main = Main(args)
gtk.main()
except Exception as e:
print( repr(e) )

View File

@ -7,14 +7,6 @@
<mime-type>inode/directory</mime-type>
</mime-types>
</object>
<object class="GtkAdjustment" id="brushSizeProp">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
<signal name="value-changed" handler="onBrushSizeChange" swapped="no"/>
</object>
<object class="GtkWindow" id="Window">
<property name="can_focus">False</property>
<property name="default_width">800</property>
@ -42,6 +34,26 @@
<placeholder/>
</child>
<child type="center">
<object class="GtkButtonBox" id="taskBarWorkspacesVer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">start</property>
<signal name="button-release-event" handler="showSystemStats" swapped="no"/>
<child>
<placeholder/>
</child>
<child type="center">
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkFileChooserButton" id="selectDirDialog">
<property name="visible">True</property>
<property name="can_focus">False</property>
@ -50,26 +62,11 @@
<property name="title" translatable="yes">Directory Chooser</property>
<signal name="file-set" handler="setNewDirectory" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="taskBarWorkspacesVer">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="layout_style">start</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
<property name="position">2</property>
</packing>
</child>
</object>
@ -108,58 +105,6 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkColorButton" id="brushColorProp">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_alpha">True</property>
<property name="rgba">rgb(138,226,52)</property>
<signal name="color-set" handler="onColorSet" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkDrawingArea" id="drawArea">
<property name="height_request">60</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="configure-event" handler="onConfigure" swapped="no"/>
<signal name="draw" handler="onDraw" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">brushSizeProp</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
@ -265,6 +210,9 @@
<property name="width_request">126</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="justify">center</property>
<property name="track_visited_links">False</property>
<attributes>
<attribute name="scale" value="1.5"/>
@ -304,6 +252,68 @@
</object>
</child>
</object>
<object class="GtkAdjustment" id="brushSizeProp">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
<signal name="value-changed" handler="onBrushSizeChange" swapped="no"/>
</object>
<object class="GtkPopover" id="systemStats">
<property name="width_request">500</property>
<property name="height_request">0</property>
<property name="can_focus">False</property>
<property name="relative_to">taskBarWorkspacesVer</property>
<property name="position">bottom</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkColorButton" id="brushColorProp">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_alpha">True</property>
<property name="rgba">rgb(138,226,52)</property>
<signal name="color-set" handler="onColorSet" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkDrawingArea" id="drawArea">
<property name="height_request">60</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="configure-event" handler="onConfigure" swapped="no"/>
<signal name="draw" handler="onDraw" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">brushSizeProp</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
<object class="GtkImage" id="createImage">
<property name="visible">True</property>
<property name="can_focus">False</property>

View File

@ -18,8 +18,10 @@ class CrossClassSignals:
# Displays Timer
def displayclock(self):
now = datetime.now()
timeStr = now.strftime("%I:%M %p %m/%d/%Y")
now = datetime.now()
hms = now.strftime("%I:%M %p")
mdy = now.strftime("%m/%d/%Y")
timeStr = hms + "\n" + mdy
self.timeLabel.set_label(timeStr)
return True

2
src/Pytop/signal_classes/DrawSignals.py Normal file → Executable file
View File

@ -111,7 +111,7 @@ class DrawSignals:
ah = area.get_allocated_height()
self.aw = aw
self.ah = ah
self.xStep = aw / 200 # For x-axis 60 * 2 per 1 sec steps
self.xStep = aw / 200 # For x-axis
self.yStep = ah / 100 # For y-axis %s
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, aw, ah)
self.brush = cairo.Context(self.surface)

View File

@ -16,6 +16,13 @@ from gi.repository import GLib
# Application imports
class MouseButton:
LEFT_BUTTON = 1
MIDDLE_BUTTON = 2
RIGHT_BUTTON = 3
class TaskbarSignals:
def __init__(self, settings):
self.settings = settings
@ -32,7 +39,7 @@ class TaskbarSignals:
now = datetime.now()
timeStr = now.strftime("%m/%d/%Y")
parts = timeStr.split("/")
month = int(parts[0])
month = int(parts[0]) - 1
day = int(parts[1])
year = int(parts[2])
calendarWid.select_day(day)
@ -42,6 +49,10 @@ class TaskbarSignals:
calendarPopup.popdown()
def showSystemStats(self, widget, eve):
if eve.type == gdk.EventType.BUTTON_RELEASE and eve.button == MouseButton.RIGHT_BUTTON:
self.builder.get_object('systemStats').popup()
def setPagerWidget(self):
pager = wnck.Pager()

55
src/Pytop/utils/Logger.py Normal file
View File

@ -0,0 +1,55 @@
# Python imports
import os, logging
# Application imports
class Logger:
def __init__(self):
self.USER_HOME = os.path.expanduser("~")
def get_logger(self, loggerName = "NO_LOGGER_NAME_PASSED", createFile = True):
"""
Create a new logging object and return it.
:note:
NOSET # Don't know the actual log level of this... (defaulting or literally none?)
Log Levels (From least to most)
Type Value
CRITICAL 50
ERROR 40
WARNING 30
INFO 20
DEBUG 10
:param loggerName: Sets the name of the logger object. (Used in log lines)
:param createFile: Whether we create a log file or just pump to terminal
:return: the logging object we created
"""
globalLogLvl = logging.DEBUG # Keep this at highest so that handlers can filter to their desired levels
chLogLevel = logging.CRITICAL # Prety musch the only one we change ever
fhLogLevel = logging.DEBUG
log = logging.getLogger(loggerName)
# Set our log output styles
fFormatter = logging.Formatter('[%(asctime)s] %(pathname)s:%(lineno)d %(levelname)s - %(message)s', '%m-%d %H:%M:%S')
cFormatter = logging.Formatter('%(pathname)s:%(lineno)d] %(levelname)s - %(message)s')
ch = logging.StreamHandler()
ch.setLevel(level=chLogLevel)
ch.setFormatter(cFormatter)
log.addHandler(ch)
if createFile:
folder = self.USER_HOME + ".config/pytop/logs"
file = folder + "/application.log"
if not os.path.exists(folder):
os.mkdir(folder)
fh = logging.FileHandler(file)
fh.setLevel(level=fhLogLevel)
fh.setFormatter(fFormatter)
log.addHandler(fh)
return log

View File

@ -15,6 +15,7 @@ import os, json
class Settings:
def __init__(self, monIndex = 0):
self.builder = None
self.SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__)) + "/"
# 'Filters'
self.office = ('.doc', '.docx', '.xls', '.xlsx', '.xlt', '.xltx', '.xlm',
@ -76,7 +77,7 @@ class Settings:
def attachBuilder(self, builder):
self.builder = builder
self.builder.add_from_file("resources/PyTop.glade")
self.builder.add_from_file(self.SCRIPT_PTH + "../resources/Main_Window.glade")
def createWindow(self):
# Get window and connect signals
@ -93,7 +94,7 @@ class Settings:
# bind css file
cssProvider = gtk.CssProvider()
cssProvider.load_from_path('resources/stylesheet.css')
cssProvider.load_from_path(self.SCRIPT_PTH + '../resources/stylesheet.css')
screen = gdk.Screen.get_default()
styleContext = gtk.StyleContext()
styleContext.add_provider_for_screen(screen, cssProvider, gtk.STYLE_PROVIDER_PRIORITY_USER)
@ -113,6 +114,10 @@ class Settings:
return monitors
def returnMonitorsInfo(self):
return self.monitors
def saveSettings(self, startPath):
data = {}
data['pytop_settings'] = []
@ -125,10 +130,6 @@ class Settings:
json.dump(data, outfile)
def returnMonitorsInfo(self):
return self.monitors
def returnSettings(self):
returnData = []

View File

@ -1,3 +1,4 @@
from utils.Dragging import Dragging
from utils.Settings import Settings
from .Logger import Logger
from utils.FileHandler import FileHandler
from utils.Settings import Settings

View File

@ -48,7 +48,6 @@ class Grid:
self.grid.connect("button_release_event", self.iconSingleClick, (self.grid,))
def setNewDirectory(self, path):
self.store.clear()
self.currentPath = path
dirPaths = ['.', '..']
vids = []
@ -109,9 +108,15 @@ class Grid:
@threaded
def updateGrid(self, model, dirPath, file, i):
image = self.iconFactory.createThumbnail(dirPath, file).get_pixbuf()
iter = model.get_iter_from_string(str(i))
glib.idle_add(self.replaceInGrid, (iter, image,))
# Sinking errors b/c too lazy to find why we get some invalid tree paths when starting..
# I really should take time to figure it out...buuuutttt....it's non-fatal. (For now.)
# Images don't seem to always load which is curious...
try:
image = self.iconFactory.createThumbnail(dirPath, file).get_pixbuf()
iter = model.get_iter_from_string(str(i))
glib.idle_add(self.replaceInGrid, (iter, image,))
except Exception as e:
print("widgets/Grid.py sinking errors on updateGrid method...")
def addToGrid(self, dataSet):
self.store.append([dataSet[0], dataSet[1]])
@ -127,6 +132,7 @@ class Grid:
fileName = model[item][1]
dir = self.currentPath
file = dir + "/" + fileName
self.store.clear()
if fileName == ".":
self.setNewDirectory(dir)

View File

@ -58,7 +58,7 @@ class Icon:
return thumbnl
except Exception as e:
print("Thumbnail generation issue:")
print(e)
print( repr(e) )
return gtk.Image.new_from_file(self.SCRIPT_PTH + "../resources/icons/video.png")
@ -85,7 +85,7 @@ class Icon:
return thumbnl
except Exception as e:
print("Icon generation issue:")
print(e)
print( repr(e) )
return gtk.Image.new_from_file(self.INTERNAL_ICON_PTH)
@ -141,7 +141,7 @@ class Icon:
return self.createScaledImage(altIconPath, self.systemIconImageWH)
except Exception as e:
print(".desktop icon generation issue:")
print(e)
print( repr(e) )
return None
@ -162,7 +162,7 @@ class Icon:
return None
except Exception as e:
print("system icon generation issue:")
print(e)
print( repr(e) )
return None
@ -173,7 +173,7 @@ class Icon:
return gtk.Image.new_from_pixbuf(scaledPixBuf)
except Exception as e:
print("Image Scaling Issue:")
print(e)
print( repr(e) )
return None
def generateVideoThumbnail(self, fullPath, hashImgPth):
@ -209,4 +209,4 @@ class Icon:
proc.wait()
except Exception as e:
print("Video thumbnail generation issue in thread:")
print(e)
print( repr(e) )

View File

@ -5,6 +5,6 @@ using namespace std;
int main() {
chdir("/opt/Pytop/");
system("python3 PyTop.py");
system("python3 .");
return 0;
}