You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Eugenio Parodi 04bb901316 Doc Updated 2 years ago
..
README.html Doc Updated 2 years ago

README.html

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ttkDesigner - Your first TextEditor &mdash; pyTermTk 0.36.0-a
documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/theme_overrides.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/ttk.css" type="text/css" />
<link rel="shortcut icon" href="https://ceccopierangiolieugenio.github.io/pyTermTk/sandbox/www/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../../genindex.html" />
<link rel="search" title="Search" href="../../../search.html" />
<link rel="next" title="Features" href="../../../info/features/index.html" />
<link rel="prev" title="pyTermTk - Your first Calculator" href="../../005-calculator.html" />
</head>

<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../../index.html" class="icon icon-home"> pyTermTk
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Tutorials</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../000-examples.html">pyTermTk - &lt; <strong>the Examples</strong> &gt;</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../001-helloworld.html">pyTermTk - Hello World</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../002-layout.html">pyTermTk - Layouts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../003-signalslots.html">pyTermTk - Signal &amp; Slots</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../004-logging.html">pyTermTk - Logging</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../005-calculator.html">pyTermTk - Your first Calculator</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">ttkDesigner - Your first TextEditor</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#start-a-new-project">Start a new project</a></li>
<li class="toctree-l2"><a class="reference internal" href="#add-the-first-buttons-undo-redo-cut-copy-paste">Add The first buttons (Undo,redo - Cut,Copy,Paste)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#add-the-textedit-widget">Add the TextEdit widget</a></li>
<li class="toctree-l2"><a class="reference internal" href="#link-the-events-slots-for-the-basic-functionalities">Link the Events/Slots for the basic functionalities</a></li>
<li class="toctree-l2"><a class="reference internal" href="#add-few-extra-controls-open-save-color">Add few extra controls (Open/Save/Color)</a></li>
<li class="toctree-l2"><a class="reference internal" href="#link-the-events-slots-for-the-color-feature">Link the Events/Slots for the color feature</a></li>
<li class="toctree-l2"><a class="reference internal" href="#preview-and-quick-export">Preview and Quick Export</a></li>
<li class="toctree-l2"><a class="reference internal" href="#import-this-widget-in-your-project">Import this widget in your project</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#option-1-include-the-open-save-routine-and-link-them-to-the-widget">Option 1) Include the Open/Save routine and link them to the widget</a></li>
<li class="toctree-l3"><a class="reference internal" href="#option-2-extend-a-custom-widget-including-the-open-save-methods">Option 2) Extend a custom widget including the open/save methods</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Features</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../info/features/index.html">Features</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../info/features/crosscompatible.html">Cross Compatibility</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../info/features/widgets.html">Widgets</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">Dev</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../info/installing.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../info/installing.html#quickstart">Quickstart</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../info/debug.html">Debug</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">API Reference</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkAbstract.html">TermTk.TTkAbstract</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkCore.html">TermTk.TTkCore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkCore.TTkTerm.html">TermTk.TTkCore.TTkTerm</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkGui.html">TermTk.TTkGui</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkLayouts.html">TermTk.TTkLayouts</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkTemplates.html">TermTk.TTkTemplates</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkTestWidgets.html">TermTk.TTkTestWidgets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkTheme.html">TermTk.TTkTheme</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkTypes.html">TermTk.TTkTypes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkUiTools.html">TermTk.TTkUiTools</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkWidgets.html">TermTk.TTkWidgets</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkWidgets.TTkModelView.html">TermTk.TTkWidgets.TTkModelView</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkWidgets.TTkPickers.html">TermTk.TTkWidgets.TTkPickers</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../autogen.TermTk/TermTk.TTkWidgets.TTkTerminal.html">TermTk.TTkWidgets.TTkTerminal</a></li>
</ul>

</div>
</div>
</nav>

<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../../index.html">pyTermTk</a>
</nav>

<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../../index.html" class="icon icon-home"></a> &raquo;</li>
<li>ttkDesigner - Your first TextEditor</li>
<li class="wy-breadcrumbs-aside">
<a href="../../../_sources/tutorial/ttkDesigner/textEdit/README.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">

