-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
misc improvements #562
misc improvements #562
Changes from 5 commits
01fb8b3
6356708
54f0d32
444a2c3
3799d46
f3ffc8b
8580a5c
b69c1a6
598fbd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,9 @@ class DataItem(Graphs.Item): | |
markerstyle = GObject.Property(type=int, default=0) | ||
markersize = GObject.Property(type=float, default=7) | ||
|
||
@staticmethod | ||
def new(params, xdata=None, ydata=None, **kwargs): | ||
return DataItem( | ||
@classmethod | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've actually been working a lot with custom constructors at work, where I've been using class methods for the exact same purpose. Seems the better way to me, yes. Also coincidentally reminds me on what I've been working on at work. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main reason, was that classmethods can be inherited. Say we introduce |
||
def new(cls, params, xdata=None, ydata=None, **kwargs): | ||
return cls( | ||
linestyle=misc.LINESTYLES.index(params["lines.linestyle"]), | ||
linewidth=params["lines.linewidth"], | ||
markerstyle=misc.MARKERSTYLES.index(params["lines.marker"]), | ||
|
@@ -68,9 +68,9 @@ class TextItem(Graphs.Item): | |
size = GObject.Property(type=float, default=12) | ||
rotation = GObject.Property(type=int, default=0, minimum=0, maximum=360) | ||
|
||
@staticmethod | ||
def new(params, xanchor=0, yanchor=0, text="", **kwargs): | ||
return TextItem( | ||
@classmethod | ||
def new(cls, params, xanchor=0, yanchor=0, text="", **kwargs): | ||
return cls( | ||
size=params["font.size"], color=params["text.color"], | ||
xanchor=xanchor, yanchor=yanchor, text=text, **kwargs, | ||
) | ||
|
@@ -85,9 +85,9 @@ class FillItem(Graphs.Item): | |
|
||
data = GObject.Property(type=object) | ||
|
||
@staticmethod | ||
def new(_params, data, **kwargs): | ||
return FillItem(data=data, **kwargs) | ||
@classmethod | ||
def new(cls, _params, data, **kwargs): | ||
return cls(data=data, **kwargs) | ||
|
||
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it actually ever reach line 95 (closing the wrapper), as it typically stops the function after the return statement no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are correct, my mistake. I've pushed a fix, where a contextmanager is used, taking care of closing the stream