Skip to content

Commit

Permalink
Added "set blender path" menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmackie committed Jul 23, 2017
1 parent 93e4b1b commit 94e378e
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 52 deletions.
76 changes: 40 additions & 36 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion slpa/applyHandCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def translate_thumb_code_to_degrees(hand, Tshape, handShapeParams):
if __name__ == '__main__':
argv = sys.argv
args = argv[argv.index(" -- ") + 1:]
print(args)
codepath = args[0]#'C:\\Users\\Scott\\Documents\\GitHub\\SLP-Annotator\\slpa'
hand = args[1]#'R'
# Read handshape coding and parse into thumb/fingers
Expand Down
122 changes: 111 additions & 11 deletions slpa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ def __init__(self,app):
def setGloss(self, text):
self.gloss.glossEdit.setText(text)

def setBlenderPath(self):
dialog = BlenderPathDialog(self.blenderPath)
dialog.exec_()
if dialog.file_path is None:
self.blenderPath = None
else:
self.blenderPath = os.path.dirname(dialog.file_path)

def deleteFromCorpus(self):
hs = self.currentHandShape()
gloss = hs.gloss
Expand Down Expand Up @@ -633,6 +641,7 @@ def writeSettings(self):
self.settings.setValue('parametersAlwaysOnTop', self.keepParametersOnTopAct.isChecked())
self.settings.setValue('restrictedTranscriptions', self.setRestrictionsAct.isChecked())
self.settings.setValue('autoSave', self.autoSaveAct.isChecked())
self.settings.setValue('blenderPath', self.blenderPath)
self.settings.endGroup()

def readSettings(self, reset=False):
Expand Down Expand Up @@ -662,6 +671,7 @@ def readSettings(self, reset=False):
self.transcriptionRestrictionsChanged.emit(self.restrictedTranscriptions)
self.autoSave = self.settings.value('autosave', type=bool)
self.autoSaveAct.setChecked(self.autoSave)
self.blenderPath = self.settings.value('blenderPath')
self.settings.endGroup()

@decorators.checkForUnsavedChanges
Expand Down Expand Up @@ -762,16 +772,43 @@ def launchBlender(self):
if not dialog.selectedTranscription:
return

blenderPath = r'C:\Program Files\Blender Foundation\Blender\blender.exe'
blenderPlayerPath = r'C:\Program Files\Blender Foundation\Blender\blenderplayer.exe'
if not os.path.exists(blenderPath):
blenderPath = r'C:\Program Files (x86)\Blender Foundation\Blender\blender.exe'
blenderPlayerPath = r'C:\Program Files (x86)\Blender Foundation\Blender\blenderplayer.exe'
if not os.path.exists(blenderPath):
blenderPath = '/Applications/blender.app'
#blenderPath = os.path.expanduser(blenderPath)
blenderPlayerPath = '/Applications/blenderplayer.app'
#blenderPlayerPath = os.path.expanduser(blenderPlayerPath)
if self.blenderPath is not None:
blenderPath = os.path.join(self.blenderPath, 'blender.exe')
blenderPlayerPath = os.path.join(self.blenderPath, 'blenderplayer.exe')
if os.path.exists(blenderPath):
foundPath = True
else:
foundPath = False
else:
foundPath = False
if os.path.exists(r'C:\Program Files\Blender Foundation\Blender\blender.exe'):
blenderPath = r'C:\Program Files\Blender Foundation\Blender\blender.exe'
blenderPlayerPath = r'C:\Program Files\Blender Foundation\Blender\blenderplayer.exe'
foundPath = True
elif os.path.exists(r'C:\Program Files (x86)\Blender Foundation\Blender\blender.exe'):
blenderPath = r'C:\Program Files (x86)\Blender Foundation\Blender\blender.exe'
blenderPlayerPath = r'C:\Program Files (x86)\Blender Foundation\Blender\blenderplayer.exe'
foundPath = True
elif os.path.exists('/Applications/blender.app'):
blenderPath = '/Applications/blender.app'
blenderPlayerPath = '/Applications/blenderplayer.app'
foundPath = True
elif os.path.exists(os.path.expanduser('/Applications/blender.app')):
blenderPath = os.path.expanduser('/Applications/blender.app')
blenderPlayerPath = os.path.expanduser('/Applications/blenderplayer.app')
foundPath = True

if not foundPath:
alert = QMessageBox()
alert.setWindowTitle('Error')
alert.setText('Unfortunately, SLPA could not detect an installation of Blender on your computer. Blender '
'is 3rd party software that SLPA uses to generate 3D models of hand shapes. You can '
'download Blender for free at www.blender.org/download \n'
'If you already have Blender installed, go to the Transcriptions menu, and click on '
'"Set path to Blender" to tell SLPA exactly where you have installed it.')
alert.exec_()
return

