Skip to content

Commit

Permalink
unicode fixes, solved multiple doubleclick bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jkakavas committed Jan 5, 2014
1 parent d26b55f commit 7ce5141
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 62 deletions.
48 changes: 26 additions & 22 deletions creepy/CreepyMain.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
# set up logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler(os.path.join(os.getcwdu(),'creepy_main.log'))
fh = logging.FileHandler(os.path.join(os.getcwd(),'creepy_main.log'))
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
#Capture stderr and stdout to a file
sys.stdout = open(os.path.join(os.getcwdu(),'creepy_stdout.log'), 'w')
sys.stderr = open(os.path.join(os.getcwdu(),'creepy_stderr.log'), 'w')
sys.stdout = open(os.path.join(os.getcwd(),'creepy_stdout.log'), 'w')
sys.stderr = open(os.path.join(os.getcwd(),'creepy_stderr.log'), 'w')
try:
_fromUtf8 = QString.fromUtf8
except AttributeError:
Expand All @@ -54,7 +54,7 @@ def __init__(self, project):
def run(self):
pluginManager = PluginManagerSingleton.get()
pluginManager.setCategoriesFilter({ 'Input': InputPlugin})
pluginManager.setPluginPlaces([os.path.join(os.getcwdu(), 'plugins')])
pluginManager.setPluginPlaces([os.path.join(os.getcwd(), 'plugins')])
pluginManager.locatePlugins()
pluginManager.loadPlugins()
locationsList = []
Expand Down Expand Up @@ -90,21 +90,22 @@ def __init__(self, parent=None):
self.ui = Ui_CreepyMainWindow()
self.ui.setupUi(self)
#Create folders for projects and temp if they do not exist
if not os.path.exists(os.path.join(os.getcwdu(),'projects')):
os.makedirs(os.path.join(os.getcwdu(),'projects'))
if not os.path.exists(os.path.join(os.getcwdu(),'temp')):
os.makedirs(os.path.join(os.getcwdu(),'temp'))
if not os.path.exists(os.path.join(os.getcwd(),'projects')):
os.makedirs(os.path.join(os.getcwd(),'projects'))
if not os.path.exists(os.path.join(os.getcwd(),'temp')):
os.makedirs(os.path.join(os.getcwd(),'temp'))
self.projectsList = []
self.currentProject = None
self.ui.webPage = QWebPage()
self.ui.webPage.mainFrame().setUrl(QUrl(os.path.join(os.getcwdu(), 'include', 'map.html')))
self.ui.webPage.mainFrame().setUrl(QUrl(os.path.join(os.getcwd(), 'include', 'map.html')))
self.ui.mapWebView.setPage(self.ui.webPage)
self.ui.menuView.addAction(self.ui.dockWProjects.toggleViewAction())
self.ui.menuView.addAction(self.ui.dockWLocationsList.toggleViewAction())
self.ui.menuView.addAction(self.ui.dockWCurrentLocationDetails.toggleViewAction())
self.ui.actionPluginsConfiguration.triggered.connect(self.showPluginsConfigurationDialog)
self.ui.actionNewPersonProject.triggered.connect(self.showPersonProjectWizard)
self.ui.actionAnalyzeCurrentProject.triggered.connect(self.analyzeProject)
self.ui.actionReanalyzeCurrentProject.triggered.connect(self.analyzeProject)
self.ui.actionDrawCurrentProject.triggered.connect(self.presentLocations)
self.ui.actionExportCSV.triggered.connect(self.exportProjectCSV)
self.ui.actionExportKML.triggered.connect(self.exportProjectKML)
Expand All @@ -125,7 +126,7 @@ def showFilterLocationsPointDialog(self):
filterLocationsPointDialog.ui.mapPage = QWebPage()
myPyObj = filterLocationsPointDialog.pyObj()
filterLocationsPointDialog.ui.mapPage.mainFrame().addToJavaScriptWindowObject('myPyObj', myPyObj)
filterLocationsPointDialog.ui.mapPage.mainFrame().setUrl(QUrl(os.path.join(os.getcwdu(), 'include', 'mapSetPoint.html')))
filterLocationsPointDialog.ui.mapPage.mainFrame().setUrl(QUrl(os.path.join(os.getcwd(), 'include', 'mapSetPoint.html')))
filterLocationsPointDialog.ui.radiusUnitComboBox.insertItem(0, QString('km'))
filterLocationsPointDialog.ui.radiusUnitComboBox.insertItem(1, QString('m'))
filterLocationsPointDialog.ui.radiusUnitComboBox.activated[str].connect(filterLocationsPointDialog.onUnitChanged)
Expand Down Expand Up @@ -210,7 +211,7 @@ def showMarkers(self):
mapFrame.evaluateJavaScript('showMarkers()')

