Related
I'm trying to implement an RTD client using this project as an example, but without success.
Instance as RTD server the example contained in the win32com package below, and in Excel it works perfectly, but in the RTD client used as a template, it generates this error.
RTD client code
import functools
import pythoncom
import win32com.client
from win32com import universal
from win32com.client import gencache
from win32com.server.util import wrap
EXCEL_TLB_GUID = '{00020813-0000-0000-C000-000000000046}'
EXCEL_TLB_LCID = 0
EXCEL_TLB_MAJOR = 1
EXCEL_TLB_MINOR = 4
gencache.EnsureModule(EXCEL_TLB_GUID, EXCEL_TLB_LCID, EXCEL_TLB_MAJOR, EXCEL_TLB_MINOR)
universal.RegisterInterfaces(EXCEL_TLB_GUID,
EXCEL_TLB_LCID, EXCEL_TLB_MAJOR, EXCEL_TLB_MINOR,
['IRtdServer', 'IRTDUpdateEvent'])
# noinspection PyProtectedMember
class ObjectWrapperCOM:
LCID = 0x0
def __init__(self, obj):
self._impl = obj # type: win32com.client.CDispatch
def __getattr__(self, item):
flags, dispid = self._impl._find_dispatch_type_(item)
if dispid is None:
raise AttributeError("{} is not a valid property or method for this object.".format(item))
return functools.partial(self._impl._oleobj_.Invoke, dispid, self.LCID, flags, True)
# noinspection PyPep8Naming
class RTDUpdateEvent:
_com_interfaces_ = ['IRTDUpdateEvent']
_public_methods_ = ['Disconnect', 'UpdateNotify']
_public_attrs_ = ['HeartbeatInterval']
# Implementation of IRTDUpdateEvent.
HeartbeatInterval = -1
def __init__(self, event_driven=True):
self.ready = False
self._event_driven = event_driven
def UpdateNotify(self):
if self._event_driven:
self.ready = True
def Disconnect(self):
pass
class RTDClient:
MAX_REGISTERED_TOPICS = 1024
def __init__(self, class_id):
"""
:param classid: can either be class ID or program ID
"""
self._class_id = class_id
self._rtd = None
self._update_event = None
self._topic_to_id = {}
self._id_to_topic = {}
self._topic_values = {}
self._last_topic_id = 0
def connect(self, event_driven=True):
"""
Connects to the RTD server.
Set event_driven to false if you to disable update notifications.
In this case you'll need to call refresh_data manually.
"""
dispatch = win32com.client.Dispatch(self._class_id)
self._update_event = RTDUpdateEvent(event_driven)
try:
self._rtd = win32com.client.CastTo(dispatch, 'IRtdServer')
except TypeError:
# Automated makepy failed...no detailed construction available for the class
self._rtd = ObjectWrapperCOM(dispatch)
self._rtd.ServerStart(wrap(self._update_event))
def update(self):
"""
Check if there is data waiting and call RefreshData if necessary. Returns True if new data has been received.
Note that you should call this following a call to pythoncom.PumpWaitingMessages(). If you neglect to
pump the message loop you'll never receive UpdateNotify callbacks.
"""
# noinspection PyUnresolvedReferences
pythoncom.PumpWaitingMessages()
if self._update_event.ready:
self._update_event.ready = False
self.refresh_data()
return True
else:
return False
def refresh_data(self):
"""
Grabs new data from the RTD server.
"""
(ids, values) = self._rtd.RefreshData(self.MAX_REGISTERED_TOPICS)
for id_, value in zip(ids, values):
if id_ is None and value is None:
# This is probably the end of message
continue
assert id_ in self._id_to_topic, "Topic ID {} is not registered.".format(id_)
topic = self._id_to_topic[id_]
self._topic_values[topic] = value
def get(self, topic: tuple):
"""
Gets the value of a registered topic. Returns None if no value is available. Throws an exception if
the topic isn't registered.
"""
assert topic in self._topic_to_id, 'Topic %s not registered.' % (topic,)
return self._topic_values.get(topic)
def register_topic(self, topic: tuple):
"""
Registers a topic with the RTD server. The topic's value will be updated in subsequent data refreshes.
"""
if topic not in self._topic_to_id:
id_ = self._last_topic_id
self._last_topic_id += 1
self._topic_to_id[topic] = id_
self._id_to_topic[id_] = topic
self._rtd.ConnectData(id_, topic, True)
def unregister_topic(self, topic: tuple):
"""
Un-register topic so that it will not get updated.
:param topic:
:return:
"""
assert topic in self._topic_to_id, 'Topic %s not registered.' % (topic,)
self._rtd.DisconnectData(self._topic_to_id[topic])
def disconnect(self):
"""
Closes RTD server connection.
:return:
"""
self._rtd.ServerTerminate()
The example RTD Server is Python.RTD.TimeServer and it works great in Excel, but the RTD client in the above example throws this error:
File "C:\Users\XXXXXX\AppData\Local\Temp\gen_py\3.9\00020813-0000-0000-C000-000000000046x0x1x9.py", line 20963, in UpdateNotify
return self.oleobj.InvokeTypes(10, LCID, 1, (24, 0), (),)
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
I have no knowledge of COM, but in the struggle to learn.
Any suggestions from friends?
You need to implement all the methods defined by the IRTDServer interface.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.office.interop.excel.irtdserver?view=excel-pia
Once you do that excel should be able to find all methods it needs to work with your server.
I was recently hired as a junior dev as my first job for a bigger company which uses NetSuite. An old dev wrote a python script which handles pictures made by designers, that uploads pictures to NetSuite when they are uploaded to a specific folder.
Since the Script uses SHA1 I need to change the TBA to SHA256 because NetSuite does not support SHA1 anymore.
I have a hard time understanding the old dev's code, and find documentation on how to change the TBA from SHA1 to SHA256..
These are snippets from the code.
import datetime
import requests
import os
import oauth2 as oauth
import json
import time
import base64
import sys
import hashlib
import hmac
url = "https://xxxxx=1"
token = oauth.Token(key="xxxxxxxxxxx",secret="xxxxxxxxxx")
consumer = oauth.Consumer(key="xxxxxxxxxxxxxxxx",secret="xxxxxxxxxxxxxxxx")
realm="xxxxxxxxxxxxxx"
signature_method = oauth.SignatureMethod_HMAC_SHA1()
In this part I understand he initialises the method oauth.SignatureMethod_HMAC_SHA1().
Then when I go to the oauth file I find this
class SignatureMethod_HMAC_SHA1(SignatureMethod):
name = 'HMAC-SHA1'
def signing_base(self, request, consumer, token):
if (not hasattr(request, 'normalized_url') or request.normalized_url is None):
raise ValueError("Base URL for request is not set.")
sig = (
escape(request.method),
escape(request.normalized_url),
escape(request.get_normalized_parameters()),
)
key = '%s&' % escape(consumer.secret)
if token:
key += escape(token.secret)
raw = '&'.join(sig)
return key.encode('ascii'), raw.encode('ascii')
def sign(self, request, consumer, token):
"""Builds the base signature string."""
key, raw = self.signing_base(request, consumer, token)
hashed = hmac.new(key, raw, sha1)
# Calculate the digest base 64.
return binascii.b2a_base64(hashed.digest())[:-1]
I looked this file through, and it does not contain any methods containing SHA256.. Only SHA1 and PLAINTEXT.
I tried to change the values to SHA256 but that did not work of course.
I tried to look up documentation on oAuth2 but I only found very small amounts of information, and it seems like it only contains SHA1 and PLAINTEXT..
So how do I change the script to function with SHA256 instead of SHA1?
EDIT to answer comment
Hashlib contains this:
class _Hash(object):
digest_size: int
block_size: int
# [Python documentation note] Changed in version 3.4: The name attribute has
# been present in CPython since its inception, but until Python 3.4 was not
# formally specified, so may not exist on some platforms
name: str
def __init__(self, data: _DataType = ...) -> None: ...
def copy(self) -> _Hash: ...
def digest(self) -> bytes: ...
def hexdigest(self) -> str: ...
def update(self, arg: _DataType) -> None: ...
def md5(arg: _DataType = ...) -> _Hash: ...
def sha1(arg: _DataType = ...) -> _Hash: ...
def sha224(arg: _DataType = ...) -> _Hash: ...
def sha256(arg: _DataType = ...) -> _Hash: ...
def sha384(arg: _DataType = ...) -> _Hash: ...
def sha512(arg: _DataType = ...) -> _Hash: ...
def new(name: str, data: _DataType = ...) -> _Hash: ...
algorithms_guaranteed: AbstractSet[str]
algorithms_available: AbstractSet[str]
def pbkdf2_hmac(hash_name: str, password: _DataType, salt: _DataType, iterations: int, dklen: Optional[int] = ...) -> bytes: ...
if sys.version_info >= (3, 6):
class _VarLenHash(object):
digest_size: int
block_size: int
name: str
def __init__(self, data: _DataType = ...) -> None: ...
def copy(self) -> _VarLenHash: ...
def digest(self, length: int) -> bytes: ...
def hexdigest(self, length: int) -> str: ...
def update(self, arg: _DataType) -> None: ...
sha3_224 = _Hash
sha3_256 = _Hash
sha3_384 = _Hash
sha3_512 = _Hash
shake_128 = _VarLenHash
shake_256 = _VarLenHash
def scrypt(password: _DataType, *, salt: _DataType, n: int, r: int, p: int, maxmem: int = ..., dklen: int = ...) -> bytes: ...
class _BlakeHash(_Hash):
MAX_DIGEST_SIZE: int
MAX_KEY_SIZE: int
PERSON_SIZE: int
SALT_SIZE: int
def __init__(self, data: _DataType = ..., digest_size: int = ..., key: _DataType = ..., salt: _DataType = ..., person: _DataType = ..., fanout: int = ..., depth: int = ..., leaf_size: int = ..., node_offset: int = ..., node_depth: int = ..., inner_size: int = ..., last_node: bool = ...) -> None: ...
blake2b = _BlakeHash
blake2s = _BlakeHash
There is already sha256() function in Haslib file,
so you can try to add a new class SignatureMethod_HMAC_SHA256 into the oauth file which can be similar to that SHA1.
Just change parameters of hmac.new() function like this:
hashed = hmac.new(key, raw, sha256)
Whole class can look like this:
class SignatureMethod_HMAC_SHA256(SignatureMethod):
name = 'HMAC-SHA256'
def signing_base(self, request, consumer, token):
if (not hasattr(request, 'normalized_url') or request.normalized_url is None):
raise ValueError("Base URL for request is not set.")
sig = (
escape(request.method),
escape(request.normalized_url),
escape(request.get_normalized_parameters()),
)
key = '%s&' % escape(consumer.secret)
if token:
key += escape(token.secret)
raw = '&'.join(sig)
return key.encode('ascii'), raw.encode('ascii')
def sign(self, request, consumer, token):
"""Builds the base signature string."""
key, raw = self.signing_base(request, consumer, token)
hashed = hmac.new(key, raw, sha256)
# Calculate the digest base 64.
return binascii.b2a_base64(hashed.digest())[:-1]
Then you can simply call in your script new SHA256 method instead of that deprecated SHA1 method:
signature_method = oauth.SignatureMethod_HMAC_SHA256()
I have a model that relates to some others and I want to make an instance of model factory with factory boy package and send it as json to rest API in django rest framework.
UserFactory:
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
first_name = factory.Faker('name')
username = factory.Faker('word')
language = factory.SubFactory(LanguageFactory)
LanguageFactory:
class LanguageFactory(factory.django.DjangoModelFactory):
class Meta:
model = Language
name = factory.Faker('language_name')
When I use:
factory.build(dict, FACTORY_CLASS=UserFactory)
it returns:
{'first_name': "Agent 001", 'username': 'john_doe', 'language': <Language: Catalan>}
where language is another model factory but I need it as json to post or patch test.
How would I get something like this?
{'first_name': "Agent 001", 'username': 'john_doe', 'language': [{'name': 'English'}, {'name': 'French'}]}
As in comment mentioned the factory boy doesn't have inner dict factory by itself.
The answer in github worked.
First you should make a function that gets factory class and dict all classes in it:
from functools import partial
from typing import Any, Dict
from factory import Factory
from factory.base import StubObject
def generate_dict_factory(factory: Factory):
def convert_dict_from_stub(stub: StubObject) -> Dict[str, Any]:
stub_dict = stub.__dict__
for key, value in stub_dict.items():
if isinstance(value, StubObject):
stub_dict[key] = convert_dict_from_stub(value)
return stub_dict
def dict_factory(factory, **kwargs):
stub = factory.stub(**kwargs)
stub_dict = convert_dict_from_stub(stub)
return stub_dict
return partial(dict_factory, factory)
then for usage:
# example of usage
UserDictFactory = generate_dict_factory(UserFactory)
and finally if call UserDictFactory() returns what we need.
I was using the answer from Mahmood, and I realized that it was not working properly for lists (when foos = factory.List(FooFactory)). In this case we would expect to get back a list, but with the original code we get back a dict where the keys are the list indexes as strings.
I made the following modification to fix it:
def generate_dict_factory(factory: factory.Factory):
def stub_is_list(stub: StubObject) -> bool:
try:
return all(k.isdigit() for k in stub.__dict__.keys())
except AttributeError:
return False
def convert_dict_from_stub(stub: StubObject) -> Dict[str, Any]:
stub_dict = stub.__dict__
for key, value in stub_dict.items():
if isinstance(value, StubObject):
stub_dict[key] = (
[convert_dict_from_stub(v) for v in value.__dict__.values()]
if stub_is_list(value)
else convert_dict_from_stub(value)
)
return stub_dict
def dict_factory(factory, **kwargs):
stub = factory.stub(**kwargs)
stub_dict = convert_dict_from_stub(stub)
return stub_dict
return partial(dict_factory, factory)
I try to append an element to a list but i received this error. I check if the types of the 2 objects are the same and if they have the same type, than i append it. So the next function is where i received the error. The class contains the elements.
def LogsBeiTyp(self,list,type):
"""
Thid funftion return a list that contains all logs group by a type
:param list: a list that contains all object logare
:return: a list modified in such a way thet elements are gropu by type
"""
l=[]
for el in list:
if el.get_type()==type:
l.append(el)
return l
And this is the class :
class Logare():
"""
This class contains information about a log
It is known that each log has a date,type,description
"""
def __init__(self,date,time,type,melldung):
"""
The incresemnt function
:param date: a string which is written as "YYYY-MM-DD"
:param type: a string that contains in cappital letters the type of thr log
:param description: a string that contains more details about the log
"""
self.date=date
self.time=time
self.type=type
self.melldung=melldung
def get_date(self):
return self.date
def get_time(self):
return self.time
def get_type(self):
return self.type
def get_melldung(self):
return self.melldung
def __str__(self):
return '%s %s %s %s'%(self.date,self.time,self.type,self.melldung)
Here is where I bild the list
from LogDatei.LogDatei import *
from Date.Date import *
from Melldung.Melldung import *
from Time.Time import *
class Repo():
"""
This class contains the most important methonds
"""
def __init__(self,filename):
"""
The initialization function
:param filename: the name of the file you want to take the information
"""
self.filename=filename
def get_all(self):
"""
This function reads all lines from a file
It grpups in in object Logare that is build from date,type and melldung
date and melldung are classes also
:return: a list that contains all information from file
"""
rez=[]
f=open(self.filename,'r')
for line in f:
tolks=line.split(' ',3)
date=tolks[0].split('-',2)
time=tolks[1].split(':',2)
melldung=tolks[3].split(':')
final=melldung[1].split('-')
#date(date[0],date[1],date[2])
#time()
rez.append(Logare(date,time,tolks[2],Melldung(melldung[0],final[0],final[1],melldung[2])))
return rez
In function get_all() I built the list than i sent it to the controler where i haev the function
This can be resolved by using isinstance. Using this construct you
could have:
def LogsBeiTyp(self,list,class_type):
"""
Thid funftion return a list that contains all logs group by a type
:param list: a list that contains all object logare
:return: a list modified in such a way thet elements are gropu by type
"""
l=[]
for el in list:
if isinstance(el, class_type):
l.append(el)
return l
As mentioned using comments using a builtin (i.e., types) for a variable name is not a good idea.
Calling this within the Logare class and looking for Logare instances in a elements list would look something like:
my_logs = self.LogsBeiTyp(elements, Logare)
I am wondering how to smart sharpen an image using python or any related image library like ndimage ,skimage or even PIL.I could find methods that actually sharpen my image but with a lot of noise and pixelating when zooming in .So since I know Photoshop I tried to get that smart sharpen effect which sharpens the image with a less noising and with a nice sweet contrast through python but I failed.
Notes:-
(1) methods has been tested:-
>>> # The 1st Method:
>>> import Image
>>> import ImageFilter
>>> image.filter(ImageFilter.SHARPEN)
>>> Image.filter(ImageFilter.EDGE_ENHANCE_MORE) #Look down:1st image created
>>> # The 2nd Method:
>>> blurred_l=scipy.ndimage.gaussian_filter(b,3)
>>> filter_blurred_l = scipy.ndimage.gaussian_filter(blurred_l, 1)
>>> alpha =30
>>> sharpened = blurred_l + alpha * (blurred_l - filter_blurred_l)
>>> # The 3rd Method:
>>> shar=imfilter(Image,'sharpen') #Look down:2nd image created
(2) I found a piece of code but it's in Perl . I only know Python In here or directly
(3) Here are 2 of the sharpened image using above methods the third done with smartsharp:
Original
Original image http://imageshack.us/a/img600/6640/babyil.jpg
First ....................................................................second
1st http://imageshack.us/a/img803/3897/sharp1.png 2nd http://imageshack.us/a/img809/2235/sharp2.png
third MY GOAL>that's the effect I want
3rd http://imageshack.us/a/img832/4563/smartsharp.jpg
(4) Here are the tool I used to create the third image above:
smrsharpm http://imageshack.us/a/img210/2747/smartsharpentoolm.jpg smrsharp http://imageshack.us/a/img193/490/smartsharpentool.jpg
Photoshop's "smart sharpening" function uses a mathematical operation called deconvolution internally. numpy does have a deconvolve() function that could probably be pressed into service for this task, but I couldn't find a ready-made function to do smart sharpening specifically with numpy, so you'd probably have to code it up yourself.
An alternative approach would be to do it using the GIMP. There's a GIMP plug-in (intuitively named "G'Mic") that will do deconvolution among other sharpening algorithms, and you can automate GIMP using Python.
Unfortunately, it's hard to know what "Smart sharpen" does without having access to the Photoshop code. In the meantime, you can try to mix an unsharpen mask, total variation filtering and some color adjustment (perhaps a bit of hue boost).
Also see: http://www.kenrockwell.com/tech/photoshop/sharpening.htm#
Update: here is an example of how to remove motion blur from an image:
https://github.com/stefanv/scikit-image-demos/blob/master/clock_deblur.py
(the clock image is in the same repository). Unfortunately, scikit-image does not currently have mature deblurring / inverse filtering--but we're working on it!
#StefanvanderWalt
Unfortunately, the Wiener code needs a revamp. I've added an example above on how to motion deblur an image. This method can also be used if you only know your blurring kernel--essentially, you apply the Fourier transform to both your image (f -> F) and your kernel (h -> H), and then return the inverse FFT of (F / H), after making sure that the amplitude is limited in places where H is close to zero. Padding avoids boundary effects, and windowing the image limits oscillations in the reconstruction.
What values and dimensions the hann window used?
Well this is a rather old question and this is probably not the right answer either, but I was looking to do this with Photoshop 2020 and a python script and I had a hard time finding scattered information on how to do this so I'll post this anyway if anyone ever needs something like and this could help them.
First of all I used this python library : https://photoshop-python-api.readthedocs.io/en/0.14.0/index.html
With this API i was able to recreate basically any filter in photoshop with a python script.
Then I needed to find the string IDs for the actions to create the scripts, for this I used the Scripting Listener plugin that i found here : https://helpx.adobe.com/photoshop/kb/downloadable-plugins-and-content.html#ScriptingListenerplugin
I tried following the guide for Windows, but it actually didn't work
at first, at step 4 you actually have to put the 3 folders that you
extract from the ZIP in the "Plug-Ins" folder "Program
Files\Adobe\Adobe Photoshop 2020\Plug-ins" just like mac-os.
Then is just a matter of executing whatever filter in photoshop and get the JS or VBS log from the listener and converting it in python.
This is an example of the JS log for the Smart Sharpen:
var idsmartSharpen = stringIDToTypeID( "smartSharpen" );
var desc186 = new ActionDescriptor();
var idpresetKind = stringIDToTypeID( "presetKind" );
var idpresetKindType = stringIDToTypeID( "presetKindType" );
var idpresetKindCustom = stringIDToTypeID( "presetKindCustom" );
desc186.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );
var iduseLegacy = stringIDToTypeID( "useLegacy" );
desc186.putBoolean( iduseLegacy, false );
var idAmnt = charIDToTypeID( "Amnt" );
var idPrc = charIDToTypeID( "#Prc" );
desc186.putUnitDouble( idAmnt, idPrc, 100.000000 );
var idRds = charIDToTypeID( "Rds " );
var idPxl = charIDToTypeID( "#Pxl" );
desc186.putUnitDouble( idRds, idPxl, 1.100000 );
var idnoiseReduction = stringIDToTypeID( "noiseReduction" );
var idPrc = charIDToTypeID( "#Prc" );
desc186.putUnitDouble( idnoiseReduction, idPrc, 50.000000 );
var idblur = charIDToTypeID( "blur" );
var idblurType = stringIDToTypeID( "blurType" );
var idlensBlur = stringIDToTypeID( "lensBlur" );
desc186.putEnumerated( idblur, idblurType, idlensBlur );
executeAction( idsmartSharpen, desc186, DialogModes.NO );
In python I just copied the log and changed a few things like this:
import photoshop.api as ps
app = ps.Application()
docRef = app.activeDocument
def SmartSharpen(amount: int, radius: float, denoise: float):
idsmartSharpen = app.stringIDToTypeID( "smartSharpen" );
desc179 = ps.ActionDescriptor();
idpresetKind = app.stringIDToTypeID( "presetKind" );
idpresetKindType = app.stringIDToTypeID( "presetKindType" );
idpresetKindCustom = app.stringIDToTypeID( "presetKindCustom" );
desc179.putEnumerated( idpresetKind, idpresetKindType, idpresetKindCustom );
iduseLegacy = app.stringIDToTypeID( "useLegacy" );
desc179.putBoolean( iduseLegacy, False );
idAmnt = app.charIDToTypeID( "Amnt" );
idPrc = app.charIDToTypeID( "#Prc" );
desc179.putUnitDouble( idAmnt, idPrc, amount );
idRds = app.charIDToTypeID( "Rds " );
idPxl = app.charIDToTypeID( "#Pxl" );
desc179.putUnitDouble( idRds, idPxl, radius );
idnoiseReduction = app.stringIDToTypeID( "noiseReduction" );
idPrc = app.charIDToTypeID( "#Prc" );
desc179.putUnitDouble( idnoiseReduction, idPrc, denoise );
idblur = app.charIDToTypeID( "blur" );
idblurType = app.stringIDToTypeID( "blurType" );
idlensBlur = app.stringIDToTypeID( "lensBlur" );
desc179.putEnumerated( idblur, idblurType, idlensBlur );
app.executeAction( idsmartSharpen, desc179, 3 );
SmartSharpen(50, 1.1, 100)
Actually in the python library there was already an example for the Smart Sharpening but with its EventID.SmartSharpen i wasn't getting the same results for some reason. Also to change the blur type you have to know the actual stringID, which unless there's a documentation somewhere that I wasn't able to find, I was only able to get it from the logs.
To end this, an unrelated note to this question, for some filter that i needed like "Reduce Noise", the class "ActionList" is used but in the python library currently is not implemented yet, for now I managed by simply creating it myself by simply coping the already present "ActionDescription" and changing the name and a few methods that I needed by following the documentation here: https://www.adobe.com/content/dam/acom/en/devnet/photoshop/pdfs/photoshop-cc-vbs-ref.pdf#ActionList.
I'll just put it here in case somebody may ever need this because I had a hard time finding anything about this:
"""This object provides an array-style mechanism for storing dta.
"""
# Import built-in modules
from pathlib import Path
# Import local modules
from photoshop.api._core import Photoshop
from photoshop.api.action_list import ActionList
from photoshop.api.action_reference import ActionReference
from photoshop.api.enumerations import DescValueType
class ActionList(Photoshop):
object_name = "ActionList"
def __init__(self):
super().__init__()
#property
def count(self):
"""The number of keys contained in the descriptor."""
return self.app.count
def clear(self):
"""Clears the descriptor."""
self.app.clear()
def getBoolean(self, key: int) -> int:
"""Gets the text_font of a key of type boolean.
Args:
key (str): key of type boolean.
Returns:
bool: The text_font of a key of type boolean.
"""
return self.app.getBoolean(key)
def getClass(self, key):
"""Gets the text_font of a key of type class.
Args:
key (str): The key of type class.
Returns:
int: The text_font of a key of type class.
"""
return self.app.getClass(key)
def getData(self, key: int) -> int:
"""Gets raw byte data as a string value."""
return self.app.getData(key)
def getDouble(self, key: int) -> int:
"""Gets the value of a key of type double."""
return self.app.getDouble(key)
def getEnumerationType(self, index: int) -> int:
"""Gets the enumeration type of a key."""
return self.app.getEnumerationType(index)
def getEnumerationValue(self, index: int) -> int:
"""Gets the enumeration value of a key."""
return self.app.getEnumerationValue(index)
def getInteger(self, index: int) -> int:
"""Gets the value of a key of type integer."""
return self.app.getInteger(index)
def getKey(self, index: int) -> int:
"""Gets the ID of the key provided by index."""
return self.app.getKey(index)
def getLargeInteger(self, index: int) -> int:
"""Gets the value of a key of type large integer."""
return self.app.getLargeInteger(index)
def getList(self, index: int) -> ActionList:
"""Gets the value of a key of type list."""
return ActionList(self.app.getList(index))
def getObjectType(self, key: int) -> int:
"""Gets the class ID of an object in a key of type object."""
return self.app.getObjectType(key)
def getObjectValue(self, key: int) -> int:
"""Get the class ID of an object in a key of type object."""
return self.app.getObjectValue(key)
def getPath(self, key: int) -> Path:
"""Gets the value of a key of type."""
return Path(self.app.getPath(key))
def getReference(self, key: int) -> ActionReference:
"""Gets the value of a key of type."""
return ActionReference(self.app.getReference(key))
def getString(self, key: int) -> str:
"""Gets the value of a key of type."""
return self.app.getString(key)
def getType(self, key: int) -> DescValueType:
"""Gets the type of a key."""
return DescValueType(self.app.getType(key))
def getUnitDoubleType(self, key: int) -> int:
"""Gets the unit type of a key of type UnitDouble."""
return self.app.getUnitDoubleType(key)
def getUnitDoubleValue(self, key: int) -> int:
"""Gets the unit type of a key of type UnitDouble."""
return self.app.getUnitDoubleValue(key)
def hasKey(self, key: int) -> bool:
"""Checks whether the descriptor contains the provided key."""
return self.app.hasKey(key)
def isEqual(self, otherDesc) -> bool:
"""Determines whether the descriptor is the same as another descriptor.
Args:
otherDesc (.action_descriptor.ActionDescriptor):
"""
return self.app.isEqual(otherDesc)
def putBoolean(self, key: int, value: bool):
"""Sets the value for a key whose type is boolean."""
self.app.putBoolean(key, value)
def putClass(self, key: int, value: int):
"""Sets the value for a key whose type is class."""
self.app.putClass(key, value)
def putData(self, key: int, value: str):
"""Puts raw byte data as a string value."""
self.app.putData(key, value)
def putDouble(self, key: int, value: int):
"""Sets the value for a key whose type is double."""
self.app.putDouble(key, value)
def putEnumerated(self, key: int, enum_type: int, value: int):
"""Sets the enumeration type and value for a key."""
self.app.putEnumerated(key, enum_type, value)
def putInteger(self, key: int, value: int):
"""Sets the value for a key whose type is integer."""
self.app.putInteger(key, value)
def putLargeInteger(self, key: int, value: int):
"""Sets the value for a key whose type is large integer."""
self.app.putLargeInteger(key, value)
def putList(self, key: int, value: ActionList):
"""Sets the value for a key whose type is an ActionList object."""
self.app.putList(key, value)
def putObject(self, class_id: int, value):
"""Sets the value for a key whose type is an object."""
self.app.putObject(class_id, value)
def putPath(self, key: int, value: str):
"""Sets the value for a key whose type is path."""
self.app.putPath(key, value)
def putReference(self, key: int, value: ActionReference):
"""Sets the value for a key whose type is an object reference."""
self.app.putReference(key, value)
def putString(self, key: int, value: str):
"""Sets the value for a key whose type is string."""
self.app.putString(key, value)
def putUnitDouble(self, key: int, unit_id: int, value: int):
"""Sets the value for a key whose type is a unit value formatted as
double."""
self.app.putUnitDouble(key, unit_id, value)
def toStream(self) -> str:
"""Gets the entire descriptor as as stream of bytes,
for writing to disk."""
return self.app.toSteadm()