前提
ラズパイ3でrpi-led-matrixのサンプルを改造して電光掲示板を動作させています。
他ファイルから以下ファイルのクラスを動作させることができず困っています。
selfといった仕組みが理解できていません。よろしくお願いいたします。
該当のソースコード
実行される側:runtext.py
Python
1#!/usr/bin/env python 2# Display a runtext with double-buffering. 3from samplebase import SampleBase 4from rgbmatrix import graphics 5import datetime 6import time 7 8print("test") 9 10class RunText(SampleBase): 11 def __init__(self, *args, **kwargs): 12 dt_now = datetime.datetime.now() 13 super(RunText, self).__init__(*args, **kwargs) 14 self.parser.add_argument("-t", "--text", help="The text to scroll on the RGB LED panel", default= dt_now.strftime('%H:%M')) 15 16 17 def run(self): 18 offscreen_canvas = self.matrix.CreateFrameCanvas() 19 font = graphics.Font() 20 font.LoadFont("../../../fonts/myfont.bdf") 21 textColor = graphics.Color(255, 255, 0) 22 pos = offscreen_canvas.width 23 my_text = self.args.text 24 25 #10秒経過で終了 26 t_end = time.time() + 10 27 28 while time.time() < t_end: 29 offscreen_canvas.Clear() 30 len = graphics.DrawText(offscreen_canvas, font, pos, 14, textColor, my_text) 31 32 pos -= 1 33 if (pos + len < 0): 34 pos = offscreen_canvas.width 35 36 time.sleep(0.05) 37 offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas) 38 39 40# Main function 41if __name__ == "__main__": 42 run_text = RunText() 43 if (not run_text.process()): 44 run_text.print_help() 45
実行する側:test.py
Python
1import runtext
試したこと
- ファイル単体での実行→class内が問題なく動作し電光掲示板に文字が流れる。print("test")も実行される
- ファイルを別ファイルから呼び出す→print("test")のみ実行されclassは無視される
↓ここからはよく理解できず試したものになります
- # Main functionを全て消す→単体でも動作しなくなる
- # 権限をchmodで拡大→変化なし
- # runtext = runtext.Runtext()をtext.pyに追加→AttributeError: module 'runtext' has no attribute 'Runtext'でエラー
補足情報(FW/ツールのバージョンなど)
環境:mac、raspberry pi3

回答2件
あなたの回答
tips
プレビュー