2013年7月5日金曜日

Solaris11のemacsをカラフルにする

Solaris11のemacsに色がほしい

 Windowsの使えない僕にはSolarisが与えられたのですが、肝心のemacsがこの状態


 白黒で味気ない、これではphpが書けないではないですか!なので色をつけてみた。

emacsに色をつけるのはこれだけ


.bach_profileへ1行追加するだけ
alias emacs='emacs --color -nw'
で起動するとぉ....ほぉーら


これならPHPが書けるような気がしてきた。

2013年7月4日木曜日

WTFormsで動的にフォームを作成する

WTFromsで動的にフォームを作成

色々試行錯誤して何とか動的にフォームを作成できたので、その時の備忘録てきなメモ。
説明とか面倒なのでコードを記載します

ソースコード

クロージャーで書いてるところがミソで、CreateForm()からどんどん追加していくだけ。
IichikoFormCreateクラスへパラメータを渡して、それを利用して色々ゴニョゴニョ設定にそってフォームを作成可能。
と言うことを伝えたいだけです。
# -*- coding: utf-8 -*-

from ReadSomeSetting import ReadSomeSetting
from wtforms import Form, BooleanField, TextField, validators, SelectField, TextAreaField


name_validates = [
    validators.Required(message=u"入力してください"),
    validators.Length(max=10, message=u"10文字以内で入力してください"),
]


class IichikoFormCreater(object):
    def __init__(self, param=None):
        super(IichikoFormCreater, self).__init__()
        self.param = param

    def CreateForm(self, form):
        ''' form class definition'''
        class IichikoForm(Form):
            pass

        def _createKicchomuField():
            setattr(IichikoForm, 'kicchomu',
                    BooleanField(u'吉四六', default=False))

        '''
            例えばDBから設定値を読み込み、それにそってFormを作成したりどうなの?
        '''
        rs = ReadSomeSetting()
        self.val = rs.GetSettings(self.param)

        IichikoForm.name = TextField(u'なまえ', name_validates)
        IichikoForm.kosa   = SelectField(u'アルコール濃度', None,
                                         choices=[(0, u'-----'),
                                                  (1, u'20度'),
                                                  (2, u'25度')], coerce=int, default=1)
        if self.val['iichiko_com'] is True:
            IichikoForm.comment = TextAreaField(u'いいちこコメント')

        _createKicchomuField()
        return IichikoForm(form)
ニセ、設定読み込みクラス
# -*- coding: utf-8 -*-


class ReadSomeSetting(object):
    def __init__(self):
        super(ReadSomeSetting, self).__init__()

    def GetSettings(self, param=None):
        # Do someting
        return dict(iichiko_com=True)

flaskで使ってみる


出来たと動くか?と言われたら動かしてみないとわからなのでflaskで動かしてみる、ファイル配置は以下のとおり。

└── iichiko
    ├── forms
    │   ├── IichikoFormCreater.py
    │   ├── ReadSomeSetting.py
    │   └── __init__.py
    ├── iichiko.py
    ├── iichiko.wsgi
    ├── static
    │   ├── script.js
    │   └── style.css
    └── templates
        ├── complete.html
        ├── index.html
        └── layout.html
# -*- coding: utf-8 -*-

from flask import Flask, render_template, request
from forms.IichikoFormCreater import IichikoFormCreater


app = Flask(__name__)

app.debug = True


@app.route("/", methods=['GET', 'POST'])
def index():
    ii = IichikoFormCreater()
    form = ii.CreateForm(request.form)
    if request.method == 'POST' and form.validate():
        return render_template("complete.html", title=u"たまんない")
    else:
        return render_template("index.html", title=u"いいちこフォーム", form=form)

if __name__ == '__main__':
    app.run()

こんな感じです

バリデーションも動いてます、ちょっと上手くいかなかったのがDjangoのCheckboxSelectMultiple的なものが無いかと調べてはみたもののいまいちでした。WTFormsだとCheckboxSelectMultipleとかでやるのか?ちょっと調べてみます。



2013年6月29日土曜日

direx.elが素晴らしい

direx.elをいれてみた 

emacsのdiredで不自由していなかったのですが、ちょっとeclipse的なファイラーのようなものが無いものかと探してみましたところなかなか素晴らしいdired.elを見つけてしまい静岡のみんなが欲しがる僕のGentooへいれてみました。

インストール

popwinパッケージを先にインストールしておく
karky7 ~ # emerge -pv app-emacs/popwin

 * IMPORTANT: config file '/etc/portage/package.keywords' needs updating.
 * See the CONFIGURATION FILES section of the emerge
 * man page to learn how to update config files.

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ~] app-emacs/popwin-0.5.1  0 kB

Total: 1 package (1 reinstall), Size of downloads: 0 kB

 * IMPORTANT: 1 news items need reading for repository 'hacking-gentoo'.
 * IMPORTANT: 13 news items need reading for repository 'gentoo'.
 * Use eselect news to read news items.
karky7 ~ #
karky7 ~ # emerge app-emacs/popwin

direx.elを設置

ここからdirex.elをダウンロードしパスの通っている場所へ設置する

init.elへ追加


;; direx-el
;; (use popwin-el devloper ver.)
;; https://github.com/m2ym/direx-el
(require 'popwin)
(setq display-buffer-function 'popwin:display-buffer)

(require 'direx)
(setq direx:leaf-icon "  "
      direx:open-icon "- "
      direx:closed-icon "+ ")
(push '(direx:direx-mode :position left :width 40 :dedicated t)
      popwin:special-display-config)
(global-set-key (kbd "C-x C-j") 'direx:jump-to-directory-other-window)

使い方

ほぼDiredと同じ使い方で非常に編集しやすくなりました、C-x C-jでファイラーが左へpopupします、こんな感じです

n,        C-n,<down>       direx:next-node              次のノードを選択する
p,        C-p,<up>         direx:previous-node          前のノードを選択する
C-M-n,    C-M-<down>       direx:next-sibling           次の兄弟ノードを選択する
C-M-p,    C-M-<up>         direx:previous-sibling       前の兄弟ノードを選択する
^, C-M-u, C-M-<left>       direx:up-node                親ノードを選択する
C-M-d,    C-M-<right>      direx:down-node              最初の子ノードを選択する
f                          direx:find-node              そのノードを現在のウィンドウに開く
o                          direx:find-node-other-window そのノードを別のウィンドウに開く
RET                        direx:maybe-find-node        そのノードをトグルする
q                          quit-window                  ウィンドウを閉じる

ターミナルを有効活用出きるようになりました、また、emacs環境が具合よくなったきがすします

参考URL