input
stringlengths 11
7.65k
| target
stringlengths 22
8.26k
|
---|---|
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def AddResultsOptions(parser):
group = optparse.OptionGroup(parser, 'Results options')
group.add_option('--chartjson', action='store_true',
help='Output Chart JSON. Ignores --output-format.')
group.add_option('--output-format', action='append', dest='output_formats',
choices=_OUTPUT_FORMAT_CHOICES, default=[],
help='Output format. Defaults to "%%default". '
'Can be %s.' % ', '.join(_OUTPUT_FORMAT_CHOICES))
group.add_option('-o', '--output',
dest='output_file',
default=None,
help='Redirects output to a file. Defaults to stdout.')
group.add_option('--output-dir', default=util.GetBaseDir(),
help='Where to save output data after the run.')
group.add_option('--output-trace-tag',
default='',
help='Append a tag to the key of each result trace. Use '
'with html, buildbot, csv-pivot-table output formats.')
group.add_option('--reset-results', action='store_true',
help='Delete all stored results.')
group.add_option('--upload-results', action='store_true',
help='Upload the results to cloud storage.')
group.add_option('--upload-bucket', default='internal',
choices=['public', 'partner', 'internal'],
help='Storage bucket to use for the uploaded results. '
'Defaults to internal. Supported values are: '
'public, partner, internal')
group.add_option('--results-label',
default=None,
help='Optional label to use for the results of a run .')
group.add_option('--suppress_gtest_report',
default=False,
help='Whether to suppress GTest progress report.')
parser.add_option_group(group) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_either():
"""Either f or g."""
p = are.above(3) | are.below(2)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, True, True] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def ProcessCommandLineArgs(parser, args):
# TODO(ariblue): Delete this flag entirely at some future data, when the
# existence of such a flag has been long forgotten.
if args.output_file:
parser.error('This flag is deprecated. Please use --output-dir instead.')
try:
os.makedirs(args.output_dir)
except OSError:
# Do nothing if the output directory already exists. Existing files will
# get overwritten.
pass
args.output_dir = os.path.expanduser(args.output_dir) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_equal_to():
"""Equal to y."""
p = are.equal_to(1)
ps = [p(x) for x in range(1, 6)]
assert ps == [True, False, False, False, False] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _GetOutputStream(output_format, output_dir):
assert output_format in _OUTPUT_FORMAT_CHOICES, 'Must specify a valid format.'
assert output_format not in ('gtest', 'none'), (
'Cannot set stream for \'gtest\' or \'none\' output formats.')
if output_format == 'buildbot':
return sys.stdout
assert output_format in _OUTPUT_FILENAME_LOOKUP, (
'No known filename for the \'%s\' output format' % output_format)
output_file = os.path.join(output_dir, _OUTPUT_FILENAME_LOOKUP[output_format])
open(output_file, 'a').close() # Create file if it doesn't exist.
return open(output_file, 'r+') |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_above():
"""Greater than y."""
p = are.above(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _GetProgressReporter(output_skipped_tests_summary, suppress_gtest_report):
if suppress_gtest_report:
return progress_reporter.ProgressReporter()
return gtest_progress_reporter.GTestProgressReporter(
sys.stdout, output_skipped_tests_summary=output_skipped_tests_summary) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_below():
"""Less than y."""
p = are.not_below(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_above_or_equal_to():
"""Greater than or equal to y."""
p = are.above_or_equal_to(4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_below_or_equal_to():
"""Less than or equal to y."""
p = are.not_below_or_equal_to(3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, False, True, True] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_strictly_between():
"""Greater than y and less than z."""
p = are.strictly_between(2, 4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_between():
"""Greater than or equal to y and less than z."""
p = are.between(3, 4)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def test_between_or_equal_to():
"""Greater than or equal to y and less than or equal to z."""
p = are.between_or_equal_to(3, 3)
ps = [p(x) for x in range(1, 6)]
assert ps == [False, False, True, False, False] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _apply_mask(y_true, sample_weight, masked_tokens, dtype):
if sample_weight is None:
sample_weight = tf.ones_like(y_true, dtype)
else:
sample_weight = tf.cast(sample_weight, dtype)
for token in masked_tokens:
mask = tf.cast(tf.not_equal(y_true, token), dtype)
sample_weight = sample_weight * mask
return sample_weight |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _copy_vars(v_list):
"""Copy variables in v_list."""
t_list = []
for v in v_list:
t_list.append(tf.identity(v))
return t_list |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, masked_tokens=None, name='num_tokens', dtype=tf.int64):
self._masked_tokens = masked_tokens or []
super().__init__(name, dtype) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _restore_vars(v_list, t_list):
"""Restore variables in v_list from t_list."""
ops = []
for v, t in zip(v_list, t_list):
ops.append(v.assign(t))
return ops |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def update_state(self, y_true, y_pred, sample_weight=None):
sample_weight = _apply_mask(y_true, sample_weight, self._masked_tokens,
self._dtype)
sample_weight = tf.reshape(sample_weight, [-1])
super().update_state(sample_weight) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _scale_vars(s, v_list):
"""Scale all variables in v_list by s."""
return [s * v for v in v_list] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def get_config(self):
config = super().get_config()
config['masked_tokens'] = tuple(self._masked_tokens)
return config |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _acc_grads(g_sum, g_w, g):
"""Accumulate gradients in g, weighted by g_w."""
return [g_sum_i + g_w * g_i for g_sum_i, g_i in zip(g_sum, g)] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, masked_tokens=None, name='accuracy', dtype=None):
self._masked_tokens = masked_tokens or []
super().__init__(name, dtype=dtype) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _compute_reg_grads(gen_grads, disc_vars):
"""Compute gradients norm (this is an upper-bpund of the full-batch norm)."""
gen_norm = tf.accumulate_n([tf.reduce_sum(u * u) for u in gen_grads])
disc_reg_grads = tf.gradients(gen_norm, disc_vars)
return disc_reg_grads |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def update_state(self, y_true, y_pred, sample_weight=None):
sample_weight = _apply_mask(y_true, sample_weight, self._masked_tokens,
self._dtype)
num_classes = tf.shape(y_pred)[-1]
y_true = tf.reshape(y_true, [-1])
y_pred = tf.reshape(y_pred, [-1, num_classes])
sample_weight = tf.reshape(sample_weight, [-1])
super().update_state(y_true, y_pred, sample_weight) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def run_model(prior, images, model, disc_reg_weight):
"""Run the model with new data and samples.
Args:
prior: the noise source as the generator input.
images: images sampled from dataset.
model: a GAN model defined in gan.py.
disc_reg_weight: regularisation weight for discrmininator gradients.
Returns:
debug_ops: statistics from the model, see gan.py for more detials.
disc_grads: discriminator gradients.
gen_grads: generator gradients.
"""
generator_inputs = prior.sample(FLAGS.batch_size)
model_output = model.connect(images, generator_inputs)
optimization_components = model_output.optimization_components
disc_grads = tf.gradients(
optimization_components['disc'].loss,
optimization_components['disc'].vars)
gen_grads = tf.gradients(
optimization_components['gen'].loss,
optimization_components['gen'].vars)
if disc_reg_weight > 0.0:
reg_grads = _compute_reg_grads(gen_grads,
optimization_components['disc'].vars)
disc_grads = _acc_grads(disc_grads, disc_reg_weight, reg_grads)
debug_ops = model_output.debug_ops
return debug_ops, disc_grads, gen_grads |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def update_model(model, disc_grads, gen_grads, disc_opt, gen_opt,
global_step, update_scale):
"""Update model with gradients."""
disc_vars, gen_vars = model.get_variables()
with tf.control_dependencies(gen_grads + disc_grads):
disc_update_op = disc_opt.apply_gradients(
zip(_scale_vars(update_scale, disc_grads),
disc_vars))
gen_update_op = gen_opt.apply_gradients(
zip(_scale_vars(update_scale, gen_grads),
gen_vars),
global_step=global_step)
update_op = tf.group([disc_update_op, gen_update_op])
return update_op |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def sample_fn(x):
return utils.optimise_and_sample(x, module=model,
data=None, is_training=False)[0] |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def setUp(self):
super().setUp()
self.project1 = self.env["project.project"].create({"name": "Project 1"})
self.task1 = self.env["project.task"].create(
{"name": "name1", "project_id": self.project1.id}
)
self.subtask1 = self.env["project.task"].create(
{"name": "2", "project_id": self.project1.id, "parent_id": self.task1.id}
)
self.subtask2 = self.env["project.task"].create(
{"name": "3", "project_id": self.project1.id, "parent_id": self.task1.id}
) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, item_spacing=ITEM_SPACING, *args, **kwargs):
super().__init__(*args, **kwargs) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, nr, nc):
self.nr = nr
self.nc = nc |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def add_item(self, item):
self._vbox_items.pack_start(item.widget, expand=False, fill=False) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def inc_r(self, ind):
r, c = self.row_col(ind)
r += 1
if r == self.nr:
r = 0
if r == (self.nr - 1) and c == (self.nc - 1):
r = 0
return self.indx(r, c) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def reorder_item(self, item, position):
new_position = min(max(position, 0), len(self._items) - 1) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def dec_r(self, ind):
r, c = self.row_col(ind)
r -= 1
if r < 0:
r = self.nr - 1
if r == (self.nr - 1) and c == (self.nc - 1):
r = self.nr - 2
return self.indx(r, c) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def remove_item(self, item):
item_position = self._get_item_position(item)
if item_position < len(self._items) - 1:
next_item_position = item_position + 1
self._items[next_item_position].item_widget.grab_focus() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def inc_c(self, ind):
r, c = self.row_col(ind)
c += 1
if c == self.nc:
c = 0
if r == (self.nr - 1) and c == (self.nc - 1):
c = 0
return self.indx(r, c) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def clear(self):
for unused_ in range(len(self._items)):
self.remove_item(self._items[0]) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def dec_c(self, ind):
r, c = self.row_col(ind)
c -= 1
if c < 0:
c = self.nc - 1
if r == (self.nr - 1) and c == (self.nc - 1):
c = self.nc - 2
return self.indx(r, c) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _setup_drag(self, item):
self._drag_and_drop_context.setup_drag(
item.item_widget,
self._get_drag_data,
self._on_drag_data_received,
[item],
[item],
self) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def row_col(self, ind):
i = 0
for r in range(self.nr):
for c in range(self.nc):
if i == ind:
return r, c
i += 1 |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _get_drag_data(self, dragged_item):
return str(self._items.index(dragged_item)) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_drag_data_received(self, dragged_item_index_str, destination_item):
dragged_item = self._items[int(dragged_item_index_str)]
self.reorder_item(dragged_item, self._get_item_position(destination_item)) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_item_widget_key_press_event(self, widget, event, item):
if event.state & gtk.gdk.MOD1_MASK: # Alt key
key_name = gtk.gdk.keyval_name(event.keyval)
if key_name in ["Up", "KP_Up"]:
self.reorder_item(
item, self._get_item_position(item) - 1)
elif key_name in ["Down", "KP_Down"]:
self.reorder_item(
item, self._get_item_position(item) + 1) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_item_button_remove_clicked(self, button, item):
self.remove_item(item) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _get_item_position(self, item):
return self._items.index(item) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, item_widget):
self._item_widget = item_widget |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def widget(self):
return self._event_box |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def item_widget(self):
return self._item_widget |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def button_remove(self):
return self._button_remove |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def remove_item_widget(self):
self._hbox.remove(self._item_widget) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _setup_item_button(self, item_button, icon, position=None):
item_button.set_relief(gtk.RELIEF_NONE) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_event_box_enter_notify_event(self, event_box, event):
if event.detail != gtk.gdk.NOTIFY_INFERIOR:
self._hbox_buttons.show() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_event_box_leave_notify_event(self, event_box, event):
if event.detail != gtk.gdk.NOTIFY_INFERIOR:
self._hbox_buttons.hide() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_event_box_size_allocate(self, event_box, allocation):
if self._is_event_box_allocated_size:
return |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_event_box_buttons_size_allocate(self, event_box, allocation):
if self._buttons_allocation is not None:
return |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(
self,
new_item_default_value,
min_size=0,
max_size=None,
item_spacing=ItemBox.ITEM_SPACING,
max_width=None,
max_height=None,
*args,
**kwargs):
"""
Parameters: |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _init_gui(self):
self._size_spin_button = gtk.SpinButton(
gtk.Adjustment(
value=0,
lower=self._min_size,
upper=self._max_size,
step_incr=1,
page_incr=10,
),
digits=0) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def add_item(self, item_value=None, index=None):
if item_value is None:
item_value = self._new_item_default_value |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def reorder_item(self, item, new_position):
orig_position = self._get_item_position(item)
processed_new_position = super().reorder_item(item, new_position) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def remove_item(self, item):
if (self._locker.is_unlocked("prevent_removal_below_min_size")
and len(self._items) == self._min_size):
return |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def set_values(self, values):
self._locker.lock("emit_size_spin_button_value_changed")
self._locker.lock("prevent_removal_below_min_size") |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _setup_drag(self, item):
self._drag_and_drop_context.setup_drag(
# Using the entire item allows dragging only by the label rather than the
# widget itself. This avoids problems with widgets such as spin buttons
# that do not behave correctly when reordering and also avoids accidental
# clicking and modifying the widget by the user.
item.widget,
self._get_drag_data,
self._on_drag_data_received,
[item],
[item],
self) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_size_spin_button_value_changed(self, size_spin_button):
if self._locker.is_unlocked("emit_size_spin_button_value_changed"):
self._locker.lock("update_spin_button") |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_item_button_remove_clicked(self, button, item):
self._locker.lock("emit_size_spin_button_value_changed") |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _on_item_widget_size_allocate(self, item_widget, allocation, item):
if item in self._items_allocations:
self._update_width(allocation.width - self._items_allocations[item].width)
self._update_height(allocation.height - self._items_allocations[item].height)
else:
self._update_width(allocation.width)
self._update_height(allocation.height + self._item_spacing) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _update_width(self, width_diff):
if self._items_total_width is None:
self._items_total_width = self.get_allocation().width |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _update_height(self, height_diff):
if self._items_total_height is None:
self._items_total_height = self.get_allocation().height |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _update_dimension(
self,
size_diff,
total_size,
max_visible_size,
dimension_request_property):
if max_visible_size is None:
is_max_visible_size_unlimited = True
else:
is_max_visible_size_unlimited = max_visible_size <= 0 |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _rename_item_names(self, start_index):
for index, item in enumerate(self._items[start_index:]):
item.label.set_label(self._get_item_name(index + 1 + start_index)) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _get_item_name(index):
return _("Element") + " " + str(index) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, item_widget):
super().__init__(item_widget) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def label(self):
return self._label |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self):
self._tokens = collections.defaultdict(int) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def lock_temp(self, key):
self.lock(key)
try:
yield
finally:
self.unlock(key) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def lock(self, key):
self._tokens[key] += 1 |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def unlock(self, key):
if self._tokens[key] > 0:
self._tokens[key] -= 1 |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def is_locked(self, key):
return self._tokens[key] > 0 |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def is_unlocked(self, key):
return self._tokens[key] == 0 |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, backendsdialog):
"""
Constructor, just initializes the gtk widgets
@param backends: a reference to the dialog in which this is
loaded
"""
super().__init__()
self.dialog = backendsdialog
self.req = backendsdialog.get_requester()
self._init_liststore()
self._init_renderers()
self._init_signals()
self.refresh() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def refresh(self):
"""refreshes the Gtk.Liststore"""
self.backendid_to_iter = {}
self.liststore.clear()
# Sort backends
# 1, put default backend on top
# 2, sort backends by human name
backends = list(self.req.get_all_backends(disabled=True))
backends = sorted(backends,
key=lambda backend: (not backend.is_default(),
backend.get_human_name()))
for backend in backends:
self.add_backend(backend)
self.on_backend_state_changed(None, backend.get_id()) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def drawMe(self, g, r):
self.g = g
self.r = r
self.g.save()
self.g.moveTo(self.x,self.y)
self.g.beginPath()
# 根據 r 半徑繪製一個圓代表點的所在位置
self.g.arc(self.x, self.y, self.r, 0, 2*math.pi, true)
self.g.moveTo(self.x,self.y)
self.g.lineTo(self.x+self.r, self.y)
self.g.moveTo(self.x, self.y)
self.g.lineTo(self.x-self.r, self.y)
self.g.moveTo(self.x, self.y)
self.g.lineTo(self.x, self.y+self.r)
self.g.moveTo(self.x, self.y)
self.g.lineTo(self.x, self.y-self.r)
self.g.restore()
self.g.stroke() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def on_backend_added(self, sender, backend_id):
"""
Signal callback executed when a new backend is loaded
@param sender: not used, only here to let this function be used as a
callback
@param backend_id: the id of the backend to add
"""
# Add
backend = self.req.get_backend(backend_id)
if not backend:
return
self.add_backend(backend)
self.refresh()
# Select
self.select_backend(backend_id)
# Update it's enabled state
self.on_backend_state_changed(None, backend.get_id()) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def Eq(self, pt):
self.x = pt.x
self.y = pt.y |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def add_backend(self, backend):
"""
Adds a new backend to the list
@param backend_id: the id of the backend to add
"""
if backend:
backend_iter = self.liststore.append([
backend.get_id(),
self.dialog.get_pixbuf_from_icon_name(backend.get_icon(),
16),
backend.get_human_name(),
self._get_markup_for_tags(backend.get_attached_tags()),
])
self.backendid_to_iter[backend.get_id()] = backend_iter |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def setPoint(self, px, py):
self.x = px
self.y = py |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def on_backend_state_changed(self, sender, backend_id):
"""
Signal callback executed when a backend is enabled/disabled.
@param sender: not used, only here to let this function be used as a
callback
@param backend_id: the id of the backend to add
"""
if backend_id in self.backendid_to_iter:
b_iter = self.backendid_to_iter[backend_id]
b_path = self.liststore.get_path(b_iter)
backend = self.req.get_backend(backend_id)
backend_name = backend.get_human_name()
if backend.is_enabled():
text = backend_name
else:
# FIXME This snippet is on more than 2 places!!!
# FIXME create a function which takes a widget and
# flag and returns color as #RRGGBB
style_context = self.get_style_context()
color = style_context.get_color(Gtk.StateFlags.INSENSITIVE)
color = rgba_to_hex(color)
text = f"<span color='{color}'>{backend_name}</span>"
self.liststore[b_path][self.COLUMN_TEXT] = text
# Also refresh the tags
new_tags = self._get_markup_for_tags(backend.get_attached_tags())
self.liststore[b_path][self.COLUMN_TAGS] = new_tags |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def distance(self, pt):
self.pt = pt
x = self.x - self.pt.x
y = self.y - self.pt.y
return math.sqrt(x * x + y * y) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _get_markup_for_tags(self, tag_names):
"""Given a list of tags names, generates the pango markup to render
that list with the tag colors used in GTG
@param tag_names: the list of the tags (strings)
@return str: the pango markup string
"""
if ALLTASKS_TAG in tag_names:
tags_txt = ""
else:
tags_txt = get_colored_tags_markup(self.req, tag_names)
return "<small>" + tags_txt + "</small>" |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def tag(self, g):
self.g = g
self.g.beginPath()
self.g.fillText("%d, %d"%(self.x, self.y),self.x, self.y)
self.g.stroke() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def remove_backend(self, backend_id):
""" Removes a backend from the treeview, and selects the first (to show
something in the configuration panel
@param backend_id: the id of the backend to remove
"""
if backend_id in self.backendid_to_iter:
self.liststore.remove(self.backendid_to_iter[backend_id])
del self.backendid_to_iter[backend_id]
self.select_backend() |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def __init__(self, p1, p2):
self.p1 = p1
self.p2 = p2
# 直線的第一點, 設為線尾
self.Tail = self.p1
# 直線組成的第二點, 設為線頭
self.Head = self.p2
# 直線的長度屬性
self.length = math.sqrt(math.pow(self.p2.x-self.p1.x, 2)+math.pow(self.p2.y-self.p1.y,2)) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _init_liststore(self):
"""Creates the liststore"""
self.liststore = Gtk.ListStore(object, GdkPixbuf.Pixbuf, str, str)
self.set_model(self.liststore) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def setPP(self, p1, p2):
self.p1 = p1
self.p2 = p2
self.Tail = self.p1
self.Head = self.p2
self.length = math.sqrt(math.pow(self.p2.x-self.p1.x, 2)+math.pow(self.p2.y-self.p1.y,2)) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _init_renderers(self):
"""Initializes the cell renderers"""
# We hide the columns headers
self.set_headers_visible(False)
# For the backend icon
pixbuf_cell = Gtk.CellRendererPixbuf()
tvcolumn_pixbuf = Gtk.TreeViewColumn('Icon', pixbuf_cell)
tvcolumn_pixbuf.add_attribute(pixbuf_cell, 'pixbuf', self.COLUMN_ICON)
self.append_column(tvcolumn_pixbuf)
# For the backend name
text_cell = Gtk.CellRendererText()
tvcolumn_text = Gtk.TreeViewColumn('Name', text_cell)
tvcolumn_text.add_attribute(text_cell, 'markup', self.COLUMN_TEXT)
self.append_column(tvcolumn_text)
text_cell.connect('edited', self.cell_edited_callback)
text_cell.set_property('editable', True)
# For the backend tags
tags_cell = Gtk.CellRendererText()
tvcolumn_tags = Gtk.TreeViewColumn('Tags', tags_cell)
tvcolumn_tags.add_attribute(tags_cell, 'markup', self.COLUMN_TAGS)
self.append_column(tvcolumn_tags) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def setRT(self, r, t):
self.r = r
self.t = t
x = self.r * math.cos(self.t)
y = self.r * math.sin(self.t)
self.Tail.Eq(self.p1)
self.Head.setPoint(self.Tail.x + x,self.Tail.y + y) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def cell_edited_callback(self, text_cell, path, new_text):
"""If a backend name is changed, it saves the changes in the Backend
@param text_cell: not used. The Gtk.CellRendererText that emitted the
signal. Only here because it's passed by the signal
@param path: the Gtk.TreePath of the edited cell
@param new_text: the new name of the backend
"""
# we strip everything not permitted in backend names
new_text = ''.join(c for c in new_text if (c.isalnum() or c in [" ", "-", "_"]))
selected_iter = self.liststore.get_iter(path)
# update the backend name
backend_id = self.liststore.get_value(selected_iter,
self.COLUMN_BACKEND_ID)
backend = self.dialog.get_requester().get_backend(backend_id)
if backend:
backend.set_human_name(new_text)
# update the text in the liststore
self.liststore.set(selected_iter, self.COLUMN_TEXT, new_text) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def getR(self):
# x 分量與 y 分量
x = self.p1.x - self.p2.x
y = self.p1.y - self.p2.y
return math.sqrt(x * x + y * y) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def _init_signals(self):
"""Initializes the backends and gtk signals """
self.connect("cursor-changed", self.on_select_row)
_signals = BackendSignals()
_signals.connect(_signals.BACKEND_ADDED, self.on_backend_added)
_signals.connect(_signals.BACKEND_STATE_TOGGLED,
self.on_backend_state_changed) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def getT(self):
x = self.p2.x - self.p1.x
y = self.p2.y - self.p1.y
if (math.fabs(x) < math.pow(10,-100)):
if(y < 0.0):
return (-math.pi/2)
else:
return (math.pi/2)
else:
return math.atan2(y, x) |
def emit(self, level, message):
raise NotImplementedError('Please implement an emit method') | def on_select_row(self, treeview=None):
"""When a row is selected, displays the corresponding editing panel
@var treeview: not used
"""
self.dialog.on_backend_selected(self.get_selected_backend_id()) |