repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
Spinmob/spinmob
egg/_gui.py
BaseObject.save_gui_settings
def save_gui_settings(self, *a): """ Saves just the current configuration of the controls if the autosettings_path is set. """ # 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_settings_dir) # make a path with a sub-directory path = _os.path.join(gui_settings_dir, self._autosettings_path) # for saving header info d = _d.databox() # add all the controls settings for x in self._autosettings_controls: self._store_gui_setting(d, x) # save the file d.save_file(path, force_overwrite=True)
python
def save_gui_settings(self, *a): """ Saves just the current configuration of the controls if the autosettings_path is set. """ # 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_settings_dir) # make a path with a sub-directory path = _os.path.join(gui_settings_dir, self._autosettings_path) # for saving header info d = _d.databox() # add all the controls settings for x in self._autosettings_controls: self._store_gui_setting(d, x) # save the file d.save_file(path, force_overwrite=True)
[ "def", "save_gui_settings", "(", "self", ",", "*", "a", ")", ":", "# only if we're supposed to!", "if", "self", ".", "_autosettings_path", ":", "# Get the gui settings directory", "gui_settings_dir", "=", "_os", ".", "path", ".", "join", "(", "_cwd", ",", "'egg_se...
Saves just the current configuration of the controls if the autosettings_path is set.
[ "Saves", "just", "the", "current", "configuration", "of", "the", "controls", "if", "the", "autosettings_path", "is", "set", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L178-L203
train
39,700
Spinmob/spinmob
egg/_gui.py
BaseObject._store_gui_setting
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" """ try: databox.insert_header(name, eval(name + ".get_value()")) except: print("ERROR: Could not store gui setting "+repr(name))
python
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" """ 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", ")", ":", "try", ":", "databox", ".", "insert_header", "(", "name", ",", "eval", "(", "name", "+", "\".get_value()\"", ")", ")", "except", ":", "print", "(", "\"ERROR: Could not store gui...
Stores the gui setting in the header of the supplied databox. hkeys in the file are set to have the format "self.controlname"
[ "Stores", "the", "gui", "setting", "in", "the", "header", "of", "the", "supplied", "databox", ".", "hkeys", "in", "the", "file", "are", "set", "to", "have", "the", "format", "self", ".", "controlname" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L288-L295
train
39,701
Spinmob/spinmob
egg/_gui.py
GridLayout.place_object
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 be placed in a new column. """ # 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: object._widget widget = object._widget # allows the user to specify a standard widget except: widget = object self._layout.addWidget(widget, row, column, row_span, column_span, _g.Qt.QtCore.Qt.Alignment(alignment)) # try to store the parent object (self) in the placed object try: object.set_parent(self) except: None return object
python
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 be placed in a new column. """ # 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: object._widget widget = object._widget # allows the user to specify a standard widget except: widget = object self._layout.addWidget(widget, row, column, row_span, column_span, _g.Qt.QtCore.Qt.Alignment(alignment)) # try to store the parent object (self) in the placed object try: object.set_parent(self) except: None return object
[ "def", "place_object", "(", "self", ",", "object", ",", "column", "=", "None", ",", "row", "=", "None", ",", "column_span", "=", "1", ",", "row_span", "=", "1", ",", "alignment", "=", "1", ")", ":", "# pick a column", "if", "column", "==", "None", ":...
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 be placed in a new column.
[ "This", "adds", "either", "one", "of", "our", "simplified", "objects", "or", "a", "QWidget", "to", "the", "grid", "at", "the", "specified", "position", "appends", "the", "object", "to", "self", ".", "objects", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L369-L408
train
39,702
Spinmob/spinmob
egg/_gui.py
GridLayout.remove_object
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. """ 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.removeWidget(object._widget) object._widget.hide() if delete: object._widget.deleteLater() else: self._layout.removeWidget(object) object.hide() if delete: object.deleteLater()
python
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. """ 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.removeWidget(object._widget) object._widget.hide() if delete: object._widget.deleteLater() else: self._layout.removeWidget(object) object.hide() if delete: object.deleteLater()
[ "def", "remove_object", "(", "self", ",", "object", "=", "0", ",", "delete", "=", "True", ")", ":", "if", "type", "(", "object", ")", "in", "[", "int", ",", "int", "]", ":", "n", "=", "object", "else", ":", "n", "=", "self", ".", "objects", "."...
Removes the supplied object from the grid. If object is an integer, it removes the n'th object.
[ "Removes", "the", "supplied", "object", "from", "the", "grid", ".", "If", "object", "is", "an", "integer", "it", "removes", "the", "n", "th", "object", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L410-L429
train
39,703
Spinmob/spinmob
egg/_gui.py
GridLayout.set_column_stretch
def set_column_stretch(self, column=0, stretch=10): """ Sets the column stretch. Larger numbers mean it will expand more to fill space. """ self._layout.setColumnStretch(column, stretch) return self
python
def set_column_stretch(self, column=0, stretch=10): """ Sets the column stretch. Larger numbers mean it will expand more to fill space. """ self._layout.setColumnStretch(column, stretch) return self
[ "def", "set_column_stretch", "(", "self", ",", "column", "=", "0", ",", "stretch", "=", "10", ")", ":", "self", ".", "_layout", ".", "setColumnStretch", "(", "column", ",", "stretch", ")", "return", "self" ]
Sets the column stretch. Larger numbers mean it will expand more to fill space.
[ "Sets", "the", "column", "stretch", ".", "Larger", "numbers", "mean", "it", "will", "expand", "more", "to", "fill", "space", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L439-L445
train
39,704
Spinmob/spinmob
egg/_gui.py
GridLayout.set_row_stretch
def set_row_stretch(self, row=0, stretch=10): """ Sets the row stretch. Larger numbers mean it will expand more to fill space. """ self._layout.setRowStretch(row, stretch) return self
python
def set_row_stretch(self, row=0, stretch=10): """ Sets the row stretch. Larger numbers mean it will expand more to fill space. """ self._layout.setRowStretch(row, stretch) return self
[ "def", "set_row_stretch", "(", "self", ",", "row", "=", "0", ",", "stretch", "=", "10", ")", ":", "self", ".", "_layout", ".", "setRowStretch", "(", "row", ",", "stretch", ")", "return", "self" ]
Sets the row stretch. Larger numbers mean it will expand more to fill space.
[ "Sets", "the", "row", "stretch", ".", "Larger", "numbers", "mean", "it", "will", "expand", "more", "to", "fill", "space", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L447-L453
train
39,705
Spinmob/spinmob
egg/_gui.py
GridLayout.new_autorow
def new_autorow(self, row=None): """ Sets the auto-add row. If row=None, increments by 1 """ if row==None: self._auto_row += 1 else: self._auto_row = row self._auto_column=0 return self
python
def new_autorow(self, row=None): """ Sets the auto-add row. If row=None, increments by 1 """ if row==None: self._auto_row += 1 else: self._auto_row = row self._auto_column=0 return self
[ "def", "new_autorow", "(", "self", ",", "row", "=", "None", ")", ":", "if", "row", "==", "None", ":", "self", ".", "_auto_row", "+=", "1", "else", ":", "self", ".", "_auto_row", "=", "row", "self", ".", "_auto_column", "=", "0", "return", "self" ]
Sets the auto-add row. If row=None, increments by 1
[ "Sets", "the", "auto", "-", "add", "row", ".", "If", "row", "=", "None", "increments", "by", "1" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L455-L463
train
39,706
Spinmob/spinmob
egg/_gui.py
Window._save_settings
def _save_settings(self): """ Saves all the parameters to a text file. """ 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 a sub-directory path = _os.path.join(gui_settings_dir, self._autosettings_path) # Create a Qt settings object settings = _g.QtCore.QSettings(path, _g.QtCore.QSettings.IniFormat) settings.clear() # Save values if hasattr_safe(self._window, "saveState"): settings.setValue('State',self._window.saveState()) settings.setValue('Geometry', self._window.saveGeometry())
python
def _save_settings(self): """ Saves all the parameters to a text file. """ 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 a sub-directory path = _os.path.join(gui_settings_dir, self._autosettings_path) # Create a Qt settings object settings = _g.QtCore.QSettings(path, _g.QtCore.QSettings.IniFormat) settings.clear() # Save values if hasattr_safe(self._window, "saveState"): settings.setValue('State',self._window.saveState()) settings.setValue('Geometry', self._window.saveGeometry())
[ "def", "_save_settings", "(", "self", ")", ":", "if", "self", ".", "_autosettings_path", "==", "None", ":", "return", "# Get the gui settings directory", "gui_settings_dir", "=", "_os", ".", "path", ".", "join", "(", "_cwd", ",", "'egg_settings'", ")", "# make s...
Saves all the parameters to a text file.
[ "Saves", "all", "the", "parameters", "to", "a", "text", "file", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L602-L624
train
39,707
Spinmob/spinmob
egg/_gui.py
Window._load_settings
def _load_settings(self): """ Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path. """ 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 the directory exists if not _os.path.exists(path): return # Create a Qt settings object settings = _g.QtCore.QSettings(path, _g.QtCore.QSettings.IniFormat) # Load it up! (Extra steps required for windows command line execution) if settings.contains('State') and hasattr_safe(self._window, "restoreState"): x = settings.value('State') if hasattr(x, "toByteArray"): x = x.toByteArray() self._window.restoreState(x) if settings.contains('Geometry'): x = settings.value('Geometry') if hasattr(x, "toByteArray"): x = x.toByteArray() self._window.restoreGeometry(x)
python
def _load_settings(self): """ Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path. """ 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 the directory exists if not _os.path.exists(path): return # Create a Qt settings object settings = _g.QtCore.QSettings(path, _g.QtCore.QSettings.IniFormat) # Load it up! (Extra steps required for windows command line execution) if settings.contains('State') and hasattr_safe(self._window, "restoreState"): x = settings.value('State') if hasattr(x, "toByteArray"): x = x.toByteArray() self._window.restoreState(x) if settings.contains('Geometry'): x = settings.value('Geometry') if hasattr(x, "toByteArray"): x = x.toByteArray() self._window.restoreGeometry(x)
[ "def", "_load_settings", "(", "self", ")", ":", "if", "self", ".", "_autosettings_path", "==", "None", ":", "return", "# Get the gui settings directory", "gui_settings_dir", "=", "_os", ".", "path", ".", "join", "(", "_cwd", ",", "'egg_settings'", ")", "# make a...
Loads all the parameters from a databox text file. If path=None, loads from self._autosettings_path.
[ "Loads", "all", "the", "parameters", "from", "a", "databox", "text", "file", ".", "If", "path", "=", "None", "loads", "from", "self", ".", "_autosettings_path", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L626-L654
train
39,708
Spinmob/spinmob
egg/_gui.py
Window.show
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. """ 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) # wait a moment in case there is some shutdown stuff. _t.sleep(0.5) return self
python
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. """ 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) # wait a moment in case there is some shutdown stuff. _t.sleep(0.5) return self
[ "def", "show", "(", "self", ",", "block_command_line", "=", "False", ",", "block_timing", "=", "0.05", ")", ":", "self", ".", "_is_open", "=", "True", "self", ".", "_window", ".", "show", "(", ")", "self", ".", "_window", ".", "raise_", "(", ")", "# ...
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.
[ "Shows", "the", "window", "and", "raises", "it", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L713-L738
train
39,709
Spinmob/spinmob
egg/_gui.py
Button.set_checked
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. """ if block_events: self._widget.blockSignals(True) self._widget.setChecked(value) if block_events: self._widget.blockSignals(False) return self
python
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. """ 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", ")", ":", "if", "block_events", ":", "self", ".", "_widget", ".", "blockSignals", "(", "True", ")", "self", ".", "_widget", ".", "setChecked", "(", "value", ...
This will set whether the button is checked. Setting block_events=True will temporarily disable signals from the button when setting the value.
[ "This", "will", "set", "whether", "the", "button", "is", "checked", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L915-L926
train
39,710
Spinmob/spinmob
egg/_gui.py
Button.click
def click(self): """ Pretends to user clicked it, sending the signal and everything. """ 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
python
def click(self): """ Pretends to user clicked it, sending the signal and everything. """ 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", ")", ":", "if", "self", ".", "is_checkable", "(", ")", ":", "if", "self", ".", "is_checked", "(", ")", ":", "self", ".", "set_checked", "(", "False", ")", "else", ":", "self", ".", "set_checked", "(", "True", ")", "self...
Pretends to user clicked it, sending the signal and everything.
[ "Pretends", "to", "user", "clicked", "it", "sending", "the", "signal", "and", "everything", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L949-L959
train
39,711
Spinmob/spinmob
egg/_gui.py
NumberBox.set_value
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. """ if block_events: self.block_events() self._widget.setValue(value) if block_events: self.unblock_events()
python
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. """ if block_events: self.block_events() self._widget.setValue(value) if block_events: self.unblock_events()
[ "def", "set_value", "(", "self", ",", "value", ",", "block_events", "=", "False", ")", ":", "if", "block_events", ":", "self", ".", "block_events", "(", ")", "self", ".", "_widget", ".", "setValue", "(", "value", ")", "if", "block_events", ":", "self", ...
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.
[ "Sets", "the", "current", "value", "of", "the", "number", "box", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1070-L1079
train
39,712
Spinmob/spinmob
egg/_gui.py
NumberBox.set_step
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. """ if block_events: self.block_events() self._widget.setSingleStep(value) if block_events: self.unblock_events()
python
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. """ if block_events: self.block_events() self._widget.setSingleStep(value) if block_events: self.unblock_events()
[ "def", "set_step", "(", "self", ",", "value", ",", "block_events", "=", "False", ")", ":", "if", "block_events", ":", "self", ".", "block_events", "(", ")", "self", ".", "_widget", ".", "setSingleStep", "(", "value", ")", "if", "block_events", ":", "self...
Sets the step of the number box. Setting block_events=True will temporarily block the widget from sending any signals when setting the value.
[ "Sets", "the", "step", "of", "the", "number", "box", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1081-L1090
train
39,713
Spinmob/spinmob
egg/_gui.py
ComboBox.get_all_items
def get_all_items(self): """ Returns all items in the combobox dictionary. """ return [self._widget.itemText(k) for k in range(self._widget.count())]
python
def get_all_items(self): """ Returns all items in the combobox dictionary. """ return [self._widget.itemText(k) for k in range(self._widget.count())]
[ "def", "get_all_items", "(", "self", ")", ":", "return", "[", "self", ".", "_widget", ".", "itemText", "(", "k", ")", "for", "k", "in", "range", "(", "self", ".", "_widget", ".", "count", "(", ")", ")", "]" ]
Returns all items in the combobox dictionary.
[ "Returns", "all", "items", "in", "the", "combobox", "dictionary", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1206-L1210
train
39,714
Spinmob/spinmob
egg/_gui.py
TabArea.add_tab
def add_tab(self, title="Yeah!", block_events=True): """ Adds a tab to the area, and creates the layout for this tab. """ 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 current tab if 'self' in self._lazy_load and self.get_tab_count() > self._lazy_load['self']: v = self._lazy_load.pop('self') self.set_current_tab(v) self._widget.blockSignals(False) return tab
python
def add_tab(self, title="Yeah!", block_events=True): """ Adds a tab to the area, and creates the layout for this tab. """ 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 current tab if 'self' in self._lazy_load and self.get_tab_count() > self._lazy_load['self']: v = self._lazy_load.pop('self') self.set_current_tab(v) self._widget.blockSignals(False) return tab
[ "def", "add_tab", "(", "self", ",", "title", "=", "\"Yeah!\"", ",", "block_events", "=", "True", ")", ":", "self", ".", "_widget", ".", "blockSignals", "(", "block_events", ")", "# create a widget to go in the tab", "tab", "=", "GridLayout", "(", ")", "self", ...
Adds a tab to the area, and creates the layout for this tab.
[ "Adds", "a", "tab", "to", "the", "area", "and", "creates", "the", "layout", "for", "this", "tab", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1271-L1292
train
39,715
Spinmob/spinmob
egg/_gui.py
TabArea.remove_tab
def remove_tab(self, tab=0): """ Removes the tab by index. """ # 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
python
def remove_tab(self, tab=0): """ Removes the tab by index. """ # 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", ")", ":", "# pop it from the list", "t", "=", "self", ".", "tabs", ".", "pop", "(", "tab", ")", "# remove it from the gui", "self", ".", "_widget", ".", "removeTab", "(", "tab", ")", "# return it in c...
Removes the tab by index.
[ "Removes", "the", "tab", "by", "index", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1294-L1306
train
39,716
Spinmob/spinmob
egg/_gui.py
Table.get_value
def get_value(self, column=0, row=0): """ Returns a the value at column, row. """ x = self._widget.item(row, column) if x==None: return x else: return str(self._widget.item(row,column).text())
python
def get_value(self, column=0, row=0): """ Returns a the value at column, row. """ 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", ")", ":", "x", "=", "self", ".", "_widget", ".", "item", "(", "row", ",", "column", ")", "if", "x", "==", "None", ":", "return", "x", "else", ":", "return", "str", ...
Returns a the value at column, row.
[ "Returns", "a", "the", "value", "at", "column", "row", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1369-L1376
train
39,717
Spinmob/spinmob
egg/_gui.py
Table.set_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. """ 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 self._widget.setItem(row, column, _g.Qt.QtGui.QTableWidgetItem(str(value))) if block_events: self.unblock_events() return self
python
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. """ 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 self._widget.setItem(row, column, _g.Qt.QtGui.QTableWidgetItem(str(value))) if block_events: self.unblock_events() return self
[ "def", "set_value", "(", "self", ",", "column", "=", "0", ",", "row", "=", "0", ",", "value", "=", "''", ",", "block_events", "=", "False", ")", ":", "if", "block_events", ":", "self", ".", "block_events", "(", ")", "# dynamically resize", "while", "co...
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.
[ "Sets", "the", "value", "at", "column", "row", ".", "This", "will", "create", "elements", "dynamically", "and", "in", "a", "totally", "stupid", "while", "-", "looping", "way", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1378-L1398
train
39,718
Spinmob/spinmob
egg/_gui.py
Table.set_column_width
def set_column_width(self, n=0, width=120): """ Sets the n'th column width in pixels. """ self._widget.setColumnWidth(n, width) return self
python
def set_column_width(self, n=0, width=120): """ Sets the n'th column width in pixels. """ self._widget.setColumnWidth(n, width) return self
[ "def", "set_column_width", "(", "self", ",", "n", "=", "0", ",", "width", "=", "120", ")", ":", "self", ".", "_widget", ".", "setColumnWidth", "(", "n", ",", "width", ")", "return", "self" ]
Sets the n'th column width in pixels.
[ "Sets", "the", "n", "th", "column", "width", "in", "pixels", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1400-L1405
train
39,719
Spinmob/spinmob
egg/_gui.py
Table.set_header_visibility
def set_header_visibility(self, column=False, row=False): """ Sets whether we can see the column and row headers. """ if row: self._widget.verticalHeader().show() else: self._widget.verticalHeader().hide() if column: self._widget.horizontalHeader().show() else: self._widget.horizontalHeader().hide() return self
python
def set_header_visibility(self, column=False, row=False): """ Sets whether we can see the column and row headers. """ 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", ")", ":", "if", "row", ":", "self", ".", "_widget", ".", "verticalHeader", "(", ")", ".", "show", "(", ")", "else", ":", "self", ".", "_widget", ".", ...
Sets whether we can see the column and row headers.
[ "Sets", "whether", "we", "can", "see", "the", "column", "and", "row", "headers", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1407-L1417
train
39,720
Spinmob/spinmob
egg/_gui.py
Table.set_row_height
def set_row_height(self, n=0, height=18): """ Sets the n'th row height in pixels. """ self._widget.setRowHeight(n, height) return self
python
def set_row_height(self, n=0, height=18): """ Sets the n'th row height in pixels. """ self._widget.setRowHeight(n, height) return self
[ "def", "set_row_height", "(", "self", ",", "n", "=", "0", ",", "height", "=", "18", ")", ":", "self", ".", "_widget", ".", "setRowHeight", "(", "n", ",", "height", ")", "return", "self" ]
Sets the n'th row height in pixels.
[ "Sets", "the", "n", "th", "row", "height", "in", "pixels", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1419-L1424
train
39,721
Spinmob/spinmob
egg/_gui.py
TableDictionary._clean_up_key
def _clean_up_key(self, key): """ Returns the key string with no naughty characters. """ for n in self.naughty: key = key.replace(n, '_') return key
python
def _clean_up_key(self, key): """ Returns the key string with no naughty characters. """ for n in self.naughty: key = key.replace(n, '_') return key
[ "def", "_clean_up_key", "(", "self", ",", "key", ")", ":", "for", "n", "in", "self", ".", "naughty", ":", "key", "=", "key", ".", "replace", "(", "n", ",", "'_'", ")", "return", "key" ]
Returns the key string with no naughty characters.
[ "Returns", "the", "key", "string", "with", "no", "naughty", "characters", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1467-L1472
train
39,722
Spinmob/spinmob
egg/_gui.py
TableDictionary._cell_changed
def _cell_changed(self, *a): """ Called whenever a cell is changed. Updates the dictionary. """ # 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) # get rid of the None's if key == None: key = '' self.set_value(0,n, '') if value == None: value = '' self.set_value(1,n, '') # if it's not an empty entry make sure it's valid if not key == '': # clean up the key key = self._clean_up_key(key) # now make sure the value is python-able try: eval(value) self._widget.item(n,1).setData(_g.QtCore.Qt.BackgroundRole, _g.Qt.QtGui.QColor('white')) except: self._widget.item(n,1).setData(_g.QtCore.Qt.BackgroundRole, _g.Qt.QtGui.QColor('pink')) # unblock all signals self.unblock_events()
python
def _cell_changed(self, *a): """ Called whenever a cell is changed. Updates the dictionary. """ # 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) # get rid of the None's if key == None: key = '' self.set_value(0,n, '') if value == None: value = '' self.set_value(1,n, '') # if it's not an empty entry make sure it's valid if not key == '': # clean up the key key = self._clean_up_key(key) # now make sure the value is python-able try: eval(value) self._widget.item(n,1).setData(_g.QtCore.Qt.BackgroundRole, _g.Qt.QtGui.QColor('white')) except: self._widget.item(n,1).setData(_g.QtCore.Qt.BackgroundRole, _g.Qt.QtGui.QColor('pink')) # unblock all signals self.unblock_events()
[ "def", "_cell_changed", "(", "self", ",", "*", "a", ")", ":", "# 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", "(", ")", ...
Called whenever a cell is changed. Updates the dictionary.
[ "Called", "whenever", "a", "cell", "is", "changed", ".", "Updates", "the", "dictionary", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1474-L1511
train
39,723
Spinmob/spinmob
egg/_gui.py
TableDictionary.get_item
def get_item(self, key): """ Returns the value associated with the key. """ 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.print_message("ERROR: '"+str(self.get_value(1,keys.index(key)))+"' cannot be evaluated.") return None
python
def get_item(self, key): """ Returns the value associated with the key. """ 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.print_message("ERROR: '"+str(self.get_value(1,keys.index(key)))+"' cannot be evaluated.") return None
[ "def", "get_item", "(", "self", ",", "key", ")", ":", "keys", "=", "list", "(", "self", ".", "keys", "(", ")", ")", "# make sure it exists", "if", "not", "key", "in", "keys", ":", "self", ".", "print_message", "(", "\"ERROR: '\"", "+", "str", "(", "k...
Returns the value associated with the key.
[ "Returns", "the", "value", "associated", "with", "the", "key", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1513-L1530
train
39,724
Spinmob/spinmob
egg/_gui.py
TableDictionary.keys
def keys(self): """ Returns a sorted list of keys """ 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
python
def keys(self): """ Returns a sorted list of keys """ 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", ")", ":", "keys", "=", "list", "(", ")", "for", "n", "in", "range", "(", "len", "(", "self", ")", ")", ":", "# only append the valid keys", "key", "=", "self", ".", "get_value", "(", ")", "if", "not", "key", "in", "[", ...
Returns a sorted list of keys
[ "Returns", "a", "sorted", "list", "of", "keys" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1534-L1545
train
39,725
Spinmob/spinmob
egg/_gui.py
TableDictionary.set_item
def set_item(self, key, value): """ Sets the item by key, and refills the table sorted. """ 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))
python
def set_item(self, key, value): """ Sets the item by key, and refills the table sorted. """ 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", ")", ":", "keys", "=", "list", "(", "self", ".", "keys", "(", ")", ")", "# if it exists, update", "if", "key", "in", "keys", ":", "self", ".", "set_value", "(", "1", ",", "keys", ".", "index...
Sets the item by key, and refills the table sorted.
[ "Sets", "the", "item", "by", "key", "and", "refills", "the", "table", "sorted", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1547-L1560
train
39,726
Spinmob/spinmob
egg/_gui.py
TextBox.get_text
def get_text(self): """ Returns the current text. """ if self._multiline: return str(self._widget.toPlainText()) else: return str(self._widget.text())
python
def get_text(self): """ Returns the current text. """ if self._multiline: return str(self._widget.toPlainText()) else: return str(self._widget.text())
[ "def", "get_text", "(", "self", ")", ":", "if", "self", ".", "_multiline", ":", "return", "str", "(", "self", ".", "_widget", ".", "toPlainText", "(", ")", ")", "else", ":", "return", "str", "(", "self", ".", "_widget", ".", "text", "(", ")", ")" ]
Returns the current text.
[ "Returns", "the", "current", "text", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1640-L1645
train
39,727
Spinmob/spinmob
egg/_gui.py
TextBox.set_text
def set_text(self, text="YEAH."): """ Sets the current value of the text box. """ # 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
python
def set_text(self, text="YEAH."): """ Sets the current value of the text box. """ # 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.\"", ")", ":", "# 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", "(", ")", ...
Sets the current value of the text box.
[ "Sets", "the", "current", "value", "of", "the", "text", "box", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1647-L1655
train
39,728
Spinmob/spinmob
egg/_gui.py
TextBox.set_colors
def set_colors(self, text='black', background='white'): """ Sets the colors of the text area. """ 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)+"}")
python
def set_colors(self, text='black', background='white'): """ Sets the colors of the text area. """ 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'", ")", ":", "if", "self", ".", "_multiline", ":", "self", ".", "_widget", ".", "setStyleSheet", "(", "\"QTextEdit {background-color: \"", "+", "str", "(", "backgr...
Sets the colors of the text area.
[ "Sets", "the", "colors", "of", "the", "text", "area", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1657-L1662
train
39,729
Spinmob/spinmob
egg/_gui.py
TreeDictionary.block_events
def block_events(self): """ Special version of block_events that loops over all tree elements. """ # 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
python
def block_events(self): """ Special version of block_events that loops over all tree elements. """ # 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", ")", ":", "# block events in the usual way", "BaseObject", ".", "block_events", "(", "self", ")", "# loop over all top level parameters", "for", "i", "in", "range", "(", "self", ".", "_widget", ".", "topLevelItemCount", "(", ")", ...
Special version of block_events that loops over all tree elements.
[ "Special", "version", "of", "block_events", "that", "loops", "over", "all", "tree", "elements", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1773-L1784
train
39,730
Spinmob/spinmob
egg/_gui.py
TreeDictionary.unblock_events
def unblock_events(self): """ Special version of unblock_events that loops over all tree elements as well. """ # 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
python
def unblock_events(self): """ Special version of unblock_events that loops over all tree elements as well. """ # 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", ")", ":", "# unblock events in the usual way", "BaseObject", ".", "unblock_events", "(", "self", ")", "# loop over all top level parameters", "for", "i", "in", "range", "(", "self", ".", "_widget", ".", "topLevelItemCount", "(", ...
Special version of unblock_events that loops over all tree elements as well.
[ "Special", "version", "of", "unblock_events", "that", "loops", "over", "all", "tree", "elements", "as", "well", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1786-L1797
train
39,731
Spinmob/spinmob
egg/_gui.py
TreeDictionary.connect_signal_changed
def connect_signal_changed(self, name, function): """ Connects a changed signal from the parameters of the specified name to the supplied function. """ 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) else: self._connection_lists[name] = [function] return self
python
def connect_signal_changed(self, name, function): """ Connects a changed signal from the parameters of the specified name to the supplied function. """ 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) else: self._connection_lists[name] = [function] return self
[ "def", "connect_signal_changed", "(", "self", ",", "name", ",", "function", ")", ":", "x", "=", "self", ".", "_find_parameter", "(", "name", ".", "split", "(", "\"/\"", ")", ")", "# if it pooped.", "if", "x", "==", "None", ":", "return", "None", "# conne...
Connects a changed signal from the parameters of the specified name to the supplied function.
[ "Connects", "a", "changed", "signal", "from", "the", "parameters", "of", "the", "specified", "name", "to", "the", "supplied", "function", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1823-L1840
train
39,732
Spinmob/spinmob
egg/_gui.py
TreeDictionary._find_parameter
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) """ # 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 r = self._clean_up_name(s.pop(0)) # search for the root name result = self._widget.findItems(r, _g.QtCore.Qt.MatchCaseSensitive | _g.QtCore.Qt.MatchFixedString) # if it pooped and we're not supposed to create it, quit if len(result) == 0 and not create_missing: if not quiet: self.print_message("ERROR: Could not find '"+r+"'") return None # otherwise use the first value elif len(result): x = result[0].param # otherwise, if there are more names in the list, # create the branch and keep going else: x = _g.parametertree.Parameter.create(name=r, type='group', children=[]) self._widget.addParameters(x) # loop over the remaining names, and use a different search method for n in s: # first clean up n = self._clean_up_name(n) # try to search for the name try: x = x.param(n) # name doesn't exist except: # if we're supposed to, create the new branch if create_missing: x = x.addChild(_g.parametertree.Parameter.create(name=n, type='group', children=[])) # otherwise poop out else: if not quiet: self.print_message("ERROR: Could not find '"+n+"' in '"+x.name()+"'") return None # return the last one we found / created. return x
python
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) """ # 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 r = self._clean_up_name(s.pop(0)) # search for the root name result = self._widget.findItems(r, _g.QtCore.Qt.MatchCaseSensitive | _g.QtCore.Qt.MatchFixedString) # if it pooped and we're not supposed to create it, quit if len(result) == 0 and not create_missing: if not quiet: self.print_message("ERROR: Could not find '"+r+"'") return None # otherwise use the first value elif len(result): x = result[0].param # otherwise, if there are more names in the list, # create the branch and keep going else: x = _g.parametertree.Parameter.create(name=r, type='group', children=[]) self._widget.addParameters(x) # loop over the remaining names, and use a different search method for n in s: # first clean up n = self._clean_up_name(n) # try to search for the name try: x = x.param(n) # name doesn't exist except: # if we're supposed to, create the new branch if create_missing: x = x.addChild(_g.parametertree.Parameter.create(name=n, type='group', children=[])) # otherwise poop out else: if not quiet: self.print_message("ERROR: Could not find '"+n+"' in '"+x.name()+"'") return None # return the last one we found / created. return x
[ "def", "_find_parameter", "(", "self", ",", "name_list", ",", "create_missing", "=", "False", ",", "quiet", "=", "False", ")", ":", "# make a copy so this isn't destructive to the supplied list", "s", "=", "list", "(", "name_list", ")", "# if the length is zero, return ...
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)
[ "Tries", "to", "find", "and", "return", "the", "parameter", "of", "the", "specified", "name", ".", "The", "name", "should", "be", "of", "the", "form" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1882-L1942
train
39,733
Spinmob/spinmob
egg/_gui.py
TreeDictionary._clean_up_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. """ for n in self.naughty: name = name.replace(n, '_') return name
python
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. """ for n in self.naughty: name = name.replace(n, '_') return name
[ "def", "_clean_up_name", "(", "self", ",", "name", ")", ":", "for", "n", "in", "self", ".", "naughty", ":", "name", "=", "name", ".", "replace", "(", "n", ",", "'_'", ")", "return", "name" ]
Cleans up the name according to the rules specified in this exact function. Uses self.naughty, a list of naughty characters.
[ "Cleans", "up", "the", "name", "according", "to", "the", "rules", "specified", "in", "this", "exact", "function", ".", "Uses", "self", ".", "naughty", "a", "list", "of", "naughty", "characters", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L1946-L1952
train
39,734
Spinmob/spinmob
egg/_gui.py
TreeDictionary.send_to_databox_header
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. """ k, d = self.get_dictionary() destination_databox.update_headers(d,k)
python
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. """ k, d = self.get_dictionary() destination_databox.update_headers(d,k)
[ "def", "send_to_databox_header", "(", "self", ",", "destination_databox", ")", ":", "k", ",", "d", "=", "self", ".", "get_dictionary", "(", ")", "destination_databox", ".", "update_headers", "(", "d", ",", "k", ")" ]
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.
[ "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", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2105-L2112
train
39,735
Spinmob/spinmob
egg/_gui.py
TreeDictionary.get_value
def get_value(self, name): """ Returns the value of the parameter with the specified name. """ # 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() # handles the two versions of pyqtgraph bounds = None # For lists, just make sure it's a valid value if x.opts['type'] == 'list': # If it's not one from the master list, choose # and return the default value. if not value in x.opts['values']: # Only choose a default if there exists one if len(x.opts('values')): self.set_value(name, x.opts['values'][0]) return x.opts['values'][0] # Otherwise, just return None and do nothing else: return None # For strings, make sure the returned value is always a string. elif x.opts['type'] in ['str']: return str(value) # Otherwise assume it is a value with bounds or limits (depending on # the version of pyqtgraph) else: if 'limits' in x.opts: bounds = x.opts['limits'] elif 'bounds' in x.opts: bounds = x.opts['bounds'] if not bounds == None: if not bounds[1]==None and value > bounds[1]: value = bounds[1] if not bounds[0]==None and value < bounds[0]: value = bounds[0] # return it return value
python
def get_value(self, name): """ Returns the value of the parameter with the specified name. """ # 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() # handles the two versions of pyqtgraph bounds = None # For lists, just make sure it's a valid value if x.opts['type'] == 'list': # If it's not one from the master list, choose # and return the default value. if not value in x.opts['values']: # Only choose a default if there exists one if len(x.opts('values')): self.set_value(name, x.opts['values'][0]) return x.opts['values'][0] # Otherwise, just return None and do nothing else: return None # For strings, make sure the returned value is always a string. elif x.opts['type'] in ['str']: return str(value) # Otherwise assume it is a value with bounds or limits (depending on # the version of pyqtgraph) else: if 'limits' in x.opts: bounds = x.opts['limits'] elif 'bounds' in x.opts: bounds = x.opts['bounds'] if not bounds == None: if not bounds[1]==None and value > bounds[1]: value = bounds[1] if not bounds[0]==None and value < bounds[0]: value = bounds[0] # return it return value
[ "def", "get_value", "(", "self", ",", "name", ")", ":", "# first clean up the name", "name", "=", "self", ".", "_clean_up_name", "(", "name", ")", "# now get the parameter object", "x", "=", "self", ".", "_find_parameter", "(", "name", ".", "split", "(", "'/'"...
Returns the value of the parameter with the specified name.
[ "Returns", "the", "value", "of", "the", "parameter", "with", "the", "specified", "name", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2162-L2209
train
39,736
Spinmob/spinmob
egg/_gui.py
TreeDictionary.get_list_values
def get_list_values(self, name): """ Returns the values for a list item of the specified name. """ # 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'])
python
def get_list_values(self, name): """ Returns the values for a list item of the specified name. """ # 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", ")", ":", "# Make sure it's a list", "if", "not", "self", ".", "get_type", "(", "name", ")", "in", "[", "'list'", "]", ":", "self", ".", "print_message", "(", "'ERROR: \"'", "+", "name", "+", "'\" is not ...
Returns the values for a list item of the specified name.
[ "Returns", "the", "values", "for", "a", "list", "item", "of", "the", "specified", "name", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2213-L2223
train
39,737
Spinmob/spinmob
egg/_gui.py
TreeDictionary.set_value
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. """ # 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.split('/'), quiet=ignore_error) # quit if it pooped. if x == None: return None # for lists, make sure the value exists!! if x.type() in ['list']: # Make sure it exists before trying to set it if str(value) in list(x.forward.keys()): x.setValue(str(value)) # Otherwise default to the first key else: x.setValue(list(x.forward.keys())[0]) # Bail to a hopeful set method for other types else: x.setValue(eval(x.opts['type'])(value)) # If we're supposed to unblock the user signals for this parameter if block_user_signals: self.unblock_user_signals(name, ignore_error) return self
python
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. """ # 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.split('/'), quiet=ignore_error) # quit if it pooped. if x == None: return None # for lists, make sure the value exists!! if x.type() in ['list']: # Make sure it exists before trying to set it if str(value) in list(x.forward.keys()): x.setValue(str(value)) # Otherwise default to the first key else: x.setValue(list(x.forward.keys())[0]) # Bail to a hopeful set method for other types else: x.setValue(eval(x.opts['type'])(value)) # If we're supposed to unblock the user signals for this parameter if block_user_signals: self.unblock_user_signals(name, ignore_error) return self
[ "def", "set_value", "(", "self", ",", "name", ",", "value", ",", "ignore_error", "=", "False", ",", "block_user_signals", "=", "False", ")", ":", "# first clean up the name", "name", "=", "self", ".", "_clean_up_name", "(", "name", ")", "# If we're supposed to, ...
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.
[ "Sets", "the", "variable", "of", "the", "supplied", "name", "to", "the", "supplied", "value", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2225-L2259
train
39,738
Spinmob/spinmob
egg/_gui.py
TreeDictionary.save
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. """ 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_settings_dir): _os.mkdir(gui_settings_dir) # Assemble the path path = _os.path.join(gui_settings_dir, self._autosettings_path) # make the databox object d = _d.databox() # get the keys and dictionary keys, dictionary = self.get_dictionary() # loop over the keys and add them to the databox header for k in keys: d.insert_header(k, dictionary[k]) # save it try: d.save_file(path, force_overwrite=True, header_only=True) except: print('Warning: could not save '+path.__repr__()+' once. Could be that this is being called too rapidly.') return self
python
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. """ 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_settings_dir): _os.mkdir(gui_settings_dir) # Assemble the path path = _os.path.join(gui_settings_dir, self._autosettings_path) # make the databox object d = _d.databox() # get the keys and dictionary keys, dictionary = self.get_dictionary() # loop over the keys and add them to the databox header for k in keys: d.insert_header(k, dictionary[k]) # save it try: d.save_file(path, force_overwrite=True, header_only=True) except: print('Warning: could not save '+path.__repr__()+' once. Could be that this is being called too rapidly.') return self
[ "def", "save", "(", "self", ",", "path", "=", "None", ")", ":", "if", "path", "==", "None", ":", "if", "self", ".", "_autosettings_path", "==", "None", ":", "return", "self", "# Get the gui settings directory", "gui_settings_dir", "=", "_os", ".", "path", ...
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.
[ "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", ...
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2280-L2315
train
39,739
Spinmob/spinmob
egg/_gui.py
TreeDictionary._set_value_safe
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 """ # 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 '"+v+"'")
python
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 """ # 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 '"+v+"'")
[ "def", "_set_value_safe", "(", "self", ",", "k", ",", "v", ",", "ignore_errors", "=", "False", ",", "block_user_signals", "=", "False", ")", ":", "# for safety: by default assume it's a repr() with python code", "try", ":", "self", ".", "set_value", "(", "k", ",",...
Actually sets the value, first by trying it directly, then by
[ "Actually", "sets", "the", "value", "first", "by", "trying", "it", "directly", "then", "by" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2382-L2392
train
39,740
Spinmob/spinmob
egg/_gui.py
DataboxPlot._button_autosave_clicked
def _button_autosave_clicked(self, checked): """ Called whenever the button is clicked. """ 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! self._autosave_directory, filename = _os.path.split(path) self._label_path.set_text(filename) self.save_gui_settings()
python
def _button_autosave_clicked(self, checked): """ Called whenever the button is clicked. """ 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! self._autosave_directory, filename = _os.path.split(path) self._label_path.set_text(filename) self.save_gui_settings()
[ "def", "_button_autosave_clicked", "(", "self", ",", "checked", ")", ":", "if", "checked", ":", "# get the path from the user", "path", "=", "_spinmob", ".", "dialogs", ".", "save", "(", "filters", "=", "self", ".", "file_type", ")", "# abort if necessary", "if"...
Called whenever the button is clicked.
[ "Called", "whenever", "the", "button", "is", "clicked", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2556-L2573
train
39,741
Spinmob/spinmob
egg/_gui.py
DataboxPlot.save_file
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 save only the state of the DataboxPlot controls **kwargs are sent to the normal databox save_file() function. """ # 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 # add all the controls settings to the header for x in self._autosettings_controls: self._store_gui_setting(d, x) # save the file using the skeleton function, so as not to recursively # call this one again! _d.databox.save_file(d, path, self.file_type, self.file_type, force_overwrite, **kwargs)
python
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 save only the state of the DataboxPlot controls **kwargs are sent to the normal databox save_file() function. """ # 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 # add all the controls settings to the header for x in self._autosettings_controls: self._store_gui_setting(d, x) # save the file using the skeleton function, so as not to recursively # call this one again! _d.databox.save_file(d, path, self.file_type, self.file_type, force_overwrite, **kwargs)
[ "def", "save_file", "(", "self", ",", "path", "=", "None", ",", "force_overwrite", "=", "False", ",", "just_settings", "=", "False", ",", "*", "*", "kwargs", ")", ":", "# Update the binary mode", "if", "not", "'binary'", "in", "kwargs", ":", "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 save only the state of the DataboxPlot controls **kwargs are sent to the normal databox save_file() function.
[ "Saves", "the", "data", "in", "the", "databox", "to", "a", "file", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2594-L2623
train
39,742
Spinmob/spinmob
egg/_gui.py
DataboxPlot.autosave
def autosave(self): """ Autosaves the currently stored data, but only if autosave is checked! """ # 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.number_file.increment()
python
def autosave(self): """ Autosaves the currently stored data, but only if autosave is checked! """ # 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.number_file.increment()
[ "def", "autosave", "(", "self", ")", ":", "# make sure we're suppoed to", "if", "self", ".", "button_autosave", ".", "is_checked", "(", ")", ":", "# save the file", "self", ".", "save_file", "(", "_os", ".", "path", ".", "join", "(", "self", ".", "_autosave_...
Autosaves the currently stored data, but only if autosave is checked!
[ "Autosaves", "the", "currently", "stored", "data", "but", "only", "if", "autosave", "is", "checked!" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2842-L2853
train
39,743
Spinmob/spinmob
egg/_gui.py
DataboxPlot.autozoom
def autozoom(self, n=None): """ Auto-scales the axes to fit all the data in plot index n. If n == None, auto-scale everyone. """ if n==None: for p in self.plot_widgets: p.autoRange() else: self.plot_widgets[n].autoRange() return self
python
def autozoom(self, n=None): """ Auto-scales the axes to fit all the data in plot index n. If n == None, auto-scale everyone. """ if n==None: for p in self.plot_widgets: p.autoRange() else: self.plot_widgets[n].autoRange() return self
[ "def", "autozoom", "(", "self", ",", "n", "=", "None", ")", ":", "if", "n", "==", "None", ":", "for", "p", "in", "self", ".", "plot_widgets", ":", "p", ".", "autoRange", "(", ")", "else", ":", "self", ".", "plot_widgets", "[", "n", "]", ".", "a...
Auto-scales the axes to fit all the data in plot index n. If n == None, auto-scale everyone.
[ "Auto", "-", "scales", "the", "axes", "to", "fit", "all", "the", "data", "in", "plot", "index", "n", ".", "If", "n", "==", "None", "auto", "-", "scale", "everyone", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2855-L2864
train
39,744
Spinmob/spinmob
egg/_gui.py
DataboxPlot._synchronize_controls
def _synchronize_controls(self): """ Updates the gui based on button configs. """ # whether the script is visible self.grid_script._widget.setVisible(self.button_script.get_value()) # whether we should be able to edit it. if not self.combo_autoscript.get_index()==0: self.script.disable() else: self.script.enable()
python
def _synchronize_controls(self): """ Updates the gui based on button configs. """ # whether the script is visible self.grid_script._widget.setVisible(self.button_script.get_value()) # whether we should be able to edit it. if not self.combo_autoscript.get_index()==0: self.script.disable() else: self.script.enable()
[ "def", "_synchronize_controls", "(", "self", ")", ":", "# whether the script is visible", "self", ".", "grid_script", ".", "_widget", ".", "setVisible", "(", "self", ".", "button_script", ".", "get_value", "(", ")", ")", "# whether we should be able to edit it.", "if"...
Updates the gui based on button configs.
[ "Updates", "the", "gui", "based", "on", "button", "configs", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2866-L2876
train
39,745
Spinmob/spinmob
egg/_gui.py
DataboxPlot._set_number_of_plots
def _set_number_of_plots(self, n): """ Adjusts number of plots & curves to the desired value the gui. """ # multi plot, right number of plots and curves = great! if self.button_multi.is_checked() \ and len(self._curves) == len(self.plot_widgets) \ and len(self._curves) == n: return # single plot, right number of curves = great! if not self.button_multi.is_checked() \ and len(self.plot_widgets) == 1 \ and len(self._curves) == n: return # time to rebuild! # don't show the plots as they are built self.grid_plot.block_events() # make sure the number of curves is on target while len(self._curves) > n: self._curves.pop(-1) while len(self._curves) < n: self._curves.append(_g.PlotCurveItem(pen = (len(self._curves), n))) # figure out the target number of plots if self.button_multi.is_checked(): n_plots = n else: n_plots = min(n,1) # clear the plots while len(self.plot_widgets): # pop the last plot widget and remove all items p = self.plot_widgets.pop(-1) p.clear() # remove it from the grid self.grid_plot.remove_object(p) # add new plots for i in range(n_plots): self.plot_widgets.append(self.grid_plot.place_object(_g.PlotWidget(), 0, i, alignment=0)) # loop over the curves and add them to the plots for i in range(n): self.plot_widgets[min(i,len(self.plot_widgets)-1)].addItem(self._curves[i]) # loop over the ROI's and add them if self.ROIs is not None: for i in range(len(self.ROIs)): # get the ROIs for this plot ROIs = self.ROIs[i] if not _spinmob.fun.is_iterable(ROIs): ROIs = [ROIs] # loop over the ROIs for this plot for ROI in ROIs: # determine which plot to add the ROI to m = min(i, len(self.plot_widgets)-1) # add the ROI to the appropriate plot if m>=0: self.plot_widgets[m].addItem(ROI) # show the plots self.grid_plot.unblock_events()
python
def _set_number_of_plots(self, n): """ Adjusts number of plots & curves to the desired value the gui. """ # multi plot, right number of plots and curves = great! if self.button_multi.is_checked() \ and len(self._curves) == len(self.plot_widgets) \ and len(self._curves) == n: return # single plot, right number of curves = great! if not self.button_multi.is_checked() \ and len(self.plot_widgets) == 1 \ and len(self._curves) == n: return # time to rebuild! # don't show the plots as they are built self.grid_plot.block_events() # make sure the number of curves is on target while len(self._curves) > n: self._curves.pop(-1) while len(self._curves) < n: self._curves.append(_g.PlotCurveItem(pen = (len(self._curves), n))) # figure out the target number of plots if self.button_multi.is_checked(): n_plots = n else: n_plots = min(n,1) # clear the plots while len(self.plot_widgets): # pop the last plot widget and remove all items p = self.plot_widgets.pop(-1) p.clear() # remove it from the grid self.grid_plot.remove_object(p) # add new plots for i in range(n_plots): self.plot_widgets.append(self.grid_plot.place_object(_g.PlotWidget(), 0, i, alignment=0)) # loop over the curves and add them to the plots for i in range(n): self.plot_widgets[min(i,len(self.plot_widgets)-1)].addItem(self._curves[i]) # loop over the ROI's and add them if self.ROIs is not None: for i in range(len(self.ROIs)): # get the ROIs for this plot ROIs = self.ROIs[i] if not _spinmob.fun.is_iterable(ROIs): ROIs = [ROIs] # loop over the ROIs for this plot for ROI in ROIs: # determine which plot to add the ROI to m = min(i, len(self.plot_widgets)-1) # add the ROI to the appropriate plot if m>=0: self.plot_widgets[m].addItem(ROI) # show the plots self.grid_plot.unblock_events()
[ "def", "_set_number_of_plots", "(", "self", ",", "n", ")", ":", "# multi plot, right number of plots and curves = great!", "if", "self", ".", "button_multi", ".", "is_checked", "(", ")", "and", "len", "(", "self", ".", "_curves", ")", "==", "len", "(", "self", ...
Adjusts number of plots & curves to the desired value the gui.
[ "Adjusts", "number", "of", "plots", "&", "curves", "to", "the", "desired", "value", "the", "gui", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/egg/_gui.py#L2879-L2945
train
39,746
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.resolve_const_spec
def resolve_const_spec(self, name, lineno): """Finds and links the ConstSpec with the given name.""" if name in self.const_specs: return self.const_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 1) if include_name in self.included_scopes: return self.included_scopes[include_name].resolve_const_spec( component, lineno ) raise ThriftCompilerError( 'Unknown constant "%s" referenced at line %d%s' % ( name, lineno, self.__in_path() ) )
python
def resolve_const_spec(self, name, lineno): """Finds and links the ConstSpec with the given name.""" if name in self.const_specs: return self.const_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 1) if include_name in self.included_scopes: return self.included_scopes[include_name].resolve_const_spec( component, lineno ) raise ThriftCompilerError( 'Unknown constant "%s" referenced at line %d%s' % ( name, lineno, self.__in_path() ) )
[ "def", "resolve_const_spec", "(", "self", ",", "name", ",", "lineno", ")", ":", "if", "name", "in", "self", ".", "const_specs", ":", "return", "self", ".", "const_specs", "[", "name", "]", ".", "link", "(", "self", ")", "if", "'.'", "in", "name", ":"...
Finds and links the ConstSpec with the given name.
[ "Finds", "and", "links", "the", "ConstSpec", "with", "the", "given", "name", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L76-L93
train
39,747
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.resolve_type_spec
def resolve_type_spec(self, name, lineno): """Finds and links the TypeSpec with the given name.""" if name in self.type_specs: return self.type_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 1) if include_name in self.included_scopes: return self.included_scopes[include_name].resolve_type_spec( component, lineno ) raise ThriftCompilerError( 'Unknown type "%s" referenced at line %d%s' % ( name, lineno, self.__in_path() ) )
python
def resolve_type_spec(self, name, lineno): """Finds and links the TypeSpec with the given name.""" if name in self.type_specs: return self.type_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 1) if include_name in self.included_scopes: return self.included_scopes[include_name].resolve_type_spec( component, lineno ) raise ThriftCompilerError( 'Unknown type "%s" referenced at line %d%s' % ( name, lineno, self.__in_path() ) )
[ "def", "resolve_type_spec", "(", "self", ",", "name", ",", "lineno", ")", ":", "if", "name", "in", "self", ".", "type_specs", ":", "return", "self", ".", "type_specs", "[", "name", "]", ".", "link", "(", "self", ")", "if", "'.'", "in", "name", ":", ...
Finds and links the TypeSpec with the given name.
[ "Finds", "and", "links", "the", "TypeSpec", "with", "the", "given", "name", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L95-L112
train
39,748
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.resolve_service_spec
def resolve_service_spec(self, name, lineno): """Finds and links the ServiceSpec with the given name.""" if name in self.service_specs: return self.service_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 2) if include_name in self.included_scopes: return self.included_scopes[ include_name ].resolve_service_spec(component, lineno) raise ThriftCompilerError( 'Unknown service "%s" referenced at line %d%s' % ( name, lineno, self.__in_path() ) )
python
def resolve_service_spec(self, name, lineno): """Finds and links the ServiceSpec with the given name.""" if name in self.service_specs: return self.service_specs[name].link(self) if '.' in name: include_name, component = name.split('.', 2) if include_name in self.included_scopes: return self.included_scopes[ include_name ].resolve_service_spec(component, lineno) raise ThriftCompilerError( 'Unknown service "%s" referenced at line %d%s' % ( name, lineno, self.__in_path() ) )
[ "def", "resolve_service_spec", "(", "self", ",", "name", ",", "lineno", ")", ":", "if", "name", "in", "self", ".", "service_specs", ":", "return", "self", ".", "service_specs", "[", "name", "]", ".", "link", "(", "self", ")", "if", "'.'", "in", "name",...
Finds and links the ServiceSpec with the given name.
[ "Finds", "and", "links", "the", "ServiceSpec", "with", "the", "given", "name", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L114-L131
train
39,749
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.add_include
def add_include(self, name, included_scope, module): """Register an imported module into this scope. Raises ``ThriftCompilerError`` if the name has already been used. """ # The compiler already ensures this. If we still get here with a # conflict, that's a bug. assert name not in self.included_scopes self.included_scopes[name] = included_scope self.add_surface(name, module)
python
def add_include(self, name, included_scope, module): """Register an imported module into this scope. Raises ``ThriftCompilerError`` if the name has already been used. """ # The compiler already ensures this. If we still get here with a # conflict, that's a bug. assert name not in self.included_scopes self.included_scopes[name] = included_scope self.add_surface(name, module)
[ "def", "add_include", "(", "self", ",", "name", ",", "included_scope", ",", "module", ")", ":", "# The compiler already ensures this. If we still get here with a", "# conflict, that's a bug.", "assert", "name", "not", "in", "self", ".", "included_scopes", "self", ".", "...
Register an imported module into this scope. Raises ``ThriftCompilerError`` if the name has already been used.
[ "Register", "an", "imported", "module", "into", "this", "scope", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L133-L143
train
39,750
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.add_service_spec
def add_service_spec(self, service_spec): """Registers the given ``ServiceSpec`` into the scope. Raises ``ThriftCompilerError`` if the name has already been used. """ assert service_spec is not None if service_spec.name in self.service_specs: raise ThriftCompilerError( 'Cannot define service "%s". That name is already taken.' % service_spec.name ) self.service_specs[service_spec.name] = service_spec
python
def add_service_spec(self, service_spec): """Registers the given ``ServiceSpec`` into the scope. Raises ``ThriftCompilerError`` if the name has already been used. """ assert service_spec is not None if service_spec.name in self.service_specs: raise ThriftCompilerError( 'Cannot define service "%s". That name is already taken.' % service_spec.name ) self.service_specs[service_spec.name] = service_spec
[ "def", "add_service_spec", "(", "self", ",", "service_spec", ")", ":", "assert", "service_spec", "is", "not", "None", "if", "service_spec", ".", "name", "in", "self", ".", "service_specs", ":", "raise", "ThriftCompilerError", "(", "'Cannot define service \"%s\". Tha...
Registers the given ``ServiceSpec`` into the scope. Raises ``ThriftCompilerError`` if the name has already been used.
[ "Registers", "the", "given", "ServiceSpec", "into", "the", "scope", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L145-L157
train
39,751
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.add_const_spec
def add_const_spec(self, const_spec): """Adds a ConstSpec to the compliation scope. If the ConstSpec's ``save`` attribute is True, the constant will be added to the module at the top-level. """ if const_spec.name in self.const_specs: raise ThriftCompilerError( 'Cannot define constant "%s". That name is already taken.' % const_spec.name ) self.const_specs[const_spec.name] = const_spec
python
def add_const_spec(self, const_spec): """Adds a ConstSpec to the compliation scope. If the ConstSpec's ``save`` attribute is True, the constant will be added to the module at the top-level. """ if const_spec.name in self.const_specs: raise ThriftCompilerError( 'Cannot define constant "%s". That name is already taken.' % const_spec.name ) self.const_specs[const_spec.name] = const_spec
[ "def", "add_const_spec", "(", "self", ",", "const_spec", ")", ":", "if", "const_spec", ".", "name", "in", "self", ".", "const_specs", ":", "raise", "ThriftCompilerError", "(", "'Cannot define constant \"%s\". That name is already taken.'", "%", "const_spec", ".", "nam...
Adds a ConstSpec to the compliation scope. If the ConstSpec's ``save`` attribute is True, the constant will be added to the module at the top-level.
[ "Adds", "a", "ConstSpec", "to", "the", "compliation", "scope", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L159-L170
train
39,752
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.add_surface
def add_surface(self, name, surface): """Adds a top-level attribute with the given name to the module.""" assert surface is not None if hasattr(self.module, name): raise ThriftCompilerError( 'Cannot define "%s". The name has already been used.' % name ) setattr(self.module, name, surface)
python
def add_surface(self, name, surface): """Adds a top-level attribute with the given name to the module.""" assert surface is not None if hasattr(self.module, name): raise ThriftCompilerError( 'Cannot define "%s". The name has already been used.' % name ) setattr(self.module, name, surface)
[ "def", "add_surface", "(", "self", ",", "name", ",", "surface", ")", ":", "assert", "surface", "is", "not", "None", "if", "hasattr", "(", "self", ".", "module", ",", "name", ")", ":", "raise", "ThriftCompilerError", "(", "'Cannot define \"%s\". The name has al...
Adds a top-level attribute with the given name to the module.
[ "Adds", "a", "top", "-", "level", "attribute", "with", "the", "given", "name", "to", "the", "module", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L172-L181
train
39,753
thriftrw/thriftrw-python
thriftrw/compile/scope.py
Scope.add_type_spec
def add_type_spec(self, name, spec, lineno): """Adds the given type to the scope. :param str name: Name of the new type :param spec: ``TypeSpec`` object containing information on the type, or a ``TypeReference`` if this is meant to be resolved during the ``link`` stage. :param lineno: Line number on which this type is defined. """ assert type is not None if name in self.type_specs: raise ThriftCompilerError( 'Cannot define type "%s" at line %d. ' 'Another type with that name already exists.' % (name, lineno) ) self.type_specs[name] = spec
python
def add_type_spec(self, name, spec, lineno): """Adds the given type to the scope. :param str name: Name of the new type :param spec: ``TypeSpec`` object containing information on the type, or a ``TypeReference`` if this is meant to be resolved during the ``link`` stage. :param lineno: Line number on which this type is defined. """ assert type is not None if name in self.type_specs: raise ThriftCompilerError( 'Cannot define type "%s" at line %d. ' 'Another type with that name already exists.' % (name, lineno) ) self.type_specs[name] = spec
[ "def", "add_type_spec", "(", "self", ",", "name", ",", "spec", ",", "lineno", ")", ":", "assert", "type", "is", "not", "None", "if", "name", "in", "self", ".", "type_specs", ":", "raise", "ThriftCompilerError", "(", "'Cannot define type \"%s\" at line %d. '", ...
Adds the given type to the scope. :param str name: Name of the new type :param spec: ``TypeSpec`` object containing information on the type, or a ``TypeReference`` if this is meant to be resolved during the ``link`` stage. :param lineno: Line number on which this type is defined.
[ "Adds", "the", "given", "type", "to", "the", "scope", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/scope.py#L183-L204
train
39,754
Spinmob/spinmob
_functions.py
coarsen_matrix
def coarsen_matrix(Z, xlevel=0, ylevel=0, method='average'): """ This returns a coarsened numpy matrix. method can be 'average', 'maximum', or 'minimum' """ # coarsen x if not ylevel: Z_coarsened = Z else: temp = [] for z in Z: temp.append(coarsen_array(z, ylevel, method)) Z_coarsened = _n.array(temp) # coarsen y if xlevel: Z_coarsened = Z_coarsened.transpose() temp = [] for z in Z_coarsened: temp.append(coarsen_array(z, xlevel, method)) Z_coarsened = _n.array(temp).transpose() return Z_coarsened # first coarsen the columns (if necessary) if ylevel: Z_ycoarsened = [] for c in Z: Z_ycoarsened.append(coarsen_array(c, ylevel, method)) Z_ycoarsened = _n.array(Z_ycoarsened) # now coarsen the rows if xlevel: return coarsen_array(Z_ycoarsened, xlevel, method) else: return _n.array(Z_ycoarsened)
python
def coarsen_matrix(Z, xlevel=0, ylevel=0, method='average'): """ This returns a coarsened numpy matrix. method can be 'average', 'maximum', or 'minimum' """ # coarsen x if not ylevel: Z_coarsened = Z else: temp = [] for z in Z: temp.append(coarsen_array(z, ylevel, method)) Z_coarsened = _n.array(temp) # coarsen y if xlevel: Z_coarsened = Z_coarsened.transpose() temp = [] for z in Z_coarsened: temp.append(coarsen_array(z, xlevel, method)) Z_coarsened = _n.array(temp).transpose() return Z_coarsened # first coarsen the columns (if necessary) if ylevel: Z_ycoarsened = [] for c in Z: Z_ycoarsened.append(coarsen_array(c, ylevel, method)) Z_ycoarsened = _n.array(Z_ycoarsened) # now coarsen the rows if xlevel: return coarsen_array(Z_ycoarsened, xlevel, method) else: return _n.array(Z_ycoarsened)
[ "def", "coarsen_matrix", "(", "Z", ",", "xlevel", "=", "0", ",", "ylevel", "=", "0", ",", "method", "=", "'average'", ")", ":", "# coarsen x", "if", "not", "ylevel", ":", "Z_coarsened", "=", "Z", "else", ":", "temp", "=", "[", "]", "for", "z", "in"...
This returns a coarsened numpy matrix. method can be 'average', 'maximum', or 'minimum'
[ "This", "returns", "a", "coarsened", "numpy", "matrix", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L128-L162
train
39,755
Spinmob/spinmob
_functions.py
erange
def erange(start, end, steps): """ Returns a numpy array over the specified range taking geometric steps. See also numpy.logspace() """ if start == 0: print("Nothing you multiply zero by gives you anything but zero. Try picking something small.") return None if end == 0: print("It takes an infinite number of steps to get to zero. Try a small number?") return None # figure out our multiplication scale x = (1.0*end/start)**(1.0/(steps-1)) # now generate the array ns = _n.array(list(range(0,steps))) a = start*_n.power(x,ns) # tidy up the last element (there's often roundoff error) a[-1] = end return a
python
def erange(start, end, steps): """ Returns a numpy array over the specified range taking geometric steps. See also numpy.logspace() """ if start == 0: print("Nothing you multiply zero by gives you anything but zero. Try picking something small.") return None if end == 0: print("It takes an infinite number of steps to get to zero. Try a small number?") return None # figure out our multiplication scale x = (1.0*end/start)**(1.0/(steps-1)) # now generate the array ns = _n.array(list(range(0,steps))) a = start*_n.power(x,ns) # tidy up the last element (there's often roundoff error) a[-1] = end return a
[ "def", "erange", "(", "start", ",", "end", ",", "steps", ")", ":", "if", "start", "==", "0", ":", "print", "(", "\"Nothing you multiply zero by gives you anything but zero. Try picking something small.\"", ")", "return", "None", "if", "end", "==", "0", ":", "print...
Returns a numpy array over the specified range taking geometric steps. See also numpy.logspace()
[ "Returns", "a", "numpy", "array", "over", "the", "specified", "range", "taking", "geometric", "steps", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L165-L188
train
39,756
Spinmob/spinmob
_functions.py
is_a_number
def is_a_number(s): """ This takes an object and determines whether it's a number or a string representing a number. """ if _s.fun.is_iterable(s) and not type(s) == str: return False try: float(s) return 1 except: try: complex(s) return 2 except: try: complex(s.replace('(','').replace(')','').replace('i','j')) return 2 except: return False
python
def is_a_number(s): """ This takes an object and determines whether it's a number or a string representing a number. """ if _s.fun.is_iterable(s) and not type(s) == str: return False try: float(s) return 1 except: try: complex(s) return 2 except: try: complex(s.replace('(','').replace(')','').replace('i','j')) return 2 except: return False
[ "def", "is_a_number", "(", "s", ")", ":", "if", "_s", ".", "fun", ".", "is_iterable", "(", "s", ")", "and", "not", "type", "(", "s", ")", "==", "str", ":", "return", "False", "try", ":", "float", "(", "s", ")", "return", "1", "except", ":", "tr...
This takes an object and determines whether it's a number or a string representing a number.
[ "This", "takes", "an", "object", "and", "determines", "whether", "it", "s", "a", "number", "or", "a", "string", "representing", "a", "number", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L190-L209
train
39,757
Spinmob/spinmob
_functions.py
array_shift
def array_shift(a, n, fill="average"): """ This will return an array with all the elements shifted forward in index by n. a is the array n is the amount by which to shift (can be positive or negative) fill="average" fill the new empty elements with the average of the array fill="wrap" fill the new empty elements with the lopped-off elements fill=37.2 fill the new empty elements with the value 37.2 """ new_a = _n.array(a) if n==0: return new_a fill_array = _n.array([]) fill_array.resize(_n.abs(n)) # fill up the fill array before we do the shift if fill is "average": fill_array = 0.0*fill_array + _n.average(a) elif fill is "wrap" and n >= 0: for i in range(0,n): fill_array[i] = a[i-n] elif fill is "wrap" and n < 0: for i in range(0,-n): fill_array[i] = a[i] else: fill_array = 0.0*fill_array + fill # shift and fill if n > 0: for i in range(n, len(a)): new_a[i] = a[i-n] for i in range(0, n): new_a[i] = fill_array[i] else: for i in range(0, len(a)+n): new_a[i] = a[i-n] for i in range(0, -n): new_a[-i-1] = fill_array[-i-1] return new_a
python
def array_shift(a, n, fill="average"): """ This will return an array with all the elements shifted forward in index by n. a is the array n is the amount by which to shift (can be positive or negative) fill="average" fill the new empty elements with the average of the array fill="wrap" fill the new empty elements with the lopped-off elements fill=37.2 fill the new empty elements with the value 37.2 """ new_a = _n.array(a) if n==0: return new_a fill_array = _n.array([]) fill_array.resize(_n.abs(n)) # fill up the fill array before we do the shift if fill is "average": fill_array = 0.0*fill_array + _n.average(a) elif fill is "wrap" and n >= 0: for i in range(0,n): fill_array[i] = a[i-n] elif fill is "wrap" and n < 0: for i in range(0,-n): fill_array[i] = a[i] else: fill_array = 0.0*fill_array + fill # shift and fill if n > 0: for i in range(n, len(a)): new_a[i] = a[i-n] for i in range(0, n): new_a[i] = fill_array[i] else: for i in range(0, len(a)+n): new_a[i] = a[i-n] for i in range(0, -n): new_a[-i-1] = fill_array[-i-1] return new_a
[ "def", "array_shift", "(", "a", ",", "n", ",", "fill", "=", "\"average\"", ")", ":", "new_a", "=", "_n", ".", "array", "(", "a", ")", "if", "n", "==", "0", ":", "return", "new_a", "fill_array", "=", "_n", ".", "array", "(", "[", "]", ")", "fill...
This will return an array with all the elements shifted forward in index by n. a is the array n is the amount by which to shift (can be positive or negative) fill="average" fill the new empty elements with the average of the array fill="wrap" fill the new empty elements with the lopped-off elements fill=37.2 fill the new empty elements with the value 37.2
[ "This", "will", "return", "an", "array", "with", "all", "the", "elements", "shifted", "forward", "in", "index", "by", "n", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L224-L259
train
39,758
Spinmob/spinmob
_functions.py
assemble_covariance
def assemble_covariance(error, correlation): """ This takes an error vector and a correlation matrix and assembles the covariance """ covariance = [] for n in range(0, len(error)): covariance.append([]) for m in range(0, len(error)): covariance[n].append(correlation[n][m]*error[n]*error[m]) return _n.array(covariance)
python
def assemble_covariance(error, correlation): """ This takes an error vector and a correlation matrix and assembles the covariance """ covariance = [] for n in range(0, len(error)): covariance.append([]) for m in range(0, len(error)): covariance[n].append(correlation[n][m]*error[n]*error[m]) return _n.array(covariance)
[ "def", "assemble_covariance", "(", "error", ",", "correlation", ")", ":", "covariance", "=", "[", "]", "for", "n", "in", "range", "(", "0", ",", "len", "(", "error", ")", ")", ":", "covariance", ".", "append", "(", "[", "]", ")", "for", "m", "in", ...
This takes an error vector and a correlation matrix and assembles the covariance
[ "This", "takes", "an", "error", "vector", "and", "a", "correlation", "matrix", "and", "assembles", "the", "covariance" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L263-L273
train
39,759
Spinmob/spinmob
_functions.py
combine_dictionaries
def combine_dictionaries(a, b): """ returns the combined dictionary. a's values preferentially chosen """ c = {} for key in list(b.keys()): c[key]=b[key] for key in list(a.keys()): c[key]=a[key] return c
python
def combine_dictionaries(a, b): """ returns the combined dictionary. a's values preferentially chosen """ c = {} for key in list(b.keys()): c[key]=b[key] for key in list(a.keys()): c[key]=a[key] return c
[ "def", "combine_dictionaries", "(", "a", ",", "b", ")", ":", "c", "=", "{", "}", "for", "key", "in", "list", "(", "b", ".", "keys", "(", ")", ")", ":", "c", "[", "key", "]", "=", "b", "[", "key", "]", "for", "key", "in", "list", "(", "a", ...
returns the combined dictionary. a's values preferentially chosen
[ "returns", "the", "combined", "dictionary", ".", "a", "s", "values", "preferentially", "chosen" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L290-L298
train
39,760
Spinmob/spinmob
_functions.py
decompose_covariance
def decompose_covariance(c): """ This decomposes a covariance matrix into an error vector and a correlation matrix """ # make it a kickass copy of the original c = _n.array(c) # first get the error vector e = [] for n in range(0, len(c[0])): e.append(_n.sqrt(c[n][n])) # now cycle through the matrix, dividing by e[1]*e[2] for n in range(0, len(c[0])): for m in range(0, len(c[0])): c[n][m] = c[n][m] / (e[n]*e[m]) return [_n.array(e), _n.array(c)]
python
def decompose_covariance(c): """ This decomposes a covariance matrix into an error vector and a correlation matrix """ # make it a kickass copy of the original c = _n.array(c) # first get the error vector e = [] for n in range(0, len(c[0])): e.append(_n.sqrt(c[n][n])) # now cycle through the matrix, dividing by e[1]*e[2] for n in range(0, len(c[0])): for m in range(0, len(c[0])): c[n][m] = c[n][m] / (e[n]*e[m]) return [_n.array(e), _n.array(c)]
[ "def", "decompose_covariance", "(", "c", ")", ":", "# make it a kickass copy of the original", "c", "=", "_n", ".", "array", "(", "c", ")", "# first get the error vector", "e", "=", "[", "]", "for", "n", "in", "range", "(", "0", ",", "len", "(", "c", "[", ...
This decomposes a covariance matrix into an error vector and a correlation matrix
[ "This", "decomposes", "a", "covariance", "matrix", "into", "an", "error", "vector", "and", "a", "correlation", "matrix" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L326-L343
train
39,761
Spinmob/spinmob
_functions.py
derivative_fit
def derivative_fit(xdata, ydata, neighbors=1): """ loops over the data points, performing a least-squares linear fit of the nearest neighbors at each point. Returns an array of x-values and slopes. xdata should probably be well-ordered. neighbors How many data point on the left and right to include. """ x = [] dydx = [] nmax = len(xdata)-1 for n in range(nmax+1): # get the indices of the data to fit i1 = max(0, n-neighbors) i2 = min(nmax, n+neighbors) # get the sub data to fit xmini = _n.array(xdata[i1:i2+1]) ymini = _n.array(ydata[i1:i2+1]) slope, intercept = fit_linear(xmini, ymini) # make x the average of the xmini x.append(float(sum(xmini))/len(xmini)) dydx.append(slope) return _n.array(x), _n.array(dydx)
python
def derivative_fit(xdata, ydata, neighbors=1): """ loops over the data points, performing a least-squares linear fit of the nearest neighbors at each point. Returns an array of x-values and slopes. xdata should probably be well-ordered. neighbors How many data point on the left and right to include. """ x = [] dydx = [] nmax = len(xdata)-1 for n in range(nmax+1): # get the indices of the data to fit i1 = max(0, n-neighbors) i2 = min(nmax, n+neighbors) # get the sub data to fit xmini = _n.array(xdata[i1:i2+1]) ymini = _n.array(ydata[i1:i2+1]) slope, intercept = fit_linear(xmini, ymini) # make x the average of the xmini x.append(float(sum(xmini))/len(xmini)) dydx.append(slope) return _n.array(x), _n.array(dydx)
[ "def", "derivative_fit", "(", "xdata", ",", "ydata", ",", "neighbors", "=", "1", ")", ":", "x", "=", "[", "]", "dydx", "=", "[", "]", "nmax", "=", "len", "(", "xdata", ")", "-", "1", "for", "n", "in", "range", "(", "nmax", "+", "1", ")", ":",...
loops over the data points, performing a least-squares linear fit of the nearest neighbors at each point. Returns an array of x-values and slopes. xdata should probably be well-ordered. neighbors How many data point on the left and right to include.
[ "loops", "over", "the", "data", "points", "performing", "a", "least", "-", "squares", "linear", "fit", "of", "the", "nearest", "neighbors", "at", "each", "point", ".", "Returns", "an", "array", "of", "x", "-", "values", "and", "slopes", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L360-L389
train
39,762
Spinmob/spinmob
_functions.py
dumbguy_minimize
def dumbguy_minimize(f, xmin, xmax, xstep): """ This just steps x and looks for a peak returns x, f(x) """ prev = f(xmin) this = f(xmin+xstep) for x in frange(xmin+xstep,xmax,xstep): next = f(x+xstep) # see if we're on top if this < prev and this < next: return x, this prev = this this = next return x, this
python
def dumbguy_minimize(f, xmin, xmax, xstep): """ This just steps x and looks for a peak returns x, f(x) """ prev = f(xmin) this = f(xmin+xstep) for x in frange(xmin+xstep,xmax,xstep): next = f(x+xstep) # see if we're on top if this < prev and this < next: return x, this prev = this this = next return x, this
[ "def", "dumbguy_minimize", "(", "f", ",", "xmin", ",", "xmax", ",", "xstep", ")", ":", "prev", "=", "f", "(", "xmin", ")", "this", "=", "f", "(", "xmin", "+", "xstep", ")", "for", "x", "in", "frange", "(", "xmin", "+", "xstep", ",", "xmax", ","...
This just steps x and looks for a peak returns x, f(x)
[ "This", "just", "steps", "x", "and", "looks", "for", "a", "peak" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L477-L495
train
39,763
Spinmob/spinmob
_functions.py
elements_are_numbers
def elements_are_numbers(array): """ Tests whether the elements of the supplied array are numbers. """ # empty case if len(array) == 0: return 0 output_value = 1 for x in array: # test it and die if it's not a number test = is_a_number(x) if not test: return False # mention if it's complex output_value = max(output_value,test) return output_value
python
def elements_are_numbers(array): """ Tests whether the elements of the supplied array are numbers. """ # empty case if len(array) == 0: return 0 output_value = 1 for x in array: # test it and die if it's not a number test = is_a_number(x) if not test: return False # mention if it's complex output_value = max(output_value,test) return output_value
[ "def", "elements_are_numbers", "(", "array", ")", ":", "# empty case", "if", "len", "(", "array", ")", "==", "0", ":", "return", "0", "output_value", "=", "1", "for", "x", "in", "array", ":", "# test it and die if it's not a number", "test", "=", "is_a_number"...
Tests whether the elements of the supplied array are numbers.
[ "Tests", "whether", "the", "elements", "of", "the", "supplied", "array", "are", "numbers", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L497-L515
train
39,764
Spinmob/spinmob
_functions.py
find_N_peaks
def find_N_peaks(array, N=4, max_iterations=100, rec_max_iterations=3, recursion=1): """ This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found. """ if recursion<0: return None # get an initial guess as to the baseline ymin = min(array) ymax = max(array) for n in range(max_iterations): # bisect the range to estimate the baseline y1 = (ymin+ymax)/2.0 # now see how many peaks this finds. p could have 40 for all we know p, s, i = find_peaks(array, y1, True) # now loop over the subarrays and make sure there aren't two peaks in any of them for n in range(len(i)): # search the subarray for two peaks, iterating 3 times (75% selectivity) p2 = find_N_peaks(s[n], 2, rec_max_iterations, rec_max_iterations=rec_max_iterations, recursion=recursion-1) # if we found a double-peak if not p2 is None: # push these non-duplicate values into the master array for x in p2: # if this point is not already in p, push it on if not x in p: p.append(x+i[n]) # don't forget the offset, since subarrays start at 0 # if we nailed it, finish up if len(p) == N: return p # if we have too many peaks, we need to increase the baseline if len(p) > N: ymin = y1 # too few? decrease the baseline else: ymax = y1 return None
python
def find_N_peaks(array, N=4, max_iterations=100, rec_max_iterations=3, recursion=1): """ This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found. """ if recursion<0: return None # get an initial guess as to the baseline ymin = min(array) ymax = max(array) for n in range(max_iterations): # bisect the range to estimate the baseline y1 = (ymin+ymax)/2.0 # now see how many peaks this finds. p could have 40 for all we know p, s, i = find_peaks(array, y1, True) # now loop over the subarrays and make sure there aren't two peaks in any of them for n in range(len(i)): # search the subarray for two peaks, iterating 3 times (75% selectivity) p2 = find_N_peaks(s[n], 2, rec_max_iterations, rec_max_iterations=rec_max_iterations, recursion=recursion-1) # if we found a double-peak if not p2 is None: # push these non-duplicate values into the master array for x in p2: # if this point is not already in p, push it on if not x in p: p.append(x+i[n]) # don't forget the offset, since subarrays start at 0 # if we nailed it, finish up if len(p) == N: return p # if we have too many peaks, we need to increase the baseline if len(p) > N: ymin = y1 # too few? decrease the baseline else: ymax = y1 return None
[ "def", "find_N_peaks", "(", "array", ",", "N", "=", "4", ",", "max_iterations", "=", "100", ",", "rec_max_iterations", "=", "3", ",", "recursion", "=", "1", ")", ":", "if", "recursion", "<", "0", ":", "return", "None", "# get an initial guess as to the basel...
This will run the find_peaks algorythm, adjusting the baseline until exactly N peaks are found.
[ "This", "will", "run", "the", "find_peaks", "algorythm", "adjusting", "the", "baseline", "until", "exactly", "N", "peaks", "are", "found", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L547-L588
train
39,765
Spinmob/spinmob
_functions.py
find_peaks
def find_peaks(array, baseline=0.1, return_subarrays=False): """ This will try to identify the indices of the peaks in array, returning a list of indices in ascending order. Runs along the data set until it jumps above baseline. Then it considers all the subsequent data above the baseline as part of the peak, and records the maximum of this data as one peak value. """ peaks = [] if return_subarrays: subarray_values = [] subarray_indices = [] # loop over the data n = 0 while n < len(array): # see if we're above baseline, then start the "we're in a peak" loop if array[n] > baseline: # start keeping track of the subarray here if return_subarrays: subarray_values.append([]) subarray_indices.append(n) # find the max ymax=baseline nmax = n while n < len(array) and array[n] > baseline: # add this value to the subarray if return_subarrays: subarray_values[-1].append(array[n]) if array[n] > ymax: ymax = array[n] nmax = n n = n+1 # store the max peaks.append(nmax) else: n = n+1 if return_subarrays: return peaks, subarray_values, subarray_indices else: return peaks
python
def find_peaks(array, baseline=0.1, return_subarrays=False): """ This will try to identify the indices of the peaks in array, returning a list of indices in ascending order. Runs along the data set until it jumps above baseline. Then it considers all the subsequent data above the baseline as part of the peak, and records the maximum of this data as one peak value. """ peaks = [] if return_subarrays: subarray_values = [] subarray_indices = [] # loop over the data n = 0 while n < len(array): # see if we're above baseline, then start the "we're in a peak" loop if array[n] > baseline: # start keeping track of the subarray here if return_subarrays: subarray_values.append([]) subarray_indices.append(n) # find the max ymax=baseline nmax = n while n < len(array) and array[n] > baseline: # add this value to the subarray if return_subarrays: subarray_values[-1].append(array[n]) if array[n] > ymax: ymax = array[n] nmax = n n = n+1 # store the max peaks.append(nmax) else: n = n+1 if return_subarrays: return peaks, subarray_values, subarray_indices else: return peaks
[ "def", "find_peaks", "(", "array", ",", "baseline", "=", "0.1", ",", "return_subarrays", "=", "False", ")", ":", "peaks", "=", "[", "]", "if", "return_subarrays", ":", "subarray_values", "=", "[", "]", "subarray_indices", "=", "[", "]", "# loop over the data...
This will try to identify the indices of the peaks in array, returning a list of indices in ascending order. Runs along the data set until it jumps above baseline. Then it considers all the subsequent data above the baseline as part of the peak, and records the maximum of this data as one peak value.
[ "This", "will", "try", "to", "identify", "the", "indices", "of", "the", "peaks", "in", "array", "returning", "a", "list", "of", "indices", "in", "ascending", "order", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L591-L636
train
39,766
Spinmob/spinmob
_functions.py
find_zero_bisect
def find_zero_bisect(f, xmin, xmax, xprecision): """ This will bisect the range and zero in on zero. """ if f(xmax)*f(xmin) > 0: print("find_zero_bisect(): no zero on the range",xmin,"to",xmax) return None temp = min(xmin,xmax) xmax = max(xmin,xmax) xmin = temp xmid = (xmin+xmax)*0.5 while xmax-xmin > xprecision: y = f(xmid) # pick the direction with one guy above and one guy below zero if y > 0: # move left or right? if f(xmin) < 0: xmax=xmid else: xmin=xmid # f(xmid) is below zero elif y < 0: # move left or right? if f(xmin) > 0: xmax=xmid else: xmin=xmid # yeah, right else: return xmid # bisect again xmid = (xmin+xmax)*0.5 return xmid
python
def find_zero_bisect(f, xmin, xmax, xprecision): """ This will bisect the range and zero in on zero. """ if f(xmax)*f(xmin) > 0: print("find_zero_bisect(): no zero on the range",xmin,"to",xmax) return None temp = min(xmin,xmax) xmax = max(xmin,xmax) xmin = temp xmid = (xmin+xmax)*0.5 while xmax-xmin > xprecision: y = f(xmid) # pick the direction with one guy above and one guy below zero if y > 0: # move left or right? if f(xmin) < 0: xmax=xmid else: xmin=xmid # f(xmid) is below zero elif y < 0: # move left or right? if f(xmin) > 0: xmax=xmid else: xmin=xmid # yeah, right else: return xmid # bisect again xmid = (xmin+xmax)*0.5 return xmid
[ "def", "find_zero_bisect", "(", "f", ",", "xmin", ",", "xmax", ",", "xprecision", ")", ":", "if", "f", "(", "xmax", ")", "*", "f", "(", "xmin", ")", ">", "0", ":", "print", "(", "\"find_zero_bisect(): no zero on the range\"", ",", "xmin", ",", "\"to\"", ...
This will bisect the range and zero in on zero.
[ "This", "will", "bisect", "the", "range", "and", "zero", "in", "on", "zero", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L701-L735
train
39,767
Spinmob/spinmob
_functions.py
frange
def frange(start, end, inc=1.0): """ A range function, that accepts float increments and reversed direction. See also numpy.linspace() """ start = 1.0*start end = 1.0*end inc = 1.0*inc # if we got a dumb increment if not inc: return _n.array([start,end]) # if the increment is going the wrong direction if 1.0*(end-start)/inc < 0.0: inc = -inc # get the integer steps ns = _n.array(list(range(0, int(1.0*(end-start)/inc)+1))) return start + ns*inc
python
def frange(start, end, inc=1.0): """ A range function, that accepts float increments and reversed direction. See also numpy.linspace() """ start = 1.0*start end = 1.0*end inc = 1.0*inc # if we got a dumb increment if not inc: return _n.array([start,end]) # if the increment is going the wrong direction if 1.0*(end-start)/inc < 0.0: inc = -inc # get the integer steps ns = _n.array(list(range(0, int(1.0*(end-start)/inc)+1))) return start + ns*inc
[ "def", "frange", "(", "start", ",", "end", ",", "inc", "=", "1.0", ")", ":", "start", "=", "1.0", "*", "start", "end", "=", "1.0", "*", "end", "inc", "=", "1.0", "*", "inc", "# if we got a dumb increment", "if", "not", "inc", ":", "return", "_n", "...
A range function, that accepts float increments and reversed direction. See also numpy.linspace()
[ "A", "range", "function", "that", "accepts", "float", "increments", "and", "reversed", "direction", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L770-L791
train
39,768
Spinmob/spinmob
_functions.py
get_shell_history
def get_shell_history(): """ This only works with some shells. """ # try for ipython if 'get_ipython' in globals(): a = list(get_ipython().history_manager.input_hist_raw) a.reverse() return a elif 'SPYDER_SHELL_ID' in _os.environ: try: p = _os.path.join(_settings.path_user, ".spyder2", "history.py") a = read_lines(p) a.reverse() return a except: pass # otherwise try pyshell or pycrust (requires wx) else: try: import wx for x in wx.GetTopLevelWindows(): if type(x) in [wx.py.shell.ShellFrame, wx.py.crust.CrustFrame]: a = x.shell.GetText().split(">>>") a.reverse() return a except: pass return ['shell history not available']
python
def get_shell_history(): """ This only works with some shells. """ # try for ipython if 'get_ipython' in globals(): a = list(get_ipython().history_manager.input_hist_raw) a.reverse() return a elif 'SPYDER_SHELL_ID' in _os.environ: try: p = _os.path.join(_settings.path_user, ".spyder2", "history.py") a = read_lines(p) a.reverse() return a except: pass # otherwise try pyshell or pycrust (requires wx) else: try: import wx for x in wx.GetTopLevelWindows(): if type(x) in [wx.py.shell.ShellFrame, wx.py.crust.CrustFrame]: a = x.shell.GetText().split(">>>") a.reverse() return a except: pass return ['shell history not available']
[ "def", "get_shell_history", "(", ")", ":", "# try for ipython", "if", "'get_ipython'", "in", "globals", "(", ")", ":", "a", "=", "list", "(", "get_ipython", "(", ")", ".", "history_manager", ".", "input_hist_raw", ")", "a", ".", "reverse", "(", ")", "retur...
This only works with some shells.
[ "This", "only", "works", "with", "some", "shells", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L850-L881
train
39,769
Spinmob/spinmob
_functions.py
index
def index(value, array): """ Array search that behaves like I want it to. Totally dumb, I know. """ i = array.searchsorted(value) if i == len(array): return -1 else: return i
python
def index(value, array): """ Array search that behaves like I want it to. Totally dumb, I know. """ i = array.searchsorted(value) if i == len(array): return -1 else: return i
[ "def", "index", "(", "value", ",", "array", ")", ":", "i", "=", "array", ".", "searchsorted", "(", "value", ")", "if", "i", "==", "len", "(", "array", ")", ":", "return", "-", "1", "else", ":", "return", "i" ]
Array search that behaves like I want it to. Totally dumb, I know.
[ "Array", "search", "that", "behaves", "like", "I", "want", "it", "to", ".", "Totally", "dumb", "I", "know", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L896-L902
train
39,770
Spinmob/spinmob
_functions.py
index_next_crossing
def index_next_crossing(value, array, starting_index=0, direction=1): """ starts at starting_index, and walks through the array until it finds a crossing point with value set direction=-1 for down crossing """ for n in range(starting_index, len(array)-1): if (value-array[n] )*direction >= 0 \ and (value-array[n+1])*direction < 0: return n # no crossing found return -1
python
def index_next_crossing(value, array, starting_index=0, direction=1): """ starts at starting_index, and walks through the array until it finds a crossing point with value set direction=-1 for down crossing """ for n in range(starting_index, len(array)-1): if (value-array[n] )*direction >= 0 \ and (value-array[n+1])*direction < 0: return n # no crossing found return -1
[ "def", "index_next_crossing", "(", "value", ",", "array", ",", "starting_index", "=", "0", ",", "direction", "=", "1", ")", ":", "for", "n", "in", "range", "(", "starting_index", ",", "len", "(", "array", ")", "-", "1", ")", ":", "if", "(", "value", ...
starts at starting_index, and walks through the array until it finds a crossing point with value set direction=-1 for down crossing
[ "starts", "at", "starting_index", "and", "walks", "through", "the", "array", "until", "it", "finds", "a", "crossing", "point", "with", "value" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L913-L926
train
39,771
Spinmob/spinmob
_functions.py
insert_ordered
def insert_ordered(value, array): """ This will insert the value into the array, keeping it sorted, and returning the index where it was inserted """ index = 0 # search for the last array item that value is larger than for n in range(0,len(array)): if value >= array[n]: index = n+1 array.insert(index, value) return index
python
def insert_ordered(value, array): """ This will insert the value into the array, keeping it sorted, and returning the index where it was inserted """ index = 0 # search for the last array item that value is larger than for n in range(0,len(array)): if value >= array[n]: index = n+1 array.insert(index, value) return index
[ "def", "insert_ordered", "(", "value", ",", "array", ")", ":", "index", "=", "0", "# search for the last array item that value is larger than", "for", "n", "in", "range", "(", "0", ",", "len", "(", "array", ")", ")", ":", "if", "value", ">=", "array", "[", ...
This will insert the value into the array, keeping it sorted, and returning the index where it was inserted
[ "This", "will", "insert", "the", "value", "into", "the", "array", "keeping", "it", "sorted", "and", "returning", "the", "index", "where", "it", "was", "inserted" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L931-L944
train
39,772
Spinmob/spinmob
_functions.py
replace_in_files
def replace_in_files(search, replace, depth=0, paths=None, confirm=True): """ Does a line-by-line search and replace, but only up to the "depth" line. """ # have the user select some files if paths==None: paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return for path in paths: lines = read_lines(path) if depth: N=min(len(lines),depth) else: N=len(lines) for n in range(0,N): if lines[n].find(search) >= 0: lines[n] = lines[n].replace(search,replace) print(path.split(_os.path.pathsep)[-1]+ ': "'+lines[n]+'"') # only write if we're not confirming if not confirm: _os.rename(path, path+".backup") write_to_file(path, join(lines, '')) if confirm: if input("yes? ")=="yes": replace_in_files(search,replace,depth,paths,False) return
python
def replace_in_files(search, replace, depth=0, paths=None, confirm=True): """ Does a line-by-line search and replace, but only up to the "depth" line. """ # have the user select some files if paths==None: paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return for path in paths: lines = read_lines(path) if depth: N=min(len(lines),depth) else: N=len(lines) for n in range(0,N): if lines[n].find(search) >= 0: lines[n] = lines[n].replace(search,replace) print(path.split(_os.path.pathsep)[-1]+ ': "'+lines[n]+'"') # only write if we're not confirming if not confirm: _os.rename(path, path+".backup") write_to_file(path, join(lines, '')) if confirm: if input("yes? ")=="yes": replace_in_files(search,replace,depth,paths,False) return
[ "def", "replace_in_files", "(", "search", ",", "replace", ",", "depth", "=", "0", ",", "paths", "=", "None", ",", "confirm", "=", "True", ")", ":", "# have the user select some files", "if", "paths", "==", "None", ":", "paths", "=", "_s", ".", "dialogs", ...
Does a line-by-line search and replace, but only up to the "depth" line.
[ "Does", "a", "line", "-", "by", "-", "line", "search", "and", "replace", "but", "only", "up", "to", "the", "depth", "line", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L1232-L1262
train
39,773
Spinmob/spinmob
_functions.py
replace_lines_in_files
def replace_lines_in_files(search_string, replacement_line): """ Finds lines containing the search string and replaces the whole line with the specified replacement string. """ # have the user select some files paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return for path in paths: _shutil.copy(path, path+".backup") lines = read_lines(path) for n in range(0,len(lines)): if lines[n].find(search_string) >= 0: print(lines[n]) lines[n] = replacement_line.strip() + "\n" write_to_file(path, join(lines, '')) return
python
def replace_lines_in_files(search_string, replacement_line): """ Finds lines containing the search string and replaces the whole line with the specified replacement string. """ # have the user select some files paths = _s.dialogs.MultipleFiles('DIS AND DAT|*.*') if paths == []: return for path in paths: _shutil.copy(path, path+".backup") lines = read_lines(path) for n in range(0,len(lines)): if lines[n].find(search_string) >= 0: print(lines[n]) lines[n] = replacement_line.strip() + "\n" write_to_file(path, join(lines, '')) return
[ "def", "replace_lines_in_files", "(", "search_string", ",", "replacement_line", ")", ":", "# have the user select some files", "paths", "=", "_s", ".", "dialogs", ".", "MultipleFiles", "(", "'DIS AND DAT|*.*'", ")", "if", "paths", "==", "[", "]", ":", "return", "f...
Finds lines containing the search string and replaces the whole line with the specified replacement string.
[ "Finds", "lines", "containing", "the", "search", "string", "and", "replaces", "the", "whole", "line", "with", "the", "specified", "replacement", "string", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L1264-L1284
train
39,774
Spinmob/spinmob
_functions.py
reverse
def reverse(array): """ returns a reversed numpy array """ l = list(array) l.reverse() return _n.array(l)
python
def reverse(array): """ returns a reversed numpy array """ l = list(array) l.reverse() return _n.array(l)
[ "def", "reverse", "(", "array", ")", ":", "l", "=", "list", "(", "array", ")", "l", ".", "reverse", "(", ")", "return", "_n", ".", "array", "(", "l", ")" ]
returns a reversed numpy array
[ "returns", "a", "reversed", "numpy", "array" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L1286-L1292
train
39,775
Spinmob/spinmob
_functions.py
submatrix
def submatrix(matrix,i1,i2,j1,j2): """ returns the submatrix defined by the index bounds i1-i2 and j1-j2 Endpoints included! """ new = [] for i in range(i1,i2+1): new.append(matrix[i][j1:j2+1]) return _n.array(new)
python
def submatrix(matrix,i1,i2,j1,j2): """ returns the submatrix defined by the index bounds i1-i2 and j1-j2 Endpoints included! """ new = [] for i in range(i1,i2+1): new.append(matrix[i][j1:j2+1]) return _n.array(new)
[ "def", "submatrix", "(", "matrix", ",", "i1", ",", "i2", ",", "j1", ",", "j2", ")", ":", "new", "=", "[", "]", "for", "i", "in", "range", "(", "i1", ",", "i2", "+", "1", ")", ":", "new", ".", "append", "(", "matrix", "[", "i", "]", "[", "...
returns the submatrix defined by the index bounds i1-i2 and j1-j2 Endpoints included!
[ "returns", "the", "submatrix", "defined", "by", "the", "index", "bounds", "i1", "-", "i2", "and", "j1", "-", "j2" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L1405-L1415
train
39,776
Spinmob/spinmob
_functions.py
trim_data_uber
def trim_data_uber(arrays, conditions): """ Non-destructively selects data from the supplied list of arrays based on the supplied list of conditions. Importantly, if any of the conditions are not met for the n'th data point, the n'th data point is rejected for all supplied arrays. Example ------- x = numpy.linspace(0,10,20) y = numpy.sin(x) trim_data_uber([x,y], [x>3,x<9,y<0.7]) This will keep only the x-y pairs in which 3<x<9 and y<0.7, returning a list of shorter arrays (all having the same length, of course). """ # dumb conditions if len(conditions) == 0: return arrays if len(arrays) == 0: return [] # find the indices to keep all_conditions = conditions[0] for n in range(1,len(conditions)): all_conditions = all_conditions & conditions[n] ns = _n.argwhere(all_conditions).transpose()[0] # assemble and return trimmed data output = [] for n in range(len(arrays)): if not arrays[n] is None: output.append(arrays[n][ns]) else: output.append(None) return output
python
def trim_data_uber(arrays, conditions): """ Non-destructively selects data from the supplied list of arrays based on the supplied list of conditions. Importantly, if any of the conditions are not met for the n'th data point, the n'th data point is rejected for all supplied arrays. Example ------- x = numpy.linspace(0,10,20) y = numpy.sin(x) trim_data_uber([x,y], [x>3,x<9,y<0.7]) This will keep only the x-y pairs in which 3<x<9 and y<0.7, returning a list of shorter arrays (all having the same length, of course). """ # dumb conditions if len(conditions) == 0: return arrays if len(arrays) == 0: return [] # find the indices to keep all_conditions = conditions[0] for n in range(1,len(conditions)): all_conditions = all_conditions & conditions[n] ns = _n.argwhere(all_conditions).transpose()[0] # assemble and return trimmed data output = [] for n in range(len(arrays)): if not arrays[n] is None: output.append(arrays[n][ns]) else: output.append(None) return output
[ "def", "trim_data_uber", "(", "arrays", ",", "conditions", ")", ":", "# dumb conditions", "if", "len", "(", "conditions", ")", "==", "0", ":", "return", "arrays", "if", "len", "(", "arrays", ")", "==", "0", ":", "return", "[", "]", "# find the indices to k...
Non-destructively selects data from the supplied list of arrays based on the supplied list of conditions. Importantly, if any of the conditions are not met for the n'th data point, the n'th data point is rejected for all supplied arrays. Example ------- x = numpy.linspace(0,10,20) y = numpy.sin(x) trim_data_uber([x,y], [x>3,x<9,y<0.7]) This will keep only the x-y pairs in which 3<x<9 and y<0.7, returning a list of shorter arrays (all having the same length, of course).
[ "Non", "-", "destructively", "selects", "data", "from", "the", "supplied", "list", "of", "arrays", "based", "on", "the", "supplied", "list", "of", "conditions", ".", "Importantly", "if", "any", "of", "the", "conditions", "are", "not", "met", "for", "the", ...
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_functions.py#L1448-L1478
train
39,777
fitnr/censusgeocode
censusgeocode/censusgeocode.py
CensusGeocode._fetch
def _fetch(self, searchtype, fields, **kwargs): '''Fetch a response from the Geocoding API.''' fields['vintage'] = self.vintage fields['benchmark'] = self.benchmark fields['format'] = 'json' if 'layers' in kwargs: fields['layers'] = kwargs['layers'] returntype = kwargs.get('returntype', 'geographies') url = self._geturl(searchtype, returntype) try: with requests.get(url, params=fields, timeout=kwargs.get('timeout')) as r: content = r.json() if "addressMatches" in content.get('result', {}): return AddressResult(content) if "geographies" in content.get('result', {}): return GeographyResult(content) raise ValueError() except (ValueError, KeyError): raise ValueError("Unable to parse response from Census") except RequestException as e: raise e
python
def _fetch(self, searchtype, fields, **kwargs): '''Fetch a response from the Geocoding API.''' fields['vintage'] = self.vintage fields['benchmark'] = self.benchmark fields['format'] = 'json' if 'layers' in kwargs: fields['layers'] = kwargs['layers'] returntype = kwargs.get('returntype', 'geographies') url = self._geturl(searchtype, returntype) try: with requests.get(url, params=fields, timeout=kwargs.get('timeout')) as r: content = r.json() if "addressMatches" in content.get('result', {}): return AddressResult(content) if "geographies" in content.get('result', {}): return GeographyResult(content) raise ValueError() except (ValueError, KeyError): raise ValueError("Unable to parse response from Census") except RequestException as e: raise e
[ "def", "_fetch", "(", "self", ",", "searchtype", ",", "fields", ",", "*", "*", "kwargs", ")", ":", "fields", "[", "'vintage'", "]", "=", "self", ".", "vintage", "fields", "[", "'benchmark'", "]", "=", "self", ".", "benchmark", "fields", "[", "'format'"...
Fetch a response from the Geocoding API.
[ "Fetch", "a", "response", "from", "the", "Geocoding", "API", "." ]
9414c331a63fbcfff6b7295cd8935c40ce54c88c
https://github.com/fitnr/censusgeocode/blob/9414c331a63fbcfff6b7295cd8935c40ce54c88c/censusgeocode/censusgeocode.py#L78-L105
train
39,778
fitnr/censusgeocode
censusgeocode/censusgeocode.py
CensusGeocode.address
def address(self, street, city=None, state=None, zipcode=None, **kwargs): '''Geocode an address.''' fields = { 'street': street, 'city': city, 'state': state, 'zip': zipcode, } return self._fetch('address', fields, **kwargs)
python
def address(self, street, city=None, state=None, zipcode=None, **kwargs): '''Geocode an address.''' fields = { 'street': street, 'city': city, 'state': state, 'zip': zipcode, } return self._fetch('address', fields, **kwargs)
[ "def", "address", "(", "self", ",", "street", ",", "city", "=", "None", ",", "state", "=", "None", ",", "zipcode", "=", "None", ",", "*", "*", "kwargs", ")", ":", "fields", "=", "{", "'street'", ":", "street", ",", "'city'", ":", "city", ",", "'s...
Geocode an address.
[ "Geocode", "an", "address", "." ]
9414c331a63fbcfff6b7295cd8935c40ce54c88c
https://github.com/fitnr/censusgeocode/blob/9414c331a63fbcfff6b7295cd8935c40ce54c88c/censusgeocode/censusgeocode.py#L117-L126
train
39,779
Spinmob/spinmob
_pylab_colormap.py
colormap.set_name
def set_name(self, name="My Colormap"): """ Sets the name. Make sure the name is something your OS could name a file. """ if not type(name)==str: print("set_name(): Name must be a string.") return self._name = name return self
python
def set_name(self, name="My Colormap"): """ Sets the name. Make sure the name is something your OS could name a file. """ if not type(name)==str: print("set_name(): Name must be a string.") return self._name = name return self
[ "def", "set_name", "(", "self", ",", "name", "=", "\"My Colormap\"", ")", ":", "if", "not", "type", "(", "name", ")", "==", "str", ":", "print", "(", "\"set_name(): Name must be a string.\"", ")", "return", "self", ".", "_name", "=", "name", "return", "sel...
Sets the name. Make sure the name is something your OS could name a file.
[ "Sets", "the", "name", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L136-L146
train
39,780
Spinmob/spinmob
_pylab_colormap.py
colormap.set_image
def set_image(self, image='auto'): """ Set which pylab image to tweak. """ if image=="auto": image = _pylab.gca().images[0] self._image=image self.update_image()
python
def set_image(self, image='auto'): """ Set which pylab image to tweak. """ if image=="auto": image = _pylab.gca().images[0] self._image=image self.update_image()
[ "def", "set_image", "(", "self", ",", "image", "=", "'auto'", ")", ":", "if", "image", "==", "\"auto\"", ":", "image", "=", "_pylab", ".", "gca", "(", ")", ".", "images", "[", "0", "]", "self", ".", "_image", "=", "image", "self", ".", "update_imag...
Set which pylab image to tweak.
[ "Set", "which", "pylab", "image", "to", "tweak", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L154-L160
train
39,781
Spinmob/spinmob
_pylab_colormap.py
colormap.update_image
def update_image(self): """ Set's the image's cmap. """ if self._image: self._image.set_cmap(self.get_cmap()) _pylab.draw()
python
def update_image(self): """ Set's the image's cmap. """ if self._image: self._image.set_cmap(self.get_cmap()) _pylab.draw()
[ "def", "update_image", "(", "self", ")", ":", "if", "self", ".", "_image", ":", "self", ".", "_image", ".", "set_cmap", "(", "self", ".", "get_cmap", "(", ")", ")", "_pylab", ".", "draw", "(", ")" ]
Set's the image's cmap.
[ "Set", "s", "the", "image", "s", "cmap", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L162-L168
train
39,782
Spinmob/spinmob
_pylab_colormap.py
colormap.pop_colorpoint
def pop_colorpoint(self, n=0): """ Removes and returns the specified colorpoint. Will always leave two behind. """ # make sure we have more than 2; otherwise don't pop it, just return it if len(self._colorpoint_list) > 2: # do the popping x = self._colorpoint_list.pop(n) # make sure the endpoints are 0 and 1 self._colorpoint_list[0][0] = 0.0 self._colorpoint_list[-1][0] = 1.0 # update the image self.update_image() return x # otherwise just return the indexed item else: return self[n]
python
def pop_colorpoint(self, n=0): """ Removes and returns the specified colorpoint. Will always leave two behind. """ # make sure we have more than 2; otherwise don't pop it, just return it if len(self._colorpoint_list) > 2: # do the popping x = self._colorpoint_list.pop(n) # make sure the endpoints are 0 and 1 self._colorpoint_list[0][0] = 0.0 self._colorpoint_list[-1][0] = 1.0 # update the image self.update_image() return x # otherwise just return the indexed item else: return self[n]
[ "def", "pop_colorpoint", "(", "self", ",", "n", "=", "0", ")", ":", "# make sure we have more than 2; otherwise don't pop it, just return it", "if", "len", "(", "self", ".", "_colorpoint_list", ")", ">", "2", ":", "# do the popping", "x", "=", "self", ".", "_color...
Removes and returns the specified colorpoint. Will always leave two behind.
[ "Removes", "and", "returns", "the", "specified", "colorpoint", ".", "Will", "always", "leave", "two", "behind", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L170-L191
train
39,783
Spinmob/spinmob
_pylab_colormap.py
colormap.insert_colorpoint
def insert_colorpoint(self, position=0.5, color1=[1.0,1.0,0.0], color2=[1.0,1.0,0.0]): """ Inserts the specified color into the list. """ L = self._colorpoint_list # if position = 0 or 1, push the end points inward if position <= 0.0: L.insert(0,[0.0,color1,color2]) elif position >= 1.0: L.append([1.0,color1,color2]) # otherwise, find the position where it belongs else: # loop over all the points for n in range(len(self._colorpoint_list)): # check if it's less than the next one if position <= L[n+1][0]: # found the place to insert it L.insert(n+1,[position,color1,color2]) break # update the image with the new cmap self.update_image() return self
python
def insert_colorpoint(self, position=0.5, color1=[1.0,1.0,0.0], color2=[1.0,1.0,0.0]): """ Inserts the specified color into the list. """ L = self._colorpoint_list # if position = 0 or 1, push the end points inward if position <= 0.0: L.insert(0,[0.0,color1,color2]) elif position >= 1.0: L.append([1.0,color1,color2]) # otherwise, find the position where it belongs else: # loop over all the points for n in range(len(self._colorpoint_list)): # check if it's less than the next one if position <= L[n+1][0]: # found the place to insert it L.insert(n+1,[position,color1,color2]) break # update the image with the new cmap self.update_image() return self
[ "def", "insert_colorpoint", "(", "self", ",", "position", "=", "0.5", ",", "color1", "=", "[", "1.0", ",", "1.0", ",", "0.0", "]", ",", "color2", "=", "[", "1.0", ",", "1.0", ",", "0.0", "]", ")", ":", "L", "=", "self", ".", "_colorpoint_list", "...
Inserts the specified color into the list.
[ "Inserts", "the", "specified", "color", "into", "the", "list", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L193-L220
train
39,784
Spinmob/spinmob
_pylab_colormap.py
colormap.modify_colorpoint
def modify_colorpoint(self, n, position=0.5, color1=[1.0,1.0,1.0], color2=[1.0,1.0,1.0]): """ Changes the values of an existing colorpoint, then updates the colormap. """ if n==0.0 : position = 0.0 elif n==len(self._colorpoint_list)-1: position = 1.0 else: position = max(self._colorpoint_list[n-1][0], position) self._colorpoint_list[n] = [position, color1, color2] self.update_image() self.save_colormap("Last Used")
python
def modify_colorpoint(self, n, position=0.5, color1=[1.0,1.0,1.0], color2=[1.0,1.0,1.0]): """ Changes the values of an existing colorpoint, then updates the colormap. """ if n==0.0 : position = 0.0 elif n==len(self._colorpoint_list)-1: position = 1.0 else: position = max(self._colorpoint_list[n-1][0], position) self._colorpoint_list[n] = [position, color1, color2] self.update_image() self.save_colormap("Last Used")
[ "def", "modify_colorpoint", "(", "self", ",", "n", ",", "position", "=", "0.5", ",", "color1", "=", "[", "1.0", ",", "1.0", ",", "1.0", "]", ",", "color2", "=", "[", "1.0", ",", "1.0", ",", "1.0", "]", ")", ":", "if", "n", "==", "0.0", ":", "...
Changes the values of an existing colorpoint, then updates the colormap.
[ "Changes", "the", "values", "of", "an", "existing", "colorpoint", "then", "updates", "the", "colormap", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L222-L232
train
39,785
Spinmob/spinmob
_pylab_colormap.py
colormap.get_cmap
def get_cmap(self): """ Generates a pylab cmap object from the colorpoint data. """ # now generate the colormap from the ordered list r = [] g = [] b = [] for p in self._colorpoint_list: r.append((p[0], p[1][0]*1.0, p[2][0]*1.0)) g.append((p[0], p[1][1]*1.0, p[2][1]*1.0)) b.append((p[0], p[1][2]*1.0, p[2][2]*1.0)) # store the formatted dictionary c = {'red':r, 'green':g, 'blue':b} # now set the dang thing return _mpl.colors.LinearSegmentedColormap('custom', c)
python
def get_cmap(self): """ Generates a pylab cmap object from the colorpoint data. """ # now generate the colormap from the ordered list r = [] g = [] b = [] for p in self._colorpoint_list: r.append((p[0], p[1][0]*1.0, p[2][0]*1.0)) g.append((p[0], p[1][1]*1.0, p[2][1]*1.0)) b.append((p[0], p[1][2]*1.0, p[2][2]*1.0)) # store the formatted dictionary c = {'red':r, 'green':g, 'blue':b} # now set the dang thing return _mpl.colors.LinearSegmentedColormap('custom', c)
[ "def", "get_cmap", "(", "self", ")", ":", "# now generate the colormap from the ordered list", "r", "=", "[", "]", "g", "=", "[", "]", "b", "=", "[", "]", "for", "p", "in", "self", ".", "_colorpoint_list", ":", "r", ".", "append", "(", "(", "p", "[", ...
Generates a pylab cmap object from the colorpoint data.
[ "Generates", "a", "pylab", "cmap", "object", "from", "the", "colorpoint", "data", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L234-L252
train
39,786
Spinmob/spinmob
_pylab_colormap.py
colormap_interface._signal_load
def _signal_load(self): """ Load the selected cmap. """ # set our name self.set_name(str(self._combobox_cmaps.currentText())) # load the colormap self.load_colormap() # rebuild the interface self._build_gui() self._button_save.setEnabled(False)
python
def _signal_load(self): """ Load the selected cmap. """ # set our name self.set_name(str(self._combobox_cmaps.currentText())) # load the colormap self.load_colormap() # rebuild the interface self._build_gui() self._button_save.setEnabled(False)
[ "def", "_signal_load", "(", "self", ")", ":", "# set our name", "self", ".", "set_name", "(", "str", "(", "self", ".", "_combobox_cmaps", ".", "currentText", "(", ")", ")", ")", "# load the colormap", "self", ".", "load_colormap", "(", ")", "# rebuild the inte...
Load the selected cmap.
[ "Load", "the", "selected", "cmap", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L406-L420
train
39,787
Spinmob/spinmob
_pylab_colormap.py
colormap_interface._color_dialog_changed
def _color_dialog_changed(self, n, top, c): """ Updates the color of the slider. """ self._button_save.setEnabled(True) cp = self._colorpoint_list[n] # if they're linked, set both if self._checkboxes[n].isChecked(): self.modify_colorpoint(n, cp[0], [c.red()/255.0, c.green()/255.0, c.blue()/255.0], [c.red()/255.0, c.green()/255.0, c.blue()/255.0]) self._buttons_top_color [n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;") self._buttons_bottom_color[n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;") elif top: self.modify_colorpoint(n, cp[0], cp[1], [c.red()/255.0, c.green()/255.0, c.blue()/255.0]) self._buttons_top_color [n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;") else: self.modify_colorpoint(n, cp[0], [c.red()/255.0, c.green()/255.0, c.blue()/255.0], cp[2]) self._buttons_bottom_color[n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;")
python
def _color_dialog_changed(self, n, top, c): """ Updates the color of the slider. """ self._button_save.setEnabled(True) cp = self._colorpoint_list[n] # if they're linked, set both if self._checkboxes[n].isChecked(): self.modify_colorpoint(n, cp[0], [c.red()/255.0, c.green()/255.0, c.blue()/255.0], [c.red()/255.0, c.green()/255.0, c.blue()/255.0]) self._buttons_top_color [n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;") self._buttons_bottom_color[n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;") elif top: self.modify_colorpoint(n, cp[0], cp[1], [c.red()/255.0, c.green()/255.0, c.blue()/255.0]) self._buttons_top_color [n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;") else: self.modify_colorpoint(n, cp[0], [c.red()/255.0, c.green()/255.0, c.blue()/255.0], cp[2]) self._buttons_bottom_color[n].setStyleSheet("background-color: rgb("+str(c.red())+","+str(c.green())+","+str(c.green())+"); border-radius: 3px;")
[ "def", "_color_dialog_changed", "(", "self", ",", "n", ",", "top", ",", "c", ")", ":", "self", ".", "_button_save", ".", "setEnabled", "(", "True", ")", "cp", "=", "self", ".", "_colorpoint_list", "[", "n", "]", "# if they're linked, set both", "if", "self...
Updates the color of the slider.
[ "Updates", "the", "color", "of", "the", "slider", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L442-L464
train
39,788
Spinmob/spinmob
_pylab_colormap.py
colormap_interface._button_plus_clicked
def _button_plus_clicked(self, n): """ Create a new colorpoint. """ self._button_save.setEnabled(True) self.insert_colorpoint(self._colorpoint_list[n][0], self._colorpoint_list[n][1], self._colorpoint_list[n][2]) self._build_gui()
python
def _button_plus_clicked(self, n): """ Create a new colorpoint. """ self._button_save.setEnabled(True) self.insert_colorpoint(self._colorpoint_list[n][0], self._colorpoint_list[n][1], self._colorpoint_list[n][2]) self._build_gui()
[ "def", "_button_plus_clicked", "(", "self", ",", "n", ")", ":", "self", ".", "_button_save", ".", "setEnabled", "(", "True", ")", "self", ".", "insert_colorpoint", "(", "self", ".", "_colorpoint_list", "[", "n", "]", "[", "0", "]", ",", "self", ".", "_...
Create a new colorpoint.
[ "Create", "a", "new", "colorpoint", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L468-L477
train
39,789
Spinmob/spinmob
_pylab_colormap.py
colormap_interface._button_minus_clicked
def _button_minus_clicked(self, n): """ Remove a new colorpoint. """ self._button_save.setEnabled(True) self.pop_colorpoint(n) self._build_gui()
python
def _button_minus_clicked(self, n): """ Remove a new colorpoint. """ self._button_save.setEnabled(True) self.pop_colorpoint(n) self._build_gui()
[ "def", "_button_minus_clicked", "(", "self", ",", "n", ")", ":", "self", ".", "_button_save", ".", "setEnabled", "(", "True", ")", "self", ".", "pop_colorpoint", "(", "n", ")", "self", ".", "_build_gui", "(", ")" ]
Remove a new colorpoint.
[ "Remove", "a", "new", "colorpoint", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L479-L486
train
39,790
Spinmob/spinmob
_pylab_colormap.py
colormap_interface._color_button_clicked
def _color_button_clicked(self, n,top): """ Opens the dialog. """ self._button_save.setEnabled(True) if top: self._color_dialogs_top[n].open() else: self._color_dialogs_bottom[n].open()
python
def _color_button_clicked(self, n,top): """ Opens the dialog. """ self._button_save.setEnabled(True) if top: self._color_dialogs_top[n].open() else: self._color_dialogs_bottom[n].open()
[ "def", "_color_button_clicked", "(", "self", ",", "n", ",", "top", ")", ":", "self", ".", "_button_save", ".", "setEnabled", "(", "True", ")", "if", "top", ":", "self", ".", "_color_dialogs_top", "[", "n", "]", ".", "open", "(", ")", "else", ":", "se...
Opens the dialog.
[ "Opens", "the", "dialog", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L497-L504
train
39,791
Spinmob/spinmob
_pylab_colormap.py
colormap_interface._load_cmap_list
def _load_cmap_list(self): """ Searches the colormaps directory for all files, populates the list. """ # store the current name name = self.get_name() # clear the list self._combobox_cmaps.blockSignals(True) self._combobox_cmaps.clear() # list the existing contents paths = _settings.ListDir('colormaps') # loop over the paths and add the names to the list for path in paths: self._combobox_cmaps.addItem(_os.path.splitext(path)[0]) # try to select the current name self._combobox_cmaps.setCurrentIndex(self._combobox_cmaps.findText(name)) self._combobox_cmaps.blockSignals(False)
python
def _load_cmap_list(self): """ Searches the colormaps directory for all files, populates the list. """ # store the current name name = self.get_name() # clear the list self._combobox_cmaps.blockSignals(True) self._combobox_cmaps.clear() # list the existing contents paths = _settings.ListDir('colormaps') # loop over the paths and add the names to the list for path in paths: self._combobox_cmaps.addItem(_os.path.splitext(path)[0]) # try to select the current name self._combobox_cmaps.setCurrentIndex(self._combobox_cmaps.findText(name)) self._combobox_cmaps.blockSignals(False)
[ "def", "_load_cmap_list", "(", "self", ")", ":", "# store the current name", "name", "=", "self", ".", "get_name", "(", ")", "# clear the list", "self", ".", "_combobox_cmaps", ".", "blockSignals", "(", "True", ")", "self", ".", "_combobox_cmaps", ".", "clear", ...
Searches the colormaps directory for all files, populates the list.
[ "Searches", "the", "colormaps", "directory", "for", "all", "files", "populates", "the", "list", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_pylab_colormap.py#L507-L527
train
39,792
Spinmob/spinmob
_dialogs.py
load
def load(filters="*.*", text='Select a file, FACEFACE!', default_directory='default_directory'): """ Pops up a dialog for opening a single file. Returns a string path or None. """ # make sure the filters contains "*.*" as an option! if not '*' in filters.split(';'): filters = filters + ";;All files (*)" # if this type of pref doesn't exist, we need to make a new one if default_directory in _settings.keys(): default = _settings[default_directory] else: default = "" # pop up the dialog result = _qtw.QFileDialog.getOpenFileName(None,text,default,filters) # If Qt5, take the zeroth element if _s._qt.VERSION_INFO[0:5] == "PyQt5": result = result[0] # Make sure it's a string result = str(result) if result == '': return None else: _settings[default_directory] = _os.path.split(result)[0] return result
python
def load(filters="*.*", text='Select a file, FACEFACE!', default_directory='default_directory'): """ Pops up a dialog for opening a single file. Returns a string path or None. """ # make sure the filters contains "*.*" as an option! if not '*' in filters.split(';'): filters = filters + ";;All files (*)" # if this type of pref doesn't exist, we need to make a new one if default_directory in _settings.keys(): default = _settings[default_directory] else: default = "" # pop up the dialog result = _qtw.QFileDialog.getOpenFileName(None,text,default,filters) # If Qt5, take the zeroth element if _s._qt.VERSION_INFO[0:5] == "PyQt5": result = result[0] # Make sure it's a string result = str(result) if result == '': return None else: _settings[default_directory] = _os.path.split(result)[0] return result
[ "def", "load", "(", "filters", "=", "\"*.*\"", ",", "text", "=", "'Select a file, FACEFACE!'", ",", "default_directory", "=", "'default_directory'", ")", ":", "# make sure the filters contains \"*.*\" as an option!", "if", "not", "'*'", "in", "filters", ".", "split", ...
Pops up a dialog for opening a single file. Returns a string path or None.
[ "Pops", "up", "a", "dialog", "for", "opening", "a", "single", "file", ".", "Returns", "a", "string", "path", "or", "None", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_dialogs.py#L59-L82
train
39,793
Spinmob/spinmob
_dialogs.py
load_multiple
def load_multiple(filters="*.*", text='Select some files, FACEFACE!', default_directory='default_directory'): """ Pops up a dialog for opening more than one file. Returns a list of string paths or None. """ # make sure the filters contains "*.*" as an option! if not '*' in filters.split(';'): filters = filters + ";;All files (*)" # if this type of pref doesn't exist, we need to make a new one if default_directory in _settings.keys(): default = _settings[default_directory] else: default = "" # pop up the dialog results = _qtw.QFileDialog.getOpenFileNames(None,text,default,filters) # If Qt5, take the zeroth element if _s._qt.VERSION_INFO[0:5] == "PyQt5": results = results[0] # Make sure it's a string result = [] for r in results: result.append(str(r)) if len(result)==0: return else: _settings[default_directory] = _os.path.split(result[0])[0] return result
python
def load_multiple(filters="*.*", text='Select some files, FACEFACE!', default_directory='default_directory'): """ Pops up a dialog for opening more than one file. Returns a list of string paths or None. """ # make sure the filters contains "*.*" as an option! if not '*' in filters.split(';'): filters = filters + ";;All files (*)" # if this type of pref doesn't exist, we need to make a new one if default_directory in _settings.keys(): default = _settings[default_directory] else: default = "" # pop up the dialog results = _qtw.QFileDialog.getOpenFileNames(None,text,default,filters) # If Qt5, take the zeroth element if _s._qt.VERSION_INFO[0:5] == "PyQt5": results = results[0] # Make sure it's a string result = [] for r in results: result.append(str(r)) if len(result)==0: return else: _settings[default_directory] = _os.path.split(result[0])[0] return result
[ "def", "load_multiple", "(", "filters", "=", "\"*.*\"", ",", "text", "=", "'Select some files, FACEFACE!'", ",", "default_directory", "=", "'default_directory'", ")", ":", "# make sure the filters contains \"*.*\" as an option!", "if", "not", "'*'", "in", "filters", ".", ...
Pops up a dialog for opening more than one file. Returns a list of string paths or None.
[ "Pops", "up", "a", "dialog", "for", "opening", "more", "than", "one", "file", ".", "Returns", "a", "list", "of", "string", "paths", "or", "None", "." ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_dialogs.py#L85-L109
train
39,794
Spinmob/spinmob
_prefs.py
Prefs.Dump
def Dump(self): """ Dumps the current prefs to the preferences.txt file """ prefs_file = open(self.prefs_path, 'w') for n in range(0,len(self.prefs)): if len(list(self.prefs.items())[n]) > 1: prefs_file.write(str(list(self.prefs.items())[n][0]) + ' = ' + str(list(self.prefs.items())[n][1]) + '\n') prefs_file.close()
python
def Dump(self): """ Dumps the current prefs to the preferences.txt file """ prefs_file = open(self.prefs_path, 'w') for n in range(0,len(self.prefs)): if len(list(self.prefs.items())[n]) > 1: prefs_file.write(str(list(self.prefs.items())[n][0]) + ' = ' + str(list(self.prefs.items())[n][1]) + '\n') prefs_file.close()
[ "def", "Dump", "(", "self", ")", ":", "prefs_file", "=", "open", "(", "self", ".", "prefs_path", ",", "'w'", ")", "for", "n", "in", "range", "(", "0", ",", "len", "(", "self", ".", "prefs", ")", ")", ":", "if", "len", "(", "list", "(", "self", ...
Dumps the current prefs to the preferences.txt file
[ "Dumps", "the", "current", "prefs", "to", "the", "preferences", ".", "txt", "file" ]
f037f5df07f194bcd4a01f4d9916e57b9e8fb45a
https://github.com/Spinmob/spinmob/blob/f037f5df07f194bcd4a01f4d9916e57b9e8fb45a/_prefs.py#L110-L119
train
39,795
thriftrw/thriftrw-python
thriftrw/compile/link.py
TypeSpecLinker.link
def link(self): """Resolve and link all types in the scope.""" type_specs = {} types = [] for name, type_spec in self.scope.type_specs.items(): type_spec = type_spec.link(self.scope) type_specs[name] = type_spec if type_spec.surface is not None: self.scope.add_surface(name, type_spec.surface) types.append(type_spec.surface) self.scope.type_specs = type_specs self.scope.add_surface('__types__', tuple(types))
python
def link(self): """Resolve and link all types in the scope.""" type_specs = {} types = [] for name, type_spec in self.scope.type_specs.items(): type_spec = type_spec.link(self.scope) type_specs[name] = type_spec if type_spec.surface is not None: self.scope.add_surface(name, type_spec.surface) types.append(type_spec.surface) self.scope.type_specs = type_specs self.scope.add_surface('__types__', tuple(types))
[ "def", "link", "(", "self", ")", ":", "type_specs", "=", "{", "}", "types", "=", "[", "]", "for", "name", ",", "type_spec", "in", "self", ".", "scope", ".", "type_specs", ".", "items", "(", ")", ":", "type_spec", "=", "type_spec", ".", "link", "(",...
Resolve and link all types in the scope.
[ "Resolve", "and", "link", "all", "types", "in", "the", "scope", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/compile/link.py#L35-L50
train
39,796
thriftrw/thriftrw-python
thriftrw/loader.py
install
def install(path, name=None): """Compiles a Thrift file and installs it as a submodule of the caller. Given a tree organized like so:: foo/ __init__.py bar.py my_service.thrift You would do, .. code-block:: python my_service = thriftrw.install('my_service.thrift') To install ``my_service`` as a submodule of the module from which you made the call. If the call was made in ``foo/bar.py``, the compiled Thrift file will be installed as ``foo.bar.my_service``. If the call was made in ``foo/__init__.py``, the compiled Thrift file will be installed as ``foo.my_service``. This allows other modules to import ``from`` the compiled module like so, .. code-block:: python from foo.my_service import MyService .. versionadded:: 0.2 :param path: Path of the Thrift file. This may be an absolute path, or a path relative to the Python module making the call. :param str name: Name of the submodule. Defaults to the basename of the Thrift file. :returns: The compiled module """ if name is None: name = os.path.splitext(os.path.basename(path))[0] callermod = inspect.getmodule(inspect.stack()[1][0]) name = '%s.%s' % (callermod.__name__, name) if name in sys.modules: return sys.modules[name] if not os.path.isabs(path): callerfile = callermod.__file__ path = os.path.normpath( os.path.join(os.path.dirname(callerfile), path) ) sys.modules[name] = mod = load(path, name=name) return mod
python
def install(path, name=None): """Compiles a Thrift file and installs it as a submodule of the caller. Given a tree organized like so:: foo/ __init__.py bar.py my_service.thrift You would do, .. code-block:: python my_service = thriftrw.install('my_service.thrift') To install ``my_service`` as a submodule of the module from which you made the call. If the call was made in ``foo/bar.py``, the compiled Thrift file will be installed as ``foo.bar.my_service``. If the call was made in ``foo/__init__.py``, the compiled Thrift file will be installed as ``foo.my_service``. This allows other modules to import ``from`` the compiled module like so, .. code-block:: python from foo.my_service import MyService .. versionadded:: 0.2 :param path: Path of the Thrift file. This may be an absolute path, or a path relative to the Python module making the call. :param str name: Name of the submodule. Defaults to the basename of the Thrift file. :returns: The compiled module """ if name is None: name = os.path.splitext(os.path.basename(path))[0] callermod = inspect.getmodule(inspect.stack()[1][0]) name = '%s.%s' % (callermod.__name__, name) if name in sys.modules: return sys.modules[name] if not os.path.isabs(path): callerfile = callermod.__file__ path = os.path.normpath( os.path.join(os.path.dirname(callerfile), path) ) sys.modules[name] = mod = load(path, name=name) return mod
[ "def", "install", "(", "path", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "name", "=", "os", ".", "path", ".", "splitext", "(", "os", ".", "path", ".", "basename", "(", "path", ")", ")", "[", "0", "]", "callermod", "="...
Compiles a Thrift file and installs it as a submodule of the caller. Given a tree organized like so:: foo/ __init__.py bar.py my_service.thrift You would do, .. code-block:: python my_service = thriftrw.install('my_service.thrift') To install ``my_service`` as a submodule of the module from which you made the call. If the call was made in ``foo/bar.py``, the compiled Thrift file will be installed as ``foo.bar.my_service``. If the call was made in ``foo/__init__.py``, the compiled Thrift file will be installed as ``foo.my_service``. This allows other modules to import ``from`` the compiled module like so, .. code-block:: python from foo.my_service import MyService .. versionadded:: 0.2 :param path: Path of the Thrift file. This may be an absolute path, or a path relative to the Python module making the call. :param str name: Name of the submodule. Defaults to the basename of the Thrift file. :returns: The compiled module
[ "Compiles", "a", "Thrift", "file", "and", "installs", "it", "as", "a", "submodule", "of", "the", "caller", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/loader.py#L111-L164
train
39,797
thriftrw/thriftrw-python
thriftrw/loader.py
Loader.loads
def loads(self, name, document): """Parse and compile the given Thrift document. :param str name: Name of the Thrift document. :param str document: The Thrift IDL as a string. """ return self.compiler.compile(name, document).link().surface
python
def loads(self, name, document): """Parse and compile the given Thrift document. :param str name: Name of the Thrift document. :param str document: The Thrift IDL as a string. """ return self.compiler.compile(name, document).link().surface
[ "def", "loads", "(", "self", ",", "name", ",", "document", ")", ":", "return", "self", ".", "compiler", ".", "compile", "(", "name", ",", "document", ")", ".", "link", "(", ")", ".", "surface" ]
Parse and compile the given Thrift document. :param str name: Name of the Thrift document. :param str document: The Thrift IDL as a string.
[ "Parse", "and", "compile", "the", "given", "Thrift", "document", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/loader.py#L61-L69
train
39,798
thriftrw/thriftrw-python
thriftrw/loader.py
Loader.load
def load(self, path, name=None): """Load and compile the given Thrift file. :param str path: Path to the ``.thrift`` file. :param str name: Name of the generated module. Defaults to the base name of the file. :returns: The compiled module. """ if name is None: name = os.path.splitext(os.path.basename(path))[0] # TODO do we care if the file extension is .thrift? with open(path, 'r') as f: document = f.read() return self.compiler.compile(name, document, path).link().surface
python
def load(self, path, name=None): """Load and compile the given Thrift file. :param str path: Path to the ``.thrift`` file. :param str name: Name of the generated module. Defaults to the base name of the file. :returns: The compiled module. """ if name is None: name = os.path.splitext(os.path.basename(path))[0] # TODO do we care if the file extension is .thrift? with open(path, 'r') as f: document = f.read() return self.compiler.compile(name, document, path).link().surface
[ "def", "load", "(", "self", ",", "path", ",", "name", "=", "None", ")", ":", "if", "name", "is", "None", ":", "name", "=", "os", ".", "path", ".", "splitext", "(", "os", ".", "path", ".", "basename", "(", "path", ")", ")", "[", "0", "]", "# T...
Load and compile the given Thrift file. :param str path: Path to the ``.thrift`` file. :param str name: Name of the generated module. Defaults to the base name of the file. :returns: The compiled module.
[ "Load", "and", "compile", "the", "given", "Thrift", "file", "." ]
4f2f71acd7a0ac716c9ea5cdcea2162aa561304a
https://github.com/thriftrw/thriftrw-python/blob/4f2f71acd7a0ac716c9ea5cdcea2162aa561304a/thriftrw/loader.py#L71-L89
train
39,799