Browse Source

Update version and license in all files to 2.1 and MIT. Add two new client test files and a bash hack

master
Nils 3 years ago
parent
commit
ddf8449c62
  1. 2
      LICENSE
  2. 2
      README.md
  3. 92
      base.py
  4. 12
      exampleBoilerplate.py
  5. 11
      exampleQt.py
  6. 12
      exampleXlib.py
  7. 38
      label.py
  8. 9
      source_me_with_port.bash
  9. 8
      test-importResource.py

2
LICENSE

@ -1,6 +1,6 @@
MIT License
Copyright 2014-2019 Nils Hilbricht https://www.hilbricht.net
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,

2
README.md

@ -3,7 +3,7 @@ Non Session Manager client library in Python - No dependencies except Python3.
PyNSMClient - A Non Session Manager Client-Library in one file.
Copyright (c) 2014-2019, Nils Hilbricht <info@hilbricht.net>, All rights reserved.
Copyright (c) 2014-2020, Nils Hilbricht <info@hilbricht.net>, All rights reserved.
This library is licensed under the MIT license. Please check the file LICENSE for more information.

92
base.py

@ -0,0 +1,92 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyNSMClient 2.1 - A Non Session Manager Client-Library in one file.
The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
API documentation: http://non.tuxfamily.org/nsm/API.html
MIT License
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
from nsmclient import NSMClient
import sys
from time import sleep
import os
from threading import Timer
sys.path.append(os.getcwd())
class BaseClient(object):
def saveCallbackFunction(self, *args):
print (__file__, "save")
def openOrNewCallbackFunction(self, *args):
print (__file__,"open/new")
def exitCallbackFunction(self, *args):
print (__file__, "quit")
sys.exit()
def event(self):
pass
def __init__(self, delayedFunctions=[], eventFunction=None):
"""delayedFunctions are a (timer delay in seconds, function call) list of tuples. They will
be executed once.
If the function is a string instead it will be evaluated in the BaseClient context,
providing self. Do not give a lambda!
Give eventFunction for repeated execution."""
self.nsmClient = NSMClient(prettyName = "testclient_base", #will raise an error and exit if this example is not run from NSM.
saveCallback = self.saveCallbackFunction,
openOrNewCallback = self.openOrNewCallbackFunction,
supportsSaveStatus = False, # Change this to True if your program announces it's save status to NSM
exitProgramCallback = self.exitCallbackFunction,
hideGUICallback = None, #replace with your hiding function. You need to answer in your function with nsmClient.announceGuiVisibility(False)
showGUICallback = None, #replace with your showing function. You need to answer in your function with nsmClient.announceGuiVisibility(True)
loggingLevel = "info", #"info" for development or debugging, "error" for production. default is error.
)
if eventFunction:
self.event = eventFunction
for delay, func in delayedFunctions:
if type(func) is str:
func = eval('lambda self=self: ' + func )
t = Timer(interval=delay, function=func, args=())
t.start()
while True:
self.nsmClient.reactToMessage()
self.event()
sleep(0.05)
if __name__ == '__main__':
"""This is the most minimal nsm client in existence"""
BaseClient() #this never returns an object.

12
exampleBoilerplate.py

@ -1,10 +1,16 @@
#!/usr/bin/env python3
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyNSMClient 2.1 - A Non Session Manager Client-Library in one file.
The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
API documentation: http://non.tuxfamily.org/nsm/API.html
MIT License
Copyright 2014-2019 Nils Hilbricht https://www.hilbricht.net
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,

11
exampleQt.py

@ -1,9 +1,16 @@
#!/usr/bin/env python3
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyNSMClient 2.1 - A Non Session Manager Client-Library in one file.
The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
API documentation: http://non.tuxfamily.org/nsm/API.html
MIT License
Copyright 2014-2019 Nils Hilbricht https://www.hilbricht.net
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,

12
exampleXlib.py

@ -1,10 +1,16 @@
#!/usr/bin/env python3
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyNSMClient 2.1 - A Non Session Manager Client-Library in one file.
The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
API documentation: http://non.tuxfamily.org/nsm/API.html
MIT License
Copyright 2014-2019 Nils Hilbricht https://www.hilbricht.net
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,

38
label.py

@ -0,0 +1,38 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyNSMClient 2.1 - A Non Session Manager Client-Library in one file.
The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
API documentation: http://non.tuxfamily.org/nsm/API.html
MIT License
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import base
if __name__ == '__main__':
funcs = [
(1, 'self.nsmClient.changeLabel("Pretty Name")'),
#(4, lambda: print ("four")),
]
base.BaseClient(funcs) #this never returns an object.

9
source_me_with_port.bash

@ -0,0 +1,9 @@
#!/bin/bash
if [[ -z "$1" ]]; then
echo "Give NSM OSC Port as only parameter. Afterwards you can run the executable pythons in this dir, directly, without ./"
exit 1
fi
export NSM_URL=osc.udp://fyps.localdomain:$1/
export PATH=$(pwd):$PATH

8
test-importResource.py

@ -1,16 +1,16 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
"""
PyNSMClient 2.0 - A Non Session Manager Client-Library in one file.
Copyright (c) 2014-2018, Nils Hilbricht <nils@hilbricht.net> http://www.hilbricht.net, All rights reserved.
PyNSMClient 2.1 - A Non Session Manager Client-Library in one file.
The Non-Session-Manager by Jonathan Moore Liles <male@tuxfamily.org>: http://non.tuxfamily.org/nsm/
With help from code fragments from https://github.com/attwad/python-osc ( DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE v2 )
API documentation: http//non.tuxfamily.org/nsm/API.html
API documentation: http://non.tuxfamily.org/nsm/API.html
MIT License
Copyright 2014-2019 Nils Hilbricht https://www.hilbricht.net
Copyright 2014-2020 Nils Hilbricht https://www.laborejo.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,