i have a custom Dialog class in file Dialog1.py
class Dialog1(wx.Dialog):
def __init__(self, prnt):
wx.Dialog.__init__(self, id=wxID_DIALOG1, name='Dialog1', parent=prnt,
pos=wx.Point(110, 140), size=wx.Size(400, 498),
style=wx.DEFAULT_DIALOG_STYLE, title='Dialog1')
in other file Frame - wx.Frame with button
self.button1.Bind(wx.EVT_BUTTON, self.Dec, id=wxID_FRAME3BUTTON1)
and method to show Dialog
def Dec(self, event):
import Dialog1
self.dialog = Dialog1(self)
self.dialog.ShowModal()
#dialog.Destroy()
return True
and When I Push this Button i have a error;
TypeError: 'module' is not Callable
Why?, please Help Me
Edit: Ok is work now, to much copy-paste method ... Sorry
REMOVE THIS QUESTION
"'module' is not Callable" errors typically mean you did something like this:
import Foo
...
foo = Foo()
... when you should have done something like:
from Foo import Foo
...
foo = Foo
In other words, you've got a bad import statement somewhere, where you're importing a whole library rather than a class or function from that module.
My guess is, you have a file named Dialog1.py that has the class Dialog1 in it. Which means you need to do:
from Dialog1 import Dialog1
...
self.dialog = Dialog1(self)
Related
JavaParser.CallContext and JavaParser.FunctionDeclContext do not seem to be able to resolve. This is modeled after page 139 in the definitive antlr reference.
Am I missing a Lib?
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.MultiMap;
import org.antlr.v4.runtime.misc.OrderedHashSet;
import org.antlr.v4.runtime.tree.ParseTree;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.*;
import org.stringtemplate.v4.ST;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Set;
static class FunctionListener extends JavaBaseListener {
Graph graph = new Graph();
String currentFunctionName = null;
public void enterFunctionDecl(JavaParser.FunctionDeclContext ctx) {
currentFunctionName = ctx.ID().getText();
graph.nodes.add(currentFunctionName);
}
public void exitCall(JavaParser.CallContext ctx) {
String funcName = ctx.ID().getText();
// map current function to the callee
graph.edge(currentFunctionName, funcName);
}
}
I think I have seen this one, and I dont have enough points to "comment", but let me ask a question first; It looks like you are trying to produce an external version of the AST on page 137, You took the examples and renamed them to the grammar you had generated already. I'm going to assume that the rest of it is working or you would have had a lot more errors than this one ! Is that the goal ? Are you after just the calling methods/classes or are you after the full homogeneous AST ?
This depends on the grammar entry points. That's not as obvious in the book as it seems. You referenced functionDecl, which looks to be an entry in the Cymbol.g4, but doesn't exist in Java.g4 So rather than JavaParser.FunctionDeclContext I suggest JavaParser.classOrInterfaceDeclarationContext. It should should pull up the right method. I will also confess that I don't know what the exitCall would map to. I could use the illumination on that myself.
Were you after the whole AST or only the call graph ? If the whole AST, I think you can use enterEveryRule or ExitEveryRule for that as well, but confirmation would be good.
So start by regenerating your grammar, change your program to reference the rule entry point in the .g4 files, then see if it all works.
Thanks
I have a class which has BaseScheduler as an attribute, nothing fancy, no frameworks etc.
class MyClass(object):
def __init__(self, ...):
...
self.Scheduler = BackgroundScheduler()
...
Later on I define methods that a) schedule jobs based on a schedule definition passed as kwargs, and b) handle the jobs when they are triggered:
def _schedule_Events(self, *args, **kwargs):
try:
Schedule_Def = kwargs.copy()
Schedule_Def['func'] = self._handle_scheduled_Event
job = self.Scheduler.add_job(**Schedule_Def)
self.Scheduled_Events.append(job)
except Exception as e:
self.Logger.exception('%s: exception in schedule_Events, details: %s' %(self.Name, e))
def _handle_scheduled_Event(self, Event_Action):
""" Callback function for scheduled jobs """
try:
.... do stuff ....
However, adding jobs with _schedule_Events fails with:
File "/usr/local/lib/python3.4/dist-packages/apscheduler/util.py", line 381, in check_callable_args
', '.join(unsatisfied_args))
ValueError: The following arguments have not been supplied: Event_Action
The reason is apparently that the 'func' argument must be globally callable, ie. not within a class instance scope. I also don't see how using a 'textual reference' as described in the documentation will help.
If I replace the 'func' callable with a function defined at the module level then it works, but I need to make it call a method within my instance object. Any ideas how to make this work ? Custom trigger ? Wrapping APS Scheduler inside another class and pass the callback ? Other ideas ?
Many thanks in advance.
I am looking through the Qt documentation. Is there a quick and dirty way to get a list of all signals that a widget can emit.
For example (withPyQt):
allSignalsList = thisWidget.getSignals()
Alternatively, is there is a nice place on the new Qt5 API that shows all the signals for a given QObject?
There's no built-in method for listing signals, but normal python object introspection will get the information fairly easily:
from PyQt5 import QtCore, QtWidgets
def get_signals(source):
cls = source if isinstance(source, type) else type(source)
signal = type(QtCore.pyqtSignal())
for subcls in cls.mro():
clsname = f'{subcls.__module__}.{subcls.__name__}'
for key, value in sorted(vars(subcls).items()):
if isinstance(value, signal):
print(f'{key} [{clsname}]')
get_signals(QtWidgets.QPushButton)
Output:
clicked [PyQt5.QtWidgets.QAbstractButton]
pressed [PyQt5.QtWidgets.QAbstractButton]
released [PyQt5.QtWidgets.QAbstractButton]
toggled [PyQt5.QtWidgets.QAbstractButton]
customContextMenuRequested [PyQt5.QtWidgets.QWidget]
windowIconChanged [PyQt5.QtWidgets.QWidget]
windowIconTextChanged [PyQt5.QtWidgets.QWidget]
windowTitleChanged [PyQt5.QtWidgets.QWidget]
destroyed [PyQt5.QtCore.QObject]
objectNameChanged [PyQt5.QtCore.QObject]
However, it's probably better to learn to use the Qt Documentation. If you go to the page for a Qt class, there's a Contents sidebar on the top-right which has links for the main member types. This usually includes a section for signals, but if it doesn't, you can drill down through the inherited classes until you find one.
So for example, the QPushButton page doesn't show a signals section, but it inherits QAbstractButton, which does have one.
The trick is to use the QObject's meta object to iterate through the QObject's methods, then pick out the ones that have a signal type.
For example, this code snippet will print out the names of QThread's signals:
QThread thread;
QMetaObject metaObject = thread.staticMetaObject;
for (int i = 0; i < metaObject.methodCount(); i++) {
QMetaMethod method = metaObject.method(i);
if (method.methodType() == QMetaMethod::Signal) {
qDebug() << "Signal: " << method.name();
}
}
It should be trivial to adapt that to put the QMetaMethods into a QList or any other data structure.
i am trying to initialize a basic stack - with push, and pop function.
the problems comes in while testing. you will notice in the code that i have pushed 2 times, so a print of the stack should display [5,5] whereas it is displaying None. I could tinker with the code to make it work eventually, but then i will not fully understand the underlying concepts and the error of my ways. so i ask for advice and pointers.
please check out these codes and tell me what i am doing wrong.
this is the code with the class with all it's functions, it is named stack_class:
class Stack:
def __init__(self):
self._values = []
print ('Stack initialized...')
return
def push(self, var):
ok = self._values.append(var)
return ok
def pop(self):
self.stack.pop()
def __str__(self):
output = "{0}".format(self.ok)
return output
this is the testing code:
from stack_class import Stack
ob_1 = Stack()
ob_1.push(5)
print(ob_1.push(5))
What happens is that append method doesn't return anything.
print [].append(1)
>>> None
It does its job, but doesn't return anything, that's why you are getting None in variable ok. I think you want to return the _values instead:
def push(self, var):
self._values.append(var)
return self._values
Output:
Stack initialized...
[5, 5]
Also, it's the first time I read about empty return convention. It's not necessary.
I have a class file myClass.m in a package folder +myPack that's on the path. A simple example of the class file is:
classdef myClass
properties
prop
end
methods
function obj = myClass(x)
obj.prop = x;
end
end
end
Now if I directly call the method and access the property using the full package name, i.e.:
x = myPack.myClass(2).prop;
returns x = 2 correctly. Now, if I try the same by importing this class (and not use the package name):
import myPack.myClass
y = myClass(2).prop
it gives me the following error:
Static method or constructor invocations cannot be indexed.
Do not follow the call to the static method or constructor with
any additional indexing or dot references.
Why does this work in the first case and not the second? As far as I understood, importing a class mainly allowed one to use the class name without the long package name (among other considerations). What is the difference in these two that causes this error and how can I work around it?
Here is some more weird for you: the behavior is different if you are running in the command window, from a script, or from a function!
1) command prompt (1st: ok, 2nd: error)
This is what you've already shown
>> x = myPack.myClass(2).prop
x =
2
>> import myPack.myClass; y = myClass(2).prop
Static method or constructor invocations cannot be indexed.
Do not follow the call to the static method or constructor with
any additional indexing or dot references.
2) Script (1st: error, 2nd: error)
testMyClassScript.m
x = myPack.myClass(2).prop
import myPack.myClass; y = myClass(2).prop
and
>> testMyClassScript
Static method or constructor invocations cannot be indexed.
Do not follow the call to the static method or constructor with
any additional indexing or dot references.
Error in testMyClassScript (line 1)
x = myPack.myClass(2).prop
(the second line would also throw the same error)
3) Function (1st: ok, 2nd: ok)
testMyClassFunction.m
function testMyClassFunction()
x = myPack.myClass(2).prop
import myPack.myClass; y = myClass(2).prop
end
and
>> testMyClassFunction
x =
2
y =
2
I would definitely call that a bug :) The expected behavior is to give an error in all cases.