-
Notifications
You must be signed in to change notification settings - Fork 0
/
atomlauncher.py
236 lines (170 loc) · 5.57 KB
/
atomlauncher.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#wx
#win32con comes from: http://sourceforge.net/projects/pywin32/files/pywin32/
#whoosh
import wx
import wx.html
import win32con
import settings as s
import indexer
TRAY_TOOLTIP = 'Atom Launcher'
TRAY_ICON = 'atom.png'
settings = s.readSettingsFile()
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.AppendItem(item)
return item
def toggleWindow():
mainWindow.Show(not mainWindow.IsShown())
def quit():
mainWindow.Destroy()
icon.Destroy()
class suggestionBox(wx.html.HtmlWindow):
def __init__(self, parent, size, pos, style=None):
self.html = wx.html.HtmlWindow(parent, 2, pos=pos, size=size, style=style)
self.html.SetRelatedFrame(parent, "HTML : %%s")
self.html.SetBorders(0)
self.suggestions = []
self.htmlCode = ''
self.defaultCommands = [
{'value': 'Google:', 'type': 'Google Search', 'search': ''},
{'value': 'Run:', 'type': 'Run', 'run': ''},
{'value': 'Find:', 'type': 'Find', 'find': ''}
]
#self.suggestion = {'value': 'Google:', 'type': 'Google Search', 'search': ''}
def addSuggestion(self, suggestion):
self.suggestions.append(suggestion)
self.updateHtml()
def addSuggestions(self, suggestions):
#fix this
print suggestions
def clearSuggestions(self):
self.suggestions = []
self.updateHtml()
def defaultSuggestions(self):
self.clearSuggestions()
self.suggestions.extend(self.defaultCommands)
self.updateHtml()
def updateHtml(self):
self.htmlCode = '<ul>'
for item in self.suggestions:
self.htmlCode += '<li>' + item['value'] + '</li>'
self.htmlCode += '</ul>'
self.html.SetPage(self.htmlCode)
class TaskBarIcon(wx.TaskBarIcon):
def __init__(self):
super(TaskBarIcon, self).__init__()
icon = wx.IconFromBitmap(wx.Bitmap(settings['trayIcon']))
self.SetIcon(icon, settings['trayToolTip'])
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.onLeftDown)
toggleWindow()
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Hide Window', self.onHideWindow)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.onExit)
return menu
def onLeftDown(self, event):
toggleWindow()
def onHideWindow(self, event):
toggleWindow()
def onExit(self, event):
quit()
class Window(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(450, 200), style=wx.NO_BORDER)
#load indexer
self.dex = indexer.indexer()
#Hotkey Setup
self.registerHotKeys()
#bind window change
self.Bind(wx.EVT_ACTIVATE, self.handleLostFocus, id=200)
#window contents
self.titleText = wx.StaticText(self, 0, 'Atom Launcher', style=wx.ALIGN_CENTRE)
self.titleFont = wx.Font(24, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
self.titleText.SetFont(self.titleFont)
self.commandBox = wx.TextCtrl(self, 1, '', size=(450, 20), style=wx.TE_PROCESS_ENTER | wx.TE_PROCESS_TAB)
self.suggestionBox = suggestionBox(self, pos=(0, 60), size=(450, 140), style=wx.html.HW_SCROLLBAR_NEVER)
#bind textevents
self.commandBox.Bind(wx.EVT_KEY_DOWN, self.onKeyDown)
self.commandBox.Bind(wx.EVT_KEY_UP, self.onKeyUp)
#sizers1
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.titleText, flag=wx.ALIGN_CENTER)
self.vbox.Add(self.commandBox, flag=wx.ALIGN_CENTER)
self.SetSizer(self.vbox)
self.Layout()
self.Center()
def registerHotKeys(self):
launchHotKey = self.convertHotKeySettings(settings['launchHotKey'])
quitHotKey = self.convertHotKeySettings(settings['quitHotKey'])
hotKeyIDs = [ 100, 101 ]
self.RegisterHotKey(hotKeyIDs[0], launchHotKey[0], launchHotKey[1])
self.RegisterHotKey(hotKeyIDs[1], quitHotKey[0], quitHotKey[1]) #81 should be q...I think?
self.Bind(wx.EVT_HOTKEY, self.handleLaunchKey, id=hotKeyIDs[0])
self.Bind(wx.EVT_HOTKEY, self.handleQuitKey, id=hotKeyIDs[1])
def convertHotKeySettings(self, setting):
hotkey = setting.split('-')
if hotkey[0] == 'ctrl':
hotkey[0] = win32con.MOD_CTRL
elif hotkey[0] == 'alt':
hotkey[0] = win32con.MOD_ALT
elif hotkey[0] == 'shift':
hotkey[0] = win32con.MOD_SHIFT
else:
print 'ERROR: Couldn\'t set hotkey ' + setting
return None
if hotkey[1] == 'enter':
hotkey[1] = win32con.VK_RETURN
#elif isalpha(hotkey[1]) or isdigit(hotkey[1]):
#figure this out when i have internet
# hotkey[1] = 81
else:
#print 'ERROR: Couldn\'t set hotkey ' + setting
#return None
hotkey[1] = 81
return hotkey
def handleLaunchKey(self, event):
toggleWindow()
#if mainWindow.IsShown():
def handleQuitKey(self, event):
quit()
def handleLostFocus(self, event):
print 'handled'
def onKeyDown(self, event):
code = event.GetKeyCode()
if code == wx.WXK_UP:
print("Up")
elif code == wx.WXK_DOWN:
print("Down")
elif code == wx.WXK_RIGHT:
print("Right")
elif code == wx.WXK_LEFT:
print("Left")
event.Skip()
def onKeyUp(self, event):
code = event.GetKeyCode()
if code == wx.WXK_RETURN:
print("Return")
#elif code == wx.WXK_BACK:
#print("Backspace")
#elif code == wx.WXK_DELETE:
#print("Delete")
elif code == wx.WXK_SPACE:
print ("Space")
else:
val = self.commandBox.GetValue()
if val == '' or val == ' ':
#self.suggestionBox.defaultSuggestions()
self.suggestionBox.clearSuggestions()
else:
self.suggestionBox.clearSuggestions()
self.searchCommand('*' + val + '*')
event.Skip()
def searchCommand(self, search):
results = unicode(self.dex.searchDocuments(search))
self.suggestionBox.addSuggestions(results)
app = wx.App(False)
mainWindow = Window(None, -1, "Atom Launcher")
icon = TaskBarIcon()
app.MainLoop()