MRTestRepo/PepProTools/hub.py

535 lines
23 KiB
Python
Executable File

#!/usr/bin/env python3
"""This is for the Hub GUI """
from tkinter import PhotoImage
from tendo import singleton
from os import path
import tkinter as tk
import tkinter.ttk as ttk
import sqlite3
import subprocess
import putilities
import actions
import os.path
# data connection srting
conn = sqlite3.connect('/opt/pypep/dbpep/welval.db')
pcur = conn.cursor()
# Create the table if it does not exist
pcur.execute(
""" CREATE TABLE IF NOT EXISTS hbchk
( id integer PRIMARY KEY AUTOINCREMENT, hstat text); """
)
conn.commit()
conn.close()
# see if there is a record table.
# If the table is empty then make a new
# record and set the hstat value to off
def newrech():
db = sqlite3.connect('/opt/pypep/dbpep/welval.db')
hbcur = db.cursor()
hbcur.execute("SELECT COUNT(*) FROM hbchk LIMIT 1")
hbckempty = hbcur.fetchall()
if hbckempty[0][0] == 0:
newrec = """ INSERT INTO hbchk(hstat) VALUES ('off'); """
hbcur.execute(newrec)
db.commit()
db.close()
# makes sure only a single instance is running
me = singleton.SingleInstance()
x = 1
class PepHub(tk.Tk):
def __init__(self):
super().__init__()
self.title("Peppermint Hub")
self.style = ttk.Style(self)
self.style.theme_use('clam')
self.resizable(False, False)
# styling for darker theme here
self.style.configure('TFrame', background='#2f2f2f')
self.style.configure('TLabel', background='#2f2f2f',
foreground='#ffffff')
self.style.configure(
'TButton',
background='#2f2f2f',
bordercolor='#ffffff',
lightcolor='#3b4536',
darkcolor='#0A0B0B',
)
self.style.map("TButton", background=[(
'pressed', '#1d221b'), (
'active', '#272e24')], darkcolor=[(
'pressed', '#0c0e0b')], lightcolor=[(
'pressed', '#0c0e0b')])
self.tk.call('wm', 'iconphoto',
self._w, tk.PhotoImage(
file='/usr/share/pixmaps/peppermint-old.png'))
detpmt = ttk.Style()
detpmt.configure(
"det.TLabel",
foreground="#ffffff",
background="#2f2f2f",
font=(
'Helvetica',
'12',
'underline'))
detpmtsmall = ttk.Style()
detpmtsmall.configure(
"detsm.TLabel",
foreground="yellow",
background="#2f2f2f",
font=('Helvetica', '10', 'italic'))
# The tabbing feature
pnb = ttk.Notebook(self)
pnb.pack(expand=True)
# tabs and thier sized.
tbdes = ttk.Frame(pnb, padding=30)
tbsys = ttk.Frame(pnb, padding=30)
# the tab names
pnb.add(tbdes, text='Desktop Environment Settings')
pnb.add(tbsys, text='Hardware & Software')
# icons section - used self.name since regular assignment
# ended with all images being garbage collected
# xfce settings icons
self.icosm = PhotoImage(
file="/usr/share/pixmaps/applications-system.png")
self.icopwm = PhotoImage(file="/usr/share/pixmaps/battery.png")
self.icomtp = PhotoImage(file="/usr/share/pixmaps/mouse.png")
self.icoclf = PhotoImage(file="/usr/share/pixmaps/glade.png")
self.icopp = PhotoImage(file="/usr/share/pixmaps/panel-applets.png")
self.icons = PhotoImage(file="/usr/share/pixmaps/cs-notifications.png")
self.icopa = PhotoImage(
file="/usr/share/pixmaps/cs-default-applications.png")
self.icoks = PhotoImage(file="/usr/share/pixmaps/keyboard.png")
self.icomon = PhotoImage(file="/usr/share/pixmaps/video-display.png")
self.icoas = PhotoImage(
file="/usr/share/pixmaps/preferences-desktop-accessibility.png")
#Harware & Software
self.icont = PhotoImage(file="/usr/share/pixmaps/network-wired.png")
self.icoptr = PhotoImage(
file="/usr/share/pixmaps/gnome-dev-printer.png")
self.icodconf = PhotoImage(file="/usr/share/pixmaps/dconf-editor.png")
self.icopav = PhotoImage(
file="/usr/share/pixmaps/stock_music-library.png")
self.icoug = PhotoImage(file="/usr/share/pixmaps/stock_people.png")
self.icodu = PhotoImage(
file="/usr/share/pixmaps/drive-harddisk-system.png")
self.icoum = PhotoImage(file="/usr/share/pixmaps/update-manager.png")
self.icosi = PhotoImage(file="/usr/share/pixmaps/gnome-session.png")
self.icoflat = PhotoImage(file="/usr/share/pixmaps/flat.png")
self.icosnap = PhotoImage(file="/usr/share/pixmaps/snap.png")
self.icoice = PhotoImage(file="/opt/pypep/icesm.png")
self.icoaih = PhotoImage(file="/usr/share/pixmaps/ai.png")
self.icospm = PhotoImage(file="/usr/share/pixmaps/synaptic.png")
self.icogno = PhotoImage(file="/usr/share/pixmaps/gnome-software.png")
self.icoghboff = PhotoImage(file="/usr/share/pixmaps/hblock.png")
self.icoghbon = PhotoImage(file="/usr/share/pixmaps/hblockon.png")
# Install Icons
self.icocr = PhotoImage(
file="/usr/share/pixmaps/peppermint-inst-48.png")
def hbon():
db = sqlite3.connect('/opt/pypep/dbpep/welval.db')
uphbon = """ UPDATE hbchk SET hstat = 'on';"""
updcur = db.cursor()
updcur.execute(uphbon)
db.commit()
db.close()
btnhbof.lower()
btnhbon.grid(row=11, column=2, ipadx=2, ipady=2, padx=2, pady=2)
cmd = "xfce4-terminal -e 'bash -c \"hblock exit 0\";bash'"
subprocess.Popen(cmd, shell=True)
# Turn off hblock
def hboff():
db = sqlite3.connect('/opt/pypep/dbpep/welval.db')
uphbof = """ UPDATE hbchk SET hstat = 'off';"""
updocur = db.cursor()
updocur.execute(uphbof)
db.commit()
db.close()
btnhbon.lower()
btnhbof.grid(row=11, column=2, ipadx=2, ipady=2, padx=2, pady=2)
cmd = "xfce4-terminal -e 'bash -c \"hblock -S none -D none exit 0\";bash'"
subprocess.Popen(cmd, shell=True)
# Button Section - Use this area to manage and configure the buttone on each tab.
# xfce settings
btnsm = ttk.Button(tbdes,
text='Settings Manager',
width='20',
command=actions.osettingsmgr,
image=self.icosm, cursor="hand2")
btnas = ttk.Button(tbdes,
text='Accessibilitity Settings',
width='20',
command=actions.ssas,
image=self.icoas,
cursor="hand2")
btndis = ttk.Button(tbdes,
text='Display',
width='20',
command=actions.nhdis,
image=self.icomon, cursor="hand2")
btnpmgr = ttk.Button(tbdes,
text='Power Manager',
width='20',
command=actions.nhpom,
image=self.icopwm, cursor="hand2")
btmtp = ttk.Button(tbdes,
text='Mouse and Touchpad',
width='20',
command=actions.omt,
image=self.icomtp, cursor="hand2")
btnks = ttk.Button(tbdes,
text='Keyboard',
width='20',
command=actions.oks,
image=self.icoks, cursor="hand2")
btnclf = ttk.Button(tbdes,
text='Customize Look and Feel',
width='20',
command=actions.oclf,
image=self.icoclf, cursor="hand2")
btnpp = ttk.Button(tbdes,
text='Panel Preferences',
width='20',
command=actions.opp,
image=self.icopp, cursor="hand2")
btnns = ttk.Button(tbdes,
text='Notification Settings',
width='20',
command=actions.ons,
image=self.icons, cursor="hand2")
btnpa = ttk.Button(tbdes,
text='Preferred Applications',
width='20',
command=actions.opa,
image=self.icopa, cursor="hand2")
#system & hardware
btnnm = ttk.Button(tbsys,
text='Network Manager',
width='20',
command=actions.nhnm,
image=self.icont, cursor="hand2")
btnprint = ttk.Button(tbsys,
text='Printers',
width='20', command=actions.nhpr,
image=self.icoptr, cursor="hand2")
btdconf = ttk.Button(tbsys,
text='dconf Editor',
width='20',
command=actions.odeconf,
image=self.icodconf, cursor="hand2")
btnuag = ttk.Button(tbsys,
text='Users & Groups',
width='20',
command=actions.ssug,
image=self.icoug,
cursor="hand2")
btnvol = ttk.Button(tbsys,
text='Pulse Audio Volume',
width='20', command=actions.nhpav,
image=self.icopav,
cursor="hand2")
btndu = ttk.Button(tbsys,
text='Disk Utilities',
width='20',
command=actions.ssdu,
image=self.icodu,
cursor="hand2")
btnupmgr = ttk.Button(tbsys,
text='Update Manager',
width='20',
image=self.icoum,
command=actions.ssum,
cursor="hand2")
btnsi = ttk.Button(tbsys,
text='System Information',
width='20',
command=actions.sssi,
image=self.icosi,
cursor="hand2")
btnflt = ttk.Button(tbsys,
text='Flathub',
width='20',
command=actions.ssfh,
image=self.icoflat,
cursor="hand2")
btnfltgnn = ttk.Button(tbsys,
text='Flathub Gnome Store',
width='20',
command=actions.ssfh,
image=self.icoflat,
cursor="hand2")
btnice = ttk.Button(tbsys,
text='ICE',
width='20',
command=actions.lice,
image=self.icoice,
cursor="hand2")
btnsnap = ttk.Button(tbsys,
text='Snap Store',
width='20',
command=actions.ssss,
image=self.icosnap,
cursor="hand2")
btnsnst = ttk.Button(tbsys,
text='Snap Store',
width='20',
command=actions.ssst,
image=self.icosnap,
cursor="hand2")
btnai = ttk.Button(tbsys,
text='App Image Hub',
width='20',
command=actions.ssai,
image=self.icoaih,
cursor="hand2")
btnsc = ttk.Button(tbsys,
text='Synaptic',
width='20',
command=actions.ssspm,
image=self.icospm,
cursor="hand2")
btncore = ttk.Button(tbsys,
text='Packages',
command=actions.packages,
image=self.icocr,
cursor="hand2")
btngnomesoftware = ttk.Button(tbsys,
text='Gnome Software',
command=actions.ssgn,
image=self.icogno,
cursor="hand2")
btngnomeweb = ttk.Button(tbsys,
text='Gnome Software',
command=actions.ssgns,
image=self.icogno,
cursor="hand2")
btnhbof = ttk.Button(tbsys,
text='hBlockRed',
command=hbon,
image=self.icoghboff,
cursor="hand2")
btnhbon = ttk.Button(tbsys,
text='hBlockgreen',
command=hboff,
image=self.icoghbon,
cursor="hand2")
# these are the label section - Use this area to manage the lables for the tabs
# xfcesettings
lblas = ttk.Label(tbdes,
text='Accessibilitity')
lblsm = ttk.Label(tbdes,
text='Settings Manager')
lblclf = ttk.Label(tbdes,
text='Appearance')
lblpp = ttk.Label(tbdes,
text='Panel')
lblns = ttk.Label(tbdes,
text='Notification Settings')
lblpa = ttk.Label(tbdes,
text='Default Applications')
lbldis = ttk.Label(tbdes,
text='Display')
lblpmgr = ttk.Label(tbdes,
text='Power Manager')
lblmtp = ttk.Label(tbdes,
text='Mouse and Touchpad')
lblks = ttk.Label(tbdes,
text='Keyboard')
lblcom = ttk.Label(tbdes,
style="det.TLabel",
text='Commonly used xfce settings')
lblall = ttk.Label(tbdes,
style="detsm.TLabel",
text='*Try the xfce Settings Manager')
# Hardware Labels
lblnm = ttk.Label(tbsys,
text='Network Connections')
lblprint = ttk.Label(tbsys,
text='Printers')
lbldu = ttk.Label(tbsys,
text='Disk Utilities')
lbluag = ttk.Label(tbsys,
text='Users & Groups')
lblvol = ttk.Label(tbsys,
text='Pulse Audio Volume')
lbldconf = ttk.Label(tbsys,
text='dconf Editor')
# Software Labels
lblcore = ttk.Label(tbsys,
text='Suggested Packages')
lblupmgr = ttk.Label(tbsys,
text='Update Manager')
lblsi = ttk.Label(tbsys,
text='System Information')
lblsnap = ttk.Label(tbsys,
text='Snap Store')
lblsnst = ttk.Label(tbsys,
text='Snap Store')
lblai = ttk.Label(tbsys,
text='App Image Hub')
lblsc = ttk.Label(tbsys,
text='Synaptic')
lblflt = ttk.Label(tbsys,
text='Flathub')
lblfltgnm = ttk.Label(tbsys,
text='Flathub')
lblgnome = ttk.Label(tbsys,
text='Gnome Store')
lblhb = ttk.Label(tbsys,
text='hBlock')
# xfce settings
btndis.grid(row=1, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnas.grid(row=1, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btnpp.grid(row=1, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btnclf.grid(row=3, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnpmgr.grid(row=3, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btnns.grid(row=3, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btnpa.grid(row=5, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btmtp.grid(row=5, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnks.grid(row=5, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btnsm.grid(row=9, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# Label POS
# xfce settings
lblcom.grid(
row=0,
column=0,
columnspan=3,
ipadx=2,
ipady=2,
padx=2,
pady=2)
lblas.grid(row=2, column=1, ipadx=2, ipady=2, padx=2, pady=2)
lblpp.grid(row=2, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lbldis.grid(row=2, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblclf.grid(row=4, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblns.grid(row=4, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lblpmgr.grid(row=4, column=1, ipadx=2, ipady=2, padx=2, pady=2)
lblmtp.grid(row=6, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblks.grid(row=6, column=1, ipadx=2, ipady=2, padx=2, pady=2)
lblpa.grid(row=6, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lblall.grid(
row=8,
column=0,
columnspan=3,
ipadx=2,
ipady=2,
padx=2,
pady=2)
lblsm.grid(row=10, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# Software Buttons
btncore.grid(row=7, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnsi.grid(row=7, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btnupmgr.grid(row=7, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btnai.grid(row=9, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btnsc.grid(row=9, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btnsnap.grid(row=11, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# System and hardware buttons
btnnm.grid(row=0, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnprint.grid(row=0, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btndu.grid(row=0, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btnvol.grid(row=2, column=2, ipadx=2, ipady=2, padx=2, pady=2)
btnuag.grid(row=2, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# Network label positioning
lblnm.grid(row=1, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblprint.grid(row=1, column=1, ipadx=2, ipady=2, padx=2, pady=2)
lbldu.grid(row=1, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lblvol.grid(row=3, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lblhb.grid(row=12, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lbluag.grid(row=3, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# Sofwtare
lblcore.grid(row=8, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblsi.grid(row=8, column=1, ipadx=2, ipady=2, padx=2, pady=2)
lblupmgr.grid(row=8, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lblai.grid(row=10, column=1, ipadx=2, ipady=2, padx=2, pady=2)
lblsc.grid(row=10, column=2, ipadx=2, ipady=2, padx=2, pady=2)
lblsnap.grid(row=12, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# Sql check stat
dbhb = sqlite3.connect('/opt/pypep/dbpep/welval.db')
hbofn = dbhb.cursor()
hbofn.execute("SELECT COUNT(*) FROM hbchk WHERE hstat ='on'")
hbresult = hbofn.fetchone()
dbhb.commit()
dbhb.close
# dconf condition
# cache['dconf-editor'].is_installed:
if putilities.installcheck('dconf-editor'):
lbldconf.grid(row=3, column=1, ipadx=2, ipady=2, padx=2, pady=2)
btdconf.grid(row=2, column=1, ipadx=2, ipady=2, padx=2, pady=2)
#check what version this is and hid and show buttons
if path.exists("/etc/devuan_version"):
btnsnap.destroy()
btnsnst.destroy()
lblsnap['text'] = "ICE"
lblsnst.destroy()
btnice.grid(row=11, column=0, ipadx=2, ipady=2, padx=2, pady=2)
elif path.exists("/etc/debian_version"):
# if snap is installed, open app, otherwise make a button to the snap
# store
if putilities.installcheck('snapd'): # cache['snapd'].is_installed:
btnsnst.grid(row=11, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblsnst.grid(row=12, column=0, ipadx=2, ipady=2, padx=2, pady=2)
else:
btnsnap.grid(row=11, column=0, ipadx=2, ipady=2, padx=2, pady=2)
lblsnap.grid(row=12, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# if FlatPak is installed, open the gnome store otherwise open flathub
# cache['flatpak'].is_installed:
if putilities.installcheck('flatpak'):
##If the Gnome store is installed dont show the Flatpak button
##If it is NOT installed Show the flatpak button
if putilities.installcheck('gnome-software'):
pass
else:
lblflt.grid(row=10, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnflt.grid(row=9, column=0, ipadx=2, ipady=2, padx=2, pady=2)
else:
lblflt.grid(row=10, column=0, ipadx=2, ipady=2, padx=2, pady=2)
btnflt.grid(row=9, column=0, ipadx=2, ipady=2, padx=2, pady=2)
# if gnome store is installed, link the applicaton, otherwise link to
# their website
# cache['gnome-software'].is_installed:
if putilities.installcheck('gnome-software'):
btngnomesoftware.grid(
row=11,
column=1,
ipadx=2,
ipady=2,
padx=2,
pady=2)
lblgnome.grid(row=12, column=1, ipadx=2, ipady=2, padx=2, pady=2)
else:
btngnomeweb.grid(
row=11,
column=1,
ipadx=2,
ipady=2,
padx=2,
pady=2)
lblgnome.grid(row=12, column=1, ipadx=2, ipady=2, padx=2, pady=2)
# see if the window should show or not.
if int(hbresult[0]) > 0:
btnhbon.grid(row=11, column=2, ipadx=2, ipady=2, padx=2, pady=2)
else:
btnhbof.grid(row=11, column=2, ipadx=2, ipady=2, padx=2, pady=2)
if __name__ == "__main__":
newrech()
PepHub().mainloop()