Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.0, 1.0.1, and 1.0.2

extract shellconfig.py out of thgtaskbar.py

Removing event logging from taskbarui.py.

taskbarui.py is now stripped down to a ui for the shell extension
settings (should probably be renamed later).

thgtaskbar.py optionally now logs to a file given as the first command
line parameter.

Changeset 80328fcaac52

Parent 815c80cd092a

by Adrian Buehlmann

Changes to 3 files · Browse files at 80328fcaac52 Showing diff from parent 815c80cd092a Diff from another changeset...

Change 1 of 1 Show Entire File shellconfig.py Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,31 @@
+# configure TortoiseHg shell extension settings + +import os +import sys +import gtk + +from tortoisehg.util.i18n import agettext as _ +from tortoisehg.util import paths +from tortoisehg.hgtk import taskbarui +# import hgtk for signal setup side-effects +from tortoisehg.hgtk import hgtk + +if hasattr(sys, "frozen"): + # Insert PATH to binary installer gtk directory + gtkpath = os.path.join(paths.bin_path, 'gtk') + os.environ['PATH'] = os.pathsep.join([gtkpath, os.environ['PATH']]) + # Give stdout/stderr closed attributes to prevent ui.py errors + sys.stdout.closed = True + sys.stderr.closed = True + +def main(): + dlg = taskbarui.TaskBarUI() + dlg.show_all() + dlg.connect('destroy', gtk.main_quit) + gtk.gdk.threads_init() + gtk.gdk.threads_enter() + gtk.main() + gtk.gdk.threads_leave() + +if __name__=='__main__': + main()
Change 1 of 10 Show Entire File thgtaskbar.py Stacked
 
1
2
 
 
3
4
5
 
28
29
30
31
32
33
34
35
36
37
38
 
39
40
41
42
43
 
93
94
95
96
97
98
99
 
112
113
114
115
116
 
117
118
119
 
127
128
129
130
131
132
133
134
135
 
136
137
138
 
140
141
142
143
144
145
146
147
 
148
149
150
 
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
 
205
206
207
208
 
209
210
211
212
213
214
215
 
 
 
216
217
218
219
220
 
 
 
 
 
221
222
223
 
453
454
455
 
456
457
458
 
462
463
464
 
 
465
466
467
 
1
 
2
3
4
5
6
 
29
30
31
 
 
 
32
33
34
35
 
36
37
 
38
39
40
 
90
91
92
 
93
94
95
 
108
109
110
 
 
111
112
113
114
 
122
123
124
 
 
 
 
 
 
125
126
127
128
 
130
131
132
 
 
 
133
 
134
135
136
137
 
157
158
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
161
162
 
173
174
175
 
176
177
 
 
 
 
 
 
178
179
180
181
182
183
 
 
184
185
186
187
188
189
190
191
 
421
422
423
424
425
426
427
 
