Best Python code snippet using dbt-osmosis_python
entrycompletion.py
Source:entrycompletion.py
1#2# Kiwi: a Framework and Enhanced Widgets for Python3#4# Copyright (C) 2006 Async Open Source5#6# This library is free software; you can redistribute it and/or7# modify it under the terms of the GNU Lesser General Public8# License as published by the Free Software Foundation; either9# version 2.1 of the License, or (at your option) any later version.10#11# This library is distributed in the hope that it will be useful,12# but WITHOUT ANY WARRANTY; without even the implied warranty of13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU14# Lesser General Public License for more details.15#16# You should have received a copy of the GNU Lesser General Public17# License along with this library; if not, write to the Free Software18# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-130719# USA20#21# Author(s): Ronaldo Maia <romaia@async.com.br>22#23import gobject24import gtk25from gtk import gdk26from gtk import keysyms27from kiwi.utils import gsignal, type_register28COMPLETION_TIMEOUT = 30029PAGE_INCREMENT = 1430class KiwiEntryCompletion(gtk.EntryCompletion):31 def __init__(self):32 gtk.EntryCompletion.__init__(self)33 self._inline_completion = False34 self._popup_completion = True35 self._entry = None36 self._completion_timeout = 037 self._match_function = None38 self._match_function_data = None39 self._key = None40 self.changed_id = 041 self._filter_model = None42 self._treeview = None43 self._popup_window = None44 self._selected_index = -145 gsignal('match-selected', 'override')46 def do_match_selected(self, model, iter):47 self._entry.set_text(model[iter][0])48 return True49 def _visible_function(self, model, iter, data=None):50 if not self._entry:51 return False52 if not self._key:53 return False54 if self._match_function:55 return self._match_function(self, self._key, iter)56 value = model[iter][0]57 if not value:58 return False59 entry_text = self._entry.get_text()60 return value.lower().startswith(entry_text.lower())61 def _connect_completion_signals(self):62 if self._popup_completion:63 self.changed_id = self._entry.connect('changed',64 self._on_completion_changed)65 self._entry.connect('key-press-event',66 self._on_completion_key_press)67 self._entry.connect('button-press-event', self._on_button_press_event)68 def _on_button_press_event(self, window, event):69 # If we're clicking outside of the window, close the popup70 if not self._popup_window:71 return72 if (event.window != self._popup_window.window or73 (tuple(self._popup_window.allocation.intersect(74 gdk.Rectangle(x=int(event.x), y=int(event.y),75 width=1, height=1)))) == (0, 0, 0, 0)):76 self.popdown()77 def _on_completion_timeout(self):78 if self._completion_timeout:79 gobject.source_remove(self._completion_timeout)80 self._completion_timeout = 081 minimum_key_length = self.get_property('minimum-key-length')82 if (self._filter_model and83 len(self._entry.get_text()) >= minimum_key_length and84 self._entry.is_focus()):85 self.complete()86 matches = self._filter_model.iter_n_children(None)87 if matches:88 self.popup()89 return False90 def _on_completion_changed(self, entry):91 if (self.get_property('minimum_key_length') > 0 and92 not self._entry.get_text()):93 self.popdown()94 return95 self._selected_index = -196 timeout = gobject.timeout_add(COMPLETION_TIMEOUT,97 self._on_completion_timeout)98 self._completion_timeout = timeout99 return True100 def _select_item(self, index):101 # Make the selection102 matches = self._filter_model.iter_n_children(None)103 if 0 <= index < matches:104 self._treeview.set_cursor((index,))105 else:106 selection = self._treeview.get_selection()107 selection.unselect_all()108 self._selected_index = index109 def _on_completion_key_press(self, entry, event):110 window = self._popup_window111 if window and not window.flags() & gtk.VISIBLE:112 return False113 if not self._treeview:114 return False115 matches = self._filter_model.iter_n_children(None)116 keyval = event.keyval117 index = self._selected_index118 if keyval == keysyms.Up or keyval == keysyms.KP_Up:119 index -= 1120 if index < -1:121 index = matches -1122 self._select_item(index)123 return True124 elif keyval == keysyms.Down or keyval == keysyms.KP_Down:125 index += 1126 if index > matches-1:127 index = -1128 self._select_item(index)129 return True130 elif keyval == keysyms.Page_Up:131 if index < 0:132 index = matches-1133 elif index > 0 and index - PAGE_INCREMENT < 0:134 index = 0135 else:136 index -= PAGE_INCREMENT137 if index < 0:138 index = -1139 self._select_item(index)140 return True141 elif keyval == keysyms.Page_Down:142 if index < 0:143 index = 0144 elif index < matches-1 and index + PAGE_INCREMENT > matches - 1:145 index = matches -1146 else:147 index += PAGE_INCREMENT148 if index > matches:149 index = -1150 self._select_item(index)151 return True152 elif keyval == keysyms.Escape:153 self.popdown()154 return True155 elif (keyval == keysyms.Return or156 keyval == keysyms.KP_Enter):157 self.popdown()158 selection = self._treeview.get_selection()159 model, titer = selection.get_selected()160 if not titer:161 return False162 self._entry.handler_block(self.changed_id)163 self.emit('match-selected', model, titer)164 self._entry.handler_unblock(self.changed_id)165 selection.unselect_all()166 return True167 return False168 def _popup_grab_window(self):169 activate_time = 0L170 if gdk.pointer_grab(self._entry.window, True,171 (gdk.BUTTON_PRESS_MASK |172 gdk.BUTTON_RELEASE_MASK |173 gdk.POINTER_MOTION_MASK),174 None, None, activate_time) == 0:175 if gdk.keyboard_grab(self._entry.window, True, activate_time) == 0:176 return True177 else:178 self._entry.window.get_display().pointer_ungrab(activate_time);179 return False180 return False181 def _popup_ungrab_window(self):182 activate_time = 0L183 self._entry.window.get_display().pointer_ungrab(activate_time);184 self._entry.window.get_display().keyboard_ungrab(activate_time);185 # Public API186 def complete(self):187 if not self._filter_model:188 return189 self._key = self._entry.get_text()190 self._filter_model.refilter()191 self._treeview.set_model(self._filter_model)192 if self._treeview.flags() & gtk.REALIZED:193 self._treeview.scroll_to_point(0,0)194 def set_entry(self, entry):195 self._entry = entry196 self._connect_completion_signals()197 def get_entry(self):198 return self._entry199 def set_popup_window(self, window):200 self._popup_window = window201 def set_treeview(self, treeview):202 self._treeview = treeview203 def get_treeview(self):204 return self._treeview205 def popup(self):206 if not self._popup_window:207 return208 self._popup_window.popup(text=None, filter=True)209 self._popup_grab_window()210 def popdown(self):211 if not self._popup_window:212 return213 self._popup_window.popdown()214 self._popup_ungrab_window()215 def set_model(self, model):216 if not model:217 if self._popup_window:218 self._popup_window.set_model(None)219 self.popdown()220 self._model = None221 self._filter_model = None222 return223 self._model = model224 self._filter_model = model.filter_new()225 self._filter_model.set_visible_func(self._visible_function)226 if self._popup_window:227 self._popup_window.set_model(self._filter_model)228 def get_model(self):229 return self._model230 def set_match_func(self, function, data=None):231 self._match_function = function232 self._match_function_data = data...
editor.py
Source:editor.py
1#!/usr/bin/env python2# -*- coding: utf-8 -*-3"""4USD Hierarchy Editor widget implementations5"""6from __future__ import print_function, division, absolute_import7__author__ = "Tomas Poveda"8__license__ = "MIT"9__maintainer__ = "Tomas Poveda"10__email__ = "tpovedatd@gmail.com"11from collections import OrderedDict12from Qt.QtCore import *13from Qt.QtWidgets import *14from pxr.UsdQt import hierarchyModel, roles15from artellapipe.libs.usd.tools.hierarchy import actions16class HierarchyEditor(QWidget, object):17 SHOW_INACTIVE = 'Show Inactive'18 SHOW_UNDEFINED = 'Show Undefined (Overs)'19 SHOW_ABSTRACT = 'Show Abstract (classes)'20 FILTER_ACROSS_ARCS = 'Filter Across Arcs'21 ContextMenuHierarchy = actions.HierarchyStandardContextMenuStrategy22 def __init__(self, parent=None):23 super(HierarchyEditor, self).__init__(parent=parent)24 self._menu_bar = QMenuBar()25 self._show_menu = QMenu('Show')26 self._menu_bar.addMenu(self._show_menu)27 self._filter_line_edit = QLineEdit()28 self._hierarchy_view = QTreeView()29 self._show_menu_items = OrderedDict(30 [31 (HierarchyEditor.SHOW_INACTIVE, QAction(HierarchyEditor.SHOW_INACTIVE, self)),32 (HierarchyEditor.SHOW_UNDEFINED, QAction(HierarchyEditor.SHOW_UNDEFINED, self)),33 (HierarchyEditor.SHOW_ABSTRACT, QAction(HierarchyEditor.SHOW_ABSTRACT, self)),34 (HierarchyEditor.FILTER_ACROSS_ARCS, QAction(HierarchyEditor.FILTER_ACROSS_ARCS, self))35 ]36 )37 for item in self._show_menu_items:38 self._show_menu_items[item].setCheckable(True)39 self._show_menu.addAction(self._show_menu_items[item])40 self._filter_model = hierarchyModel.HierarchyStandardFilterModel()41 self._show_menu_items[HierarchyEditor.SHOW_INACTIVE].toggled.connect(self._filter_model.TogglePrimInactive)42 self._show_menu_items[HierarchyEditor.SHOW_UNDEFINED].toggled.connect(self._filter_model.TogglePrimUndefined)43 self._show_menu_items[HierarchyEditor.SHOW_ABSTRACT].toggled.connect(self._filter_model.TogglePrimAbstract)44 self._show_menu_items[HierarchyEditor.FILTER_ACROSS_ARCS].toggled.connect(45 self._filter_model.ToggleFilterAcrossArcs)46 self._show_menu_items[HierarchyEditor.SHOW_INACTIVE].setChecked(False)47 self._show_menu_items[HierarchyEditor.SHOW_UNDEFINED].setChecked(False)48 self._show_menu_items[HierarchyEditor.SHOW_ABSTRACT].setChecked(False)49 self._show_menu_items[HierarchyEditor.FILTER_ACROSS_ARCS].setChecked(True)50 self._layout = QVBoxLayout(self)51 self.setLayout(self._layout)52 self._layout.addWidget(self._menu_bar)53 self._layout.addWidget(self._filter_line_edit)54 self._layout.addWidget(self._hierarchy_view)55 self._hierarchy_view.setModel(self._filter_model)56 self._hierarchy_view.setSelectionMode(QAbstractItemView.ExtendedSelection)57 self._filter_line_edit.returnPressed.connect(self._on_filter_return_pressed)58 self._setup_context_menu()59 @property60 def primSelectionChanged(self):61 """62 Provides access to the internal QItemSelectionModel's selectionChanged signal for callbacks63 on prim selection changes64 """65 return self._hierarchy_view.selectionModel().selectionChanged66 def select_paths(self, paths):67 item_selection = QItemSelection()68 source_model = self._filter_model.sourceModel()69 for path in paths:70 index = source_model.GetIndexFromPath(path)71 if index and index.isValid():72 item_selection.select(index, index)73 mapped_selection = self._filter_model.mapSelectionFromSource(item_selection)74 self._hierarchy_view.selectionModel().select(mapped_selection, QItemSelectionModel.ClearAndSelect)75 def get_selected_prims(self):76 selected_indices = self._hierarchy_view.selectedIndexes()77 ordered_prims = list()78 unordered_prims = set()79 for index in selected_indices:80 prim = index.data(role=roles.HierarchyPrimRole)81 if prim not in unordered_prims:82 unordered_prims.add(prim)83 ordered_prims.append(prim)84 return ordered_prims85 def set_source_model(self, model):86 self._filter_model.setSourceModel(model)87 def _setup_context_menu(self):88 self._context_menu = self.ContextMenuHierarchy(self)89 self.setContextMenuPolicy(Qt.CustomContextMenu)90 self.customContextMenuRequested.connect(self._context_menu.construct)91 def _on_filter_return_pressed(self):92 self._filter_model.SetPathContainsFilter(self._filter_line_edit.text())93class HierarchyEditorListener(QObject, object):94 def __init__(self, parent=None):95 super(HierarchyEditorListener, self).__init__(parent=parent)96 def OnPrimSelectionChanged(self, selected=None, deselected=None):97 for index in self.sender().selectedIndexes():...
coredisc.py
Source:coredisc.py
1# Copyright 2019 The GNOME Music developers2#3# GNOME Music is free software; you can redistribute it and/or modify4# it under the terms of the GNU General Public License as published by5# the Free Software Foundation; either version 2 of the License, or6# (at your option) any later version.7#8# GNOME Music is distributed in the hope that it will be useful,9# but WITHOUT ANY WARRANTY; without even the implied warranty of10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11# GNU General Public License for more details.12#13# You should have received a copy of the GNU General Public License along14# with GNOME Music; if not, write to the Free Software Foundation, Inc.,15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.16#17# The GNOME Music authors hereby grant permission for non-GPL compatible18# GStreamer plugins to be used and distributed together with GStreamer19# and GNOME Music. This permission is above and beyond the permissions20# granted by the GPL license by which GNOME Music is covered. If you21# modify this code, you may extend this exception to your version of the22# code, but you are not obligated to do so. If you do not wish to do so,23# delete this exception statement from your version.24from gi.repository import Dazzle, GObject, Gio, Gfm, Grl25from gi._gi import pygobject_new_full26class CoreDisc(GObject.GObject):27 disc_nr = GObject.Property(type=int, default=0)28 duration = GObject.Property(type=int, default=None)29 media = GObject.Property(type=Grl.Media, default=None)30 def __init__(self, media, nr, coremodel):31 super().__init__()32 self._coremodel = coremodel33 self._filter_model = None34 self._model = None35 self._old_album_ids = []36 self._selected = False37 self.update(media)38 self.props.disc_nr = nr39 def update(self, media):40 self.props.media = media41 @GObject.Property(type=Gio.ListModel, default=None)42 def model(self):43 if self._model is None:44 self._filter_model = Dazzle.ListModelFilter.new(45 self._coremodel.props.songs)46 self._filter_model.set_filter_func(lambda a: False)47 self._model = Gfm.SortListModel.new(self._filter_model)48 self._model.set_sort_func(49 self._wrap_sort_func(self._disc_sort))50 self._coremodel.props.songs.connect(51 "items-changed", self._on_core_changed)52 self._model.connect("items-changed", self._on_disc_changed)53 self._get_album_disc(54 self.props.media, self.props.disc_nr, self._filter_model)55 return self._model56 def _on_core_changed(self, model, position, removed, added):57 self._get_album_disc(58 self.props.media, self.props.disc_nr, self._filter_model)59 def _on_disc_changed(self, model, position, removed, added):60 with self.freeze_notify():61 duration = 062 for coresong in model:63 coresong.props.selected = self._selected64 duration += coresong.props.duration65 self.props.duration = duration66 def _disc_sort(self, song_a, song_b):67 return song_a.props.track_number - song_b.props.track_number68 def _wrap_sort_func(self, func):69 def wrap(a, b, *user_data):70 a = pygobject_new_full(a, False)71 b = pygobject_new_full(b, False)72 return func(a, b, *user_data)73 return wrap74 def _get_album_disc(self, media, discnr, model):75 album_ids = []76 model_filter = model77 def _filter_func(core_song):78 return core_song.props.grlid in album_ids79 def _reverse_sort(song_a, song_b, data=None):80 return song_a.props.track_number - song_b.props.track_number81 def _callback(source, dunno, media, something, something2):82 if media is None:83 if sorted(album_ids) == sorted(self._old_album_ids):84 return85 model_filter.set_filter_func(_filter_func)86 self._old_album_ids = album_ids87 return88 album_ids.append(media.get_source() + media.get_id())89 self._coremodel.props.grilo.populate_album_disc_songs(90 media, discnr, _callback)91 @GObject.Property(92 type=bool, default=False, flags=GObject.BindingFlags.SYNC_CREATE)93 def selected(self):94 return self._selected95 @selected.setter96 def selected(self, value):97 self._selected = value98 # The model is loaded on-demand, so the first time the model is99 # returned it can still be empty. This is problem for returning100 # a selection. Trigger loading of the model here if a selection101 # is requested, it will trigger the filled model update as102 # well....
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!