def addMarkerToMap(self, mapFrame, location):
mapFrame.evaluateJavaScript(QString('addMarker(' + str(location.latitude) + ',' + str(location.longitude) + ',\"' + location.infowindow.encode('utf-8') + '\")'))
mapFrame.evaluateJavaScript(QString('addMarker(' + str(location.latitude) + ',' + str(location.longitude) + ',\"' + location.infowindow + '\")'))

def centerMap(self, mapFrame, location):
mapFrame.evaluateJavaScript(QString('centerMap(' + str(location.latitude) + ',' + str(location.longitude) + ')'))
Expand All @@ -229,7 +230,7 @@ def deleteCurrentProject(self, project):
return
projectName = project.projectName+'.db'
verifyDeleteDialog = VerifyDeleteDialog()
verifyDeleteDialog.ui.label.setText(str(verifyDeleteDialog.ui.label.text()).replace('@project@', project.projectName))
verifyDeleteDialog.ui.label.setText(unicode(verifyDeleteDialog.ui.label.text(),'utf-8').replace('@project@', project.projectName))
verifyDeleteDialog.show()
if verifyDeleteDialog.exec_():
project.deleteProject(projectName)
Expand All @@ -247,7 +248,7 @@ def exportProjectCSV(self, project,filtering=False):
self.showWarning(self.trUtf8('No locations found'), self.trUtf8('The selected project has no locations to be exported'))
self.ui.statusbar.showMessage(self.trUtf8('The selected project has no locations to be exported'))
return
fileName = QFileDialog.getSaveFileName(None, self.trUtf8('Save CSV export as...'), os.getcwdu(), 'All files (*.*)')
fileName = QFileDialog.getSaveFileName(None, self.trUtf8('Save CSV export as...'), os.getcwd(), 'All files (*.*)')
if fileName:
try:
fileobj = open(fileName, 'wb')
Expand Down Expand Up @@ -283,7 +284,7 @@ def exportProjectKML(self, project, filtering=False):
self.ui.statusbar.showMessage(self.trUtf8('The selected project has no locations to be exported'))
return

