From 2c93e86aa46f0f6ccb37dfc6c01e1ae9bdf1a371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 3 Apr 2023 17:38:12 +0200 Subject: [PATCH] Enum, Image --- README.md | 16 ++++++++-------- index.html | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2f6c996..3a4bad1 100644 --- a/README.md +++ b/README.md @@ -1328,13 +1328,13 @@ from enum import Enum, auto ```python class (Enum): - = - = , - = auto() + = auto() + = + = , ``` -* **If there are no numeric values before auto(), it returns 1.** -* **Otherwise it returns an increment of the last numeric value.** +* **Function auto() returns an increment of the last numeric value or 1.** * **Accessing a member named after a reserved keyword causes SyntaxError.** +* **Methods receive the member they were called on as the 'self' argument.** ```python = . # Returns a member. @@ -1353,7 +1353,7 @@ class (Enum): ```python def get_next_member(member): - members = list(member.__class__) + members = list(type(member)) index = members.index(member) + 1 return members[index % len(members)] ``` @@ -2754,7 +2754,7 @@ Image ----- ```python # $ pip3 install pillow -from PIL import Image, ImageFilter, ImageEnhance, ImageDraw +from PIL import Image, ImageDraw ``` ```python @@ -2774,7 +2774,6 @@ from PIL import Image, ImageFilter, ImageEnhance, ImageDraw ``` ```python - = .resize((width, height)) # Use .width/height for original sizes. = .filter() # ` = ImageFilter.([])` = .enhance() # ` = ImageEnhance.()` ``` @@ -2820,6 +2819,7 @@ img.show() .rectangle((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). .polygon((x1, y1, x2, y2, ...)) # Last point gets connected to the first. .ellipse((x1, y1, x2, y2)) # To rotate use Image's rotate() and paste(). +.text((x, y), text, font=) # ` = ImageFont.truetype(, size)` ``` * **Use `'fill='` to set the primary color.** * **Use `'width='` to set the width of lines or contours.** diff --git a/index.html b/index.html index 15a57ea..0f58077 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@
- +
@@ -1143,14 +1143,14 @@ Hello World!
class <enum_name>(Enum):
-    <member_name_1> = <value_1>
-    <member_name_2> = <value_2_a>, <value_2_b>
-    <member_name_3> = auto()
+    <member_name> = auto()
+    <member_name> = <value>
+    <member_name> = <value>, <value>
 
    -
  • If there are no numeric values before auto(), it returns 1.
  • -
  • Otherwise it returns an increment of the last numeric value.
  • +
  • Function auto() returns an increment of the last numeric value or 1.
  • Accessing a member named after a reserved keyword causes SyntaxError.
  • +
  • Methods receive the member they were called on as the 'self' argument.
<member> = <enum>.<member_name>           # Returns a member.
 <member> = <enum>['<member_name>']        # Returns a member. Raises KeyError.
@@ -1164,7 +1164,7 @@ Hello World!
 <member> = random.choice(list(<enum>))    # Returns a random member.
 
def get_next_member(member):
-    members = list(member.__class__)
+    members = list(type(member))
     index = members.index(member) + 1
     return members[index % len(members)]
 
@@ -2252,7 +2252,7 @@ right = [[0.1, 0.6

#Image

# $ pip3 install pillow
-from PIL import Image, ImageFilter, ImageEnhance, ImageDraw
+from PIL import Image, ImageDraw
 
<Image> = Image.new('<mode>', (width, height))  # Also `color=<int/tuple/str>`.
@@ -2267,8 +2267,7 @@ right = [[0.1,  0.6# Writes a flattened sequence of pixels.
 <Image>.paste(<Image>, (x, y))                  # Writes passed image to the image.
 
-
<Image> = <Image>.resize((width, height))       # Use <Image>.width/height for original sizes.
-<Image> = <Image>.filter(<Filter>)              # `<Filter> = ImageFilter.<name>([<args>])`
+
<Image> = <Image>.filter(<Filter>)              # `<Filter> = ImageFilter.<name>([<args>])`
 <Image> = <Enhance>.enhance(<float>)            # `<Enhance> = ImageEnhance.<name>(<Image>)`
 
<array> = np.array(<Image>)                     # Creates NumPy array from the image.
@@ -2305,6 +2304,7 @@ img.show()
 <ImageDraw>.rectangle((x1, y1, x2, y2))         # To rotate use Image's rotate() and paste().
 <ImageDraw>.polygon((x1, y1, x2, y2, ...))      # Last point gets connected to the first.
 <ImageDraw>.ellipse((x1, y1, x2, y2))           # To rotate use Image's rotate() and paste().
+<ImageDraw>.text((x, y), text, font=<Font>)     # `<Font> = ImageFont.truetype(<path>, size)`
 
    @@ -2935,7 +2935,7 @@ $ pyinstaller script.py --add-data '<path>:.'