Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F63570655
image.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, May 21, 01:55
Size
3 KB
Mime Type
text/x-python
Expires
Thu, May 23, 01:55 (2 d)
Engine
blob
Format
Raw Data
Handle
17789752
Attached To
rNIETZSCHEPYTHON nietzsche-python
image.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This super class can be used to represent all image types.
"""
# Copyright (C) University of Basel 2019 {{{1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/> 1}}}
__author__
=
"Christian Steiner"
__maintainer__
=
__author__
__copyright__
=
'University of Basel'
__email__
=
"christian.steiner@unibas.ch"
__status__
=
"Development"
__license__
=
"GPL v3"
__version__
=
"0.0.1"
from
lxml
import
etree
as
ET
from
os.path
import
isfile
from
.attachable_object
import
AttachableObject
from
.class_spec
import
SemanticClass
class
Image
(
AttachableObject
,
SemanticClass
):
"""
This super class represents all types of images.
Args:
file_name (str): name of the image file.
node (lxml.etree.Element) node, containing information
URL (str): URL of image file.
height (float): height of image
width (float): width of image
"""
stringKeys
=
[
'file_name'
,
'URL'
]
floatKeys
=
[
'height'
,
'width'
]
def
__init__
(
self
,
node
=
None
,
file_name
=
None
,
URL
=
None
,
height
=
0.0
,
width
=
0.0
,
tag
=
'image'
):
if
node
is
not
None
:
self
.
file_name
=
node
.
get
(
'file-name'
)
self
.
URL
=
node
.
get
(
'absolute-path'
)
self
.
height
=
float
(
node
.
get
(
'height'
))
self
.
width
=
float
(
node
.
get
(
'width'
))
else
:
self
.
tag
=
tag
self
.
file_name
=
file_name
self
.
URL
=
URL
self
.
height
=
height
self
.
width
=
width
def
attach_object_to_tree
(
self
,
target_tree
):
"""Attach object to tree.
"""
obj_node
=
target_tree
.
getroot
()
.
find
(
'.//'
+
self
.
tag
)
\
if
(
len
(
target_tree
.
getroot
()
.
findall
(
'.//'
+
self
.
tag
))
>
0
)
\
else
ET
.
SubElement
(
target_tree
.
getroot
(),
self
.
tag
)
for
key
in
self
.
floatKeys
:
if
self
.
__dict__
[
key
]
is
not
None
:
obj_node
.
set
(
key
.
replace
(
'_'
,
'-'
),
str
(
round
(
self
.
__dict__
[
key
],
3
)))
for
key
in
self
.
stringKeys
:
if
self
.
__dict__
[
key
]
is
not
None
:
obj_node
.
set
(
key
.
replace
(
'_'
,
'-'
),
self
.
__dict__
[
key
])
@staticmethod
def
get_semantic_dict
():
"""Returns semantic dictionary of this class.
"""
class_dict
=
{}
class_dict
.
update
({
'class'
:
__class__
})
class_dict
.
update
(
dict
(
zip
(
Image
.
floatKeys
,
[
float
for
i
in
Image
.
floatKeys
])))
class_dict
.
update
(
dict
(
zip
(
Image
.
stringKeys
,
[
str
for
i
in
Image
.
stringKeys
])))
return
class_dict
Event Timeline
Log In to Comment