<div class="contents topic" id="contents">
<p class="topic-title">Contents</p>
<ul class="simple">
<li><p><a class="reference internal" href="#ttkdesigner-your-first-texteditor" id="id3">ttkDesigner - Your first TextEditor</a></p>
<ul>
<li><p><a class="reference internal" href="#start-a-new-project" id="id4">Start a new project</a></p></li>
<li><p><a class="reference internal" href="#add-the-first-buttons-undo-redo-cut-copy-paste" id="id5">Add The first buttons (Undo,redo - Cut,Copy,Paste)</a></p></li>
<li><p><a class="reference internal" href="#add-the-textedit-widget" id="id6">Add the TextEdit widget</a></p></li>
<li><p><a class="reference internal" href="#link-the-events-slots-for-the-basic-functionalities" id="id7">Link the Events/Slots for the basic functionalities</a></p></li>
<li><p><a class="reference internal" href="#add-few-extra-controls-open-save-color" id="id8">Add few extra controls (Open/Save/Color)</a></p></li>
<li><p><a class="reference internal" href="#link-the-events-slots-for-the-color-feature" id="id9">Link the Events/Slots for the color feature</a></p></li>
<li><p><a class="reference internal" href="#preview-and-quick-export" id="id10">Preview and Quick Export</a></p></li>
<li><p><a class="reference internal" href="#import-this-widget-in-your-project" id="id11">Import this widget in your project</a></p>
<ul>
<li><p><a class="reference internal" href="#option-1-include-the-open-save-routine-and-link-them-to-the-widget" id="id12">Option 1) Include the Open/Save routine and link them to the widget</a></p></li>
<li><p><a class="reference internal" href="#option-2-extend-a-custom-widget-including-the-open-save-methods" id="id13">Option 2) Extend a custom widget including the open/save methods</a></p></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<section id="ttkdesigner-your-first-texteditor">
<h1><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/ttkDesigner">ttkDesigner</a> - Your first TextEditor<a class="headerlink" href="#ttkdesigner-your-first-texteditor" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h1>
<section id="start-a-new-project">
<h2><a class="toc-backref" href="#id4">Start a new project</a><a class="headerlink" href="#start-a-new-project" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<ul class="simple">
<li><p>Create a new Window (<strong>File</strong> -&gt; <strong>New</strong> -&gt; <strong>New Window</strong>)</p></li>
<li><p>Set your favourite window params:</p>
<ul>
<li><p>Your preferred size</p></li>
<li><p>Some catcy Title</p></li>
<li><p>An Amazing Name - (This is the unique name that will be used to identify this <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.widget.html">Widget</a>)</p></li>
<li><p>Change the Layout to <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkLayouts.gridlayout.html#ttkgridlayout">TTkGridLayout</a> (This will allow all the components to be placed in a grid aligned to the content of the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.window.html">window</a>)</p></li>
<li><p>Add the “Maximize Button” through the Window Flags (I forgot to add this step in the video)</p></li>
</ul>
</li>
</ul>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455166-7c4905b9-572e-49e6-9f71-12fa5545fd90.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455166-7c4905b9-572e-49e6-9f71-12fa5545fd90.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/textEdit.01.tui.json">textEdit.01.tui.json</a></p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># You can quickly open this file using:</span>
ttkDesigner tutorial/ttkDesigner/textEdit/textEdit.01.tui.json
</pre></div>
</div>
</section>
<section id="add-the-first-buttons-undo-redo-cut-copy-paste">
<h2><a class="toc-backref" href="#id5">Add The first buttons (Undo,redo - Cut,Copy,Paste)</a><a class="headerlink" href="#add-the-first-buttons-undo-redo-cut-copy-paste" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<ul class="simple">
<li><p>Define the <strong>Undo</strong>, <strong>Redo</strong> commands</p></li>
</ul>
<blockquote>
<div><ul class="simple">
<li><p>Drag 2 <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.button.html">buttons</a> inside the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.window.html">window</a> aligning them in the preferred <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkLayouts.gridlayout.html#ttkgridlayout">grid</a> position</p></li>
<li><p>Define the proper button Text (”<strong>Undo</strong>”,”<strong>Redo</strong>”)</p></li>
<li><p>Choose a proper unique name (This step is not mandatory but useful to identify this <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.widget.html">Widget</a>)</p></li>
<li><p>Disable those buttons by default because at the beginning the Text Editor is not going to have any Undo/Redo Buffers (I forgot to add this step in the video)</p></li>
</ul>
</div></blockquote>
<ul class="simple">
<li><p>Define the <strong>Cut</strong>, <strong>Copy</strong>, <strong>Paste</strong> commands</p>
<ul>
<li><p>Well, try to guess…</p></li>
</ul>
</li>
</ul>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455152-4f7440c3-868c-47ce-9c6c-56047b9348ea.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455152-4f7440c3-868c-47ce-9c6c-56047b9348ea.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/textEdit.02.tui.json">textEdit.02.tui.json</a></p>
</section>
<section id="add-the-textedit-widget">
<h2><a class="toc-backref" href="#id6">Add the TextEdit widget</a><a class="headerlink" href="#add-the-textedit-widget" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<ul>
<li><p>Drag the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html">TextEdit</a> aligning it in the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkLayouts.gridlayout.html#ttkgridlayout">grid</a> below any of the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.button.html">buttons</a> previously placed</p></li>
<li><div class="line-block">
<div class="line">Expand the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html">TextEdit</a> widget in order to fill the entire area below the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.button.html">buttons</a></div>
<div class="line">Use the rainbow [🟥🟨🟩🩵🟦🦄] button to help identify the different widgets in the main window</div>
</div>
</li>
<li><div class="line-block">
<div class="line">Force the top grid to a fixed size (3 Chars)</div>
<div class="line">In order to achieve this it is enough to force the MaxSize of any of the buttons in the top row to 3 Chars</div>
</div>
</li>
<li><p>Check the line number, this will show the line number in the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html">TextEdit</a> when used</p></li>
<li><p>Choose a proper unique name (This step is not mandatory but useful to identify this <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.widget.html">Widget</a>)</p></li>
</ul>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455144-dae0cae7-42f0-4db9-983d-cedc980a8dad.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455144-dae0cae7-42f0-4db9-983d-cedc980a8dad.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/textEdit.03.tui.json">textEdit.03.tui.json</a></p>
</section>
<section id="link-the-events-slots-for-the-basic-functionalities">
<h2><a class="toc-backref" href="#id7">Link the Events/Slots for the basic functionalities</a><a class="headerlink" href="#link-the-events-slots-for-the-basic-functionalities" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<ul>
<li><div class="line-block">
<div class="line">Connect the TextEdit <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.undoAvailable">undo</a> / <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.redoAvailable">redo</a> availability signals with the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.widget.html#TermTk.TTkWidgets.widget.TTkWidget.setEnabled">setEnabled</a> slots of the undo/redo buttons</div>
<div class="line">This allow the TextEdit to control directly the availability status of the Buttons</div>
</div>
</li>
<li><p>Connect the undo/redo buttons <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.button.html#TermTk.TTkWidgets.button.TTkButton.clicked">clicked</a> event to the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.undo">undo</a> / <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.redo">redo</a> slots of the TextEditor</p></li>
<li><p>Same for the <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.cut">Cut</a>, <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.copy">Copy</a>, <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.texedit.html#TermTk.TTkWidgets.texedit.TTkTextEdit.paste">Paste</a></p></li>
</ul>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455133-2f13549a-5096-4ae0-87f7-55d419b220dd.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455133-2f13549a-5096-4ae0-87f7-55d419b220dd.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/textEdit.04.tui.json">textEdit.04.tui.json</a></p>
</section>
<section id="add-few-extra-controls-open-save-color">
<h2><a class="toc-backref" href="#id8">Add few extra controls (Open/Save/Color)</a><a class="headerlink" href="#add-few-extra-controls-open-save-color" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<p>I used those emoji as file open/save text 📂 💾</p>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455116-57cfe842-e581-4dc7-ac74-dead0e440793.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455116-57cfe842-e581-4dc7-ac74-dead0e440793.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/textEdit.05.tui.json">textEdit.05.tui.json</a></p>
</section>
<section id="link-the-events-slots-for-the-color-feature">
<h2><a class="toc-backref" href="#id9">Link the Events/Slots for the color feature</a><a class="headerlink" href="#link-the-events-slots-for-the-color-feature" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455110-faac9646-e025-43bd-8833-624b9339db1b.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455110-faac9646-e025-43bd-8833-624b9339db1b.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/textEdit.06.tui.json">textEdit.06.tui.json</a></p>
</section>
<section id="preview-and-quick-export">
<h2><a class="toc-backref" href="#id10">Preview and Quick Export</a><a class="headerlink" href="#preview-and-quick-export" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<video width="800"
src="https://user-images.githubusercontent.com/8876552/236455105-25cd73a3-901f-4b96-a729-0723d9f80a93.mp4"
data-canonical-src="https://user-images.githubusercontent.com/8876552/236455105-25cd73a3-901f-4b96-a729-0723d9f80a93.mp4"
controls="controls" muted="muted" class="d-block rounded-bottom-2 border-top width-fit" ></video><p>Exported: <a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/texteditor.01.py">texteditor.01.py</a>
(<a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/sandbox/sandbox.html?filePath=tutorial/ttkDesigner/textEdit/texteditor.01.py">tryItOnline</a>):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># If you want to try without installation, run from the pyTermTk root folder</span>
<span class="nv">PYTHONPATH</span><span class="o">=</span><span class="sb">`</span><span class="nb">pwd</span><span class="sb">`</span> python3 tutorial/ttkDesigner/textEdit/texteditor.01.py
</pre></div>
</div>
</section>
<section id="import-this-widget-in-your-project">
<h2><a class="toc-backref" href="#id11">Import this widget in your project</a><a class="headerlink" href="#import-this-widget-in-your-project" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h2>
<p>The <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkUiTools.uiloader.html#TermTk.TTkUiTools.uiloader.TTkUiLoader">TTkUiLoader</a> provide different methods to use the content generated by <a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/tree/main/ttkDesigner">ttkDesigner</a></p>
<p>Each method is capable of (1) returning a new <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.widget.html">Widget</a> or (2) extending a custom defined widget</p>
<section id="option-1-include-the-open-save-routine-and-link-them-to-the-widget">
<h3><a class="toc-backref" href="#id12">Option 1) Include the Open/Save routine and link them to the widget</a><a class="headerlink" href="#option-1-include-the-open-save-routine-and-link-them-to-the-widget" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h3>
<p>Once (quick)exported the code, we need to define the appropriate routines and link them to the file(open/save) pickers <a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/autogen.TermTk/TermTk.TTkWidgets.TTkPickers.filepicker.html#TermTk.TTkWidgets.TTkPickers.filepicker.TTkFileButtonPicker.filePicked">signals</a></p>
<p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/texteditor.02.py">texteditor.02.py</a>
(<a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/sandbox/sandbox.html?filePath=tutorial/ttkDesigner/textEdit/texteditor.02.py">tryItOnline</a>):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># If you want to try without installation, run from the pyTermTk root folder</span>
<span class="nv">PYTHONPATH</span><span class="o">=</span><span class="sb">`</span><span class="nb">pwd</span><span class="sb">`</span> python3 tutorial/ttkDesigner/textEdit/texteditor.02.py
</pre></div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Retrieve the widgets we need to use</span>
<span class="n">btnOpen</span> <span class="o">=</span> <span class="n">textEditWindow</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;BtnOpen&quot;</span><span class="p">)</span>
<span class="n">btnSave</span> <span class="o">=</span> <span class="n">textEditWindow</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;BtnSave&quot;</span><span class="p">)</span>
<span class="n">textEdit</span> <span class="o">=</span> <span class="n">textEditWindow</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;TextEdit&quot;</span><span class="p">)</span>


<span class="c1"># This is a generic routine to open/read a file</span>
<span class="c1"># and push the content to the &quot;TextEdit&quot; widget</span>
<span class="n">pyTTkSlot</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">openRoutine</span><span class="p">(</span><span class="n">fileName</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="n">textEdit</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>

<span class="c1"># Connect the open routine to the (open)&quot;filePicked&quot; event</span>
<span class="n">btnOpen</span><span class="o">.</span><span class="n">filePicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">openRoutine</span><span class="p">)</span>


<span class="c1"># This is a generic routine to save the content of</span>
<span class="c1"># the &quot;TextEdit&quot; widget to the chosen file</span>
<span class="n">pyTTkSlot</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">saveRoutine</span><span class="p">(</span><span class="n">fileName</span><span class="p">):</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="n">fp</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">textEdit</span><span class="o">.</span><span class="n">toPlainText</span><span class="p">())</span>

<span class="c1"># Connect the save routine to the (save)&quot;filePicked&quot; event</span>
<span class="n">btnSave</span><span class="o">.</span><span class="n">filePicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">saveRoutine</span><span class="p">)</span>
</pre></div>
</div>
</section>
<section id="option-2-extend-a-custom-widget-including-the-open-save-methods">
<h3><a class="toc-backref" href="#id13">Option 2) Extend a custom widget including the open/save methods</a><a class="headerlink" href="#option-2-extend-a-custom-widget-including-the-open-save-methods" title="Permalink to this heading"><span class="escaped-code-point" data-escaped="[U+F0C1]"><span class="char"></span></span></a></h3>
<p><a class="reference external" href="https://github.com/ceccopierangiolieugenio/pyTermTk/blob/main/tutorial/ttkDesigner/textEdit/texteditor.03.py">texteditor.03.py</a>
(<a class="reference external" href="https://ceccopierangiolieugenio.github.io/pyTermTk/sandbox/sandbox.html?filePath=tutorial/ttkDesigner/textEdit/texteditor.03.py">tryItOnline</a>):</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="c1"># If you want to try without installation, run from the pyTermTk root folder</span>
<span class="nv">PYTHONPATH</span><span class="o">=</span><span class="sb">`</span><span class="nb">pwd</span><span class="sb">`</span> python3 tutorial/ttkDesigner/textEdit/texteditor.03.py
</pre></div>
</div>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">MyTextEditor</span><span class="p">(</span><span class="n">TTkWindow</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="c1"># The &quot;TTkUiLoader&quot; is responsible to init this custom object</span>
<span class="c1"># and extend it to the &quot;textEditWindow&quot; created in this tutorial</span>
<span class="c1"># NOTE: no &quot;super().__init__()&quot; is required</span>
<span class="n">TTkUiLoader</span><span class="o">.</span><span class="n">loadDict</span><span class="p">(</span><span class="n">TTkUtil</span><span class="o">.</span><span class="n">base64_deflate_2_obj</span><span class="p">(</span>
<span class="c1"># &lt;Copy here the Compressed string representing the object&gt;</span>
<span class="p">),</span> <span class="bp">self</span><span class="p">)</span>

<span class="c1"># Connect the open routine to the (open)&quot;filePicked&quot; event</span>
<span class="bp">self</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;BtnOpen&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">filePicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">openRoutine</span><span class="p">)</span>
<span class="c1"># Connect the save routine to the (save)&quot;filePicked&quot; event</span>
<span class="bp">self</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;BtnSave&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">filePicked</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">saveRoutine</span><span class="p">)</span>

<span class="c1"># This is a generic routine to open/read a file</span>
<span class="c1"># and push the content to the &quot;TextEdit&quot; widget</span>
<span class="n">pyTTkSlot</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">openRoutine</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fileName</span><span class="p">):</span>
<span class="n">textEdit</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;TextEdit&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="n">textEdit</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">())</span>

<span class="c1"># This is a generic routine to save the content of</span>
<span class="c1"># the &quot;TextEdit&quot; widget to the chosen file</span>
<span class="n">pyTTkSlot</span><span class="p">(</span><span class="nb">str</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">saveRoutine</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fileName</span><span class="p">):</span>
<span class="n">textEdit</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">getWidgetByName</span><span class="p">(</span><span class="s2">&quot;TextEdit&quot;</span><span class="p">)</span>
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">fileName</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span>
<span class="n">fp</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">textEdit</span><span class="o">.</span><span class="n">toPlainText</span><span class="p">())</span>
</pre></div>
</div>
</section>
</section>
</section>


</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="../../005-calculator.html" class="btn btn-neutral float-left" title="pyTermTk - Your first Calculator" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="../../../info/features/index.html" class="btn btn-neutral float-right" title="Features" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>

<hr/>

<div role="contentinfo">
<p>&#169; Copyright 2021, Eugenio Parodi.</p>
</div>

Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.


</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>

</body>
</html>