code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
def I(x,y): xout, iout = _fun.integrate_data(x, y, autozero=autozero) print("Total =", scale*iout[-1]) return xout, scale*iout if fyname==1: fyname = "$"+str(scale)+"\\times \\int dx$" manipulate_shown_data(I, fxname=None, fyname=fyname, **kwargs)
def integrate_shown_data(scale=1, fyname=1, autozero=0, **kwargs)
Numerically integrates the data visible on the current/specified axes using scale*fun.integrate_data(x,y). Modifies the visible data using manipulate_shown_data(**kwargs) autozero is the number of data points used to estimate the background for subtraction. If autozero = 0, no background subtraction is...
7.442212
6.049955
1.230127
# get the axes if input_axes == "gca": a1 = _pylab.gca() else: a1 = input_axes # get the xlimits xmin, xmax = a1.get_xlim() # get the name to stick on the x and y labels if fxname==1: fxname = f.__name__ if fyname==1: fyname = f.__name__ # get the output ...
def manipulate_shown_data(f, input_axes="gca", output_axes=None, fxname=1, fyname=1, clear=1, pause=False, **kwargs)
Loops over the visible data on the specified axes and modifies it based on the function f(xdata, ydata), which must return new_xdata, new_ydata input_axes which axes to pull the data from output_axes which axes to dump the manipulated data (None for new figure) fxname the name of the function on...
2.746079
2.745585
1.00018
def f(x,y): return fx(x), y f.__name__ = fx.__name__ manipulate_shown_data(f, fxname=fxname, fyname=None, **kwargs)
def manipulate_shown_xdata(fx, fxname=1, **kwargs)
This defines a function f(xdata,ydata) returning fx(xdata), ydata and runs manipulate_shown_data() with **kwargs sent to this. See manipulate_shown_data() for more info.
5.264899
3.865858
1.361897
def f(x,y): return x, fy(y) f.__name__ = fy.__name__ manipulate_shown_data(f, fxname=None, fyname=fyname, **kwargs)
def manipulate_shown_ydata(fy, fyname=1, **kwargs)
This defines a function f(xdata,ydata) returning xdata, fy(ydata) and runs manipulate_shown_data() with **kwargs sent to this. See manipulate_shown_data() for more info.
4.688021
3.614085
1.297153
for fig in figures: # get the temp path temp_path = _os.path.join(_settings.path_home, "temp") # make the temp folder _settings.MakeDir(temp_path) # output the figure to postscript path = _os.path.join(temp_path, "graph."+file_format) # get the dimen...
def _print_figures(figures, arguments='', file_format='pdf', target_width=8.5, target_height=11.0, target_pad=0.5)
figure printing loop designed to be launched in a separate thread.
3.107793
3.115774
0.997439
global _settings if 'instaprint' not in _settings.keys(): print("No print command setup. Set the user variable settings['instaprint'].") return if figure=='gcf': figure=[_pylab.gcf().number] elif figure=='all': figure=_pylab.get_fignums() if not getattr(figure,'__iter__',Fa...
def instaprint(figure='gcf', arguments='', threaded=False, file_format='pdf')
Quick function that saves the specified figure as a postscript and then calls the command defined by spinmob.prefs['instaprint'] with this postscript file as the argument. figure='gcf' can be 'all', a number, or a list of numbers
4.185012
4.102739
1.020053
if _fun.is_a_number(f): f = _pylab.figure(f) f.canvas.manager.window.raise_()
def raise_figure_window(f=0)
Raises the supplied figure number or figure window.
7.491014
5.98767
1.251073
if type(fig)==str: fig = _pylab.gcf() elif _fun.is_a_number(fig): fig = _pylab.figure(fig) # Qt4Agg backend. Probably would work for other Qt stuff if _pylab.get_backend().find('Qt') >= 0: w = fig.canvas.window() if not size == None: w.resize(size[0],size[1])...
def set_figure_window_geometry(fig='gcf', position=None, size=None)
This will currently only work for Qt4Agg and WXAgg backends. postion = [x, y] size = [width, height] fig can be 'gcf', a number, or a figure object.
3.319223
3.067472
1.082071
if axes=="gca": axes = _pylab.gca() # first get one of the tick label locations xposition = axes.yaxis.get_ticklabels()[0].get_position()[0] # get the bounds ymin, ymax = axes.get_ylim() # get the starting tick nstart = int(_pylab.floor((ymin-start)/step)) nstop = int(_pylab.cei...
def set_yticks(start, step, axes="gca")
This will generate a tick array and apply said array to the axis
3.00935
3.045151
0.988243
if axes=="gca": axes = _pylab.gca() # first get one of the tick label locations yposition = axes.xaxis.get_ticklabels()[0].get_position()[1] # get the bounds xmin, xmax = axes.get_xlim() # get the starting tick nstart = int(_pylab.floor((xmin-start)/step)) nstop = int(_pylab.cei...
def set_xticks(start, step, axes="gca")
This will generate a tick array and apply said array to the axis
2.985276
3.020258
0.988418
# get the actual data values xdata = line.get_xdata() ydata = line.get_ydata() xdata,ydata = _fun.coarsen_data(xdata, ydata, level=level, exponential=exponential) # don't do anything if we don't have any data left if len(ydata) == 0: print("There's nothing left in "+str(line)+"!") ...
def coarsen_line(line, level=2, exponential=False, draw=True)
Coarsens the specified line (see spinmob.coarsen_data() for more information). Parameters ---------- line Matplotlib line instance. level=2 How strongly to coarsen. exponential=False If True, use the exponential method (great for log-x plots). draw=True Redra...
4.574931
4.511933
1.013962
if axes=="gca": axes=_pylab.gca() if axes=="all": if not figure: f = _pylab.gcf() axes = f.axes if not _fun.is_iterable(axes): axes = [axes] for a in axes: # get the lines from the plot lines = a.get_lines() # loop over the lines and trim the data ...
def coarsen_all_traces(level=2, exponential=False, axes="all", figure=None)
This function does nearest-neighbor coarsening of the data. See spinmob.fun.coarsen_data for more information. Parameters ---------- level=2 How strongly to coarsen. exponential=False If True, use the exponential method (great for log-x plots). axes="all" Which axes...
3.776865
4.0759
0.926633
if axes=='gca': axes = _pylab.gca() lines = axes.get_lines() for line in lines: if isinstance(line, _mpl.lines.Line2D): xdata, ydata = line.get_data() if not fx==None: xdata = fx(xdata) if not fy==None: ydata = fy(ydata) line.set_data(xdata,yda...
def line_math(fx=None, fy=None, axes='gca')
applies function fx to all xdata and fy to all ydata.
2.065186
2.01022
1.027344
if figure=="gcf": figure = _pylab.gcf() if path==None: path = _s.dialogs.Save("*.*", default_directory="save_plot_default_directory") if path=="": print("aborted.") return figure.savefig(path, dpi=dpi)
def export_figure(dpi=200, figure="gcf", path=None)
Saves the actual postscript data for the figure.
7.58169
7.665332
0.989088
global line_attributes # choose a path to save to if path==None: path = _s.dialogs.Save("*.plot", default_directory="save_plot_default_directory") if path=="": print("aborted.") return if not path.split(".")[-1] == "plot": path = path+".plot" f = file(path, "w") # ...
def save_plot(axes="gca", path=None)
Saves the figure in my own ascii format
3.288429
3.246181
1.013014
# choose a path to save to path = _s.dialogs.Save(**kwargs) if path=="": return "aborted." # if no argument was given, get the current axes if figure=="gcf": figure = _pylab.gcf() for n in range(len(figure.axes)): a = figure.axes[n] for m in range(len(a.lines)): ...
def save_figure_raw_data(figure="gcf", **kwargs)
This will just output an ascii file for each of the traces in the shown figure. **kwargs are sent to dialogs.Save()
3.098055
2.902569
1.06735
i = self.line_colors_index self.line_colors_index += increment if self.line_colors_index >= len(self.line_colors): self.line_colors_index = self.line_colors_index-len(self.line_colors) if self.line_colors_index >= len(self.line_colors): self.line_colors_index=0...
def get_line_color(self, increment=1)
Returns the current color, then increments the color by what's specified
2.332338
2.368683
0.984656
i = self.markers_index self.markers_index += increment if self.markers_index >= len(self.markers): self.markers_index = self.markers_index-len(self.markers) if self.markers_index >= len(self.markers): self.markers_index=0 # to be safe return self.marke...
def get_marker(self, increment=1)
Returns the current marker, then increments the marker by what's specified
2.887839
3.043481
0.948861
i = self.linestyles_index self.linestyles_index += increment if self.linestyles_index >= len(self.linestyles): self.linestyles_index = self.linestyles_index-len(self.linestyles) if self.linestyles_index >= len(self.linestyles): self.linestyles_index=0 # to be s...
def get_linestyle(self, increment=1)
Returns the current marker, then increments the marker by what's specified
2.323085
2.366953
0.981466
i = self.face_colors_index self.face_colors_index += increment if self.face_colors_index >= len(self.face_colors): self.face_colors_index = self.face_colors_index-len(self.face_colors) if self.face_colors_index >= len(self.face_colors): self.face_colors_index=0...
def get_face_color(self, increment=1)
Returns the current face, then increments the face by what's specified
2.308787
2.355811
0.980039
i = self.edge_colors_index self.edge_colors_index += increment if self.edge_colors_index >= len(self.edge_colors): self.edge_colors_index = self.edge_colors_index-len(self.edge_colors) if self.edge_colors_index >= len(self.edge_colors): self.edge_colors_index=0...
def get_edge_color(self, increment=1)
Returns the current face, then increments the face by what's specified
2.33054
2.349435
0.991958
if axes == "gca": axes = _pylab.gca() self.reset() lines = axes.get_lines() for l in lines: l.set_color(self.get_line_color(1)) l.set_mfc(self.get_face_color(1)) l.set_marker(self.get_marker(1)) l.set_mec(self.get_edge_color(1)) ...
def apply(self, axes="gca")
Applies the style cycle to the lines in the axes specified
2.517169
2.388187
1.054008
assert any([message, image_files]) attachment_items = None if image_files: attachment_items = Photo._upload_messages_photos_for_group(session, user_id, image_files) message_id = session.fetch("messages.send", user_id=user_id, message=message, attachment=attachment_...
def _send_message(session, user_id, message=None, image_files=None)
https://vk.com/dev/messages.send
3.866201
3.324058
1.163097
response = session.fetch("messages.getDialogs", unread=unread, important=important, unanswered=unanswered) dialog_json_items = response["items"] return (Message.from_json(session, dialog_json["message"]) for dialog_json in dialog_json_items)
def get_dialog(session, unread=False, important=False, unanswered=False)
https://vk.com/dev/messages.getDialogs
4.030981
3.337165
1.207906
return self._session.fetch_items("groups.getMembers", User.from_json, 1000, group_id=self.id, sort=sort, fields=User.__slots__ + User.USER_FIELDS)
def get_members(self, sort='id_asc')
:param: sort {id_asc, id_desc, time_asc, time_desc} string Docs: https://vk.com/dev/groups.getMembers
9.322867
7.926385
1.176181
return session.fetch_items('groups.get', Group.from_json, count=1000, user_id=user_id, filter=filter, extended=1, fields=",".join(Group.GROUP_FIELDS))
def _get_user_groups(session, user_id, filter)
https://vk.com/dev/groups.get :param filter: {admin, editor, moder, groups, publics, events} :yield: Groups
8.552027
6.086686
1.405038
b = spline_array() b.x_splines = a.x_splines b.y_splines = a.y_splines b.max_y_splines = a.max_y_splines b.xmin = a.xmin b.xmax = a.xmax b.ymin = a.ymin b.ymax = a.ymax b.xlabel = a.xlabel b.ylabel = a.ylabel b.zlabel = a.zlabel b.simple = a.simple b...
def copy_spline_array(a)
This returns an instance of a new spline_array with all the fixins, and the data from a.
2.646739
2.632854
1.005274
if axes=="gca": axes = _pylab.gca() xlabel = axes.xaxis.label.get_text() ylabel = axes.yaxis.label.get_text() xdata = axes.get_lines()[0].get_xdata() ydata = axes.get_lines()[0].get_ydata() if interactive: return splinteractive(xdata, ydata, smoothing, degree, presmoothing...
def splot(axes="gca", smoothing=5000, degree=5, presmoothing=0, plot=True, spline_class=spline_single, interactive=True, show_derivative=1)
gets the data from the plot and feeds it into splint returns an instance of spline_single axes="gca" which axes to get the data from. smoothing=5000 spline_single smoothing parameter presmoothing=0 spline_single data presmoothing factor (nearest neighbor) ...
2.354342
2.375809
0.990964
if simple=='auto': simple = self.simple # make it into an array if it isn't one, and remember that we did is_array = True if not type(x) == type(_pylab.array([])): x = _pylab.array([x]) is_array = False if simple: ...
def evaluate(self, x, derivative=0, smooth=0, simple='auto')
smooth=0 is how much to smooth the spline data simple='auto' is whether we should just use straight interpolation you may want smooth > 0 for this, when derivative=1
3.151011
3.147034
1.001264
if simple=='auto': simple = self.simple # find which values y is in between for n in range(0, len(self.y_values)-1): # if it's in between, interpolate! if self.y_values[n] <= y and self.y_values[n+1] >= y: y1 = self.y_values[n] ...
def evaluate(self, x, y, x_derivative=0, smooth=0, simple='auto')
this evaluates the 2-d spline by doing linear interpolation of the curves
2.489598
2.409192
1.033375
if simple=='auto': simple=self.simple # get the min and max if ymin=="auto": ymin = self.ymin if ymax=="auto": ymax = self.ymax if clear: _pylab.gca().clear() if not type(x_values) in [type([]), type(_pylab.array([]))]: x_values = [x_values] fo...
def plot_fixed_x(self, x_values, x_derivative=0, steps=1000, smooth=0, simple='auto', ymin="auto", ymax="auto", format=True, clear=1)
plots the data at fixed x-value, so z vs x
4.26214
4.216013
1.010941
if simple=='auto': simple=self.simple # get the min and max if xmin=="auto": xmin = self.xmin if xmax=="auto": xmax = self.xmax if clear: _pylab.gca().clear() if not type(y_values) in [type([]), type(_pylab.array([]))]: y_values = [y_values] for y in ...
def plot_fixed_y(self, y_values, x_derivative=0, steps=1000, smooth=0, simple='auto', xmin="auto", xmax="auto", format=True, clear=1)
plots the data at a fixed y-value, so z vs y
4.003571
3.988875
1.003684
def get_window(self): x = self while not x._parent == None and \ not isinstance(x._parent, Window): x = x._parent return x._parent
Returns the object's parent window. Returns None if no window found.
null
null
null
t0 = _t.time() while _t.time()-t0 < seconds: # Pause a bit to avoid heavy CPU _t.sleep(dt) # process events self.process_events()
def sleep(self, seconds=0.05, dt=0.01)
A "smooth" version of time.sleep(): waits for the time to pass but processes events every dt as well. Note this requires that the object is either a window or embedded somewhere within a window.
6.228767
5.635485
1.105276
self._widget.blockSignals(True) self._widget.setUpdatesEnabled(False)
def block_events(self)
Prevents the widget from sending signals.
6.674905
3.988963
1.673343
self._widget.blockSignals(False) self._widget.setUpdatesEnabled(True)
def unblock_events(self)
Allows the widget to send signals.
6.682495
4.298124
1.554747
if self.log == None: print(message) else: self.log.append_text(message)
def print_message(self, message="heya!")
If self.log is defined to be an instance of TextLog, it print the message there. Otherwise use the usual "print" to command line.
6.851211
4.124657
1.661038
# only if we're supposed to! if self._autosettings_path: # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') # make sure the directory exists if not _os.path.exists(gui_settings_dir): _os.mkdir(gui_se...
def save_gui_settings(self, *a)
Saves just the current configuration of the controls if the autosettings_path is set.
5.769457
5.112167
1.128574
# only do this if we're supposed to if self._autosettings_path is not None: # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') # assemble the path with a sub-directory path = _os.path.join(gui_settings_dir, ...
def load_gui_settings(self, lazy_only=False)
Loads the settings (if we're supposed to). Parameters ---------- lazy_only=False If True, it will only load the settings into self._lazy_load, and not try to update the value. Presumably the widget will apply these settings later, e.g., when enough ta...
7.49051
7.086994
1.056938
# Whether we should pop the value from the dictionary when we set it. pop_value = False # If d is None, assume we're using the lazy load settings. if d == None: d = self._lazy_load pop_value = True # If we have a databox, take t...
def _load_gui_setting(self, key, d=None)
Safely reads the header setting and sets the appropriate control value. Parameters ---------- key Key string of the format 'self.controlname'. d = None Databox instance or dictionary, presumably containing the aforementioned key. If d...
8.099641
6.635951
1.22057
try: databox.insert_header(name, eval(name + ".get_value()")) except: print("ERROR: Could not store gui setting "+repr(name))
def _store_gui_setting(self, databox, name)
Stores the gui setting in the header of the supplied databox. hkeys in the file are set to have the format "self.controlname"
10.262356
7.970569
1.287531
# pick a column if column==None: column = self._auto_column self._auto_column += 1 # pick a row if row==None: row = self._auto_row # create the object self.objects.append(object) # add the widget to the layout try: ...
def place_object(self, object, column=None, row=None, column_span=1, row_span=1, alignment=1)
This adds either one of our simplified objects or a QWidget to the grid at the specified position, appends the object to self.objects. alignment=0 Fill the space. alignment=1 Left-justified. alignment=2 Right-justified. If column isn't specified, the new object will...
5.193965
5.023944
1.033842
if type(object) in [int, int]: n = object else: n = self.objects.index(object) # pop it from the list object = self.objects.pop(n) # remove it from the GUI and delete it if hasattr_safe(object, '_widget'): self._layout.remo...
def remove_object(self, object=0, delete=True)
Removes the supplied object from the grid. If object is an integer, it removes the n'th object.
3.276462
3.293329
0.994878
self._layout.setColumnStretch(column, stretch) return self
def set_column_stretch(self, column=0, stretch=10)
Sets the column stretch. Larger numbers mean it will expand more to fill space.
5.522826
6.61227
0.835239
self._layout.setRowStretch(row, stretch) return self
def set_row_stretch(self, row=0, stretch=10)
Sets the row stretch. Larger numbers mean it will expand more to fill space.
5.837384
6.548813
0.891365
if row==None: self._auto_row += 1 else: self._auto_row = row self._auto_column=0 return self
def new_autorow(self, row=None)
Sets the auto-add row. If row=None, increments by 1
5.396101
4.680495
1.152891
# map of options m = dict(top = _g.QtCore.Qt.TopDockWidgetArea, bottom = _g.QtCore.Qt.BottomDockWidgetArea, left = _g.QtCore.Qt.LeftDockWidgetArea, right = _g.QtCore.Qt.RightDockWidgetArea) # set the parent ...
def place_docker(self, docker, area='top')
IN DEVELOPMENT Places a DockWindow instance at the specified area ('top', 'bottom', 'left', 'right', or None)
4.220308
3.960363
1.065637
if self._autosettings_path == None: return # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') # make sure the directory exists if not _os.path.exists(gui_settings_dir): _os.mkdir(gui_settings_dir) # make a path with...
def _save_settings(self)
Saves all the parameters to a text file.
4.209072
4.040203
1.041797
if self._autosettings_path == None: return # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') # make a path with a sub-directory path = _os.path.join(gui_settings_dir, self._autosettings_path) # make sure th...
def _load_settings(self)
Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path.
4.443498
4.189521
1.060622
self._is_open = True self._window.show() self._window.raise_() # start the blocking loop if block_command_line: # stop when the window closes while self._is_open: _a.processEvents() _t.sleep(block_timing) ...
def show(self, block_command_line=False, block_timing=0.05)
Shows the window and raises it. If block_command_line is 0, this will start the window up and allow you to monkey with the command line at the same time. Otherwise, the window will block the command line and process events every block_timing seconds.
5.459306
5.320993
1.025994
if block_events: self._widget.blockSignals(True) self._widget.setChecked(value) if block_events: self._widget.blockSignals(False) return self
def set_checked(self, value=True, block_events=False)
This will set whether the button is checked. Setting block_events=True will temporarily disable signals from the button when setting the value.
2.650209
3.048473
0.869356
if self.is_checkable(): if self.is_checked(): self.set_checked(False) else: self.set_checked(True) self.signal_clicked.emit(self.is_checked()) else: self.signal_clicked.emit(True) return self
def click(self)
Pretends to user clicked it, sending the signal and everything.
3.228928
2.764674
1.167924
# assemble the string s = "QLabel {" for a in args: s = s+a+"; " for k in list(kwargs.keys()): s = s+k.replace("_","-")+": "+kwargs[k]+"; " s = s+"}" # set it! self._widget.setStyleSheet(s) return self
def set_style(self, *args, **kwargs)
Provides access to any number of style sheet settings via self._widget.SetStyleSheet() *args can be any element between semicolons, e.g. self.set_stylesheet('text-align: right; padding-left: 5px') **kwargs can be any key-value pair, replacing '-' with '_' in the key, e.g. ...
4.463258
3.994131
1.117454
if block_events: self.block_events() self._widget.setValue(value) if block_events: self.unblock_events()
def set_value(self, value, block_events=False)
Sets the current value of the number box. Setting block_events=True will temporarily block the widget from sending any signals when setting the value.
3.04774
3.606718
0.845018
if block_events: self.block_events() self._widget.setSingleStep(value) if block_events: self.unblock_events()
def set_step(self, value, block_events=False)
Sets the step of the number box. Setting block_events=True will temporarily block the widget from sending any signals when setting the value.
3.649306
3.860302
0.945342
if index==None: return self.get_text(self.get_value()) else: return str(self._widget.itemText(index))
def get_text(self, index=None)
Gets text from a given index. If index=None, returns the current value self.get_text(self.get_value())
5.109552
3.117928
1.638765
return [self._widget.itemText(k) for k in range(self._widget.count())]
def get_all_items(self)
Returns all items in the combobox dictionary.
7.235255
4.288013
1.687321
self._widget.blockSignals(block_events) # create a widget to go in the tab tab = GridLayout() self.tabs.append(tab) tab.set_parent(self) # create and append the tab to the list self._widget.addTab(tab._widget, title) # try to lazy set the curre...
def add_tab(self, title="Yeah!", block_events=True)
Adds a tab to the area, and creates the layout for this tab.
4.593005
4.493444
1.022157
# pop it from the list t = self.tabs.pop(tab) # remove it from the gui self._widget.removeTab(tab) # return it in case someone cares return t
def remove_tab(self, tab=0)
Removes the tab by index.
6.1774
6.124012
1.008718
x = self._widget.item(row, column) if x==None: return x else: return str(self._widget.item(row,column).text())
def get_value(self, column=0, row=0)
Returns a the value at column, row.
5.79921
5.245749
1.105507
if block_events: self.block_events() # dynamically resize while column > self._widget.columnCount()-1: self._widget.insertColumn(self._widget.columnCount()) while row > self._widget.rowCount() -1: self._widget.insertRow( self._widget.rowCount()) # set the value...
def set_value(self, column=0, row=0, value='', block_events=False)
Sets the value at column, row. This will create elements dynamically, and in a totally stupid while-looping way. Setting block_events=True will temporarily block the widget from sending any signals when setting the value.
3.320919
3.604674
0.921281
self._widget.setColumnWidth(n, width) return self
def set_column_width(self, n=0, width=120)
Sets the n'th column width in pixels.
6.108934
4.553643
1.341549
if row: self._widget.verticalHeader().show() else: self._widget.verticalHeader().hide() if column: self._widget.horizontalHeader().show() else: self._widget.horizontalHeader().hide() return self
def set_header_visibility(self, column=False, row=False)
Sets whether we can see the column and row headers.
2.937875
2.751423
1.067766
self._widget.setRowHeight(n, height) return self
def set_row_height(self, n=0, height=18)
Sets the n'th row height in pixels.
6.054098
4.639045
1.305031
for n in self.naughty: key = key.replace(n, '_') return key
def _clean_up_key(self, key)
Returns the key string with no naughty characters.
8.987054
4.280204
2.099679
# block all signals during the update (to avoid re-calling this) self.block_events() # loop over the rows for n in range(self.get_row_count()): # get the keys and values (as text) key = self.get_value(0,n) value = self.get_value(1,n) ...
def _cell_changed(self, *a)
Called whenever a cell is changed. Updates the dictionary.
3.789555
3.694435
1.025747
keys = list(self.keys()) # make sure it exists if not key in keys: self.print_message("ERROR: '"+str(key)+"' not found.") return None try: x = eval(self.get_value(1,keys.index(key))) return x except: self.pri...
def get_item(self, key)
Returns the value associated with the key.
3.4399
3.279207
1.049004
keys = list() for n in range(len(self)): # only append the valid keys key = self.get_value() if not key in ['', None]: keys.append(key) return keys
def keys(self)
Returns a sorted list of keys
7.472954
7.269361
1.028007
keys = list(self.keys()) # if it exists, update if key in keys: self.set_value(1,keys.index(key),str(value)) # otherwise we have to add an element else: self.set_value(0,len(self), str(key)) self.set_value(1,len(self)-1, str(value)...
def set_item(self, key, value)
Sets the item by key, and refills the table sorted.
4.106662
3.915533
1.048813
if not dictionary == None: kwargs.update(dictionary) for k in list(kwargs.keys()): self[k] = kwargs[k]
def update(self, dictionary=None, **kwargs)
Adds/overwrites all the keys and values from the dictionary.
4.257622
3.557228
1.196893
if self._multiline: return str(self._widget.toPlainText()) else: return str(self._widget.text())
def get_text(self)
Returns the current text.
6.421324
5.086069
1.262532
# Make sure the text is actually different, so as not to # trigger a value changed signal s = str(text) if not s == self.get_text(): self._widget.setText(str(text)) return self
def set_text(self, text="YEAH.")
Sets the current value of the text box.
9.356293
8.111247
1.153496
if self._multiline: self._widget.setStyleSheet("QTextEdit {background-color: "+str(background)+"; color: "+str(text)+"}") else: self._widget.setStyleSheet("QLineEdit {background-color: "+str(background)+"; color: "+str(text)+"}")
def set_colors(self, text='black', background='white')
Sets the colors of the text area.
2.546198
2.53331
1.005087
# block events in the usual way BaseObject.block_events(self) # loop over all top level parameters for i in range(self._widget.topLevelItemCount()): self._widget.topLevelItem(i).param.blockSignals(True) return self
def block_events(self)
Special version of block_events that loops over all tree elements.
8.381206
7.869361
1.065043
# unblock events in the usual way BaseObject.unblock_events(self) # loop over all top level parameters for i in range(self._widget.topLevelItemCount()): self._widget.topLevelItem(i).param.blockSignals(False) return self
def unblock_events(self)
Special version of unblock_events that loops over all tree elements as well.
7.913323
7.118501
1.111656
# loop over all top level parameters for i in range(self._widget.topLevelItemCount()): # make sure there is only one connection! try: self._widget.topLevelItem(i).param.sigTreeStateChanged.connect( function, typ...
def connect_any_signal_changed(self, function)
Connects the "anything changed" signal for all of the tree to the specified function. Parameters ---------- function Function to connect to this signal.
7.945632
8.770937
0.905905
x = self._find_parameter(name.split("/")) # if it pooped. if x==None: return None # connect it x.sigValueChanged.connect(function) # Keep track of the functions if name in self._connection_lists: self._connection_lists[name].append(function) ...
def connect_signal_changed(self, name, function)
Connects a changed signal from the parameters of the specified name to the supplied function.
6.242416
6.070303
1.028353
x = self._find_parameter(name.split("/"), quiet=ignore_error) # if it pooped. if x==None: return None # disconnect it from all its functions if name in self._connection_lists: for f in self._connection_lists[name]: x.sigValueChanged.disconnect(f...
def block_user_signals(self, name, ignore_error=False)
Temporarily disconnects the user-defined signals for the specified parameter name. Note this only affects those connections made with connect_signal_changed(), and I do not recommend adding new connections while they're blocked!
11.172383
11.004062
1.015296
x = self._find_parameter(name.split("/"), quiet=ignore_error) # if it pooped. if x==None: return None # reconnect it to all its functions if name in self._connection_lists: for f in self._connection_lists[name]: x.sigValueChanged.connect(f) ...
def unblock_user_signals(self, name, ignore_error=False)
Reconnects the user-defined signals for the specified parameter name (blocked with "block_user_signal_changed") Note this only affects those connections made with connect_signal_changed(), and I do not recommend adding new connections while they're blocked!
12.249015
11.620962
1.054045
# make a copy so this isn't destructive to the supplied list s = list(name_list) # if the length is zero, return the root widget if len(s)==0: return self._widget # the first name must be treated differently because it is # the main widget, not a branch ...
def _find_parameter(self, name_list, create_missing=False, quiet=False)
Tries to find and return the parameter of the specified name. The name should be of the form ['branch1','branch2', 'parametername'] Setting create_missing=True means if it doesn't find a branch it will create one. Setting quiet=True will suppress error messages (for checking)
4.231642
4.349226
0.972964
for n in self.naughty: name = name.replace(n, '_') return name
def _clean_up_name(self, name)
Cleans up the name according to the rules specified in this exact function. Uses self.naughty, a list of naughty characters.
9.117823
4.508784
2.022235
# first clean up the name name = self._clean_up_name(name) # split into (presumably existing) branches and parameter s = name.split('/') # make sure it doesn't already exist if not self._find_parameter(s, quiet=True) == None: self.print_message("Er...
def add_button(self, name, checkable=False, checked=False)
Adds (and returns) a button at the specified location.
8.468097
8.360334
1.01289
# update the default kwargs other_kwargs = dict(type=None) other_kwargs.update(kwargs) # Auto typing if other_kwargs['type'] == None: other_kwargs['type'] = type(value).__name__ # Fix 'values' for list objects to be only strings if othe...
def add_parameter(self, name='test', value=42.0, **kwargs)
Adds a parameter "leaf" to the tree. Parameters ---------- name='test' The name of the leaf. It should be a string of the form "branch1/branch2/parametername" and will be nested as indicated. value=42.0 Value of the leaf. Com...
6.023531
5.538133
1.087647
# assemble the key for this parameter k = base_name + "/" + parameter.name() # first add this parameter (if it has a value) if not parameter.value()==None: sorted_keys.append(k[1:]) dictionary[sorted_keys[-1]] = parameter.value() # now loop ove...
def _get_parameter_dictionary(self, base_name, dictionary, sorted_keys, parameter)
Recursively loops over the parameter's children, adding keys (starting with base_name) and values to the supplied dictionary (provided they do not have a value of None).
3.527936
3.247877
1.086228
k, d = self.get_dictionary() destination_databox.update_headers(d,k)
def send_to_databox_header(self, destination_databox)
Sends all the information currently in the tree to the supplied databox's header, in alphabetical order. If the entries already exists, just updates them.
14.021369
10.905882
1.28567
# output k = list() d = dict() # loop over the root items for i in range(self._widget.topLevelItemCount()): # grab the parameter item, and start building the name x = self._widget.topLevelItem(i).param # now start the recursive loo...
def get_dictionary(self)
Returns the list of parameters and a dictionary of values (good for writing to a databox header!) Return format is sorted_keys, dictionary
9.03949
8.638081
1.04647
# first clean up the name name = self._clean_up_name(name) # now get the parameter object x = self._find_parameter(name.split('/')) # quit if it pooped. if x == None: return None # get the value and test the bounds value = x.value() ...
def get_value(self, name)
Returns the value of the parameter with the specified name.
5.055206
4.963501
1.018476
# Make sure it's a list if not self.get_type(name) in ['list']: self.print_message('ERROR: "'+name+'" is not a list.') return # Return a copy of the list values return list(self.get_widget(name).opts['values'])
def get_list_values(self, name)
Returns the values for a list item of the specified name.
5.245977
5.222075
1.004577
# first clean up the name name = self._clean_up_name(name) # If we're supposed to, block the user signals for this parameter if block_user_signals: self.block_user_signals(name, ignore_error) # now get the parameter object x = self._find_parameter(name....
def set_value(self, name, value, ignore_error=False, block_user_signals=False)
Sets the variable of the supplied name to the supplied value. Setting block_user_signals=True will temporarily block the widget from sending any signals when setting the value.
5.421531
5.537076
0.979133
if path==None: if self._autosettings_path == None: return self # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') # make sure the directory exists if not _os.path.exists(gui_sett...
def save(self, path=None)
Saves all the parameters to a text file using the databox functionality. If path=None, saves to self._autosettings_path. If self._autosettings_path=None, does not save.
5.37445
4.675804
1.149417
if path==None: # Bail if there is no path if self._autosettings_path == None: return self # Get the gui settings directory gui_settings_dir = _os.path.join(_cwd, 'egg_settings') # Get the final path path...
def load(self, path=None, ignore_errors=True, block_user_signals=False)
Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path (provided this is not None). Parameters ---------- path=None Path to load the settings from. If None, will load from the specified autosettings_path. ...
5.241292
4.533242
1.15619
if not type(d) == dict: d = d.headers # Update the lazy load self._lazy_load.update(d) # loop over the dictionary and update for k in list(self._lazy_load.keys()): # Only proceed if the parameter exists if not self._find_parameter(k.split('/'),...
def update(self, d, ignore_errors=True, block_user_signals=False)
Supply a dictionary or databox with a header of the same format and see what happens! (Hint: it updates the existing values.) This will store non-existent key-value pairs in the dictionary self._lazy_load. When you add settings in the future, these will be checked for the defau...
5.523884
4.571023
1.208457
# for safety: by default assume it's a repr() with python code try: self.set_value(k, v, ignore_error = ignore_errors, block_user_signals = block_user_signals) except: print("TreeDictionary ERROR: Could not set '"+k+"' to ...
def _set_value_safe(self, k, v, ignore_errors=False, block_user_signals=False)
Actually sets the value, first by trying it directly, then by
9.781616
10.081442
0.97026
if checked: # get the path from the user path = _spinmob.dialogs.save(filters=self.file_type) # abort if necessary if not path: self.button_autosave.set_checked(False) return # otherwise, save the info! ...
def _button_autosave_clicked(self, checked)
Called whenever the button is clicked.
7.547621
7.303655
1.033403
# Update the binary mode if not 'binary' in kwargs: kwargs['binary'] = self.combo_binary.get_text() # if it's just the settings file, make a new databox if just_settings: d = _d.databox() # otherwise use the internal databox else: d = self # ad...
def save_file(self, path=None, force_overwrite=False, just_settings=False, **kwargs)
Saves the data in the databox to a file. Parameters ---------- path=None Path for output. If set to None, use a save dialog. force_overwrite=False Do not question the overwrite if the file already exists. just_settings=False Set to True to sa...
9.517209
8.819817
1.079071
# if it's just the settings file, make a new databox if just_settings: d = _d.databox() header_only = True # otherwise use the internal databox else: d = self header_only = False # import the settings if they exist in the...
def load_file(self, path=None, just_settings=False)
Loads a data file. After the file is loaded, calls self.after_load_file(self), which you can overwrite if you like! just_settings=True will only load the configuration of the controls, and will not plot anything or run after_load_file
8.456978
8.128654
1.040391
# This should never happen unless I screwed up. if self.combo_autoscript.get_index() == 0: return "ERROR: Ask Jack." # if there is no data, leave it blank if len(self)==0: return "x = []; y = []; xlabels=[]; ylabels=[]" # if there is one column, make up a one...
def _autoscript(self)
Automatically generates a python script for plotting.
2.204135
2.154533
1.023023
# if we're disabled or have no data columns, clear everything! if not self.button_enabled.is_checked() or len(self) == 0: self._set_number_of_plots(0) return self # if there is no script, create a default if not self.combo_autoscript.get_index()==0: ...
def plot(self)
Sets the internal databox to the supplied value and plots it. If databox=None, this will plot the internal databox.
3.788102
3.80371
0.995897
# make sure we're suppoed to if self.button_autosave.is_checked(): # save the file self.save_file(_os.path.join(self._autosave_directory, "%04d " % (self.number_file.get_value()) + self._label_path.get_text())) # increment the counter self.numbe...
def autosave(self)
Autosaves the currently stored data, but only if autosave is checked!
7.495974
6.805351
1.101482
if n==None: for p in self.plot_widgets: p.autoRange() else: self.plot_widgets[n].autoRange() return self
def autozoom(self, n=None)
Auto-scales the axes to fit all the data in plot index n. If n == None, auto-scale everyone.
6.807909
6.519088
1.044304