Send Motion-user mailing list submissions to
        motion-user@lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.sourceforge.net/lists/listinfo/motion-user
or, via email, send a message with subject or body 'help' to
        motion-user-requ...@lists.sourceforge.net

You can reach the person managing the list at
        motion-user-ow...@lists.sourceforge.net

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Motion-user digest..."


Today's Topics:

   1. Little useful tkinter program to accompany motion (Rainer)
   2. Re: MySQL - access denied (Bill Visick)


----------------------------------------------------------------------

Message: 1
Date: Wed, 17 Mar 2021 19:15:17 -0400
From: Rainer <feyerpictu...@gmail.com>
To: motion-user@lists.sourceforge.net
Subject: [Motion-user] Little useful tkinter program to accompany
        motion
Message-ID: <83c02f14-0dc3-8710-d58c-32eecd8b6...@gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed

Hey all,

I have pretty much finished with the little tkinter/ python program I 
wrote to View, Move, Delete, Copy the files generated by motion.

If anyone can use it - be my guest. If anyone has suggestions/ 
improvements: I will love to hear.

I am NOT a brain when it comes to motion and python - the code below is 
about 50% gotten off the internet forums then changed by me, with a good 
amount of additions I researched.

The first portion is rGUIConfig.py (save the code with that filename 
exactly). the variables created in it are used by the main program for 
folder directories mainly in which clips are saved. and also a folder 
name where you which to copy (archive) files into.

-------------------------------------------------------------------------------

#!/usr/bin/python3
# -*- coding: utf-8 -*-
# name this file rGUIconfig.py
# the below variables are used in the main program and correspond to the 
folders used for the lcips and pictures (if you are savig pictures) from 
each camera. So, garage is a camera mounted at our garage, mountains a 
camera pointed at the mountains etc etc

dest_import = "/mnt/data/Motion_Data/Clip_Archive/"

orig_import = "/mnt/data/Motion_Data/Motion_Clips/Garage-62/"

garage_import = "/mnt/data/Motion_Data/Motion_Clips/Garage-62/"
garage_p_import = "/mnt/data/Motion_Data/Motion_Snapshots/sGarage-62/"
mountains_import = "/mnt/data/Motion_Data/Motion_Clips/Mountains-86/"
mountains_p_import = "/mnt/data/Motion_Data/Motion_Snapshots/sMountains-86/"
tocoop_import = "/mnt/data/Motion_Data/Motion_Clips/HouseToCoop-90/"
tocoop_p_import = "/mnt/data/Motion_Data/Motion_Snapshots/sHouseToCoop-90/"
tractor_import? = "/mnt/data/Motion_Data/Motion_Clips/Tractor-60/"
tractor_p_import = "/mnt/data/Motion_Data/Motion_Snapshots/sTractor-60/"

-----------------------------------------------------------------------------------

The second program code can be saved under any file name with .py 
extension (mine is called mRaiGUI.py)

----------------------------------------------------------------------


# When viewing video clips, instruction are on south side of frame
# When viewing Images, it is best to pause auto play (right click on 
display Frame
#? and then right arrow to next clips. '<' will go backwards a few frames.

import tkinter as tk
from tkinter import *
import os
from os import listdir
from os.path import isfile, join
import shutil
from tkinter import ttk, messagebox
import webbrowser
import mpv

if os.environ.get('DISPLAY','') == "":
 ??? print('no display found.Using :0.0')
 ??? os.environ.__setitem__('DISPLAY',':0.0')

