How to use to_index method in pandera

Best Python code snippet using pandera_python

dock.py

Source:dock.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2#3# Copyright © Spyder Project Contributors4# Licensed under the terms of the MIT License5# (see spyder/__init__.py for details)6"""7Dock widgets for plugins8"""9from qtpy.QtCore import QEvent, QObject, QPoint, Qt, Signal10from qtpy.QtGui import QCursor11from qtpy.QtWidgets import QApplication, QDockWidget, QTabBar12class TabFilter(QObject):13 """14 Filter event attached to each QTabBar that holds 2 or more dockwidgets in15 charge of handling tab rearangement.16 This filter also holds the methods needed for the detection of a drag and17 the movement of tabs.18 """19 def __init__(self, dock_tabbar, main):20 QObject.__init__(self)21 self.dock_tabbar = dock_tabbar22 self.main = main23 self.moving = False24 self.from_index = None25 self.to_index = None26 # Helper methods27 def _get_plugin(self, index):28 """Get plugin reference based on tab index."""29 for plugin in self.main.widgetlist:30 tab_text = self.dock_tabbar.tabText(index).replace('&', '')31 if plugin.get_plugin_title() == tab_text:32 return plugin33 def _get_plugins(self):34 """35 Get a list of all plugin references in the QTabBar to which this36 event filter is attached.37 """38 plugins = []39 for index in range(self.dock_tabbar.count()):40 plugin = self._get_plugin(index)41 plugins.append(plugin)42 return plugins43 def _fix_cursor(self, from_index, to_index):44 """Fix mouse cursor position to adjust for different tab sizes."""45 # The direction is +1 (moving to the right) or -1 (moving to the left)46 direction = abs(to_index - from_index)/(to_index - from_index)47 tab_width = self.dock_tabbar.tabRect(to_index).width()48 tab_x_min = self.dock_tabbar.tabRect(to_index).x()49 tab_x_max = tab_x_min + tab_width50 previous_width = self.dock_tabbar.tabRect(to_index - direction).width()51 delta = previous_width - tab_width52 if delta > 0:53 delta = delta * direction54 else:55 delta = 056 cursor = QCursor()57 pos = self.dock_tabbar.mapFromGlobal(cursor.pos())58 x, y = pos.x(), pos.y()59 if x < tab_x_min or x > tab_x_max:60 new_pos = self.dock_tabbar.mapToGlobal(QPoint(x + delta, y))61 cursor.setPos(new_pos)62 def eventFilter(self, obj, event):63 """Filter mouse press events.64 Events that are captured and not propagated return True. Events that65 are not captured and are propagated return False.66 """67 event_type = event.type()68 if event_type == QEvent.MouseButtonPress:69 self.tab_pressed(event)70 return False71 if event_type == QEvent.MouseMove:72 try:73 self.tab_moved(event)74 except TypeError:75 pass76 return True77 if event_type == QEvent.MouseButtonRelease:78 self.tab_released(event)79 return True80 return False81 def tab_pressed(self, event):82 """Method called when a tab from a QTabBar has been pressed."""83 self.from_index = self.dock_tabbar.tabAt(event.pos())84 self.dock_tabbar.setCurrentIndex(self.from_index)85 if event.button() == Qt.RightButton:86 if self.from_index == -1:87 self.show_nontab_menu(event)88 else:89 self.show_tab_menu(event)90 def tab_moved(self, event):91 """Method called when a tab from a QTabBar has been moved."""92 # If the left button isn't pressed anymore then return93 if not event.buttons() & Qt.LeftButton:94 self.to_index = None95 return96 self.to_index = self.dock_tabbar.tabAt(event.pos())97 if not self.moving and self.from_index != -1 and self.to_index != -1:98 QApplication.setOverrideCursor(Qt.ClosedHandCursor)99 self.moving = True100 if self.to_index in (-1, None):101 self.to_index = self.from_index102 from_index, to_index = self.from_index, self.to_index103 if from_index not in (to_index, -1, None):104 self.move_tab(from_index, to_index)105 self._fix_cursor(from_index, to_index)106 self.from_index = to_index107 def tab_released(self, event):108 """Method called when a tab from a QTabBar has been released."""109 QApplication.restoreOverrideCursor()110 self.moving = False111 def move_tab(self, from_index, to_index):112 """Move a tab from a given index to a given index position."""113 plugins = self._get_plugins()114 from_plugin = self._get_plugin(from_index)115 to_plugin = self._get_plugin(to_index)116 from_idx = plugins.index(from_plugin)117 to_idx = plugins.index(to_plugin)118 plugins[from_idx], plugins[to_idx] = plugins[to_idx], plugins[from_idx]119 for i in range(len(plugins)-1):120 self.main.tabify_plugins(plugins[i], plugins[i+1])121 from_plugin.dockwidget.raise_()122 def show_tab_menu(self, event):123 """Show the context menu assigned to tabs."""124 self.show_nontab_menu(event)125 def show_nontab_menu(self, event):126 """Show the context menu assigned to nontabs section."""127 menu = self.main.createPopupMenu()128 menu.exec_(self.dock_tabbar.mapToGlobal(event.pos()))129class SpyderDockWidget(QDockWidget):130 """Subclass to override needed methods"""131 plugin_closed = Signal()132 def __init__(self, title, parent):133 super(SpyderDockWidget, self).__init__(title, parent)134 # Needed for the installation of the event filter135 self.title = title136 self.main = parent137 self.dock_tabbar = None138 # To track dockwidget changes the filter is installed when dockwidget139 # visibility changes. This installs the filter on startup and also140 # on dockwidgets that are undocked and then docked to a new location.141 self.visibilityChanged.connect(self.install_tab_event_filter)142 def closeEvent(self, event):143 """144 Reimplement Qt method to send a signal on close so that "Panes" main145 window menu can be updated correctly146 """147 self.plugin_closed.emit()148 def install_tab_event_filter(self, value):149 """150 Install an event filter to capture mouse events in the tabs of a151 QTabBar holding tabified dockwidgets.152 """153 dock_tabbar = None154 tabbars = self.main.findChildren(QTabBar)155 for tabbar in tabbars:156 for tab in range(tabbar.count()):157 title = tabbar.tabText(tab)158 if title == self.title:159 dock_tabbar = tabbar160 break161 if dock_tabbar is not None:162 self.dock_tabbar = dock_tabbar163 # Install filter only once per QTabBar164 if getattr(self.dock_tabbar, 'filter', None) is None:165 self.dock_tabbar.filter = TabFilter(self.dock_tabbar,166 self.main)...

Full Screen

Full Screen

last_digit_of_the_sum_of_fibonacci_numbers_again.py

Source:last_digit_of_the_sum_of_fibonacci_numbers_again.py Github

copy

Full Screen

1# python32from last_digit_of_the_sum_of_fibonacci_numbers import *3def last_digit_of_the_sum_of_fibonacci_numbers_again_naive(from_index, to_index):4 assert 0 <= from_index <= to_index <= 10 ** 185 if to_index == 0:6 return 07 fibonacci_numbers = [0] * (to_index + 1)8 fibonacci_numbers[0] = 09 fibonacci_numbers[1] = 110 for i in range(2, to_index + 1):11 fibonacci_numbers[i] = fibonacci_numbers[i - 2] + fibonacci_numbers[i - 1]12 return sum(fibonacci_numbers[from_index:to_index + 1]) % 1013def last_digit_of_the_sum_of_fibonacci_numbers_again(from_index, to_index):14 assert 0 <= from_index <= to_index <= 10 ** 1815 last = last_digit_of_the_sum_of_fibonacci_numbers(to_index) - \16 last_digit_of_the_sum_of_fibonacci_numbers(from_index - 1)17 return last % 1018if __name__ == '__main__':19 input_from, input_to = map(int, input().split())20 print(last_digit_of_the_sum_of_fibonacci_numbers_again(input_from, input_to))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful