pretty code

顯示具有 wxWidgets 標籤的文章。 顯示所有文章
顯示具有 wxWidgets 標籤的文章。 顯示所有文章

2020年12月17日 星期四

使用 wxWidgets 開發剪貼簿相關工具解決閱讀技術文件痛點

最近一直在閱讀技術文件,這份文件需要搭配某個實體服務,參照它服務裡面各個連結的相關資訊,才能有助於理解此份技術文件。由於它的資料都是 JSON 格式,參照某個項目時,可能需要再開啟相關的其他連結,故只能很克難的不斷複製,並在 Chrome 裡面新增視窗後貼上。

看了幾天後就覺得很阿雜,複製貼上還是小事,之後可能會不斷的開啟這些開啟過的連結,如果每次都是使用人工方式操作,勢必很沒效率。還好這樣的需求我很久以前就有類似的經驗,解決的方式也很簡單,就是去監控 Windows 剪貼簿的變化,只要剪貼簿的資料是我剛才複製的連結,就自動傳遞給 Chrome,Chrome 預設行為就是新開視窗,我就可以從 3 個操作步驟減少成 1 個操作步驟,減輕了不少人力。除此之外,我還可以把這些開啟的各個連結儲存下來,隨時有需要都可以再開啟,甚至不要用複製方式,直接用滑鼠點擊到該行連結,直接去觸發 Chrome 做事。

以前的程式是使用 BCB 6.0 個人版開發,目前手邊並沒有安裝該套軟體。於是便打算使用幾年以前曾經玩過的 wxWidgets 來開發此工具。雖然程式沒有超過 300 行,但還是找了一下資料,解決了一些問題。

1. 開啟 Adobe PDF Reader 遇到的剪貼簿問題。
2. 如何加上 wxDev-Cpp 沒有內建的 Windows Event。
3. 使用 wxWidgets 的 File IO。
4. 使用 wxWidgets 的 INI class。
5. 如何得知 wxTextCtl 點擊時的行數。

其中搞了我最久的就是問題 1,只要在 Adobe PDF Reader 裡面複製文字,就會讓我的程式觸發一個 Error 視窗,而這個視窗是因為程式嘗試要 GetData 而導致失敗。不論我用什麼關鍵字去 Google 查詢,找不到資料就是找不到,可見使用 wxWidgets 的人算是小眾。後來還是去看原始碼,發現它是使用 wxLogSysError 這個函數去彈出視窗,接著便是去找 wxLog 相關的說明文件,終於讓我發現可以使用 wxLog::EnableLogging(false) 來停止這個程式行為。

我終於可以從技術文件中鬆一口氣,雖然我私心認為這個規格不太會成為共通標準,但目前也只能且戰且走。

2018年12月26日 星期三

ImportError when using pyinstaller to package up wxPython

如果是使用 Python 3.7
Pyinstaller with wxPython 會出現 wx._core import error

試著改用 Python 3.6 即可

底下是我測試能用的版本

Python 3.6.8 32 bit
PyInstaller 3.4
wxPython 4.0.3

2018年11月1日 星期四

Build wxWidgets Project in Linux

OS: Ubuntu

使用 apt-get install 相關程式
apt-get install libwx*
apt-get install wx3.0*

執行 wx-config --cxxflags
-I/usr/lib/x86_64-linux-gnu/wx/include/gtk2-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread

執行 wx-config --libs
-L/usr/lib/x86_64-linux-gnu -pthread   -lwx_gtk2u_xrc-3.0 -lwx_gtk2u_webview-3.0 -lwx_gtk2u_html-3.0 -lwx_gtk2u_qa-3.0 -lwx_gtk2u_adv-3.0 -lwx_gtk2u_core-3.0 -lwx_baseu_xml-3.0 -lwx_baseu_net-3.0 -lwx_baseu-3.0

綜合上面參數,使用 g++ 便可以成功編譯

假設你寫了一支 Test.cpp,裡面簡單的創建一個視窗,你也可以這樣下指令來直接編譯
g++ Test.cpp `wx-config --cxxflags --libs` -o Test
如果需要顯示中文,記得使用 UTF8 編碼



Test.cpp

#include <wx/wx.h>

class Test : public wxFrame
{
public:
    Test(const wxString& title)
        : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(400, 200))
    {
        Center();
    }
};

class MyApp : public wxApp
{
public:
    bool OnInit()
    {
        Test *test = new Test(wxT("醉裡挑燈看 Code"));
        test->Show(true);
        return true;
    }
};

wxIMPLEMENT_APP(MyApp);

2014年10月26日 星期日

Autosize in wxWidgets with wxDev-C++

If you want the app to change it's layout when window is maximal, you must use sizers. There are many sizers in wxWidgets, such as wxBoxSizer, wxGridSizer and wxFlexGridSizer.

When I have two vertical parts in window and I want the bottom part is fixed size, I can use wxBoxSizer and put two panels on wxBoxSizer. Here is settings about these components.

wxBoxSizer:
Orientation is wxVertical.

wxPanel1(top):
wxALIGN_TOP is true.
wxEXPAND is true.
Stretch Factor is 1.

wxPanel2(bottom):
wxALIGN_BOTTOM is true.
wxEXPAND is true.

If you set Stretch Factor, the part will be adjusted size when window is maximal.


2014年10月18日 星期六

How to catch windows message in wxWidgets

1. Add define in your header file.

WXLRESULT MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam);

2. Add implement in your cpp file.

WXLRESULT XXX::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
{
    switch(message)
    {
        case WM_KEY:
            break;
        default:
            break;
    }  
 
    return ZZZ::MSWWindowProc(message, wParam, lParam);
 }

XXX is your class name and ZZZ is the base class that you derive.

3. You can catch the windows message what you want now.

2014年10月10日 星期五

Update wxWidgets' libs in wxDev-C++

Because the wxWidgets's version is 2.9.3 in wxDev-C++, I want to use the new version, this is the steps how to do:

My wxDev-C++'s installing path is "C:\wxDev-Cpp".

1. Download the wxWidget's source and unzip to C:\wxWidgets.
2. Open cmd window and type "set path=C:\wxDev-Cpp\MinGW32\bin". Then "cd wxWidgets\build\msw".
3. Type "mingw32-make -f makefile.gcc UNICODE=1 SHARED=0 BUILD=release MONOLITHIC=1".
4. After compiling it, copy "C:\wxWidgets\lib\gcc_lib\*.a" to C:\wxDev-Cpp\lib\wx\gcc_lib".
5. Replace "C:\wxDev-Cpp\include\common" from "C:\wxWidgets\include".
6. Copy "C:\wxWidgets\lib\gcc_lib\mswu\wx\setup.h" to "C:\wxDev-Cpp\include\common\wx".
7. Change wxWidgets's version in wxDev-C++ -> Tools -> Compiler Options -> Version info.
8. Before you compile old project, remember to del all *.o in "project\Objects\MingW".
9. Enjoy it.