From d1693a4bfbcb54e7ea05b674f74445c489e3bc54 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 31 Jan 2025 19:00:21 +0530 Subject: [PATCH] use python3 --- bin/calcool | 49 ++++++++++++++++++---------------- calcool/AboutCalcoolDialog.py | 4 ++- data/media/icon.png | Bin 756 -> 771 bytes data/media/large.png | Bin 19190 -> 19190 bytes data/media/logo.png | Bin 4412 -> 4427 bytes data/ui/AboutCalcoolDialog.ui | 3 +-- 6 files changed, 30 insertions(+), 26 deletions(-) diff --git a/bin/calcool b/bin/calcool index 821a5a3..0b67979 100755 --- a/bin/calcool +++ b/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 @@ -14,12 +14,15 @@ # You should have received a copy of the GNU General Public License along # with this program. If not, see . ### 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") diff --git a/calcool/AboutCalcoolDialog.py b/calcool/AboutCalcoolDialog.py index 6d56ce1..dd56a5c 100644 --- a/calcool/AboutCalcoolDialog.py +++ b/calcool/AboutCalcoolDialog.py @@ -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 diff --git a/data/media/icon.png b/data/media/icon.png index b080e140c64912b99187df14233fe686c4883f0f..d8e5fa78debbf10b9202dd63cdeabfa788ada876 100644 GIT binary patch delta 43 zcmeyu+RQd#J)`=>4I!Wfx&{VT1_m-$?aen{P+`@%Y5J)^|L4I(@SX1az3x&~%@@@fq?-dAA)0Ef5Copyright (C) 2010 jan gerber <j@mailb.org>5 ../media/icon.png normal - False Calcool 12.06 Calcool allows you to do calculations in a document, @@ -49,4 +48,4 @@ calcool might be what you are looking for. - \ No newline at end of file +