Python GUI 選択肢
QRコード隠し(準備編)
画像中からQRコードを見つけて別画像で隠したい件。
もうずっとPython触ってないのでPythonでやりたい。Python3 on WindowsでOpenCVできるようだし。
とりま情報ならべとく
Pythonで画像ファイルからQRコードを読み込む (MacOS) - Qiita
OpenCVでQRコード検出器を書く
QRコードを読み込むならZbarがいいらしいが、今回はQRコードの位置を出したいだけ。
三角の四角見つけて短形で、、、というアプローチがたぶんQRコードの定義的に正解。
あとバリバリOpenCVみたいな感じでてんしょんあがる。
+αでおもしろげな記事も置いておく。あとで読む。
Vue.js
全然一定しない。今日はVue.js。
こちら参照させていただく。
Vue.js資料まとめ
MVVM
View - ViewModel - Model
という構成。ViewModelって何だ!理解して説明する図を描いてみよう!
と思っていたけど最高な図が既に描かれていたので参照。
MVVMフレームワーク vue.js を使ってみた - 水無月の余韻 開発Sc.
データの双方向バインディング
html内に{{データ名}}
と書いておくと、javascript側で作成するvueオブジェクト内のデータとリンクさせる(=バインドする)ことができる。
js側でその値を変更するとブラウザ上の要素ツリーにも反映されて表示が変わる。
逆に要素ツリー側でユーザがそのデータを変更(inputタグ中などだとユーザから変更できるので)すると、js側でもその値が変わる。
これが双方向バインディング。
一度対応関係を定めてしまえば、jsのvueオブジェクト中のデータを操作するだけでViewが操作できる。
いちいち要素ツリーを辿って操作する必要はない。
また、html中の要素には「ここをクリックしたらvueオブジェクトのこのメソッドを呼ぶ」といった定義ができる。
View屋さんとViewModel屋さんの間では、
+ この名前のデータにはこのデータを入れるよ
+ この名前のメソッドにはこの機能を持たせるよ
ということだけ取り決めておけばお互いに好きに作れそう。もし別の人が担当するなら、ですが。
そして更に、ViewModelのメソッドから呼び出す関数としてModel層のビジネスロジックは定義される感じ。
実際にViewModel層のデータを書き換えるのはViewModel層のメソッドからのみ。
そういうことですね!
いいじゃんうまく動きそうじゃん。
jQueryプラグイン使いたい
Vue.jsのView ModelにjQueryプラグインを統合する - Qiita
Auto focus new field (vue@master) - JSFiddle
自分はjQueryプラグインを使ったこと無いのだが、これを使う方針で周りがものを作っている。
なのでVue.jsを調べつつそれにも乗っかる方向。
Djangoに触れてみよう
Djangoに入門するよ
OSはWindows。MinicondaでPython3導入済み。condaで環境分離済み。
conda install django # Djangoインストールして django-admin startproject mysite # Djangoプロジェクト作って cd mysite python manage.py migrate # DBマイグレート?して python manage.py runserver 8080 # サーバ起動
で、http://127.0.0.1:8080/
にアクセスすると「Welcome to Django」
やったぜジャンゴ!
DBマイグレートでSQLite3のファイルdb.sqlite3
ができている。
マイグレートってデータ移行みたいな意味じゃなかったっけ?
Django ドキュメント — Django 1.4 documentation
FAQ: 全般 — Django v1.0 documentation
Model-View-Controllerに対してModel-Template-Viewを主張している。
ユーザに見せるデータはViewが用意し、それをユーザにどう見せるかはTemplateが決めるから、ということらしい。
とりあえずさわりは見たって感じで チュートリアルやっていくかな
D3.jsに触れてみよう(作業メモにつき随時更新するかも
Lighttpd+CGI(Python)+D3.js+jQueryくらいの連携でグラフでっち上げページをローカルに作ってみたい。
目的はD3.jsとAjaxの練習。
D3.jsは定番のようで、記事もいっぱいあって素敵だと思います。
D3.js を使ってみる - Qiita
D3.js をラップするライブラリを使う - Qiita
NVD3かっこいい!
でもとりあえず素のD3.js触ってみよう。
とりあえず必要なものをDL
D3.js - Data-Driven Documents
Download jQuery | jQuery
この2つに関しては以下でもよさ気。ありがたい
<script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> <script src="http://code.jquery.com/jquery-2.2.0.min.js" charset="utf-8"></script>
まだなんもしてないけど眠い。今日はここまで。
WindowsでSelenium+PhantomJS@Pythonでエラー
WindowsのPythonでseleniumしてみたらエラーが出た。
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x00000000023B4CF8>> Traceback (most recent call last): File "D:\Miniconda3\envs\myenv3\lib\site-packages\selenium\webdriver\common\service.py", line 136, in __del__ File "D:\Miniconda3\envs\myenv3\lib\site-packages\selenium\webdriver\common\service.py", line 124, in stop AttributeError: 'NoneType' object has no attribute 'close'
Serviceクラスのstopメソッドでプロセス停止のため(?)のself.process.stdout.close()
が実行されている?
しかしself.process.stdout
がNoneになっている?
部分的に抜粋
def __init__(self, executable, port=0, log_file=PIPE, env=None, start_error_message=""): self.log_file = log_file def start(self): try: self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', stdout=self.log_file, stderr=self.log_file) def stop(self): try: if self.process: self.process.stdout.close()
大丈夫そうに見えるんだがなあ
17.1. subprocess — サブプロセス管理 — Python 2.7.x ドキュメント
この辺に「Windowsのみ~」みたいな文言が散見される。関係あるかも。
バージョン 3.3 で追加. Popen.stdin If the stdin argument was PIPE, this attribute is a writeable stream object as returned by open(). If the universal_newlines argument was True, the stream is a text stream, otherwise it is a byte stream. If the stdin argument was not PIPE, this attribute is None. Popen.stdout If the stdout argument was PIPE, this attribute is a readable stream object as returned by open(). Reading from the stream provides output from the child process. If the universal_newlines argument was True, the stream is a text stream, otherwise it is a byte stream. If the stdout argument was not PIPE, this attribute is None. Popen.stderr If the stderr argument was PIPE, this attribute is a readable stream object as returned by open(). Reading from the stream provides error output from the child process. If the universal_newlines argument was True, the stream is a text stream, otherwise it is a byte stream. If the stderr argument was not PIPE, this attribute is None.
stdoutにPIPEを指定していればNoneにはならない筈...
一旦self.log_fileに入れてるのがまずいのかな?
self.process = subprocess.Popen(cmd, env=self.env, close_fds=platform.system() != 'Windows', - stdout=self.log_file, stderr=self.log_file) + stdout=PIPE, stderr=PIPE)