Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Fix #76. Fix #26. Backport annotation_viewer branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
pafonta committed May 30, 2018
1 parent fa63ddb commit 63b45a8
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions neurocurator/mainWin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import getpass
import os
import pickle
import sys
import time
import webbrowser
from glob import glob
from os.path import join
from subprocess import call
from threading import Thread

import numpy as np
from PySide import QtGui, QtCore
from PySide.QtCore import QUrl
from PySide.QtCore import Qt, QModelIndex, Slot
from PySide.QtGui import QAction, QItemSelection
from PySide.QtGui import QDesktopServices

from nat.annotation import Annotation
from nat.gitManager import GitManager, GitMngError
Expand Down Expand Up @@ -443,8 +443,8 @@ def setupWindowsUI(self) :
self.annotSearchWgt.annotationSelected.connect(self.viewAnnotation)
self.paramSearchWgt.parameterSelected.connect(self.viewParameter)

self.mainTabs.addTab(self.searchTabs, "Search")
self.mainTabs.addTab(self.searchTabs, "Search")

#self.mainWidget.setSizes([1,1])
#self.mainWidget.setStretchFactor(0, 1)
#self.mainWidget.setStretchFactor(1, 1)
Expand Down Expand Up @@ -894,34 +894,23 @@ def removeTag(self, tag):
def removeSuggestedTag(self, tag):
self.addTagToAnnotation(tag.id)



def openPDF(self):
pdfFileName = join(self.dbPath, Id2FileName(self.IdTxt.text())) + ".pdf"
base_path = join(self.dbPath, Id2FileName(self.IdTxt.text()))
pdf_path = base_path + ".pdf"

if not os.path.isfile(pdfFileName):
if not os.path.isfile(pdf_path):
msgBox = QtGui.QMessageBox(self)
msgBox.setWindowTitle("Missing PDF")
msgBox.setText("The PDF file seems to be missing. Do you want to attach one?")
msgBox.setStandardButtons(QtGui.QMessageBox.No | QtGui.QMessageBox.Yes)
msgBox.setDefaultButton(QtGui.QMessageBox.Yes)
if msgBox.exec_() == QtGui.QMessageBox.Yes:
fileName, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
if fileName != '':
self.importPDF()
#self.restClient.importPDF(fileName, self.IdTxt.text(), self.dbPath)
else:
if not self.importPDF():
return
else:
return

if sys.platform.startswith('darwin'):
call(('open', pdfFileName))
elif os.name == 'nt':
os.startfile(pdfFileName)
elif os.name == 'posix':
call(('xdg-open', pdfFileName))

QDesktopServices.openUrl(QUrl.fromLocalFile(pdf_path))

def checkSavingAnnot(self):
if self.needSaving:
Expand Down Expand Up @@ -1110,8 +1099,7 @@ def importPDF(self):

if not checkID(self.IdTxt.text()):
errorMessage(self, "Error", "This ID seem to be invalid.")
return

return

fileName, _ = QtGui.QFileDialog.getOpenFileName(self, 'Open file')
fileName = fileName.encode("utf-8").decode("utf-8")
Expand Down Expand Up @@ -1139,10 +1127,13 @@ def importPDF(self):
thread.start()
return False

with open(saveFileName + ".pcr", 'w', encoding="utf-8", errors='ignore'):
self.gitMng.addFiles([saveFileName + ".pcr"])

pcr_path = saveFileName + ".pcr"
if not os.path.isfile(pcr_path):
with open(pcr_path, "w", encoding="utf-8", errors="ignore"):
self.gitMng.addFiles([pcr_path])

return True

return False


Expand Down

0 comments on commit 63b45a8

Please sign in to comment.