Autoimport toggle button
This commit is contained in:
parent
ec7c21621d
commit
cbac52ccbb
|
@ -71,7 +71,8 @@ class GuiAutoImport (threading.Thread):
|
||||||
|
|
||||||
self.addSites(self.mainVBox)
|
self.addSites(self.mainVBox)
|
||||||
|
|
||||||
self.startButton=gtk.Button("Start Autoimport")
|
self.doAutoImportBool = False
|
||||||
|
self.startButton=gtk.ToggleButton("Start Autoimport")
|
||||||
self.startButton.connect("clicked", self.startClicked, "start clicked")
|
self.startButton.connect("clicked", self.startClicked, "start clicked")
|
||||||
self.mainVBox.add(self.startButton)
|
self.mainVBox.add(self.startButton)
|
||||||
self.startButton.show()
|
self.startButton.show()
|
||||||
|
@ -103,7 +104,7 @@ class GuiAutoImport (threading.Thread):
|
||||||
"""Callback for timer to do an import iteration."""
|
"""Callback for timer to do an import iteration."""
|
||||||
self.importer.runUpdated()
|
self.importer.runUpdated()
|
||||||
print "GuiAutoImport.import_dir done"
|
print "GuiAutoImport.import_dir done"
|
||||||
return True
|
return self.doAutoImportBool
|
||||||
|
|
||||||
def startClicked(self, widget, data):
|
def startClicked(self, widget, data):
|
||||||
"""runs when user clicks start on auto import tab"""
|
"""runs when user clicks start on auto import tab"""
|
||||||
|
@ -117,34 +118,42 @@ class GuiAutoImport (threading.Thread):
|
||||||
# That is not correct. It should open another dir for importing while piping the
|
# That is not correct. It should open another dir for importing while piping the
|
||||||
# results to the same pipe. This means that self.path should be a a list of dirs
|
# results to the same pipe. This means that self.path should be a a list of dirs
|
||||||
# to watch.
|
# to watch.
|
||||||
try: #uhhh, I don't this this is the best way to check for the existence of an attr
|
if widget.get_active(): # toggled on
|
||||||
getattr(self, "pipe_to_hud")
|
self.doAutoImportBool = True
|
||||||
except AttributeError:
|
widget.set_label(u'Stop Autoimport')
|
||||||
if os.name == 'nt':
|
try: #uhhh, I don't this this is the best way to check for the existence of an attr
|
||||||
command = "python HUD_main.py" + " %s" % (self.database)
|
getattr(self, "pipe_to_hud")
|
||||||
bs = 0 # windows is not happy with line buffing here
|
except AttributeError:
|
||||||
self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE,
|
if os.name == 'nt':
|
||||||
universal_newlines=True)
|
command = "python HUD_main.py" + " %s" % (self.database)
|
||||||
else:
|
bs = 0 # windows is not happy with line buffing here
|
||||||
cwd = os.getcwd()
|
self.pipe_to_hud = subprocess.Popen(command, bufsize = bs, stdin = subprocess.PIPE,
|
||||||
command = os.path.join(cwd, 'HUD_main.py')
|
universal_newlines=True)
|
||||||
bs = 1
|
else:
|
||||||
self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
|
cwd = os.getcwd()
|
||||||
universal_newlines=True)
|
command = os.path.join(cwd, 'HUD_main.py')
|
||||||
# self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
|
bs = 1
|
||||||
# universal_newlines=True)
|
self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
|
||||||
# command = command + " %s" % (self.database)
|
universal_newlines=True)
|
||||||
# print "command = ", command
|
# self.pipe_to_hud = subprocess.Popen((command, self.database), bufsize = bs, stdin = subprocess.PIPE,
|
||||||
# self.pipe_to_hud = os.popen(command, 'w')
|
# universal_newlines=True)
|
||||||
|
# command = command + " %s" % (self.database)
|
||||||
|
# print "command = ", command
|
||||||
|
# self.pipe_to_hud = os.popen(command, 'w')
|
||||||
|
|
||||||
# Add directories to importer object.
|
# Add directories to importer object.
|
||||||
for site in self.input_settings:
|
for site in self.input_settings:
|
||||||
self.importer.addImportDirectory(self.input_settings[site][0], True, site, self.input_settings[site][1])
|
self.importer.addImportDirectory(self.input_settings[site][0], True, site, self.input_settings[site][1])
|
||||||
print "Adding import directories - Site: " + site + " dir: "+ str(self.input_settings[site][0])
|
print "Adding import directories - Site: " + site + " dir: "+ str(self.input_settings[site][0])
|
||||||
self.do_import()
|
self.do_import()
|
||||||
|
|
||||||
interval=int(self.intervalEntry.get_text())
|
interval=int(self.intervalEntry.get_text())
|
||||||
gobject.timeout_add(interval*1000, self.do_import)
|
gobject.timeout_add(interval*1000, self.do_import)
|
||||||
|
else: # toggled off
|
||||||
|
self.doAutoImportBool = False # do_import will return this and stop the gobject callback timer
|
||||||
|
#TODO: other clean up, such as killing HUD
|
||||||
|
print "Stopping autoimport"
|
||||||
|
widget.set_label(u'Start Autoimport')
|
||||||
#end def GuiAutoImport.startClicked
|
#end def GuiAutoImport.startClicked
|
||||||
|
|
||||||
def get_vbox(self):
|
def get_vbox(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user