431
432
433
434
435
436
437
438
@@ -1,5 +1,6 @@
 # Creates a task-bar icon. Run from Python.exe to see the -# messages printed. +# messages printed. Takes an optional logfile as first command +# line parameter    import gc  import os @@ -28,16 +29,12 @@
 from tortoisehg.util import thread2, paths, shlib    if hasattr(sys, "frozen"): - # Insert PATH to binary installer gtk directory - gtkpath = os.path.join(paths.bin_path, 'gtk') - os.environ['PATH'] = os.pathsep.join([gtkpath, os.environ['PATH']])   # Give stdout/stderr closed attributes to prevent ui.py errors   sys.stdout.closed = True   sys.stderr.closed = True   -APP_TITLE = _('TortoiseHg RPC server') +APP_TITLE = _('TortoiseHg Overlay Icon Server')   -SHOWLOG_CMD = 1023  EXIT_CMD = 1025    def SetIcon(hwnd, name, add=False): @@ -93,7 +90,6 @@
  0, 0, win32con.CW_USEDEFAULT, win32con.CW_USEDEFAULT, \   0, 0, hinst, None)   UpdateWindow(self.hwnd) - self.guithread = None   self._DoCreateIcons()     def _DoCreateIcons(self): @@ -112,8 +108,7 @@
  def OnTaskbarNotify(self, hwnd, msg, wparam, lparam):   if lparam==win32con.WM_RBUTTONUP or lparam==win32con.WM_LBUTTONUP:   menu = CreatePopupMenu() - AppendMenu(menu, win32con.MF_STRING, SHOWLOG_CMD, _('Options...')) - AppendMenu(menu, win32con.MF_SEPARATOR, 0, '') + # AppendMenu(menu, win32con.MF_SEPARATOR, 0, '')   AppendMenu(menu, win32con.MF_STRING, EXIT_CMD, _('Exit'))   pos = GetCursorPos()   # See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/menus_0hdi.asp @@ -127,12 +122,7 @@
    def OnCommand(self, hwnd, msg, wparam, lparam):   id = LOWORD(wparam) - if id == SHOWLOG_CMD: - if not self.guithread or not self.guithread.isAlive(): - self.launchgui() - else: - print "TortoiseHG options dialog already running" - elif id == EXIT_CMD: + if id == EXIT_CMD:   self.exit_application()   else:   print "Unknown command -", id @@ -140,11 +130,8 @@
  def exit_application(self):   if self.stop_pipe_server():   DestroyWindow(self.hwnd) - if self.guithread and self.guithread.isAlive(): - import gobject - gobject.idle_add(self.dialog.destroy)   print "Goodbye" - +   def stop_pipe_server(self):   print "Stopping pipe server..."   if not self.pipethread.isAlive(): @@ -170,25 +157,6 @@
  else:   return True   - def launchgui(self): - def launch(): - import gtk - # Import hgtk for signal setup side-effects - from tortoisehg.hgtk import hgtk - from tortoisehg.hgtk import taskbarui - dlg = taskbarui.TaskBarUI(logger.getqueue(), requests) - dlg.show_all() - dlg.connect('destroy', gtk.main_quit) - self.dialog = dlg - gtk.gdk.threads_init() - gtk.gdk.threads_enter() - gtk.main() - gtk.gdk.threads_leave() - logger.reset() - - self.guithread = thread2.Thread(target=launch) - self.guithread.start() -   def start_pipe_server(self):   def servepipe():   self.svc = PipeServer(self.hwnd) @@ -205,19 +173,19 @@
   class Logger():   def __init__(self): - self.q = None + self.file = None   - def getqueue(self): - self.q = Queue.Queue() - return self.q - - def reset(self): - self.q = None + def setfile(self, name): + self.file = open(name, 'wb') + self.msg('Logging to file started')     def msg(self, msg):   ts = '[%s] ' % time.strftime('%c') - if self.q: - self.q.put(ts + msg) + f = self.file + if f: + f.write(ts + msg + '\n') + f.flush() + os.fsync(f.fileno())   print 'L' + ts + msg   else:   print ts + msg @@ -453,6 +421,7 @@
 RUNMUTEXNAME = 'thgtaskbar-' + GetUserName()    def main(): + args = sys.argv[1:]   sa = win32security.SECURITY_ATTRIBUTES()   sa.SetSecurityDescriptorDacl(1, None, 0) # allow full access   runmutex = win32event.CreateMutex(sa, 1, RUNMUTEXNAME) @@ -462,6 +431,8 @@
  # see http://www.jrsoftware.org/iskb.php?mutexsessions   installmutex1 = win32event.CreateMutex(sa, 1, INSTALLMUTEXNAME)   installmutex2 = win32event.CreateMutex(sa, 1, 'Global\\' + INSTALLMUTEXNAME) + if len(args) >= 1: + logger.setfile(args[0])   w=MainWindow()   PumpMessages()  
 
1
 
2
3
4
 
19
20
21
22
 
23
24
25
26
27
28
29
 
30
31
32
 
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
 
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
 
 
1
2
3
4
 
19
20
21
 
22
23
24
25
26
27
28
 
29
30
31
32
 
155
156
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
159
160
 
210
211
212
 
 
 
 
 
 
 
 
 
 
 
 
 
213
214
215
@@ -1,4 +1,4 @@
-# taskbarui.py - User interface for the TortoiseHg taskbar app +# taskbarui.py - User interface for the TortoiseHg shell extension settings  #  # Copyright 2009 Steve Borho <steve@borho.org>  # @@ -19,14 +19,14 @@
   class TaskBarUI(gtk.Window):   'User interface for the TortoiseHg taskbar application' - def __init__(self, inputq, requestq): + def __init__(self):   'Initialize the Dialog'   gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)   gtklib.set_tortoise_icon(self, 'hg.ico')   gtklib.set_tortoise_keys(self)     self.set_default_size(400, 520) - self.set_title(_('TortoiseHg Taskbar')) + self.set_title(_('TortoiseHg Shell Configuration'))     about = gtk.Button(_('About'))   okay = gtk.Button(_('OK')) @@ -155,20 +155,6 @@
    self.load_shell_configs()   - # Event log page - frame = self.add_page(notebook, _('Event Log')) - frame.set_border_width(2) - - scrolledwindow = gtk.ScrolledWindow() - scrolledwindow.set_shadow_type(gtk.SHADOW_ETCHED_IN) - scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) - scrolledwindow.set_border_width(2) - textview = gtk.TextView() - textview.set_editable(False) - scrolledwindow.add(textview) - frame.add(scrolledwindow) - gobject.timeout_add(100, self.pollq, inputq, textview) -   accelgroup = gtk.AccelGroup()   self.add_accel_group(accelgroup)   @@ -224,19 +210,6 @@
  dlg = about.AboutDialog()   dlg.show_all()   - def pollq(self, queue, textview): - 'Poll the input queue' - buf = textview.get_buffer() - enditer = buf.get_end_iter() - while queue.qsize(): - try: - msg = queue.get(0) - buf.insert(enditer, msg+'\n') - textview.scroll_to_mark(buf.get_insert(), 0) - except Queue.Empty: - pass - return True -   def load_shell_configs(self):   overlayenable = True   localdisks = False