Skip to content

Commit

Permalink
Ran hatch fmt (provides addnl rules for ruff)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Fleming committed Jan 29, 2024
1 parent 33671dd commit a7a0c3d
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 126 deletions.
24 changes: 15 additions & 9 deletions examples/autostart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@
"metadata": {},
"outputs": [],
"source": [
"# @my_module.autostart.py \n",
"# @my_module.autostart.py\n",
"\n",
"import pluggy\n",
"import asyncio\n",
"\n",
"import ipylab\n",
"\n",
"app = ipylab.JupyterFrontEnd()\n",
"\n",
"\n",
"def create_app():\n",
" # Ensure this function provides all the imports.\n",
" import ipylab\n",
" import ipywidgets as ipw\n",
" \n",
"\n",
" import ipylab\n",
"\n",
" ma = ipylab.MainArea(name=\"My demo app\")\n",
" console_button = ipw.Button(description=\"Toggle console\")\n",
" console_button.on_click(\n",
Expand All @@ -62,22 +65,25 @@
" console_button,\n",
" ]\n",
" ma.load()\n",
" print('Finshed creating my app')\n",
" print(\"Finshed creating my app\")\n",
"\n",
" # Retun ma so it doesn't accidentally get garbage collected.\n",
" return ma \n",
" return ma\n",
"\n",
"\n",
"async def load_app_async():\n",
" session = await app.newNotebook(path='my app')\n",
" kernelId = session['kernel']['id']\n",
" session = await app.newNotebook(path=\"my app\")\n",
" kernelId = session[\"kernel\"][\"id\"]\n",
" await app.injectCode(kernelId, create_app)\n",
" print(\"Done\")\n",
"\n",
"\n",
"class MyPlugins:\n",
" @ipylab.hookspecs.hookimpl()\n",
" def run_once_at_startup(self):\n",
" asyncio.create_task(load_app_async())\n",
" \n",
"\n",
"\n",
"MyPlugins()"
]
},
Expand Down
36 changes: 23 additions & 13 deletions examples/commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
"metadata": {},
"outputs": [],
"source": [
"import ipylab\n",
"import ipywidgets as ipw\n",
"\n",
"import ipylab\n",
"\n",
"app = ipylab.JupyterFrontEnd()"
]
},
Expand Down Expand Up @@ -77,7 +78,7 @@
" \"console:create\",\n",
" insertMode=\"split-right\",\n",
" kernelPreference={\"id\": app.kernelId},\n",
" transform={\"mode\": ipylab.TransformMode.attribute, \"parts\": [\"id\"]}, #optional\n",
" transform={\"mode\": ipylab.TransformMode.attribute, \"parts\": [\"id\"]}, # optional\n",
")"
]
},
Expand All @@ -103,7 +104,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.commands.execute('apputils:change-theme', theme = 'JupyterLab Dark')"
"app.commands.execute(\"apputils:change-theme\", theme=\"JupyterLab Dark\")"
]
},
{
Expand All @@ -112,7 +113,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.commands.execute('apputils:change-theme', theme = 'JupyterLab Light')"
"t = app.commands.execute(\"apputils:change-theme\", theme=\"JupyterLab Light\")"
]
},
{
Expand All @@ -137,7 +138,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.commands.execute('terminal:create-new')\n",
"app.commands.execute(\"terminal:create-new\")\n",
"# It can take up to 10 seconds for the terminal to show up after the cell returns."
]
},
Expand All @@ -156,7 +157,9 @@
"metadata": {},
"outputs": [],
"source": [
"split_panel = ipylab.SplitPanel(children = [ipw.Button(description=\"Item A\"), ipw.Button(description=\"Item B\")])\n",
"split_panel = ipylab.SplitPanel(\n",
" children=[ipw.Button(description=\"Item A\"), ipw.Button(description=\"Item B\")]\n",
")\n",
"split_panel.addToShell()"
]
},
Expand All @@ -174,7 +177,9 @@
"outputs": [],
"source": [
"def toggle_orientation():\n",
" split_panel.orientation = list({'horizontal', 'vertical'}.difference((split_panel.orientation,)))[0]\n",
" split_panel.orientation = list(\n",
" {\"horizontal\", \"vertical\"}.difference((split_panel.orientation,))\n",
" )[0]\n",
" split_panel.title.label = split_panel.orientation\n",
" return \"Data returned from this custom function 'toggle_orientation'\""
]
Expand Down Expand Up @@ -203,7 +208,12 @@
"metadata": {},
"outputs": [],
"source": [
"app.commands.addPythonCommand('swap_orientation', execute=toggle_orientation, label=\"Swap orientation\", icon_class=\"jp-PythonIcon\")"
"app.commands.addPythonCommand(\n",
" \"swap_orientation\",\n",
" execute=toggle_orientation,\n",
" label=\"Swap orientation\",\n",
" icon_class=\"jp-PythonIcon\",\n",
")"
]
},
{
Expand All @@ -219,7 +229,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.commands.execute('swap_orientation')"
"t = app.commands.execute(\"swap_orientation\")"
]
},
{
Expand Down Expand Up @@ -260,7 +270,7 @@
"metadata": {},
"outputs": [],
"source": [
"assert 'swap_orientation' in app.commands.commands"
"assert \"swap_orientation\" in app.commands.commands"
]
},
{
Expand All @@ -283,7 +293,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.command_pallet.add_item('swap_orientation', 'Python Commands')"
"t = app.command_pallet.add_item(\"swap_orientation\", \"Python Commands\")"
]
},
{
Expand Down Expand Up @@ -317,7 +327,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.commands.remove_command('swap_orientation')"
"app.commands.remove_command(\"swap_orientation\")"
]
},
{
Expand All @@ -326,7 +336,7 @@
"metadata": {},
"outputs": [],
"source": [
"assert 'swap_orientation' not in app.commands.commands"
"assert \"swap_orientation\" not in app.commands.commands"
]
}
],
Expand Down
16 changes: 10 additions & 6 deletions examples/icons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
},
"outputs": [],
"source": [
"import ipylab\n",
"import json\n",
"\n",
"import ipywidgets as ipw\n",
"import traitlets\n",
"import json"
"\n",
"import ipylab"
]
},
{
Expand Down Expand Up @@ -116,7 +118,9 @@
"background = ipw.SelectionSlider(description=\"background\", options=options)\n",
"foreground = ipw.SelectionSlider(description=\"foreground\", options=options)\n",
"\n",
"repaint = lambda: SVG.replace(\"jp-icon3\", background.value).replace(\"jp-contrast0\", foreground.value)\n",
"repaint = lambda: SVG.replace(\"jp-icon3\", background.value).replace(\n",
" \"jp-contrast0\", foreground.value\n",
")\n",
"\n",
"traitlets.dlink((background, \"value\"), (icon, \"svgstr\"), lambda x: SVG.replace(\"jp-icon3\", x))\n",
"traitlets.dlink((foreground, \"value\"), (icon, \"svgstr\"), lambda x: SVG.replace(\"jp-contrast0\", x))\n",
Expand Down Expand Up @@ -171,11 +175,10 @@
},
"outputs": [],
"source": [
"\n",
"\n",
"def noop(value):\n",
" return value\n",
"\n",
"\n",
"def as_json(value):\n",
" try:\n",
" return json.loads(value)\n",
Expand All @@ -188,7 +191,7 @@
" link_fn = noop\n",
" placeholder = \"\"\n",
" if field_name == \"dataset\":\n",
" placeholder = \"{}\" \n",
" placeholder = \"{}\"\n",
" link_fn = as_json\n",
" field = ipw.Text(description=field_name, placeholder=placeholder)\n",
" traitlets.dlink((field, \"value\"), (panel.title, field_name), link_fn)\n",
Expand Down Expand Up @@ -221,6 +224,7 @@
"import asyncio\n",
"import random\n",
"\n",
"\n",
"async def randomize_icon(count=10):\n",
" for i in range(count):\n",
" background.value = random.choice(options)\n",
Expand Down
44 changes: 21 additions & 23 deletions examples/ipytree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"outputs": [],
"source": [
"import os\n",
"\n",
"from pathlib import PurePath"
]
},
Expand All @@ -57,7 +56,7 @@
" \"lib\",\n",
" \"node_modules\",\n",
" \"__pycache__\",\n",
" \".ipynb_checkpoints\"\n",
" \".ipynb_checkpoints\",\n",
"}"
]
},
Expand All @@ -74,7 +73,7 @@
"metadata": {},
"outputs": [],
"source": [
"def collect_files(root_path='..'):\n",
"def collect_files(root_path=\"..\"):\n",
" files = []\n",
" for dirpath, dirnames, filenames in os.walk(root_path, followlinks=True):\n",
" dirnames[:] = [d for d in dirnames if d not in EXCLUDES]\n",
Expand Down Expand Up @@ -190,13 +189,13 @@
" if len(children) == 0:\n",
" leaf = TreeNode(name)\n",
" leaf.fullpath = os.path.join(*fullpath)\n",
" leaf.icon = 'file'\n",
" leaf.icon_style = 'warning'\n",
" leaf.icon = \"file\"\n",
" leaf.icon_style = \"warning\"\n",
" node.add_node(leaf)\n",
" else:\n",
" subtree = create_tree_widget(children, fullpath, depth + 1)\n",
" subtree.icon = 'folder'\n",
" subtree.icon_style = 'info'\n",
" subtree.icon = \"folder\"\n",
" subtree.icon_style = \"info\"\n",
" subtree.name = name\n",
" node.add_node(subtree)\n",
" return node"
Expand Down Expand Up @@ -273,16 +272,12 @@
"metadata": {},
"outputs": [],
"source": [
"from ipywidgets import Button, Layout, HBox\n",
"from ipywidgets import Button, HBox, Layout\n",
"\n",
"open_button = Button(description='Open', button_style='success', icon='folder')\n",
"expand_button = Button(description='Expand', button_style='info', icon='chevron-down')\n",
"collapse_button = Button(description='Collapse', button_style='info', icon='chevron-right')\n",
"hbox = HBox([\n",
" open_button,\n",
" expand_button,\n",
" collapse_button\n",
"], layout=Layout(overflow='unset'))\n",
"open_button = Button(description=\"Open\", button_style=\"success\", icon=\"folder\")\n",
"expand_button = Button(description=\"Expand\", button_style=\"info\", icon=\"chevron-down\")\n",
"collapse_button = Button(description=\"Collapse\", button_style=\"info\", icon=\"chevron-right\")\n",
"hbox = HBox([open_button, expand_button, collapse_button], layout=Layout(overflow=\"unset\"))\n",
"hbox"
]
},
Expand All @@ -303,13 +298,15 @@
" for node in tree.nodes:\n",
" node.opened = expand\n",
"\n",
"\n",
"def on_expand_click(b):\n",
" expand_tree(file_tree)\n",
"\n",
" \n",
"\n",
"def on_collapse_click(b):\n",
" expand_tree(file_tree, False)\n",
"\n",
"\n",
"expand_button.on_click(on_expand_click)\n",
"collapse_button.on_click(on_collapse_click)"
]
Expand All @@ -331,7 +328,8 @@
" for node in file_tree.selected_nodes:\n",
" filepath = node.fullpath\n",
" if filepath:\n",
" app.commands.execute('docmanager:open', { 'path': filepath})\n",
" app.commands.execute(\"docmanager:open\", {\"path\": filepath})\n",
"\n",
"\n",
"open_button.on_click(on_open_clicked)"
]
Expand All @@ -350,7 +348,7 @@
"outputs": [],
"source": [
"expand_tree(file_tree, False)\n",
"file_tree.layout = Layout(overflow='auto')"
"file_tree.layout = Layout(overflow=\"auto\")"
]
},
{
Expand All @@ -369,9 +367,9 @@
"from ipylab import Panel\n",
"\n",
"panel = Panel(children=[hbox, file_tree])\n",
"panel.title.label = 'File Browser'\n",
"panel.title.icon_class = 'jp-FileIcon'\n",
"panel.layout = Layout(overflow='auto')"
"panel.title.label = \"File Browser\"\n",
"panel.title.icon_class = \"jp-FileIcon\"\n",
"panel.layout = Layout(overflow=\"auto\")"
]
},
{
Expand All @@ -387,7 +385,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.shell.add(panel, 'left', {'rank': 10000})"
"app.shell.add(panel, \"left\", {\"rank\": 10000})"
]
},
{
Expand Down
Loading

0 comments on commit a7a0c3d

Please sign in to comment.