[#12] Added the Custom Command preference on the Qt side.

This commit is contained in:
Virgil Dupras 2010-04-13 09:02:09 +01:00
parent 5c80ac1c74
commit 7346b422d5
7 changed files with 54 additions and 19 deletions

View File

@ -12,6 +12,7 @@ import os
import os.path as op
import logging
import subprocess
import re
from send2trash import send2trash
from hsutil import io, files
@ -233,7 +234,16 @@ class DupeGuru(RegistrableApplication, Broadcaster):
ref = group.ref
cmd = cmd.replace('%d', unicode(dupe.path))
cmd = cmd.replace('%r', unicode(ref.path))
subprocess.Popen(cmd, shell=True)
match = re.match(r'"([^"]+)"(.*)', cmd)
if match is not None:
# This code here is because subprocess. Popen doesn't seem to accept, under Windows,
# executable paths with spaces in it, *even* when they're enclosed in "". So this is
# a workaround to make the damn thing work.
exepath, args = match.groups()
path, exename = op.split(exepath)
subprocess.Popen(exename + args, shell=True, cwd=path)
else:
subprocess.Popen(cmd, shell=True)
def load(self):
self._start_job(JOB_LOAD, self._do_load)

View File

@ -171,6 +171,14 @@ class DupeGuru(DupeGuruBase, QObject):
def askForRegCode(self):
self.reg.ask_for_code()
def invokeCustomCommand(self):
cmd = self.prefs.custom_command
if cmd:
self.invoke_command(cmd)
else:
msg = "You have no custom command set up. Please, set it up in your preferences."
QMessageBox.warning(self.main_window, 'Custom Command', msg)
def openDebugLog(self):
debugLogPath = op.join(self.appdata, 'debug.log')
self._open_path(debugLogPath)

View File

@ -37,6 +37,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
self.connect(QCoreApplication.instance(), SIGNAL('aboutToQuit()'), self.application_will_terminate)
self.connect(self.resultsView, SIGNAL('doubleClicked()'), self.resultsDoubleClicked)
self.connect(self.resultsView, SIGNAL('spacePressed()'), self.resultsSpacePressed)
self.actionInvokeCustomCommand.triggered.connect(self.app.invokeCustomCommand)
def _setupUi(self):
self.setupUi(self)
@ -76,6 +77,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
actionMenu.addSeparator()
actionMenu.addAction(self.actionOpenSelected)
actionMenu.addAction(self.actionRevealSelected)
actionMenu.addAction(self.actionInvokeCustomCommand)
actionMenu.addAction(self.actionRenameSelected)
self.actionActions.setMenu(actionMenu)
button = QToolButton(self.toolBar)
@ -194,7 +196,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
exported_path = self.app.export_to_xhtml(column_ids)
url = QUrl.fromLocalFile(exported_path)
QDesktopServices.openUrl(url)
def makeReferenceTriggered(self):
self.app.make_selected_reference()

View File

@ -44,6 +44,9 @@
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
<attribute name="headerStretchLastSection">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
@ -54,7 +57,7 @@
<x>0</x>
<y>0</y>
<width>630</width>
<height>22</height>
<height>20</height>
</rect>
</property>
<widget class="QMenu" name="menuColumns">
@ -77,6 +80,7 @@
<addaction name="separator"/>
<addaction name="actionOpenSelected"/>
<addaction name="actionRevealSelected"/>
<addaction name="actionInvokeCustomCommand"/>
<addaction name="actionRenameSelected"/>
<addaction name="separator"/>
<addaction name="actionApplyFilter"/>
@ -428,6 +432,14 @@
<string>Open Debug Log</string>
</property>
</action>
<action name="actionInvokeCustomCommand">
<property name="text">
<string>Invoke Custom Command</string>
</property>
<property name="shortcut">
<string>Ctrl+I</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -26,6 +26,7 @@ class Preferences(PreferencesBase):
self.use_regexp = get('UseRegexp', self.use_regexp)
self.remove_empty_folders = get('RemoveEmptyFolders', self.remove_empty_folders)
self.destination_type = get('DestinationType', self.destination_type)
self.custom_command = get('CustomCommand', self.custom_command)
widths = get('ColumnsWidth', self.columns_width)
# only set nonzero values
for index, width in enumerate(widths[:len(self.columns_width)]):
@ -46,6 +47,7 @@ class Preferences(PreferencesBase):
self.use_regexp = False
self.remove_empty_folders = False
self.destination_type = 1
self.custom_command = ''
self.registration_code = ''
self.registration_email = ''
self._reset_specific()
@ -64,6 +66,7 @@ class Preferences(PreferencesBase):
set_('UseRegexp', self.use_regexp)
set_('RemoveEmptyFolders', self.remove_empty_folders)
set_('DestinationType', self.destination_type)
set_('CustomCommand', self.custom_command)
set_('ColumnsWidth', self.columns_width)
set_('ColumnsVisible', self.columns_visible)
set_('RegistrationCode', self.registration_code)

View File

@ -50,6 +50,7 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog):
setchecked(self.ignoreSmallFilesBox, prefs.ignore_small_files)
self.sizeThresholdEdit.setText(unicode(prefs.small_file_threshold))
self.copyMoveDestinationComboBox.setCurrentIndex(prefs.destination_type)
self.customCommandEdit.setText(prefs.custom_command)
def save(self):
prefs = self.app.prefs
@ -64,6 +65,7 @@ class PreferencesDialog(QDialog, Ui_PreferencesDialog):
prefs.ignore_small_files = ischecked(self.ignoreSmallFilesBox)
prefs.small_file_threshold = tryint(self.sizeThresholdEdit.text())
prefs.destination_type = self.copyMoveDestinationComboBox.currentIndex()
prefs.custom_command = unicode(self.customCommandEdit.text())
def resetToDefaults(self):
self.load(preferences.Preferences())

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>449</width>
<height>312</height>
<width>308</width>
<height>361</height>
</rect>
</property>
<property name="windowTitle">
@ -19,9 +19,9 @@
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0,1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -174,15 +174,6 @@
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="wordWeightingBox">
<property name="text">
@ -220,9 +211,6 @@
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="ignoreSmallFilesBox">
<property name="text">
@ -319,6 +307,16 @@
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Custom Command (arguments: %d for dupe, %r for ref):</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="customCommandEdit"/>
</item>
</layout>
</item>
<item>