# Copyright (C) Weimin Wang
# This file is distributed under the same license as the PyWebIO package.
#
# FIRST AUTHOR <EMAIL@ADDRESS>, 2022.
# Pikhosh <pikhosh@gmail.com>, 2022.
msgid ""
msgstr ""
"Project-Id-Version: PyWebIO 1.5.2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-26 16:35+0330\n"
"PO-Revision-Date: 2022-02-28 12:33+0330\n"
"Last-Translator: Pikhosh <pikhosh@gmail.com>\n"
"Language-Team: Persian <>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.9.1\n"
"Language: fa\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Lokalize 21.12.2\n"

#: ../../cookbook.rst:2
msgid "Cookbook"
msgstr "دستور های پخت"

#: ../../cookbook.rst:8
msgid "Interaction related"
msgstr ""

#: ../../cookbook.rst:11
msgid "Equivalent to \"Press any key to continue\""
msgstr ""

#: ../../cookbook.rst:13
msgid ""
"actions(buttons=[\"Continue\"])\n"
"put_text(\"Go next\")  # ..demo-only"
msgstr ""

#: ../../cookbook.rst:22
msgid "Output pandas dataframe"
msgstr ""

#: ../../cookbook.rst:24
msgid ""
"import numpy as np\n"
"import pandas as pd\n"
"\n"
"df = pd.DataFrame(np.random.randn(6, 4), columns=list(\"ABCD\"))\n"
"put_html(df.to_html(border=0))"
msgstr ""

#: ../../cookbook.rst:34
msgid ""
"`pandas.DataFrame.to_html — pandas documentation "
"<https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html"
"#pandas-dataframe-to-html>`_"
msgstr ""

#: ../../cookbook.rst:37
msgid "Output Matplotlib figure"
msgstr ""

#: ../../cookbook.rst:39
msgid ""
"Simply do not call ``matplotlib.pyplot.show``, directly save the figure "
"to in-memory buffer and output the buffer via "
":func:`pywebio.output.put_image`:"
msgstr ""

#: ../../cookbook.rst:42
msgid ""
"import matplotlib\n"
"import matplotlib.pyplot as plt\n"
"import io\n"
"import pywebio\n"
"\n"
"matplotlib.use('agg')  # required, use a non-interactive backend\n"
"\n"
"fig, ax = plt.subplots()  # Create a figure containing a single axes.\n"
"ax.plot([1, 2, 3, 4], [1, 4, 2, 3])  # Plot some data on the axes.\n"
"\n"
"buf = io.BytesIO()\n"
"fig.savefig(buf)\n"
"pywebio.output.put_image(buf.getvalue())"
msgstr ""

#: ../../cookbook.rst:60
msgid ""
"The ``matplotlib.use('agg')`` is required so that the server does not try"
" to create (and then destroy) GUI windows that will never be seen."
msgstr ""

#: ../../cookbook.rst:63
msgid ""
"When using Matplotlib in a web server (multiple threads environment), "
"pyplot may cause some conflicts in some cases, read the following "
"articles for more information:"
msgstr ""

#: ../../cookbook.rst:66
msgid ""
"`Multi Threading in Python and Pyplot | by Ranjitha Korrapati | Medium "
"<https://medium.com/@ranjitha.korrapati/multi-threading-in-python-and-"
"pyplot-46f325e6a9d0>`_"
msgstr ""

#: ../../cookbook.rst:68
msgid ""
"`Embedding in a web application server (Flask) — Matplotlib documentation"
" "
"<https://matplotlib.org/stable/gallery/user_interfaces/web_application_server_"
"sgskip.html>`_"
msgstr ""

#: ../../cookbook.rst:72
msgid "Blocking confirm model"
msgstr ""

#: ../../cookbook.rst:74
msgid ""
"The following code uses the lock mechanism to make the button callback "
"function synchronous:"
msgstr ""

#: ../../cookbook.rst:78
msgid ""
"import threading\n"
"from pywebio import output\n"
"\n"
"def confirm(title, content=None, timeout=None):\n"
"    \"\"\"Show a confirm model.\n"
"\n"
"    :param str title: Model title.\n"
"    :param list/put_xxx() content: Model content.\n"
"    :param None/float timeout: Seconds for operation time out.\n"
"    :return: Return `True` when the \"CONFIRM\" button is clicked,\n"
"        return `False` when the \"CANCEL\" button is clicked,\n"
"        return `None` when a timeout is given and the operation times "
"out.\n"
"    \"\"\"\n"
"    if not isinstance(content, list):\n"
"        content = [content]\n"
"\n"
"    event = threading.Event()\n"
"    result = None\n"
"\n"
"    def onclick(val):\n"
"        nonlocal result\n"
"        result = val\n"
"        event.set()\n"
"\n"
"    content.append(output.put_buttons([\n"
"        {'label': 'CONFIRM', 'value': True},\n"
"        {'label': 'CANCEL', 'value': False, 'color': 'danger'},\n"
"    ], onclick=onclick))\n"
"    output.popup(title=title, content=content, closable=False)\n"
"\n"
"    event.wait(timeout=timeout)  # wait the model buttons are clicked\n"
"    output.close_popup()\n"
"    return result\n"
"\n"
"\n"
"res = confirm('Confirm', 'You have 5 seconds to make s choice', "
"timeout=5)\n"
"output.put_text(\"Your choice is:\", res)"
msgstr ""

#: ../../cookbook.rst:121
msgid "Input in the popup"
msgstr ""

#: ../../cookbook.rst:124
msgid ""
"In the following code, we define a ``popup_input()`` function, which can "
"be used to get input in popup:"
msgstr ""

#: ../../cookbook.rst:128
msgid ""
"def popup_input(pins, names, title='Please fill out the form'):\n"
"    \"\"\"Show a form in popup window.\n"
"\n"
"    :param list pins: pin output list.\n"
"    :param list pins: pin name list.\n"
"    :param str title: model title.\n"
"    :return: return the form as dict, return None when user cancel the "
"form.\n"
"    \"\"\"\n"
"    if not isinstance(pins, list):\n"
"        pins = [pins]\n"
"\n"
"    from pywebio.utils import random_str\n"
"    action_name = 'action_' + random_str(10)\n"
"\n"
"    pins.append(put_actions(action_name, buttons=[\n"
"        {'label': 'Submit', 'value': True},\n"
"        {'label': 'Cancel', 'value': False, 'color': 'danger'},\n"
"    ]))\n"
"    popup(title=title, content=pins, closable=False)\n"
"\n"
"    change_info = pin_wait_change(action_name)\n"
"    result = None\n"
"    if change_info['name'] == action_name and change_info['value']:\n"
"        result = {name: pin[name] for name in names}\n"
"    close_popup()\n"
"    return result\n"
"\n"
"\n"
"from pywebio.pin import put_input\n"
"\n"
"result = popup_input([\n"
"    put_input('name', label='Input your name'),\n"
"    put_input('age', label='Input your age', type=\"number\")\n"
"], names=['name', 'age'])\n"
"put_text(result)"
msgstr ""

#: ../../cookbook.rst:168
msgid ""
"The code uses :doc:`pin module </pin>` to add input widgets to popup "
"window, and uses the lock mechanism to wait the form buttons to be "
"clicked."
msgstr ""

#: ../../cookbook.rst:173
msgid "Redirect stdout to PyWebIO application"
msgstr ""

#: ../../cookbook.rst:176
msgid ""
"The following code shows how to redirect stdout of python code and "
"subprocess to PyWebIO application:"
msgstr ""

#: ../../cookbook.rst:180
msgid ""
"import io\n"
"import time\n"
"import subprocess  # ..doc-only\n"
"from contextlib import redirect_stdout\n"
"\n"
"# redirect `print()` to pywebio\n"
"class WebIO(io.IOBase):\n"
"    def write(self, content):\n"
"        put_text(content, inline=True)\n"
"\n"
"with redirect_stdout(WebIO()):\n"
"    for i in range(10):\n"
"        print(i, time.time())\n"
"        time.sleep(0.2)\n"
"\n"
"## ----\n"
"import subprocess  # ..demo-only\n"
"# redirect a subprocess' stdout to pywebio\n"
"process = subprocess.Popen(\"ls -ahl\", shell=True, "
"stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\n"
"while True:\n"
"    output = process.stdout.readline()\n"
"    if output:\n"
"        put_text(output.decode('utf8'), inline=True)\n"
"\n"
"    if not output and process.poll() is not None:\n"
"        break"
msgstr ""

#: ../../cookbook.rst:213
msgid "Add missing syntax highlight for code output"
msgstr ""

#: ../../cookbook.rst:215
msgid ""
"When output code via `put_markdown()` or `put_code()`, PyWebIO provides "
"syntax highlight for some common languages. If you find your code have no"
" syntax highlight, you can add the syntax highlighter by two following "
"steps:"
msgstr ""

#: ../../cookbook.rst:218
msgid ""
"Go to `prismjs CDN page "
"<https://www.jsdelivr.com/package/npm/prismjs?version=1.23.0&path=components"
">`_"
" to get your syntax highlighter link."
msgstr ""

#: ../../cookbook.rst:219
msgid ""
"Use :func:`config(js_file=...) <pywebio.config>` to load the syntax "
"highlight module"
msgstr ""

#: ../../cookbook.rst:223
msgid ""
"@config(js_file=\"https://cdn.jsdelivr.net/npm/prismjs@1.23.0/components"
"/prism-diff.min.js\")\n"
"def main():\n"
"    put_code(\"\"\"\n"
"+ AAA\n"
"- BBB\n"
"CCC\n"
"    \"\"\".strip(), language='diff')\n"
"\n"
"    put_markdown(\"\"\"\n"
"    ```diff\n"
"    + AAA\n"
"    - BBB\n"
"    CCC\n"
"    ```\n"
"    \"\"\", lstrip=True)"
msgstr ""

#: ../../cookbook.rst:242
msgid "Web application related"
msgstr ""

#: ../../cookbook.rst:245
msgid "Get URL parameters of current page"
msgstr ""

#: ../../cookbook.rst:247
msgid ""
"You can use URL parameter (known also as \"query strings\" or \"URL query"
" parameters\") to pass information to your web application. In PyWebIO "
"application, you can use the following code to get the URL parameters as "
"a Python dict."
msgstr ""

#: ../../cookbook.rst:250
msgid ""
"# `query` is a dict\n"
"query = eval_js(\"Object.fromEntries(new "
"URLSearchParams(window.location.search))\")\n"
"put_text(query)"
msgstr ""

#: ../../cookbook.rst:260
msgid "Add Google AdSense/Analytics code"
msgstr ""

#: ../../cookbook.rst:262
msgid ""
"When you setup Google AdSense/Analytics, you will get a javascript file "
"and a piece of code that needs to be inserted into your application page,"
" you can use :func:`pywebio.config()` to inject js file and code to your "
"PyWebIO application::"
msgstr ""

#: ../../cookbook.rst:265
msgid ""
"from pywebio import start_server, output, config\n"
"\n"
"js_file = \"https://www.googletagmanager.com/gtag/js?id=G-xxxxxxx\"\n"
"js_code = \"\"\"\n"
"window.dataLayer = window.dataLayer || [];\n"
"function gtag(){dataLayer.push(arguments);}\n"
"gtag('js', new Date());\n"
"\n"
"gtag('config', 'G-xxxxxxx');\n"
"\"\"\"\n"
"\n"
"@config(js_file=js_file, js_code=js_code)\n"
"def main():\n"
"    output.put_text(\"hello world\")\n"
"\n"
"start_server(main, port=8080)"
msgstr ""

#: ../../cookbook.rst:284
msgid "Refresh page on connection lost"
msgstr ""

#: ../../cookbook.rst:286
msgid ""
"Add the following code to the beginning of your PyWebIO application main "
"function::"
msgstr ""

#: ../../cookbook.rst:288
msgid ""
"session.run_js('WebIO._state.CurrentSession.on_session_close(()="
">{setTimeout(()=>location.reload(),"
" 4000})')"
msgstr ""

#: ../../cookbook.rst:291
msgid "Cookie and localStorage manipulation"
msgstr ""

#: ../../cookbook.rst:294
msgid ""
"You can use `pywebio.session.run_js()` and `pywebio.session.eval_js()` to"
" deal with cookies or localStorage with js."
msgstr ""

#: ../../cookbook.rst:296
msgid "``localStorage`` manipulation:"
msgstr ""

#: ../../cookbook.rst:298
msgid ""
"set_localstorage = lambda key, value: run_js(\"localStorage.setItem(key, "
"value)\", key=key, value=value)\n"
"get_localstorage = lambda key: eval_js(\"localStorage.getItem(key)\", "
"key=key)\n"
"\n"
"set_localstorage('hello', 'world')\n"
"val = get_localstorage('hello')\n"
"put_text(val)"
msgstr ""

#: ../../cookbook.rst:310
msgid "Cookie manipulation:"
msgstr ""

#: ../../cookbook.rst:314
msgid ""
"# https://stackoverflow.com/questions/14573223/set-cookie-and-get-cookie-"
"with-javascript\n"
"run_js(\"\"\"\n"
"window.setCookie = function(name,value,days) {\n"
"    var expires = \"\";\n"
"    if (days) {\n"
"        var date = new Date();\n"
"        date.setTime(date.getTime() + (days*24*60*60*1000));\n"
"        expires = \"; expires=\" + date.toUTCString();\n"
"    }\n"
"    document.cookie = name + \"=\" + (value || \"\")  + expires + \"; "
"path=/\";\n"
"}\n"
"window.getCookie = function(name) {\n"
"    var nameEQ = name + \"=\";\n"
"    var ca = document.cookie.split(';');\n"
"    for(var i=0;i < ca.length;i++) {\n"
"        var c = ca[i];\n"
"        while (c.charAt(0)==' ') c = c.substring(1,c.length);\n"
"        if (c.indexOf(nameEQ) == 0) return "
"c.substring(nameEQ.length,c.length);\n"
"    }\n"
"    return null;\n"
"}\n"
"\"\"\")\n"
"\n"
"def setcookie(key, value, days=0):\n"
"    run_js(\"setCookie(key, value, days)\", key=key, value=value, "
"days=days)\n"
"\n"
"def getcookie(key):\n"
"    return eval_js(\"getCookie(key)\", key=key)\n"
"\n"
"setcookie('hello', 'world')\n"
"val = getcookie('hello')\n"
"put_text(val)"
msgstr ""

