use python3
This commit is contained in:
parent
2a9f5822e5
commit
d1693a4bfb
6 changed files with 30 additions and 26 deletions
49
bin/calcool
49
bin/calcool
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python
|
||||
#! /usr/bin/python3
|
||||
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
|
||||
### BEGIN LICENSE
|
||||
# Copyright (C) 2010 jan gerber <j@mailb.org>
|
||||
|
|
@ -14,12 +14,15 @@
|
|||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
### END LICENSE
|
||||
from __future__ import division
|
||||
import sys
|
||||
import os
|
||||
import gtk
|
||||
|
||||
from gtksourceview2 import View as GtkSourceView
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk as gtk
|
||||
gi.require_version("GtkSource", "4")
|
||||
from gi.repository import GtkSource
|
||||
GtkSourceView = GtkSource.View()
|
||||
|
||||
from math import *
|
||||
safe_list = ['math','acos', 'asin', 'atan', 'atan2', 'ceil', 'cos',
|
||||
|
|
@ -51,7 +54,6 @@ from calcool.calcoolconfig import getdatapath
|
|||
class CalcoolWindow(gtk.Window):
|
||||
__gtype_name__ = "CalcoolWindow"
|
||||
|
||||
record_type = "http://wiki.ubuntu.com/Quickly/CalcoolDocument"
|
||||
database_name = "calcool"
|
||||
filename = ''
|
||||
|
||||
|
|
@ -96,19 +98,19 @@ class CalcoolWindow(gtk.Window):
|
|||
def update_output(self):
|
||||
self.builder.get_object('status').set_text('Calculating...')
|
||||
txt = self.builder.get_object('input').get_buffer()
|
||||
text = txt.get_text(txt.get_start_iter(), txt.get_end_iter())
|
||||
text = txt.get_text(txt.get_start_iter(), txt.get_end_iter(), 0)
|
||||
rows = text.split('\n')
|
||||
otxt = []
|
||||
computed_values = []
|
||||
def expand_lines(line):
|
||||
return re.sub('line(\d+)', lambda m: 'line%010d'%int(m.groups(0)[0]), line)
|
||||
return re.sub(r'line(\d+)', lambda m: 'line%010d'%int(m.groups(0)[0]), line)
|
||||
def resolve_row(r, line):
|
||||
#if r not in self._results:
|
||||
try:
|
||||
r_ = r
|
||||
r_ = expand_lines(r_)
|
||||
|
||||
match = re.compile('line(\d+)').findall(r)
|
||||
match = re.compile(r'line(\d+)').findall(r)
|
||||
match = filter(lambda l: int(l) <= len(rows), match)
|
||||
if match:
|
||||
for l in match:
|
||||
|
|
@ -117,7 +119,7 @@ class CalcoolWindow(gtk.Window):
|
|||
value = '(%s)' % expand_lines(rows[l-1])
|
||||
r_ = r_.replace('line%010d' % l, value)
|
||||
r_ = resolve_row(r_, line)
|
||||
#print r, r_
|
||||
#print (r, r_)
|
||||
result = str(eval(r_, {"__builtins__":None}, safe_dict))
|
||||
|
||||
#highlight computed values
|
||||
|
|
@ -134,9 +136,9 @@ class CalcoolWindow(gtk.Window):
|
|||
output.set_text('\n'.join(otxt))
|
||||
|
||||
tagTable = output.get_tag_table()
|
||||
computed = tagTable.lookup('computed')
|
||||
computed = tagTable.lookup(name='computed')
|
||||
if not computed:
|
||||
computed = gtk.TextTag('computed')
|
||||
computed = gtk.TextTag(name='computed')
|
||||
computed.set_property('weight', 700) # pango.WEIGHT_BOLD = 700
|
||||
tagTable.add(computed)
|
||||
|
||||
|
|
@ -158,7 +160,7 @@ class CalcoolWindow(gtk.Window):
|
|||
|
||||
def load_file(self, filename):
|
||||
with open(filename) as f:
|
||||
text = f.read().decode('utf-8')
|
||||
text = f.read()
|
||||
#set the UI to display the string
|
||||
buff = self.builder.get_object("input").get_buffer()
|
||||
buff.set_text(text)
|
||||
|
|
@ -166,10 +168,9 @@ class CalcoolWindow(gtk.Window):
|
|||
self.filename = filename
|
||||
|
||||
def open_file(self, widget, data=None):
|
||||
dialog = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_OPEN,
|
||||
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||
|
||||
dialog.set_default_response(gtk.RESPONSE_OK)
|
||||
dialog = gtk.FileChooserDialog(title=None,action=gtk.FileChooserAction.OPEN)
|
||||
dialog.add_buttons(gtk.STOCK_CANCEL,gtk.ResponseType.CANCEL,gtk.STOCK_OPEN,gtk.ResponseType.OK)
|
||||
dialog.set_default_response(gtk.ResponseType.OK)
|
||||
|
||||
filter = gtk.FileFilter()
|
||||
filter.set_name("Calcool Documents")
|
||||
|
|
@ -183,7 +184,7 @@ class CalcoolWindow(gtk.Window):
|
|||
dialog.add_filter(filter)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
if response == gtk.ResponseType.OK:
|
||||
filename = dialog.get_filename()
|
||||
dialog.destroy()
|
||||
self.load_file(filename)
|
||||
|
|
@ -201,13 +202,13 @@ class CalcoolWindow(gtk.Window):
|
|||
start_iter = buff.get_start_iter()
|
||||
end_iter = buff.get_end_iter()
|
||||
|
||||
text = buff.get_text(start_iter,end_iter)
|
||||
with open(self.filename, "w") as f:
|
||||
text = buff.get_text(start_iter,end_iter, 0)
|
||||
with open(self.filename, "wb") as f:
|
||||
f.write(text.encode('utf-8'))
|
||||
|
||||
def save_as_file(self, widget, data=None):
|
||||
dialog = gtk.FileChooserDialog(title=None,action=gtk.FILE_CHOOSER_ACTION_SAVE,
|
||||
buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK))
|
||||
dialog = gtk.FileChooserDialog(title=None,action=gtk.FileChooserAction.SAVE)
|
||||
dialog.add_buttons(gtk.STOCK_CANCEL,gtk.ResponseType.CANCEL,gtk.STOCK_OPEN,gtk.ResponseType.OK)
|
||||
filter = gtk.FileFilter()
|
||||
filter.set_name("Calcool Documents")
|
||||
filter.add_mime_type("text/x-calcool")
|
||||
|
|
@ -220,8 +221,10 @@ class CalcoolWindow(gtk.Window):
|
|||
dialog.add_filter(filter)
|
||||
|
||||
response = dialog.run()
|
||||
if response == gtk.RESPONSE_OK:
|
||||
if response == gtk.ResponseType.OK:
|
||||
self.filename = dialog.get_filename()
|
||||
if not self.filename.endswith(".calc"):
|
||||
self.filename += ".calc"
|
||||
self.save_file(widget)
|
||||
dialog.destroy()
|
||||
|
||||
|
|
@ -270,4 +273,4 @@ if __name__ == "__main__":
|
|||
window.load_file(args[0])
|
||||
gtk.main()
|
||||
def save_file(self, widget, data=None):
|
||||
print "save"
|
||||
print("save")
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
import sys
|
||||
import os
|
||||
import gtk
|
||||
import gi
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk as gtk
|
||||
|
||||
from calcool.calcoolconfig import getdatapath
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
Before Width: | Height: | Size: 756 B After Width: | Height: | Size: 771 B |
Binary file not shown.
|
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 19 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
|
|
@ -6,7 +6,6 @@
|
|||
<property translatable="yes" name="copyright">Copyright (C) 2010 jan gerber <j@mailb.org></property><property name="border_width">5</property>
|
||||
<property name="icon">../media/icon.png</property>
|
||||
<property name="type_hint">normal</property>
|
||||
<property name="has_separator">False</property>
|
||||
<property name="program_name">Calcool</property>
|
||||
<property name="version">12.06</property>
|
||||
<property name="comments" translatable="yes">Calcool allows you to do calculations in a document,
|
||||
|
|
@ -49,4 +48,4 @@ calcool might be what you are looking for.</property>
|
|||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
</interface>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue