Best Python code snippet using pandera_python
remove_tile_entities.py
Source:remove_tile_entities.py
1from typing import TYPE_CHECKING, Tuple2import wx3import re4from amulet_map_editor.api.wx.ui.base_select import EVT_PICK5from amulet_map_editor.api.wx.ui.block_select import BlockDefine6from amulet_map_editor.programs.edit.api.operations import DefaultOperationUI7from amulet_map_editor import log8from amulet.api.selection import SelectionGroup9from amulet.api.block import Block10from amulet.api.data_types import Dimension, OperationReturnType11if TYPE_CHECKING:12 from amulet.api.level import BaseLevel13 from amulet_map_editor.programs.edit.api.canvas import EditCanvas14def remove_tiles_and_blocks(15 world: "BaseLevel",16 dimension: Dimension,17 target_box: SelectionGroup,18 regex_filter: str,19 fill_block: Block,20) -> OperationReturnType:21 if not isinstance(fill_block, Block):22 raise Exception("Remove Tile Entities was not given a replacement Block object")23 iter_count = 024 for chunk, _, _ in world.get_chunk_slice_box(dimension, target_box, True):25 for tile in chunk.block_entities:26 tile_id = f"{tile.namespace}:{tile.base_name}"27 if target_box.contains_block(tile.location) and re.match(regex_filter, tile_id):28 iter_count += 129 count = 030 for chunk, _, _ in world.get_chunk_slice_box(dimension, target_box, True):31 keys = []32 for tile in chunk.block_entities:33 tile_id = f"{tile.namespace}:{tile.base_name}"34 if not target_box.contains_block(tile.location):35 continue36 log.info(f"Found {tile_id} at {tile.location}")37 if re.match(regex_filter, tile_id):38 log.info(f" Matched {regex_filter}, removing")39 keys.append(tile.location)40 chunk.set_block(tile.x % 16, tile.y, tile.z % 16, fill_block)41 chunk.changed = True42 count += 143 yield count / iter_count44 for key in keys:45 chunk._block_entities.__delitem__(key)46 log.info(f"Removed {count} Tile Entities")47class RemoveTileEntities(wx.Panel, DefaultOperationUI):48 def __init__(49 self,50 parent: wx.Window,51 canvas: "EditCanvas",52 world: "BaseLevel",53 options_path: str,54 ):55 wx.Panel.__init__(self, parent)56 DefaultOperationUI.__init__(self, parent, canvas, world, options_path)57 self.Freeze()58 self._sizer = wx.BoxSizer(wx.VERTICAL)59 self.SetSizer(self._sizer)60 options = self._load_options({})61 self._regex_filter_label = wx.StaticText(62 self,63 label="ID Filter (regex match): "64 )65 self._sizer.Add(self._regex_filter_label, 0, wx.ALL | wx.CENTER, 5)66 self._regex_filter = wx.TextCtrl(67 self,68 name="ID Filter (regex)",69 value=options.get("regex_filter") or "^namespace:basename$"70 )71 self._sizer.Add(self._regex_filter, 0, wx.ALL | wx.CENTER, 5)72 self._block_define = BlockDefine(73 self,74 world.translation_manager,75 wx.VERTICAL,76 show_pick_block=True,77 **(options.get("fill_block_options") or {"platform": world.level_wrapper.platform, "block_name": "air"})78 )79 self._block_define.Bind(EVT_PICK, self._on_pick_block_button)80 self._sizer.Add(self._block_define, 1, wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, 5)81 self._run_button = wx.Button(self, label="Run Operation")82 self._run_button.Bind(wx.EVT_BUTTON, self._run_operation)83 self._sizer.Add(self._run_button, 0, wx.ALL | wx.ALIGN_CENTRE_HORIZONTAL, 5)84 self.Layout()85 self.Thaw()86 @property87 def wx_add_options(self) -> Tuple[int, ...]:88 return (1,)89 def _on_pick_block_button(self, evt):90 """Set up listening for the block click"""91 self._show_pointer = True92 def _on_box_click(self):93 if self._show_pointer:94 self._show_pointer = False95 x, y, z = self._pointer.pointer_base96 self._block_define.universal_block = (97 self.world.get_block(x, y, z, self.canvas.dimension),98 None,99 )100 def _get_fill_block(self):101 return self._block_define.universal_block[0]102 def disable(self):103 self._save_options(104 {105 "regex_filter": self._regex_filter.GetLineText(0),106 "fill_block": self._get_fill_block(),107 "fill_block_options": {108 'platform': self._block_define.platform,109 'version_number': self._block_define.version_number,110 'force_blockstate': self._block_define.force_blockstate,111 'namespace': self._block_define.namespace,112 'block_name': self._block_define.block_name,113 'properties': self._block_define.properties,114 },115 }116 )117 def _run_operation(self, _):118 regex_filter = self._regex_filter.GetLineText(0)119 log.info(f"Starting Remove Tile Entities Operation ({regex_filter})")120 self.canvas.run_operation(121 lambda: remove_tiles_and_blocks(122 self.world,123 self.canvas.dimension,124 self.canvas.selection.selection_group,125 regex_filter,126 self._get_fill_block(),127 )128 )129export = {130 "name": "Remove Tile Entities", # the name of the plugin131 "operation": RemoveTileEntities, # the actual function to call when running the plugin...
logger.py
Source:logger.py
1from .widget import Widget2import tkinter as tk3from tkinter import ttk, END4from tkinter.scrolledtext import ScrolledText5import logging6import re789class Logger(Widget):10 class LoggingFilter(logging.Filter):11 def filter(self, record):12 return record.level == self._level and re.match(self._regex_filter, record.message)131415 class Handler(logging.Handler):16 def __init__(self, widget):17 logging.Handler.__init__(self)18 self.setFormatter(logging.Formatter("%(asctime)s: %(message)s"))19 self._tk = widget20 self._tk.config(state='disabled')2122 def emit(self, record):23 self._tk.config(state='normal')24 if record.msg.startswith("INIT"):25 self._tk.insert(END, self.format(record) + "\n", "init")26 elif record.msg.startswith("DISPOSE"):27 self._tk.insert(END, self.format(record) + "\n", "dispose")28 else:29 self._tk.insert(END, self.format(record) + "\n")30 self._tk.see(END)31 self._tk.config(state='disabled')32 33 def __init__(self, **kwargs):34 self._tk = ScrolledText(master=kwargs.get("master").container)35 Widget.__init__(self, **kwargs)3637 self.logging_handler = Logger.Handler(self._tk)3839 self._logger.addHandler(self.logging_handler)40 self._level = self.get_attr("level", "DEBUG")41 self._regex_filter = self.get_attr("filter", ".*")42 43 def on_changed_level(self, value):44 self._level = value45 self._setFilters()4647 def on_changed_filter(self, value):48 self._regex_filter = value49 self._setFilters()50 51 def clear(self):52 self._tk.delete("1.0", tk.END)5354 def _setFilters(self):55 for log_filter in self.logging_handler.filters:56 self.logging_handler.removeFilter(log_filter)5758 self.logging_handler.addFilter(LoggingFilter)5960 def dispose(self):61 self._logger.removeHandler(self.logging_handler)
...
camera_transfer.py
Source:camera_transfer.py
1# import re2# from typing import Any34# from homeassistant.config_entries import ConfigEntry5# from homeassistant.core import HomeAssistant67# from ..common.ifile_info import IFileInfo8# from ..common.memory_storage import MemoryStorage9# from ..common.transfer_component import TransferComponent10# from ..common.transfer_component_id import TransferComponentId11# from ..const import CONF_CAMERA, CONF_FILTER, DOMAIN121314# class CameraTransfer(TransferComponent):15# platform = CONF_CAMERA1617# def __init__(self, id: TransferComponentId, hass: HomeAssistant, config: ConfigEntry):18# super().__init__(id, hass, config)19# self._regex_filter = None20# if CONF_FILTER in config:21# pattern = config[CONF_FILTER]22# self._regex_filter = re.compile(pattern)23# self._storage = MemoryStorage(hass, id.Entity)2425# def get_files(self, max=None) -> list[IFileInfo]:26# ''' OVERRIDE '''27# files: list[IFileInfo] = []28# return files2930# def file_read(self, file: IFileInfo) -> Any:31# ''' OVERRIDE '''32# pass3334# def file_delete(self, file: IFileInfo):35# ''' OVERRIDE '''36# pass3738# def file_save(self, file: IFileInfo, content) -> str:39# ''' OVERRIDE '''40# if self._regex_filter and not self._regex_filter.match(file.basename):41# return None4243# self._storage.append_file(self._id.id, content)
...
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!!