From fb9b326e1877831af6bffcd79138baf161965ed8 Mon Sep 17 00:00:00 2001 From: igo95862 Date: Sun, 25 Apr 2021 22:14:12 +0300 Subject: [PATCH] python: Updated examples to use new code --- python/examples/000-print-version.py | 4 ++-- python/examples/001-init-notcurses.py | 4 ++-- python/examples/002-hello-world.py | 12 +++++++----- python/examples/003-color-example.py | 27 +++++++++++++++------------ python/examples/004-dimensions.py | 16 +++++++++------- python/examples/007-plane_split.py | 26 +++++++++++++++++--------- python/examples/008-put-lines.py | 11 ++++++----- 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/python/examples/000-print-version.py b/python/examples/000-print-version.py index 1946c55b7..0e0ec5dac 100644 --- a/python/examples/000-print-version.py +++ b/python/examples/000-print-version.py @@ -13,6 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from notcurses import get_notcurses_version +from notcurses import notcurses_version -print(get_notcurses_version()) +print(notcurses_version()) diff --git a/python/examples/001-init-notcurses.py b/python/examples/001-init-notcurses.py index 8173caf04..b01e20652 100644 --- a/python/examples/001-init-notcurses.py +++ b/python/examples/001-init-notcurses.py @@ -15,8 +15,8 @@ # limitations under the License. from time import sleep -from notcurses import get_std_plane +from notcurses import Notcurses -std_plane = get_std_plane() +Notcurses() sleep(1) diff --git a/python/examples/002-hello-world.py b/python/examples/002-hello-world.py index ee52d4c3a..802d6cde2 100644 --- a/python/examples/002-hello-world.py +++ b/python/examples/002-hello-world.py @@ -16,11 +16,13 @@ from time import sleep -from notcurses import get_std_plane +from notcurses import Notcurses -std_plane = get_std_plane() -std_plane.putstr("Hello, World!") +nc = Notcurses() -std_plane.context.render() +stdplane = nc.stdplane() +stdplane.putstr("Hello, World!") -sleep(5) +nc.render() + +sleep(3) diff --git a/python/examples/003-color-example.py b/python/examples/003-color-example.py index 7f81552f6..7ddaa2501 100644 --- a/python/examples/003-color-example.py +++ b/python/examples/003-color-example.py @@ -16,21 +16,24 @@ from time import sleep -from notcurses import get_std_plane +from notcurses import Notcurses -std_plane = get_std_plane() -std_plane.set_background_rgb(0, 0, 255) -std_plane.set_foreground_rgb(255, 0, 0) -std_plane.putstr("Red on blue", y_pos=0) -std_plane.set_background_rgb(0, 255, 0) -std_plane.set_foreground_rgb(255, 255, 255) -std_plane.putstr("White on green", y_pos=1, x_pos=0) +nc = Notcurses() -std_plane.set_background_rgb(0, 0, 0) -std_plane.set_foreground_rgb(255, 0, 255) -std_plane.putstr("Purple on black", y_pos=2, x_pos=0) +stdplane = nc.stdplane() +stdplane.set_bg_rgb8_clipped(0, 0, 255) +stdplane.set_fg_rgb8_clipped(255, 0, 0) +stdplane.putstr_yx(0, 0, "Red on blue") -std_plane.context.render() +stdplane.set_bg_rgb8(0, 255, 0) +stdplane.set_fg_rgb8(255, 255, 255) +stdplane.putstr_yx(1, 0, "White on green") + +stdplane.set_bg_rgb8(0, 0, 0) +stdplane.set_fg_rgb8(255, 0, 255) +stdplane.putstr_yx(2, 0, "Purple on black") + +nc.render() sleep(5) diff --git a/python/examples/004-dimensions.py b/python/examples/004-dimensions.py index 2074ecd1a..5748ada33 100644 --- a/python/examples/004-dimensions.py +++ b/python/examples/004-dimensions.py @@ -15,21 +15,23 @@ # limitations under the License. from time import sleep -from notcurses import get_std_plane +from notcurses import Notcurses -std_plane = get_std_plane() +nc = Notcurses() + +stdplane = nc.stdplane() red = 0x80 green = 0x80 blue = 0x80 -y_dimension, x_dimension = std_plane.dimensions_yx +y_dimension, x_dimension = stdplane.dim_yx() for y in range(y_dimension): for x in range(x_dimension): - std_plane.set_foreground_rgb(red, green, blue) - std_plane.set_background_rgb(blue, red, green) - std_plane.putstr('X', y_pos=y, x_pos=x) + stdplane.set_fg_rgb8(red, green, blue) + stdplane.set_bg_rgb8(blue, red, green) + stdplane.putstr_yx(y, x, 'X') blue += 2 if blue == 256: blue = 0 @@ -39,6 +41,6 @@ for y in range(y_dimension): red = (red + 2) % 256 -std_plane.context.render() +nc.render() sleep(5) diff --git a/python/examples/007-plane_split.py b/python/examples/007-plane_split.py index 0d7457ec3..7d04c2999 100644 --- a/python/examples/007-plane_split.py +++ b/python/examples/007-plane_split.py @@ -17,21 +17,29 @@ from time import sleep -from notcurses import get_std_plane +from notcurses import Notcurses -std_plane = get_std_plane() +nc = Notcurses() -sub_plane_left = std_plane.create_sub_plane() +stdplane = nc.stdplane() -sub_plane_right = std_plane.create_sub_plane( - x_pos=(std_plane.dimensions_yx[1] // 2)) +sub_plane_left = stdplane.create( + rows=5, + cols=5, +) -sub_plane_left.set_foreground_rgb(0, 255, 0) +sub_plane_right = stdplane.create( + x_pos=(stdplane.dim_x() // 2), + rows=5, + cols=5, +) + +sub_plane_left.set_fg_rgb8(0, 255, 0) sub_plane_left.putstr("Left") -sub_plane_right.set_foreground_rgb(255, 0, 0) +sub_plane_right.set_fg_rgb8(255, 0, 0) sub_plane_right.putstr("Right") -std_plane.context.render() +nc.render() -sleep(4) +sleep(3) diff --git a/python/examples/008-put-lines.py b/python/examples/008-put-lines.py index 5f1ea8b29..9e0bc10aa 100644 --- a/python/examples/008-put-lines.py +++ b/python/examples/008-put-lines.py @@ -17,8 +17,11 @@ from time import sleep -from notcurses import get_std_plane +from notcurses import Notcurses +nc = Notcurses() + +stdplane = nc.stdplane() test_str = '''Sapiente quaerat expedita repellendus ea quae. Ut enim natus iure laborum. Assumenda sed placeat provident similique cum quidem. Sit voluptas facilis vitae culpa asperiores eos neque. Aspernatur rerum quae minus natus. Vero autem suscipit nisi eligendi dolorum sed vero. Illum odio repudiandae odit in voluptas reiciendis amet. @@ -27,10 +30,8 @@ Laboriosam expedita ut enim velit occaecati qui neque. Et voluptatem eligendi ha Dolores quaerat sint dolorum. Corrupti temporibus nam corrupti. Iusto non perspiciatis et quisquam minima nesciunt quia esse. ''' -std_plane = get_std_plane() - -std_plane.put_lines(test_str.splitlines(), wrap_lines=True) +wr = stdplane.puttext(-1, 0, test_str) -std_plane.context.render() +nc.render() sleep(3)