Add a search function for the text field. I should be shown as a small symbol in the…
- User
Add a search function for the text field. I should be shown as a small symbol in the upper right corner of the text field. When the user clicks on it a small bar should open that aligns with the text field and only covers 25% of its width and has a height that fits the font size. When the user types something in this field it should search for what the user typed in in the text field and only show the lines of results that include what ever the user searched for. Python 3.12 Code: import math import re from typing import Any, Union, Callable from math import ceil
from PySide6.QtWidgets import ( QApplication, QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QTextEdit, QScrollBar, QPushButton, QLabel, QFrame, QGridLayout ) from PySide6.QtGui import QFont from PySide6.QtCore import Qt
-- Utility Functions --
def convert_angle(func: Callable[[float], float], x: float, use_degrees: bool) -> float: """Convert angle based on degree mode.""" return func(math.radians(x) if use_degrees else x)
-- Conversions Category --
def kilograms_to_pounds(kg: float) -> float: """Convert kilograms to pounds.""" return kg / 0.45359237
def pounds_to_kilograms(lb: float) -> float: """Convert pounds to kilograms.""" return lb * 0.45359237
def celsius_to_kelvin(c: float) -> float: """Convert Celsius to Kelvin.""" return c + 273.15
def kelvin_to_celsius(k: float) -> float: """Convert Kelvin to Celsius.""" return k - 273.15
def celsius_to_fahrenheit(c: float) -> float: """Convert Celsius to Fahrenheit.""" return c * 9/5 + 32
def fahrenheit_to_celsius(f: float) -> float: """Convert Fahrenheit to Celsius.""" return (f - 32) * 5/9
-- Text Category --
def capitalize_sentence(sentence: str) -> str: """Capitalize the first letter of each word in the sentence.""" return ' '.join(word.capitalize() for word in sentence.split())
def remove_duplicates(text: str) -> str: """Remove duplicate words and empty lines from a string.""" words = ' '.join(line.strip() for line in text.splitlines() if line.strip()).split() return ' '.join(dict.fromkeys(words))
-- Processing --
def get_safe_globals(use_degrees: bool, variables: dict) -> dict: """Return a dictionary of safe globals for expression evaluation, including user-defined variables.""" trig_funcs = {'sin', 'cos', 'tan', 'asin', 'acos', 'atan'} safe_globals = { "sqrt": math.sqrt, "log": math.log10, "ln": math.log, "pi": math.pi, "e": math.e, "lb": kilograms_to_pounds, "kg": pounds_to_kilograms, "C": kelvin_to_celsius, "K": celsius_to_kelvin, "F": celsius_to_fahrenheit, "CF": fahrenheit_to_celsius, "capitalize": capitalize_sentence, "duplicates": remove_duplicates, } # Add trigonometric functions with angle conversion safe_globals.update({ func: (lambda f: (lambda x: convert_angle(getattr(math, f), x, use_degrees)))(func) for func in trig_funcs }) # Include user-defined variables safe_globals.update(variables) return safe_globals
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.