버튼을 누르면 특정 프로그램이 실행되는 Launcher 어플의 Template입니다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
#!/usr/bin/python
 
import wx
import subprocess
 
BUTTON_ID_1 = 101
BUTTON_ID_2 = 102
BUTTON_ID_3 = 103
BUTTON_ID_4 = 104
 
COMMAND_PATH_1 = "" # 첫번째 버튼으로 실행할 실행파일 경로 예) "C:\\Windows\\explorer.exe"
COMMAND_PATH_2 = "" # 두번째 버튼으로 실행할 실행파일 경로
COMMAND_PATH_3 = "" # 세번째 버튼으로 실행할 실행파일 경로
COMMAND_PATH_4 = "" # 네번째 버튼으로 실행할 실행파일 경로
 
COMMAND_PARAM_1 = "" # 첫번째 버튼으로 실행할 실행파일 파라미터
COMMAND_PARAM_2 = "" # 두번째 버튼으로 실행할 실행파일 파라미터
COMMAND_PARAM_3 = "" # 세번째 버튼으로 실행할 실행파일 파라미터
COMMAND_PARAM_4 = "" # 네번째 버튼으로 실행할 실행파일 파라미터
 
def ShellExecute(path, param="", cwd=None, nonExecutable = False):
    # path  : 실행 파일 경로
    # param : 파라미터
    # cwd   : 현재 디렉토리
    # nonExecutable : True일 경우, 실행 파일이 아니어도 연결 프로그램으로 실행 가능
    try:
        if param == "":
            subprocess.Popen([path], cwd = cwd, shell=nonExecutable)
        else:
            subprocess.Popen([path, param], cwd = cwd, shell=nonExecutable)
    except OSError:
        wx.MessageBox(u"Launch Failed!", u"Info")
 
class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size = (320, 240),
            style = wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
             
        vbox = wx.BoxSizer(wx.VERTICAL)
 
        button = wx.Button(self, id = BUTTON_ID_1, label = u"Button 1", size = (-1, 50))
        vbox.Add(button, 0, wx.EXPAND | wx.ALL)
        self.Bind(wx.EVT_BUTTON, self.OnButton, button)
         
        button = wx.Button(self, id = BUTTON_ID_2, label = u"Button 2", size = (-1, 50))
        vbox.Add(button, 0, wx.EXPAND | wx.ALL)
        self.Bind(wx.EVT_BUTTON, self.OnButton, button)
 
        button = wx.Button(self, id = BUTTON_ID_3, label = u"Button 3", size = (-1, 50))
        vbox.Add(button, 0, wx.EXPAND | wx.ALL)
        self.Bind(wx.EVT_BUTTON, self.OnButton, button)
 
        button = wx.Button(self, id = BUTTON_ID_4, label = u"Button 4", size = (-1, 50))
        vbox.Add(button, 0, wx.EXPAND | wx.ALL)
        self.Bind(wx.EVT_BUTTON, self.OnButton, button)
 
        self.SetSizer(vbox, True)
        self.Layout()
         
    def OnButton(self, event):
        buttonId = event.GetId()
         
        if buttonId == BUTTON_ID_1:
            ShellExecute(COMMAND_PATH_1, COMMAND_PARAM_1)
        if buttonId == BUTTON_ID_2:
            ShellExecute(COMMAND_PATH_2, COMMAND_PARAM_2)
        if buttonId == BUTTON_ID_3:
            ShellExecute(COMMAND_PATH_3, COMMAND_PARAM_3)
        if buttonId == BUTTON_ID_4:
            ShellExecute(COMMAND_PATH_4, COMMAND_PARAM_4)
 
             
app = wx.App(False)
frame = MainWindow(None, -1, u"Title")
frame.Show(1)
app.MainLoop()




<테스트 환경>
OS : Windows 7
Python 버전 : 2.7
wxPython 버전 : 2.8.12.1


,