2018年8月26日 星期日

python 3 SWIG on windows 10

For python 3:

/* File : example.c */
 
 #include  <time.h>
 double My_variable = 3.0;
 
 int fact(int n) {
     if (n <= 1) return 1;
     else return n*fact(n-1);
 }
 
 int my_mod(int x, int y) {
     return (x%y);
 }
  
 char *get_time()
 {
     time_t ltime;
     time(&ltime);
     return ctime(&ltime);
 }

Interface file

 /* example.i */
 %module example
 %{
 /* Put header files here or function declarations like below */
 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
 %}
 
 extern double My_variable;
 extern int fact(int n);
 extern int my_mod(int x, int y);
 extern char *get_time();
 

Building a Python module

D:\temp\Documents\Python_call_C\example>swig -python -py3 example.i D:\temp\Documents\Python_call_C\example>gcc -c example.c example_wrap.c -I"D:\Program Files (x86)\Python36-32\include" D:\temp\Documents\Python_call_C\example>gcc -shared example.o example_wrap.o "D:\Program Files (x86)\Python36-32\python36.dll" "C:\Windows\System32\msvcr120.dll" -o _example.pyd
We can now use the Python module:
import example
print(example.fact(5))
print(example.my_mod(7,3))
print(example.get_time())
>>>>>>>>>>>>>>>>>>>>>>
Example Result:
120 1 Sun Aug 26 21:26:01 2018

2018年4月13日 星期五

用SeaMonkey製作WYSIWYG 網頁

1. Launch SeaMonkey
2. Click the third icon "設計師" from left bottom corner

==> Composer is web page editor 

2018年3月5日 星期一

Pygame超新手常中的陷阱

不曉得是Pygame本身的缺陷或bug,Pygame程式執行一段時間,必需要呼叫event一下,否則程式會變成沒有回應的情況,而程式畫面也會暫時停止更新。解決方法,就是確定程式沒互動時,get一下event,但也不是隨時都可以get event,因為當有event要處理時,例如按下滑鼠鍵,不適當處理event的話,可能造成沒處理event,例如可能造成吃鍵現像。一般,如果沒有multi-thread的話,可以在程式sleep前,get event以防止程式沒有回應。
例如,可以用以下delay(second),取代原本的time.sleep(second):

def delay(second):
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()           
    time.sleep(second)

2018年3月4日 星期日

Pyinstaller

If you want to hide the console window, here is the documentation: This is how you use the --noconsole option
python pyinstaller.py --noconsole yourscript.py
==> pyinstaller --noconsole main.py

Create a one-file bundled executable.
==> pyinstaller --noconsole -F main.py

個人合成作品