## These variables imported from rGUIconfig rpresent paths to directories
## of camera pictures and clips. I use separate folders for each.
## rGUIconfig should first be set to the paths in order to find the 
Clips/Pics
## Also, the below section of 'def RadioButtons' has to be set up to 
correspond
## to the cameras being used; and the 'values' of each radioButton used 
for each camera (which corresponds
## to the variables imported from rGUIimport below here
from rGUIconfig import dest_import,? orig_import
from rGUIconfig import garage_import, garage_p_import
from rGUIconfig import mountains_import, mountains_p_import
from rGUIconfig import tocoop_import, tocoop_p_import
from rGUIconfig import tractor_import, tractor_p_import

from rGUIconfig import archive_import

root = tk.Tk()
root.title("MotionGUI")
root.geometry("1500x800")
root.minsize(width=900, height=600)
 ??? #root.maxsize(width=1400, height = 900)
root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(0, weight=1)
root.configure( bg = '#000080' )

global selected_text_list
global directory
global dest_loc
global fl_var

directory = StringVar()
directory = orig_import

dest_loc = dest_import
inRadio = StringVar()
fl_var = StringVar()
fl_var = "Name of File Playing"


########## Frames #########

DisplayFrame = tk.Frame(root, width=1400, height = 760, bg = 
'#152053')?????? #0059b3')
DisplayFrame.grid(column=0,row=0, in_ = root)

rightFrame = tk.Frame(root, width = 100, height = 790, bg = '#000080')
rightFrame.grid(column = 1, row = 0)

lbFrame = tk.Frame(root, height = 470, width = 170, bg = 'black')
lbFrame.grid(column = 0, row = 0, in_ = root)

##'W' stands for West = WrightFrmae (west fframe on the right of screen
WrightFrame = tk.Frame(rightFrame, width = 70, height = 300, bg = '#000080')
WrightFrame.grid(column = 0, row = 1)

WidgetFrame = tk.Frame(rightFrame, height = 300, width = 70, bg = '#000080')
WidgetFrame.grid(column=0,row=0)

player = mpv.MPV(wid=str(int(DisplayFrame.winfo_id())), hwdec = 'auto',
input_default_bindings=True,input_vo_keyboard=True,osc=True)
# ? add above: hwdec='auto' # also, can try ao='null'


def SelectAll():
 ??? lb.select_set(0, END)

def SourceBrowse():
 ??? player.stop()
 ??? global directory
 ??? directory = inRadio.get()
 ??? lbFrame.lift()
 ??? if not directory:
 ??????? print("it's empty!")
 ??????? directory = orig_import
 ??? populate_lb()


def ViewFile():
 ??? lbFrame.lower()? ## lbFrame.lift() to raise back up
 ??? DisplayFrame.lift()
 ??? player.stop()
 ??? global directory
 ??? selected_text_list = [lb.get(i) for i in lb.curselection()]
 ??? for f in selected_text_list:
 ??????? path_and_file = directory + f
 ??????? player.playlist_append(path_and_file)
 ??????? player.playlist_pos = 0

def stop_player():
 ??? player.stop()
 ??? lbFrame.lift()

def MotionHTTP():
 ?? webbrowser.open("http://192.168.0.26:8080";)? ## point this toward 
your motion setup, obviously don't use mine

def CopyFile():
 ??? global directory
 ??? selected_text_list = [lb.get(i) for i in lb.curselection()]
 ??? destination_location = dest_loc
 ??? # Looping through the files present in the list
 ??? for f in selected_text_list:
 ??????? path_and_file = directory + f
 ??????? shutil.copy(path_and_file, destination_location)
 ??? SourceBrowse()


def MoveFile():
 ??? global directory
 ??? selected_text_list = [lb.get(i) for i in lb.curselection()]
 ??? destination_location = dest_loc
 ??? for f in selected_text_list:
 ??????? path_and_file = directory + f
 ??????? shutil.move(path_and_file, destination_location)
 ??? SourceBrowse()

def DeleteFile():
 ??? global directory
 ??? selected_text_list = [lb.get(i) for i in lb.curselection()]
 ??? for f in selected_text_list:
 ??????? path_and_file = directory + f
 ??????? os.remove(path_and_file)

# the below radio buttons should correspond the imported variables 
fromrGuiconfi.py - corresponding tot he cameras you have
def Rad_Buttons():
 ??? vGarage??? = tk.Radiobutton(WidgetFrame, 
text="Garage",variable=inRadio,value = garage_import, command = 
SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 
10).grid(row=1,column=0,pady=0 )
 ??? pGarage??? = tk.Radiobutton(WidgetFrame, 
text="Pics",variable=inRadio,value = garage_p_import, command = 
SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 
7).grid(row=1,column=1,pady=0 )
 ??? vMountains = tk.Radiobutton(WidgetFrame, text="Mountains", 
variable=inRadio, value = mountains_import, command = SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 10).grid(row = 
2, column = 0, pady = 0 )
 ??? pMountains = tk.Radiobutton(WidgetFrame, 
text="Pics",variable=inRadio,value = mountains_p_import, command = 
SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 
7).grid(row=2,column=1,pady=0 )
 ??? vToCoop??? = tk.Radiobutton(WidgetFrame, text="To Coop", 
variable=inRadio, value = tocoop_import, command = SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 10).grid(row = 
3, column = 0, pady = 0 )
 ??? pToCoop??? = tk.Radiobutton(WidgetFrame, 
text="Pics",variable=inRadio,value = tocoop_p_import, command = 
SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 
7).grid(row=3,column=1,pady=0 )
 ??? vToTractor = tk.Radiobutton(WidgetFrame, text="To Tractor", 
variable=inRadio, value = tractor_import, command = SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 10).grid(row = 
4, column = 0, pady = 0 )
 ??? pToTractor = tk.Radiobutton(WidgetFrame, text="Pics", 
variable=inRadio, value = tractor_p_import, command = SourceBrowse,
 ??????????????????????????????? bg = '#FFEBCD', width = 7).grid(row = 
4, column = 1, pady = 0 )



ClipLabel = tk.Label(WidgetFrame, text = "Video Clips")
ClipLabel.grid( column = 0, row = 0 )
PicLabel = tk.Label(WidgetFrame, text = "Pictures")
PicLabel.grid( column = 1, row = 0 )

source_browseButton = tk.Button(WrightFrame, text ="Browse Clips/Pics", 
command = SourceBrowse, width = 17, bg='#F4A460')
source_browseButton.grid(row = 0, column = 0, pady = 7, padx = 7)


AllSelectButton = Button(WrightFrame, text= 'Select All', command = 
SelectAll )
AllSelectButton.grid( column = 0, row = 1 )

viewButton = tk.Button(WrightFrame, text ="View File(s)", command = 
ViewFile, width = 15, bg= "#F4A460")
viewButton.grid(column = 0, row = 2, pady = 5, padx = 5)

stop_button = tk.Button(WrightFrame, text="Stop Viewing",? width = 15, 
command = stop_player, bg= "#F4A460")
stop_button.grid(column=0,row=3, pady = 5, padx = 5 )

MotionButton = tk.Button(WrightFrame, text="IP Streams", width = 15, 
command=MotionHTTP, bg= "cyan")
MotionButton.grid(column = 0, row = 4, pady = 1,padx = 1)

additionButton = tk.Button(WrightFrame, text = "Addition", width = 15, 
command = additionHTTP, bg= "cyan")
additionButton.grid(column = 0, row = 5)

coopButton = tk.Button(WrightFrame, text = "Coop",? width = 15,command = 
coopHTTP, bg= "cyan")
coopButton.grid(column = 0, row = 6)

viewInstruction = ttk.Label(root, text = "'Right Click' = Pause or Play; 
'[' = reduce speed or ']' = increase, " +
 ???????????????????????????????????????? "'<' = previous 10 secs,'>' = 
next 10';for pictues, right arrow to advance")
viewInstruction.grid(row = 1, column = 0)

copyButton = tk.Button(WrightFrame, text ="Copy File", command = 
CopyFile, width = 17, bg= "yellow")
copyButton.grid(row = 8, column = 0, pady = 5, padx = 5)

moveButton = tk.Button(WrightFrame, text ="Move File", command = 
MoveFile, width = 17, bg= "yellow")
moveButton.grid(row = 9, column = 0, pady = 5, padx = 5)

deleteButton = tk.Button(WrightFrame, text ="Delete File(s)", command = 
DeleteFile,bg='red', width = 17)
deleteButton.grid(row = 10, column = 0, pady = 7, padx = 7)

exitButton = tk.Button(WrightFrame, text="Quit the Program", width = 17, 
command=root.destroy, bg= "magenta")
exitButton.grid(row = 11, column = 0,pady = 10, padx = 10)


# for scrolling vertically
yscrollbar = Scrollbar(lbFrame)
yscrollbar.pack(side = RIGHT, fill = Y )

lb = Listbox(lbFrame, height = 40, width = 50, selectmode = 
"extended",yscrollcommand = yscrollbar.set,
 ???????????? bg = '#153549', fg = 'white', selectbackground = 'lime')
lb.bind("<Double-1>", lambda x: viewButton.invoke())
lb.pack(padx = 2, pady = 2, fill = "both")
yscrollbar.config(command = lb.yview)


# Populating listbox: filenames only, then add directory when 
manipulating files
def populate_lb():
 ??? global directory
 ??? lb.delete(0, END)? #clear listbox
 ??? file_list = [f for f in listdir(directory) if 
isfile(join(directory,f))]
 ??? sorted_list = sorted(file_list, reverse=True)
 ??? for file in sorted_list:
 ??????? lb.insert(0, file)

populate_lb()

# define all Radio Buttons
Rad_Buttons()

root.mainloop()





------------------------------

Message: 2
Date: Thu, 18 Mar 2021 12:19:31 +0000 (GMT)
From: Bill Visick <bvis...@btinternet.com>
To: Motion discussion list <motion-user@lists.sourceforge.net>
Subject: Re: [Motion-user] MySQL - access denied
Message-ID: <6c1ef69c.253ac.1784546cc7b.webtop...@btinternet.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"


Thaanks to Tosaria for his comment, sorry I can't see how to respond 
directly to it!


Anyway, I understand motion can't fix mysql problems but was hoping 
there was maybe a config option that I'd set wrong somewhere.

On the command prompt I enter:
./mysql -u root -pxxxxxxxxxx

and get:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 41
Server version: 10.3.21-MariaDB Source distribution
etc.

For info, the user table has:
+-----------+------+
| host      | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1       | root |
| localhost | root |
+-----------+------+

Could there be a path problem? At the command prompt I have to cd to the 
relevant directory first (/usr/local/mariadb10/bin) but the fact that 
motion says Access denied rather than being unable to find mysql 
suggests that's not the problem.



Regards
      Bill Visick


------ Original Message ------
From: "Bill Visick via Motion-user" <motion-user@lists.sourceforge.net>
To: motion-user@lists.sourceforge.net
Cc: "Bill Visick" <bvis...@btinternet.com>
Sent: Wednesday, 17 Mar, 21 At 17:31
Subject: [Motion-user] MySQL - access denied

I'm trying to insert records in a database but motion can't connect to 
it. I have the following in motion.conf:


database_type mysql
database_dbname clips
daabase_host localhost
database_port 3306
database_user root
database_password xxxxxxxxxxxxxxxx
sql_log_picture on
sql_log_snapshot on
sql_log_movie on
sql_query insert into motion(camera, filename, event, frame, file_type, 
time_stamp, text_event) values('%$_%t', '%f', '%v', '%q', '%n', 
'%Y-%m-%d %T', '%C')

In motion.log I get:

motion_init: Database backend mysql
motion_init: Cannot connect to MySQL database clips on host localhost 
with user root
motion_init: MySQL error was Access denied for user 'root'@'localhost' 
(using password: YES)
motion_loop: Thread exiting

I can log in to MySQL successfully using the same credentials from a 
command prompt.

I'm sure I'm missing something simple, thanks very much for any 
suggestions.


Bill Visick

  _______________________________________________
Motion-user mailing list
Motion-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/motion-user 
<https://lists.sourceforge.net/lists/listinfo/motion-user>
https://motion-project.github.io/ <https://motion-project.github.io/>
Unsubscribe: https://lists.sourceforge.net/lists/options/motion-user 
<https://lists.sourceforge.net/lists/options/motion-user>
-------------- next part --------------
An HTML attachment was scrubbed...

------------------------------



------------------------------

Subject: Digest Footer

_______________________________________________
Motion-user mailing list
Motion-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/motion-user


------------------------------

End of Motion-user Digest, Vol 177, Issue 7
*******************************************

Reply via email to