import sys, os, csv
from PyQt4 import QtGui
from PyQt4.Qt import *
def __init__(self, *args):
super(Spreadsheet, self).__init__(*args)
def setData(self):
r = 0
for row in self.rows:
c = 0
for item in row:
self.setItem(r, c, i)
c += 1
r += 1
def __init__(self):
super(MainWindow, self).__init__()
self.initUi()
def setTooltipFont(self, font, size):
def createAction(self, path, title, shortcut, tip, funct):
icon
= QIcon(os.
path.
join(path
)) action
= QAction(icon, str
(title
), self
) action.setShortcut(str(shortcut))
action.setStatusTip(str(tip))
action.triggered.connect(funct)
return action
def getOpenDiologTip(self):
return 'Open an Excel Workbook or Worksheet in CSV format.'
def xls2csv(self, xls): pass
def initOpenDiolog(self):
self, self.getOpenDiologTip(), '/home')
name, ext = os.path.splitext(str(fname))
with open(fname, 'r') as f:
editor = None
if ext == '.txt':
self.textEdit.setText(f.read())
editor = self.textEdit
elif ext == '.csv':
self.worksheetEdit.rows = list(csv.reader(f, 'excel'))
self.worksheetEdit.setData()
editor = self.worksheetEdit
self.setCentralWidget(editor)
def initFileMenu(self, menubar):
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(self.createAction(
os.path.join('resources', 'icons', 'Open.ico'),
'Open', 'Ctrl+O', self.getOpenDiologTip(), self.initOpenDiolog))
fileMenu.addAction(self.createAction(
os.path.join('resources', 'icons', 'Exit.ico'),
'Quit', 'Ctrl+Q', 'Quit application.', self.close))
def getVersionInfo(self):
try:
with open('version_info.txt', 'r') as v:
split_lines = [line.split() for line in v.readlines()]
s = ''
for l, line in enumerate(split_lines):
s += makeString(split_lines[l])
if l < len(split_lines) - 1:
s += ', '
return s
except:
return '>>>>> ERROR <<<<< - Could not retrieve version info.'
def initUi(self):
menubar = self.menuBar()
statusbar = self.statusBar()
self.worksheetEdit = Spreadsheet()
self.initFileMenu(menubar)
self.setGeometry(150, 150, 1024, 768)
self.setWindowTitle(self.getVersionInfo())
self.
setWindowIcon(QIcon(os.
path.
join( 'resources', 'icons', 'logo.png')))
self.show()
def makeString(line):
""" Concatenates a single string using the given list of strings. """
s = ''
for w, word in enumerate(line):
W = word
if w == 0:
word += ' '
elif w == len(line) - 1:
word = ' ' + word
if len(line) == 1:
word = W
s += word
return s
def main():
mw = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
import sys, os, csv
from PyQt4 import QtGui
from PyQt4.Qt import *
class Spreadsheet(QTableWidget):
def __init__(self, *args):
super(Spreadsheet, self).__init__(*args)
def setData(self):
r = 0
for row in self.rows:
c = 0
for item in row:
i = QTableWidgetItem(item)
self.setItem(r, c, i)
c += 1
r += 1
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.initUi()
def setTooltipFont(self, font, size):
QToolTip.setFont(QFont(str(font), int(size)))
def createAction(self, path, title, shortcut, tip, funct):
icon = QIcon(os.path.join(path))
action = QAction(icon, str(title), self)
action.setShortcut(str(shortcut))
action.setStatusTip(str(tip))
action.triggered.connect(funct)
return action
def getOpenDiologTip(self):
return 'Open an Excel Workbook or Worksheet in CSV format.'
def xls2csv(self, xls): pass
def initOpenDiolog(self):
fname = QFileDialog.getOpenFileName(
self, self.getOpenDiologTip(), '/home')
name, ext = os.path.splitext(str(fname))
with open(fname, 'r') as f:
editor = None
if ext == '.txt':
self.textEdit.setText(f.read())
editor = self.textEdit
elif ext == '.csv':
self.worksheetEdit.rows = list(csv.reader(f, 'excel'))
self.worksheetEdit.setData()
editor = self.worksheetEdit
self.setCentralWidget(editor)
def initFileMenu(self, menubar):
fileMenu = menubar.addMenu('&File')
fileMenu.addAction(self.createAction(
os.path.join('resources', 'icons', 'Open.ico'),
'Open', 'Ctrl+O', self.getOpenDiologTip(), self.initOpenDiolog))
fileMenu.addAction(self.createAction(
os.path.join('resources', 'icons', 'Exit.ico'),
'Quit', 'Ctrl+Q', 'Quit application.', self.close))
def getVersionInfo(self):
try:
with open('version_info.txt', 'r') as v:
split_lines = [line.split() for line in v.readlines()]
s = ''
for l, line in enumerate(split_lines):
s += makeString(split_lines[l])
if l < len(split_lines) - 1:
s += ', '
return s
except:
return '>>>>> ERROR <<<<< - Could not retrieve version info.'
def initUi(self):
menubar = self.menuBar()
statusbar = self.statusBar()
self.textEdit = QTextEdit()
self.worksheetEdit = Spreadsheet()
self.initFileMenu(menubar)
self.setGeometry(150, 150, 1024, 768)
self.setWindowTitle(self.getVersionInfo())
self.setWindowIcon(QIcon(os.path.join(
'resources', 'icons', 'logo.png')))
self.show()
def makeString(line):
""" Concatenates a single string using the given list of strings. """
s = ''
for w, word in enumerate(line):
W = word
if w == 0:
word += ' '
elif w == len(line) - 1:
word = ' ' + word
if len(line) == 1:
word = W
s += word
return s
def main():
app = QApplication(sys.argv)
mw = MainWindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
To copy to clipboard, switch view to plain text mode
Bookmarks