質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Pythonista

Pythonistaは、iOS上でPythonプログラミングができる開発アプリです。さらに、Pythonの関数・変数などを自動で補完する便利なコードエディタや、PythonスクリプトをiOS上で多様な形で機能させる各種機能も内包しています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

0回答

1474閲覧

pythonista3でSceneViewを重ねた時、背面の画像が表示できない(前面を透過できない)

dice1989

総合スコア2

Pythonista

Pythonistaは、iOS上でPythonプログラミングができる開発アプリです。さらに、Pythonの関数・変数などを自動で補完する便利なコードエディタや、PythonスクリプトをiOS上で多様な形で機能させる各種機能も内包しています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2021/12/02 14:50

編集2021/12/02 16:19

pythonista3で製図アプリを作りたいと思っています。
具体的にはiPad純正メモアプリでできる定規に沿ってペンで直線を描いたりできるアプリです。
デモのSketch.pyと自作した定規を移動させるクラスを合体させて以下のようなプログラムを組みました。SceneViewを背面に移動させることでペンと定規を別々に動作させています。2種類以上の定規を作成した際(SceneViewを2つ以上用意)、背面に移動させたSceneViewの画像が表示できません。前面を透過させたら良いと思うのですがうまくいきません。ご教示いただければ幸いです。

import ui import photos import console from scene import* from scene import * class MainScene (Scene): def setup(self): self.background_color = (256, 256, 256, 0) self.ruler = SpriteNode('画像1.PNG',scale=0.3, alpha = 0.5) self.ruler.anchor_point = (0.5,0.5) self.ruler.position = (self.size.w/2, self.size.h/2) self.add_child(self.ruler) def update(self): pass def touch_began(self, touch): touch_loc = self.point_from_scene(touch.location) if touch_loc in self.ruler.frame: self.ruler.anchor_point = ((touch.location.x-self.ruler.frame.x)/self.ruler.frame.w ,(touch.location.y-self.ruler.frame.y)/self.ruler.frame.h) self.ruler.position = (touch.location.x,touch.location.y) def touch_moved(self, touch): touch_loc = self.point_from_scene(touch.location) if touch_loc in self.ruler.frame: self.ruler.position = (touch.location.x,touch.location.y) def touch_ended(self, touch): pass class rulerScene (Scene): def setup(self): self.background_color = (256, 256, 256, 0) self.ruler = SpriteNode('画像2.PNG',scale=0.3, alpha = 0.5) self.ruler.anchor_point = (0.5,0.5) self.ruler.position = (self.size.w/2, self.size.h/2) self.add_child(self.ruler) def update(self): pass def touch_began(self, touch): touch_loc = self.point_from_scene(touch.location) if touch_loc in self.ruler.frame: self.ruler.anchor_point = ((touch.location.x-self.ruler.frame.x)/self.ruler.frame.w ,(touch.location.y-self.ruler.frame.y)/self.ruler.frame.h) self.ruler.position = (touch.location.x,touch.location.y) def touch_moved(self, touch): touch_loc = self.point_from_scene(touch.location) if touch_loc in self.ruler.frame: self.ruler.position = (touch.location.x,touch.location.y) def touch_ended(self, touch): pass # The PathView class is responsible for tracking # touches and drawing the current stroke. # It is used by SketchView. class PathView (ui.View): def __init__(self, frame): self.frame = frame self.flex = 'WH' self.path = None self.action = None def touch_began(self, touch): x, y = touch.location self.path = ui.Path() self.path.line_width = 4.0 self.path.line_join_style = ui.LINE_JOIN_ROUND self.path.line_cap_style = ui.LINE_CAP_ROUND self.path.move_to(x, y) def touch_moved(self, touch): x, y = touch.location self.path.line_to(x, y) self.set_needs_display() def touch_ended(self, touch): # Send the current path to the SketchView: if callable(self.action): self.action(self) # Clear the view (the path has now been rendered # into the SketchView's image view): self.path = None self.set_needs_display() def draw(self): if self.path: self.path.stroke() # The main SketchView contains a PathView for the current # line and an ImageView for rendering completed strokes. # It also manages the 'Clear' and 'Save' ButtonItems that # are shown in the title bar. class SketchView (ui.View): def __init__(self, width=1024, height=1024): self.bg_color = (256,256,256,0) self.iv = ui.ImageView(frame=(0, 0, width, height)) self.pv = PathView(frame=self.bounds) self.pv.action = self.path_action self.ruler_sv = SceneView(frame=(0,0,width,height)) self.ruler_sv.scene = rulerScene() self.m_sv = SceneView(frame=(0,0,width,height)) self.m_sv.scene = MainScene() self.add_subview(self.m_sv) self.add_subview(self.ruler_sv) self.add_subview(self.iv) self.add_subview(self.pv) m_button = ui.ButtonItem() m_button.title = 'm' m_button.action = self.m_action ruler_button = ui.ButtonItem() ruler_button.title = 'Ruler' ruler_button.action = self.ruler_action pen_button = ui.ButtonItem() pen_button.title = 'Pen' pen_button.action = self.pen_action save_button = ui.ButtonItem() save_button.title = 'Save Image' save_button.action = self.save_action clear_button = ui.ButtonItem() clear_button.title = 'Clear' clear_button.tint_color = 'red' clear_button.action = self.clear_action self.right_button_items = [save_button, clear_button, ruler_button, pen_button, m_button] self.image_view = self.iv def m_action(self,sender): self.ruler_sv.send_to_back() self.pv.send_to_back() def pen_action(self,sender): self.ruler_sv.send_to_back() self.m_sv.send_to_back() def ruler_action(self,sender): self.pv.send_to_back() self.m_sv.send_to_back() def path_action(self, sender): path = sender.path old_img = self.image_view.image width, height = self.image_view.width, self.image_view.height with ui.ImageContext(width, height) as ctx: if old_img: old_img.draw() path.stroke() self.image_view.image = ctx.get_image() def clear_action(self, sender): self.image_view.image = None def save_action(self, sender): if self.image_view.image: # We draw a new image here, so that it has the current # orientation (the canvas is quadratic). with ui.ImageContext(self.width, self.height) as ctx: self.image_view.image.draw() img = ctx.get_image() photos.save_image(img) console.hud_alert('Saved') else: console.hud_alert('No Image', 'error') # We use a square canvas, so that the same image # can be used in portrait and landscape orientation. w, h = ui.get_screen_size() canvas_size = max(w, h) sv = SketchView(canvas_size, canvas_size) sv.name = 'Sketch' sv.present('fullscreen')

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問