GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Workbook is not passed to macros anymore. · Winand/SimplePython@451349d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • general.py
  • main.py
  • simplepython.ui
  • source
    • default.py
  • threaded_ui.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
-3Lines changed: 0 additions & 3 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,3 @@
22
Call Python code from Microsoft Office with ease
33

44
![Screenshot](/screenshot.png?raw=true "Spyder, SimplePython, Microsoft Excel")
5-
6-
TODO:
7-
Trying to call another macro while previous one is still running breaks system
Collapse file

‎general.py‎

Copy file name to clipboardExpand all lines: general.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ def wrapper(doc):
4747
if doc_obj:
4848
with Context(doc_obj, modules[module]):
4949
try:
50-
return func(doc_obj)
50+
return func()
5151
except Exception as e:
5252
frame = sys.exc_info()[2].tb_next
5353
if not frame: frame = sys.exc_info()[2]
5454
print("Exception in macro '%s': %s[%s:%d] %s" %
5555
(func.__name__, type(e).__name__, module, frame.tb_lineno, e))
56+
finally:
57+
context.context_app.ScreenUpdating = True #Turn back updating!
5658
else: print("Opened document '%s' not found"%doc)
5759

5860
return wrapper
Collapse file

‎main.py‎

Copy file name to clipboardExpand all lines: main.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def __init__(self):
116116
self.server = TCPServer((SHARED_SERVER_ADDR, SHARED_SERVER_PORT), Handler)
117117
threading.Thread(target=lambda:(pythoncom.CoInitialize(), self.server.serve_forever())).start()
118118
self.tray.addMenuItem("Exit", self.btnExit_clicked)
119+
self.terminated.connect(self.btnExit_clicked)
119120

120121
def tray_activated(self, reason):
121122
if reason == QtGui.QSystemTrayIcon.Trigger:
Collapse file

‎simplepython.ui‎

Copy file name to clipboardExpand all lines: simplepython.ui
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
</item>
6868
<item row="1" column="1">
6969
<widget class="QPushButton" name="btnUpdate">
70+
<property name="toolTip">
71+
<string>Update tree of currently available macros</string>
72+
</property>
7073
<property name="text">
7174
<string>Update</string>
7275
</property>
Collapse file

‎source/default.py‎

Copy file name to clipboardExpand all lines: source/default.py
+23-8Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from context import *
99

1010
@macro
11-
def unmerge_and_fill(wb):
11+
def unmerge_and_fill():
1212
"разгруппировать все ячейки в Selection и ячейки каждой \
1313
бывшей группы заполнить значениями из их первых ячеек"
1414
if TypeName(Selection) != "Range": return
@@ -24,7 +24,7 @@ def fitFactor(ws, hs, wd, hd):
2424
return f2 if f2 < f1 else f1
2525

2626
@macro
27-
def ЭкспортВПрезентацию(wb):
27+
def ЭкспортВПрезентацию():
2828
SLIDE_MARGIN = 8
2929
pp = CreateObject("PowerPoint.Application")
3030
pr = pp.Presentations.Add()
@@ -64,21 +64,36 @@ def copy(text=None):
6464
win32clipboard.CloseClipboard()
6565

6666
@macro
67-
def я_asrb_format_org(wb):
67+
def я_asrb_format_org():
6868
'Вспомогательный макрос, форматирует имя организации для добавления в GenerateOrgs'
6969
copy(clean(str(ActiveCell.Value)))
7070

7171
@macro
72-
def ttt(wb):
72+
def ttt():
73+
from context import context_app
74+
context_app.ScreenUpdating=False
7375
for i in Selection:
7476
x = i.Value
7577
if type(x) is str and len(x):
7678
ch = x.strip("г. ").split(".")
7779
if len(ch)==2:
78-
res = "01.%02s.%s%02s" % (ch[0], "20" if len(ch[1])==2 else "", ch[1])
80+
res = "1.%s.%s%s" % (ch[0], "20" if len(ch[1])==2 else "", ch[1])
7981
elif len(ch)==3:
80-
res = "%02s.%02s.%s%02s" % (ch[0], ch[1], "20" if len(ch[2])==2 else "", ch[2])
82+
res = "%s.%s.%s%s" % (ch[0], ch[1], "20" if len(ch[2])==2 else "", ch[2])
8183
else: print(x, ch)
8284
i.Value = res
83-
84-
85+
@macro
86+
def ttt2():
87+
from context import context_app
88+
context_app.ScreenUpdating=False
89+
for i in Selection:
90+
x = i.Value
91+
if type(x) is str and len(x):
92+
ch = tuple(x.strip("г. ").split("."))
93+
if len(ch)==2:
94+
res = "%s.%s.2015"%ch
95+
elif len(ch)==3:
96+
res = "%s.%s.%s%s"%(ch[0], ch[1], "20" if len(ch[2])==2 else "", ch[2])
97+
else: print(x, ch)
98+
i.Value = res
99+
Collapse file

‎threaded_ui.py‎

Copy file name to clipboardExpand all lines: threaded_ui.py
+14-3Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__author__ = 'МакаровАС'
22

33
from PyQt4 import QtCore, QtGui, uic
4-
import sys, queue, pythoncom, types, pathlib
4+
import sys, queue, pythoncom, types, pathlib, win32con, win32gui
55

66
DEBUG = False
77
print_def = lambda *args: not DEBUG or print(*args, file=sys.__stdout__)
@@ -134,11 +134,21 @@ def wrap_func(self, *args1, **kwargs1):
134134
def module_path(cls):
135135
"Get module folder path from class"
136136
return pathlib.Path(sys.modules[cls.__module__].__file__).absolute().parent
137+
138+
class QApplication(QtGui.QApplication):
139+
terminated = QtCore.pyqtSignal()
140+
def winEventFilter(self, message):
141+
if message.message == win32con.WM_DESTROY:
142+
if win32gui.GetClassName(int(message.hwnd)
143+
).startswith("QEventDispatcherWin32_Internal_Widget"):
144+
self.terminated.emit()
145+
return QtGui.QApplication.winEventFilter(self, message)
137146

138-
#Events: trayIconActivated
147+
#Widget events are connected to appropriate defs - <widget>_<signal>()
148+
#To catch terminated signal connect it manually
139149
def QtApp(Form, *args, flags=QtCore.Qt.WindowType(), ui=None, stdout=None, tray=None, hidden=False, ontop=False, **kwargs):
140150
"Create new QApplication and specified window"
141-
app = QtGui.QApplication(sys.argv)
151+
app = QApplication(sys.argv)
142152
class Form_(Form):
143153
def __init__(self, flags, ui):
144154
super(Form, self).__init__(flags=flags|(QtCore.Qt.WindowStaysOnTopHint if ontop else 0))
@@ -161,6 +171,7 @@ def __init__(self, flags, ui):
161171
signal = getattr(widgets[i], m[len(i)+1:], None)
162172
if signal: signal.connect(bind(members[m], self))
163173
else: print("Signal '%s' of '%s' not found" % (m[len(i)+1:], i))
174+
self.terminated = app.terminated
164175
if "__init__" in members:
165176
super().__init__(*args, **kwargs)
166177
form = Form_(flags, ui)

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.