fileName = QFileDialog.getSaveFileName(None, self.trUtf8('Save KML export as...'), os.getcwdu(), 'All files (*.*)')
fileName = QFileDialog.getSaveFileName(None, self.trUtf8('Save KML export as...'), os.getcwd(), 'All files (*.*)')
if fileName:
try:
fileobj = open(fileName, 'wb')
Expand Down Expand Up @@ -406,10 +407,10 @@ def updateCurrentLocationDetails(self, index):
displayed on the Current Target Details Window
'''
location = self.locationsTableModel.locations[index.row()]
self.ui.currentTargetDetailsLocationValue.setText(location.shortName.encode('utf-8'))
self.ui.currentTargetDetailsLocationValue.setText(location.shortName)
self.ui.currentTargetDetailsDateValue.setText(location.datetime.strftime('%a %b %d,%H:%M:%S %z'))
self.ui.currentTargetDetailsSourceValue.setText(location.plugin)
self.ui.currentTargetDetailsContextValue.setText(location.context.encode('utf-8'))
self.ui.currentTargetDetailsContextValue.setText(location.context)

def changeMainWidgetPage(self, pageType):
'''
Expand Down Expand Up @@ -547,9 +548,9 @@ def showPersonProjectWizard(self):
personProjectWizard.ProjectWizardSelectedTargetsTable = ProjectWizardSelectedTargetsTable([], self)
if personProjectWizard.exec_():
project = Project()
project.projectName = str(personProjectWizard.ui.personProjectNameValue.text())
project.projectKeywords = [keyword.strip() for keyword in str(personProjectWizard.ui.personProjectKeywordsValue.text()).split(',')]
project.projectDescription = str(personProjectWizard.ui.personProjectDescriptionValue.toPlainText())
project.projectName = unicode(personProjectWizard.ui.personProjectNameValue.text(), 'utf-8')
project.projectKeywords = [keyword.strip() for keyword in unicode(personProjectWizard.ui.personProjectKeywordsValue.text(), 'utf-8').split(',')]
project.projectDescription = personProjectWizard.ui.personProjectDescriptionValue.toPlainText()
project.enabledPlugins = personProjectWizard.readSearchConfiguration()
project.dateCreated = datetime.datetime.now()
project.dateEdited = datetime.datetime.now()
Expand All @@ -570,7 +571,7 @@ def loadProjectsFromStorage(self):
Loads all the existing projects from the storage to be shown in the UI
"""
# Show the existing Projects
projectsDir = os.path.join(os.getcwdu(), 'projects')
projectsDir = os.path.join(os.getcwd(), 'projects')
projectFileNames = [ os.path.join(projectsDir, f) for f in os.listdir(projectsDir) if (os.path.isfile(os.path.join(projectsDir, f)) and f.endswith('.db'))]
rootNode = ProjectTreeNode(self.trUtf8('Projects'))
for projectFile in projectFileNames:
Expand All @@ -584,7 +585,7 @@ def loadProjectsFromStorage(self):
self.ui.treeViewProjects.setModel(self.projectTreeModel)
self.ui.treeViewProjects.doubleClicked.connect(self.doubleClickProjectItem)
self.ui.treeViewProjects.setContextMenuPolicy(Qt.CustomContextMenu)
self.ui.treeViewProjects.customContextMenuRequested.connect(self.rightClickMenu)
self.ui.treeViewProjects.customContextMenuRequested.connect(self.showRightClickMenu)
self.ui.treeViewProjects.clicked.connect(self.currentProjectChanged)

def currentProjectChanged(self, index):
Expand All @@ -599,6 +600,7 @@ def currentProjectChanged(self, index):
self.currentProject = nodeObject.parent().project
elif nodeObject.nodeType() == 'ANALYSIS':
self.currentProject = nodeObject.parent().project

def doubleClickProjectItem(self):
'''
Called when the user double-clicks on an item in the tree of the existing projects
Expand All @@ -616,7 +618,7 @@ def doubleClickProjectItem(self):
self.currentProject = nodeObject.parent().project
self.changeMainWidgetPage('analysis')

def rightClickMenu(self, pos):
def showRightClickMenu(self, pos):
'''
Called when the user right-clicks somewhere in the area of the existing projects
'''
Expand All @@ -638,6 +640,8 @@ def rightClickMenu(self, pos):
rightClickMenu.addAction(self.ui.actionExportFilteredKML)
else:
rightClickMenu.addAction(self.ui.actionAnalyzeCurrentProject)
rightClickMenu.addAction(self.ui.actionDeleteCurrentProject)

if rightClickMenu.exec_(self.ui.treeViewProjects.viewport().mapToGlobal(pos)):
pass

Expand Down
2 changes: 1 addition & 1 deletion creepy/models/LocationsList.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def data(self, index, role):
if column == 0:
return QVariant(location.datetime.isoformat())
if column == 1:
return QVariant(location.shortName.encode('utf-8'))
return QVariant(location.shortName)
else:
return QVariant()

Expand Down
7 changes: 4 additions & 3 deletions creepy/models/Project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ def storeProject(self, projectNodeObject):
Receives a projectNodeObject and stores it using the selected data persistence method.
Decoupled here for flexibility
'''
projectName = projectNodeObject.name()+'.db'
projectName = projectNodeObject.name().encode('utf-8')+'.db'

storedProject = shelve.open(os.path.join(os.getcwdu(),'projects',projectName))
storedProject = shelve.open(os.path.join(os.getcwd(),'projects',projectName))
try:
storedProject['project'] = projectNodeObject
except Exception,err:
Expand All @@ -44,8 +44,9 @@ def storeProject(self, projectNodeObject):
storedProject.close()

def deleteProject(self, projectName):
#projectName comes as a Unicode, so we need to encode it to a string for shelve to find it
try:
os.remove(os.path.join(os.getcwdu(),'projects',projectName))
os.remove(os.path.join(os.getcwd(),'projects',projectName.encode('utf-8')))
except Exception,err:
logger.error('Error deleting the project')
logger.exception(err)
2 changes: 1 addition & 1 deletion creepy/plugins/flickr/flickr.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[string_options]
hidden_api_key = d42d9307a0ee4d9f81962e651defef4f
infowindow_html = <div><div><h3>Retrieved from @PLUGIN@ </h3></div><div><p>Link to the original photo: @LINK@ <p><p>It was taken on : @DATE@ <p></div></div>
hidden_api_key = d42d9307a0ee4d9f81962e651defef4f

[boolean_options]

Expand Down
37 changes: 20 additions & 17 deletions creepy/plugins/flickr/flickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,24 @@ def getLocationsFromPhotos(self, photos):
locations = []
if photos:
for photo in photos:
if photo.attrib['latitude'] != '0':
loc = {}
loc['plugin'] = "flickr"
photo_link = 'http://www.flickr.com/photos/%s/%s' % (photo.attrib['owner'], photo.attrib['id'])
title = photo.attrib['title']
#If the title is a string, make it unicode
if isinstance(title,str):
title = title.decode('utf-8')
loc['context'] = u'Photo from flickr \n Title : %s \n ' % (title)
loc['date'] = datetime.datetime.strptime(photo.attrib['datetaken'], "%Y-%m-%d %H:%M:%S")
loc['lat'] = photo.attrib['latitude']
loc['lon'] = photo.attrib['longitude']
loc['shortName'] = "Unavailable"
loc['infowindow'] = self.constructContextInfoWindow(photo_link, loc['date'])
locations.append(loc)
try:
if photo.attrib['latitude'] != '0':
loc = {}
loc['plugin'] = "flickr"
photo_link = 'http://www.flickr.com/photos/%s/%s' % (photo.attrib['owner'], photo.attrib['id'])
title = photo.attrib['title']
#If the title is a string, make it unicode
if isinstance(title,str):
title = title.decode('utf-8')
loc['context'] = u'Photo from flickr \n Title : %s \n ' % (title)
loc['date'] = datetime.datetime.strptime(photo.attrib['datetaken'], "%Y-%m-%d %H:%M:%S")
loc['lat'] = photo.attrib['latitude']
loc['lon'] = photo.attrib['longitude']
loc['shortName'] = "Unavailable"
loc['infowindow'] = self.constructContextInfoWindow(photo_link, loc['date'])
locations.append(loc)
except Exception,err:
logger.error(err)
return locations

def returnLocations(self, target, search_params):
Expand Down Expand Up @@ -156,8 +159,8 @@ def returnLocations(self, target, search_params):


def constructContextInfoWindow(self, link, date):
html = self.options_string['infowindow_html']
return html.replace("@LINK@",link).replace("@DATE@",date.strftime("%a %b %d,%H:%M:%S %z")).replace("@PLUGIN@", "flickr")
html = unicode(self.options_string['infowindow_html'], 'utf-8')
return html.replace("@LINK@",link).replace("@DATE@",date.strftime("%a %b %d,%H:%M:%S %z")).replace("@PLUGIN@", u"flickr")

def getLabelForKey(self, key):
'''
Expand Down
2 changes: 1 addition & 1 deletion creepy/plugins/instagram/instagram.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[string_options]
hidden_client_secret = aad972efd8454fa5b6ff57405ea3f285
redirect_uri = https://creepy.ilektrojohn.com
hidden_access_token = ""
hidden_access_token =
hidden_client_id = 05f8e4eb06664006a839f0dd49a50969
infowindow_html = <div><div><h3>Retrieved from @PLUGIN@ </h3></div><div><p>Caption was : @TEXT@ <p><p>Link to the original image : @LINK@ <p><p>It was taken on : @DATE@ <p></div></div>

Expand Down
10 changes: 5 additions & 5 deletions creepy/plugins/instagram/instagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def returnLocations(self, target, search_params):
if hasattr(i, 'location'):
loc = {}
loc['plugin'] = "instagram"
loc['context'] = i.caption.text if i.caption else u'No Caption'
loc['infowindow'] = self.constructContextInfoWindow(i)
loc['context'] = i.caption.text if i.caption else unicode('No Caption','utf-8')
loc['infowindow'] = self.constructContextInfoWindow(i)
loc['date'] = i.created_time
loc['lat'] = i.location.point.latitude
loc['lon'] = i.location.point.longitude
Expand Down Expand Up @@ -182,9 +182,9 @@ def showWarning(self, title, text):
QMessageBox.warning(self.wizard, title, text)

def constructContextInfoWindow(self, photo):
html = self.options_string['infowindow_html']
caption = photo.caption.text if photo.caption else "No Caption"
return html.replace("@TEXT@",caption).replace("@DATE@",photo.created_time.strftime("%a %b %d,%H:%M:%S %z")).replace("@PLUGIN@", "instagram").replace("@LINK@", photo.link)
html = unicode(self.options_string['infowindow_html'],'utf-8')
caption = photo.caption.text if photo.caption else unicode('No Caption', 'utf-8')
return html.replace("@TEXT@",caption).replace("@DATE@",photo.created_time.strftime("%a %b %d,%H:%M:%S %z")).replace("@PLUGIN@", u"instagram").replace("@LINK@", photo.link)


def getLabelForKey(self, key):
Expand Down
8 changes: 4 additions & 4 deletions creepy/plugins/twitter/twitter.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[string_options]
hidden_access_token_secret = ""
hidden_application_secret = sX1TWFHT7xsUXpNVPZZgqasaC4OFjdFpI4s5KH8GI
hidden_access_token = ""
hidden_application_key = B6DTlnTBKROLI6bQlGurSw
hidden_access_token_secret =
infowindow_html = <div><div><h3>Retrieved from @PLUGIN@ </h3></div><div><p>Tweet was : @TEXT@ <p><p>It was sent on : @DATE@ <p></div></div>
hidden_access_token =
hidden_application_key = B6DTlnTBKROLI6bQlGurSw
hidden_application_secret = sX1TWFHT7xsUXpNVPZZgqasaC4OFjdFpI4s5KH8GI

[boolean_options]
exclude_geo_disabled = True
Expand Down
Loading

0 comments on commit 7ce5141

Please sign in to comment.