Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[pyqgis-console] increases height of the row in QListView and QTreeWi…
…dget for Windows OS

- small fixes for the run script command
  • Loading branch information
slarosa committed May 21, 2013
1 parent a7923a1 commit 3f58142
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
30 changes: 21 additions & 9 deletions python/console/console_editor.py
Expand Up @@ -485,16 +485,20 @@ def createTempFile(self):
return tmpFileName

def _runSubProcess(self, filename, tmp=False):
dir, name = os.path.split(unicode(filename))
dir = QFileInfo(filename).path()
file = QFileInfo(filename).fileName()
name = QFileInfo(filename).baseName()
if dir not in sys.path:
sys.path.append(dir)
if name in sys.modules:
reload(sys.modules[name])
try:
## set creationflags for running command without shell window
if sys.platform.startswith('win'):
p = subprocess.Popen(['python', str(filename)], shell=False, stdin=subprocess.PIPE,
p = subprocess.Popen(['python', unicode(filename)], shell=False, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, stdout=subprocess.PIPE, creationflags=0x08000000)
else:
p = subprocess.Popen(['python', str(filename)], shell=False, stdin=subprocess.PIPE,
p = subprocess.Popen(['python', unicode(filename)], shell=False, stdin=subprocess.PIPE,
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
out, _traceback = p.communicate()

Expand All @@ -511,18 +515,18 @@ def _runSubProcess(self, filename, tmp=False):
raise e
if tmp:
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in ')
name = name + tmpFileTr + dir + ']'
file = file + tmpFileTr + dir + ']'
if _traceback:
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: %1').arg(name)
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: %1').arg(file)
print "## %s" % datetime.datetime.now()
print msgTraceTr
print unicode(msgTraceTr)
sys.stderr.write(_traceback)
p.stderr.close()
else:
msgSuccessTr = QCoreApplication.translate('PythonConsole',
'## Script executed successfully: %1').arg(name)
'## Script executed successfully: %1').arg(file)
print "## %s" % datetime.datetime.now()
print msgSuccessTr
print unicode(msgSuccessTr)
sys.stdout.write(out)
p.stdout.close()
del p
Expand Down Expand Up @@ -602,7 +606,9 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):
#source = open(filename, 'r').read() + '\n'
if type(source) == type(u""):
source = source.encode('utf-8')
compile(source, str(filename), 'exec')
if type(filename) == type(u""):
filename = filename.encode('utf-8')
compile(source, filename, 'exec')
except SyntaxError, detail:
s = traceback.format_exception_only(SyntaxError, detail)
fn = detail.filename
Expand Down Expand Up @@ -1126,6 +1132,8 @@ def listObject(self, tab):
else:
classItem.setText(0, name)
classItem.setToolTip(0, name)
if sys.platform.startswith('win'):
classItem.setSizeHint(0, QSize(18, 18))
classItem.setText(1, str(class_data.lineno))
iconClass = QgsApplication.getThemeIcon("console/iconClassTreeWidgetConsole.png")
classItem.setIcon(0, iconClass)
Expand All @@ -1137,6 +1145,8 @@ def listObject(self, tab):
methodItem.setToolTip(0, meth)
iconMeth = QgsApplication.getThemeIcon("console/iconMethodTreeWidgetConsole.png")
methodItem.setIcon(0, iconMeth)
if sys.platform.startswith('win'):
methodItem.setSizeHint(0, QSize(18, 18))
classItem.addChild(methodItem)
dictObject[meth] = lineno
self.parent.listClassMethod.addTopLevelItem(classItem)
Expand All @@ -1149,6 +1159,8 @@ def listObject(self, tab):
funcItem.setToolTip(0, func_name)
iconFunc = QgsApplication.getThemeIcon("console/iconFunctionTreeWidgetConsole.png")
funcItem.setIcon(0, iconFunc)
if sys.platform.startswith('win'):
funcItem.setSizeHint(0, QSize(18, 18))
dictObject[func_name] = data.lineno
self.parent.listClassMethod.addTopLevelItem(funcItem)
if found:
Expand Down
2 changes: 2 additions & 0 deletions python/console/console_sci.py
Expand Up @@ -586,6 +586,8 @@ def _reloadHistory(self):
self.model.clear()
for i in self.parent.history:
item = QStandardItem(i)
if sys.platform.startswith('win'):
item.setSizeHint(QSize(18, 18))
self.model.appendRow(item)

self.listView.setModel(self.model)
Expand Down

0 comments on commit 3f58142

Please sign in to comment.