Skip to content

Commit 3d44c77

Browse files
authored
Merge pull request #321 from ferdnyc/map-dicts
WIP: Towards a more Pythonic openshot.Fraction
2 parents 066110c + 1d0ce06 commit 3d44c77

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/bindings/python/openshot.i

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,34 @@
123123
}
124124
}
125125

126+
/* Instantiate the required template specializations */
127+
%template() std::map<std::string, int>;
128+
129+
/* Make openshot.Fraction more Pythonic */
130+
%extend openshot::Fraction {
131+
%{
132+
#include <sstream>
133+
#include <map>
134+
%}
135+
double __float__() {
136+
return $self->ToDouble();
137+
}
138+
int __int__() {
139+
return $self->ToInt();
140+
}
141+
std::map<std::string, int> GetMap() {
142+
std::map<std::string, int> map1;
143+
map1.insert({"num", $self->num});
144+
map1.insert({"den", $self->den});
145+
return map1;
146+
}
147+
std::string __repr__() {
148+
std::ostringstream result;
149+
result << $self->num << ":" << $self->den;
150+
return result.str();
151+
}
152+
}
153+
126154
%extend openshot::OpenShotVersion {
127155
// Give the struct a string representation
128156
const std::string __str__() {

0 commit comments

Comments
 (0)