This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import py5 | |
import PySimpleGUI as sg | |
bg = True | |
values = {'-Text-': '', '-Hue-': 0, '-BG-': False} | |
def setup(): | |
global window | |
py5.size(600, 600) | |
py5.color_mode(py5.HSB) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from urllib.request import Request, urlopen | |
# I used the publish feature from a Google Spreadsheet | |
url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vT7etkg--Axh_CJlmZdlJ3rrE71rZ10kNQpbqUr8rcPL8WLNepgaIJMN6ZbUHbscjBv014rjaB9Qkwy/pub?gid=0&single=true&output=csv" # change to your own! | |
response = urlopen(Request(url)) | |
content = response.read().decode('utf-8') | |
data = csv.DictReader(content.splitlines()) | |
cols = data.fieldnames |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PIL.Image | |
import io | |
def image_as_png_bytes(file_path, resize=None): | |
""" | |
Open an image file and convert it into PNG formated bytes, resize optional. | |
Return tuple (bytes, <dict from PIL.Image.info>) | |
""" | |
img = PIL.Image.open(file_path) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# py5coding.org imported mode | |
particulas = [] | |
def setup(): | |
size(900, 900) | |
background(0) | |
color_mode(HSB) | |
# for _ in range(100): | |
# p = Particula(width / 2, height / 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Executa os testes no arquivo de documentaçao `demo_doctest.txt` | |
# Note que lá tem um `import` do módulo a ser testado no começo | |
import doctest | |
print('início dos testes') | |
doctest.testfile("demo_doctest.txt") | |
print('terminou') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
import tkinter.ttk as ttk | |
from tkinter import filedialog | |
root = tk.Tk() | |
style = ttk.Style(root) | |
style.theme_use("clam") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
# Requires pdfrw2 - https://pypi.org/project/pdfrw2/ | |
from pdfrw import PdfReader, PdfWriter, PdfDict, PdfName, PageMerge | |
def write_side_by_side(input_a, input_b, output_file): | |
""" | |
Write to the output file a PDF with the combined contents of 2 | |
input files. Each page gets 2 pages from each of the input files, | |
scaled down by a factor of 0.5, side by side in a 4 pages up layout. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using Paul McGuire's littletable https://pypi.org/project/littletable/ | |
# Needs py5 imported mode https://py5.ixora.io for drawing | |
import csv | |
import littletable as lt | |
# Reading a CSV from a GitHub repo, but it can be used | |
# to read from a Google Spreadsheet if you use the 'publish' feature | |
url = "https://raw.githubusercontent.com/villares/Resources-for-teaching-programming/main/II%20-%20Books%20%26%20References.csv" # change to your own! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I'm counting now on a JPype enviroment provided by importing py5 (so I can use javax.swing pane) | |
# see the previous revision if you don't want that! | |
def get_arduino(port=None): | |
""" | |
This is a PyFirmata 'helper' that tries to connect to an Arduino | |
compatible board. | |
If no port is informed, using pyserial's serial.tools.list_ports.comports(), | |
if one port is found, tries that one. If more than one port is found, |