blend = 'rightHand.blend' if dialog.hand == 'R' else 'leftHand.blend'
blenderFile = os.path.join(os.getcwd(), blend)
blenderScript = os.path.join(os.getcwd(), 'applyHandCode.py')
Expand Down Expand Up @@ -1030,6 +1067,7 @@ def createMenus(self):
self.transcriptionMenu = self.menuBar().addMenu('&Transcriptions')
self.transcriptionMenu.addAction(self.setRestrictionsAct)
self.transcriptionMenu.addAction(self.changeTranscriptionFlagsAct)
self.transcriptionMenu.addAction(self.setBlenderPathAct)

self.notesMenu = self.menuBar().addMenu('&Notes')
self.notesMenu.addAction(self.addCorpusNotesAct)
Expand Down Expand Up @@ -1087,7 +1125,12 @@ def changeTranscriptionFlags(self):

def createActions(self):

self.changeTranscriptionFlagsAct = QAction('Set transcription &flags',
self.setBlenderPathAct = QAction('Set path to Blender...',
self,
statusTip = 'Set path to Blender',
triggered = self.setBlenderPath)

self.changeTranscriptionFlagsAct = QAction('Set transcription &flags...',
self,
statusTip = 'Change multiple flags at once',
triggered = self.changeTranscriptionFlags)
Expand Down Expand Up @@ -1380,6 +1423,63 @@ def accept(self):
alert.setText(text)
alert.exec_()

class BlenderPathDialog(QDialog):

def __init__(self, current_path=None):
super().__init__()
self.setWindowTitle('Set path to Blender')
label = QLabel('Path to Blender executable: ')
self.pathEdit = QLineEdit()
if current_path is not None:
self.pathEdit.setText(os.path.join(current_path, 'blender.exe'))
self.file_path = current_path
else:
self.file_path = None
explore = QPushButton('Find')
explore.clicked.connect(self.findPath)
explanation = QLabel('Blender is 3rd party software that the Sign Language Phonetic Annotator uses to generate '
'3D models of hand shapes. You can download Blender for free from '
'https://www.blender.org/download/. '
'\n\nYou must download and install Blender in order for '
'the "Visualize Handshape" button to work. This is completely optional, however, and '
'it is not required for the general use of SLPA.\n\n'
'If you have already installed Blender, click the "Find" button above to locate it on '
'your computer. Look for a file called "blender.exe" (Windows) or "blender.app" (Mac). '
'It is typically located in C:\\Program Files\\Blender Foundation\\Blender on Windows, or '
'in /Applications/Blender on Mac.')
explanation.setWordWrap(True)
font = QFont(FONT_NAME, FONT_SIZE)
explanation.setFont(font)
topLayout = QHBoxLayout()
topLayout.addWidget(label)
topLayout.addWidget(self.pathEdit)
topLayout.addWidget(explore)
midLayout = QHBoxLayout()
ok = QPushButton('OK')
cancel = QPushButton('Cancel')
ok.clicked.connect(self.accept)
cancel.clicked.connect(self.reject)
midLayout.addWidget(ok)
midLayout.addWidget(cancel)

mainLayout = QVBoxLayout()
mainLayout.addLayout(topLayout)
mainLayout.addLayout(midLayout)
mainLayout.addWidget(explanation)
self.setLayout(mainLayout)

def findPath(self):
file_path = QFileDialog.getOpenFileName(self,
'Find Blender', os.getcwd(), 'blender.exe')
file_path = file_path[0]
if not file_path:
self.file_path = None
self.pathEdit.setText('')
else:
path = os.path.abspath(file_path)
self.file_path = path
self.pathEdit.setText(path)

def clean(item):
"""Clean up the memory by closing and deleting the item if possible."""
if isinstance(item, list):
Expand Down
8 changes: 4 additions & 4 deletions slpa/transcriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,13 +652,13 @@ def __init__(self, copiedTranscription, otherTranscriptions):
self.transcriptionRadioButtons.addButton(hand2config2)
self.transcriptionRadioButtons.setId(hand2config2, 3)

radioLayout.addWidget(QLabel('Hand 1, Config 1'), 0, 0)
radioLayout.addWidget(QLabel('Config 1, Hand 1'), 0, 0)
radioLayout.addWidget(hand1config1, 0, 1)
radioLayout.addWidget(QLabel('Hand 1, Config 2'), 1, 0)
radioLayout.addWidget(QLabel('Config 1, Hand 2'), 1, 0)
radioLayout.addWidget(hand1config2, 1, 1)
radioLayout.addWidget(QLabel('Hand 2, Config 1'), 2, 0)
radioLayout.addWidget(QLabel('Config 2, Hand 1'), 2, 0)
radioLayout.addWidget(hand2config1, 2, 1)
radioLayout.addWidget(QLabel('Hand 2, Config 2'), 3, 0)
radioLayout.addWidget(QLabel('Config 2, Hand 2'), 3, 0)
radioLayout.addWidget(hand2config2, 3, 1)

buttonLayout = QHBoxLayout()
Expand Down

0 comments on commit 94e378e

Please sign in to comment.