Tkinter 기본 Sample Window

|

Tkinter를 이용해서 Empty Window 만들어보기

tkinter를 이용해서 빈 Window를 만들어보는 예제입니다.

만약 tkinter가 설치되어 있지 않으면 다음 명령어를 이용해서 설치할 수 있습니다. (Ubuntu 기준)

sudo apt install python-tk


예제

import tkinter as tk


def initWindow():
    window = tk.Tk()
    window.title("Simple Window")
    window.resizable(False, False)
    window.geometry("1024x768")

    window.mainloop()


def main(args=None):
    initWindow()


if __name__ == '__main__':
    main()


버튼 추가해보기

import tkinter as tk


def initWindow():
    window = tk.Tk()
    window.title("Simple Window")
    window.resizable(False, False)
    window.geometry("1024x768")

    button = tk.Button(master=window, text="Test Button", command=callback_button_clicked)
    button.pack()

    window.mainloop()


def callback_button_clicked():
    print("Button Clicked !!")


def main(args=None):
    initWindow()


if __name__ == '__main__':
    main()


간단한 이미지 출력해보기

import tkinter as tk


window = tk.Tk()
window.title("Simple Window")
window.resizable(False, False)
window.geometry("1024x768")

canvas = tk.Canvas(window, width=1024, height=768)
canvas.pack(expand=tk.YES, fill=tk.BOTH)

img = tk.PhotoImage(file="01.png")
canvas.create_image(20, 20, anchor=tk.NW, image=img)

window.mainloop()

Terminator 사용자 정의 세팅하는 방법

|

Terminator Config

terminator는 개인적으로 많이 애용하고 있는 터미널 프로그램입니다. 사용자 정의 세팅을 하는 방법은 다음과 같습니다.

만약 ~/.config/terminator/config 파일이 없으면 새로 만들어주면 됩니다.


~/.config/terminator/config

[global_config]
  handle_size = 0
  focus = system
[keybindings]
[layouts]
  [[default]]
    [[[child1]]]
      parent = window0
      type = Terminal
    [[[window0]]]
      parent = ""
      size = 1200, 600
      type = Window
[plugins]
[profiles]
  [[default]]
    scrollbar_position = hidden
    scrollback_infinite = True
    use_system_font = False
    background_darkness = 0.9
    background_type = transparent
    background_image = None
    show_titlebar = False
    font = D2Coding 12

저는 스크롤바가 화면에 있는게 더 편해서 위 설정에서 scrollbar_position = hidden 항목은 제외합니다.


Terminator 단축키

  • 위/아래로 화면 나누기 : Ctrl + Shift + O
  • 좌/우로 화면 나누기 : Ctrl + Shift + E
  • 현재 화면 닫기 : Ctrl + Shift + W

  • 화면간 이동 : Alt + 방향키

  • 스크롤바 Toggle : Ctrl + Shift + S

  • 검색 : Ctrl + Shift + F
  • 화면 Clear : Ctrl + Shift + G

Git Submodule 삭제 방법

|

Git Submodule 삭제 방법

먼저 git submodule deinit -f 명령어를 통해서 해당 모듈을 deinit 해줍니다.

git submodule deinit -f test_app

그 다음 .git/modules 폴더에 들어가서 해당 폴더를 삭제합니다.

rm -rf .git/modules/test_app

마지막으로 git에서 해당 폴더를 제거해주면 됩니다.

git rm -f test_app

curl 사용법

|

CURL 사용방법

참고 : https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

-d, --data <data> Send specified data in POST request. Details provided below.

-f, --fail Fail silently (don’t output HTML error form if returned).

-F, --form <name=content> Submit form data.

-H, --header <header> Headers to supply with request.

-i, --include Include HTTP headers in the output.

-I, --head Fetch headers only.

-k, --insecure Allow insecure connections to succeed.

-L, --location Follow redirects.

-o, --output <file> Write output to . Can use `--create-dirs` in conjunction with this to create any directories specified in the `-o` path.

-O, --remote-name Write output to file named like the remote file (only writes to current directory).

-s, --silent Silent (quiet) mode. Use with -S to force it to show errors.

-v, --verbose Provide more information (useful for debugging).

-w, --write-out <format> Make curl display information on stdout after a completed transfer. See man page for more details on available variables. Convenient way to force curl to append a newline to output: -w "\n" (can add to ~/.curlrc).

-X, --request The request method to use.

POST

When sending data via a POST or PUT request, two common formats (specified via the Content-Type header) are:

  • application/json
  • application/x-www-form-urlencoded

Many APIs will accept both formats, so if you’re using curl at the command line, it can be a bit easier to use the form urlencoded format instead of json because

  • the json format requires a bunch of extra quoting
  • curl will send form urlencoded by default, so for json the Content-Type header must be explicitly set

This gist provides examples for using both formats, including how to use sample data files in either format with your curl requests.

curl usage

For sending data with POST and PUT requests, these are common curl options:

  • request type
    • -X POST
    • -X PUT
  • content type header
  • -H "Content-Type: application/x-www-form-urlencoded"
  • -H "Content-Type: application/json"

  • data
    • form urlencoded: -d "param1=value1&param2=value2" or -d @data.txt
    • json: -d '{"key1":"value1", "key2":"value2"}' or -d @data.json


Examples

POST application/x-www-form-urlencoded

application/x-www-form-urlencoded is the default:

curl -d "param1=value1&param2=value2" -X POST http://localhost:3000/data

explicit:

curl -d "param1=value1&param2=value2" -H "Content-Type: application/x-www-form-urlencoded" -X POST http://localhost:3000/data

with a data file

curl -d "@data.txt" -X POST http://localhost:3000/data

POST application/json

curl -d '{"key1":"value1", "key2":"value2"}' -H "Content-Type: application/json" -X POST http://localhost:3000/data

with a data file

curl -d "@data.json" -X POST http://localhost:3000/data

data.json

{
  "key1":"value1",
  "key2":"value2"
}

data.txt

param1=value1&param2=value2

package.json

{
  "name": "postdemo",
  "version": "1.0.0",
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "body-parser": "^1.15.0",
    "express": "^4.13.4"
  }
}

server.js

var app = require('express')();
var bodyParser = require('body-parser');

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded

app.post('/data', function (req, res) {
  console.log(req.body);
  res.end();
});

app.listen(3000);

BroadcastReceiver 코딩 템플릿

|

BroadcastReceiver 코딩 템플릿

다음은 BroadcastReceiver 프로그래밍 템플릿입니다. register/unregister를 BroadcastReceiver 외부에서 하는 방법도 있는데, 개인적으로는 해당 클래스 내부에 하는 것이 결합도는 낮아지고 응집력도 더 높아지며 코드도 깔끔해지는 것 같습니다.

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

public class EventBroadcastReceiver extends BroadcastReceiver {

  static final String ACTION_EVENT_DEBUG_ON = "ACTION_EVENT_DEBUG_ON";
  static final String ACTION_EVENT_DEBUG_OFF = "ACTION_EVENT_DEBUG_OFF";

  final Context context;

  public EventBroadcastReceiver(Context ctx) {
    this.context = ctx;
  }

  public void init() {
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_EVENT_DEBUG_ON);
    filter.addAction(ACTION_EVENT_DEBUG_OFF);

    context.registerReceiver(this, filter);
  }

  public void fin() {
    context.unregisterReceiver(this);
  }

  @Override
  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (ACTION_EVENT_DEBUG_ON.equals(action)) {
      // TODO
    } else if (ACTION_EVENT_DEBUG_OFF.equals(action)) {
      // TODO
    }
  }
}