{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "514a8420",
   "metadata": {},
   "source": [
    "# 16-10 · Pętla wydarzeń i mainloop\n",
    "\n",
    "Praktyka do sekcji [„Jak działa pętla zdarzeń i mainloop”](/pl/chapters/rozdzial-16/16-10-event-loop-i-mainloop.html)."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "21f7de62",
   "metadata": {},
   "source": [
    "## Cel\n",
    "\n",
    "Symuluj kolejność przetwarzania zdarzeń i skonsoliduj różnicę function vs function()."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "45d28206",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T21:45:08.657332Z",
     "iopub.status.busy": "2026-08-18T21:45:08.657219Z",
     "iopub.status.idle": "2026-08-18T21:45:08.681245Z",
     "shell.execute_reply": "2026-08-18T21:45:08.680739Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['click', 'timer', 'type']\n"
     ]
    }
   ],
   "source": [
    "log = []\n",
    "\n",
    "def on_click(): log.append(\"click\")\n",
    "def on_timer(): log.append(\"timer\")\n",
    "def on_type(): log.append(\"type\")\n",
    "\n",
    "handlers = {\"click\": on_click, \"timer\": on_timer, \"type\": on_type}\n",
    "\n",
    "def run_event_loop(queue):\n",
    "    for event in queue:\n",
    "        handlers[event]()\n",
    "\n",
    "run_event_loop([\"click\", \"timer\", \"type\"])\n",
    "print(log)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56792f74",
   "metadata": {},
   "source": [
    "## Podstawowe zadanie ★ – command bez nawiasów"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "14bea1fb",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-08-18T21:45:08.682818Z",
     "iopub.status.busy": "2026-08-18T21:45:08.682642Z",
     "iopub.status.idle": "2026-08-18T21:45:08.685850Z",
     "shell.execute_reply": "2026-08-18T21:45:08.685358Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 hello True\n"
     ]
    }
   ],
   "source": [
    "calls = []\n",
    "\n",
    "def greet():\n",
    "    calls.append(\"greet called\")\n",
    "    return \"hello\"\n",
    "\n",
    "command_correct = greet     # правильно: сама функция\n",
    "command_wrong = greet()     # неправильно: вызов прямо сейчас\n",
    "\n",
    "print(len(calls), command_wrong, callable(command_correct))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Cartesian Python 3.14",
   "language": "python",
   "name": "cartesian-python314"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
