I found a couple of tutorials (PyGTK) that use this code:
from gi.repository import Gtk
[...]
self.toolbar = Gtk.Toolbar()
self.toolbar.set_style(Gtk.TOOLBAR_BOTH)
[...]
but using Python3 and GTK3 (PyGobject) I get the message:
AttributeError: 'gi.repository.Gtk' object has no attribute 'TOOLBAR_BOTH'
Does anyone know how to handle this in PyGobject?
Most likely Gtk.ToolbarStyle.BOTH; to convert a C constant to Python like GTK_TOOLBAR_BOTH which is a member of the GtkToolbarStyle enum, it's (module name).(enum name without module name).(constant name without enum prefix).
Related
I am struggling with nanopb to get the enum of another package which has * mangle_names:M_STRIP_PACKAGE in .options file. Here is a way to reproduce the problem easily :
I have a root_folder containing folder_A and folder_B.
In folder_A, I have file_A.proto and file_A.options :
file_A.proto:
syntax = "proto2";
package folder_A;
enum my_enum {
ENUM_0 = 0;
ENUM_1 = 1;
ENUM_2 = 2;
}
file_A.options:
* mangle_names:M_STRIP_PACKAGE
In folder_B, I have file_B.proto :
syntax = "proto2";
package folder_B;
import "folder_A/file_A.proto";
message dummy {
required folder_A.my_enum value = 1;
}
I try to generate proto file with the following command:
nanopb_generator.py -D . -I . -I .\folder_B\ .\folder_A\file_A.proto .\folder_B\file_B.proto
The script fails with error Exception: Could not find enum type folder_A_my_enum while generating default values for folder_B_dummy.
But if I remove the file_A.options, it works correctly.
Also if I replace the enum by a message, it works correctly even with file_A.options.
My question is : do you know if it is possible to use the option * mangle_names:M_STRIP_PACKAGE and import enum at the same time ?
I use nanopb-0.4.5.
Thank you !
Currently M_STRIP_PACKAGE does not work when there are imports from another package. I have added the problem to the issue tracker: https://github.com/nanopb/nanopb/issues/783
Imports with name mangling seem to work fine, as long as all imported files belong to the same package and have same name mangling settings.
It is also questionable whether stripping the package name from types is a good idea when you are using multiple package names. It sounds like a recipe for name collisions.
The name 'LocationAccuracy' is defined in the libraries 'package:geolocation/geolocation.dart', 'package:geolocator/geolocator.dart' and 'package:location_platform_interface/location_platform_interface.dart (via package:location/location.dart)'.
Try using 'as prefix' for one of the import directives, or hiding the name from all but one of the imports.dartambiguous_import
This message is because there's a LocationAccuracy defined in more than one library. So you need define from which library you are getting this LocationAccuracy. So you need specify a prefix after the import like this:
import 'package:geolocation/geolocation.dart' as geo; // or whatever name you want
import 'package:geolocator/geolocator.dart' as geolocator; // or whatever name you want
And then you can refer to the specific LocationAccuracy you want to use in this way:
geo.LocationAccuracy or
geolocator.LocationAccuracy
I'm hitting some problems extending Quill.
I want to modify the List and ListItem classes in Quill, so I tried to copy formats/list.js into my code base as a starting point. I then import my local copy and register it with Quill like so...
import { List, ListItem } from './quill/list';
Quill.register({
'formats/list': List,
'formats/list/item': ListItem
}, true);
However, when I attempt to create a list in the editor the code crashes in the List class with the following error:
ParchmentError {message: "[Parchment] Unable to create list-item blot", name: "ParchmentError"}
This happens on this line... https://github.com/quilljs/quill/blob/develop/formats/list.js#L99
I assume it relates to the imports I was forced to change, but I can't figure out what's wrong. I've not made any other changes to list.js. The original file has the following:-
import Block from '../blots/block';
import Container from '../blots/container';
Which I changed to this:-
import Quill from 'quill';
let Block = Quill.import('blots/block');
let Container = Quill.import('blots/container');
Is the way I am importing wrong? What is causing the error?
Figured it out (well a colleague did).
I needed to import Parchment like so :-
let Parchment = Quill.import('parchment');
instead of import Parchment from 'parchment';
This is because you'll end up with a different static Parchment class to the one used internally to Quill, so asking Quill for it's instance ensures you are both working with the same one (ie, the one where the blots were registered).
I came across that problem a couple hours ago.
In Quill's source code, List is a default export while ListItem is a named export.
So your import should look like this:
import List, { ListItem } from './quill/list';
Be sure to export them appropriately on your custom list.js file.
Good luck!
I have a custom bundle for mathjs that looks something like so:
var core = require('mathjs/core');
var math = core.create();
math.import(require('mathjs/lib/type'));
math.import(require('mathjs/lib/function/arithmetic'));
math.import(require('mathjs/lib/function/trigonometry'));
math.import(require('mathjs/lib/expression'));
which I then export. If I then try math.eval('pi'), I get an Exception:
Exception: Error: Undefined symbol pi
I don't see this error if I import the entire mathjs library but, then, that rather defeats the purpose of the small custom bundle.
Question: What is the minimal import so that math.eval('pi') returns 3.14...?
var core = require('mathjs/core');
var math = core.create();
math.import(require('mathjs/lib/type'));
math.import(require('mathjs/lib/expression'));
math.import(require('mathjs/lib/constants'));
console.log(math.eval('pi')) // 3.141592653589793
See the constants module in the github repository of mathjs.
The value of PI is taken from the standard, built-in Javascript object Math. See this.
I'm new to Python and trying to understand classes. Not sure the following error is coming from the use of my IDE, which is Spyder, or if it is intended behaviour.
I define a class message in the file C:\mydir\class_def.py. Here is what the file contains:
class message:
def __init__(self,msg1,msg2):
self.msg1 = msg1
self.msg2 = msg2
I have another script were I want to execute code, called execute.py. In this script I import the class and make an instance of the class object. Here is the code from the script execute.py:
import os
os.chdir('C:\mydir')
from class_def import message
message_obj = message('Hello','world')
So far no problems!
Then I edit class_def.py to the following:
class message:
def __init__(self,msg1):
self.msg1 = msg1
and edit execute.py to match the new class, so removing one input tomessage:
import os
os.chdir('C:\mydir')
from class_def import message
message_obj = message('Hello')
and I get the following error:
TypeError: __init__() takes exactly 3 arguments (2 given)
It seems like Python keeps the old version of class_def.py and does not import the new one, even though it is saved.
Is this normal behaviour or is Spyder doing something funny?
If you have a .pyc file such as class_def.pyc, delete it.
I'd remove all .pyc files in your working directory and then try again. If that doesn't work, maybe you're not using the module you think you are? To be certain try something like:
import myModule
print myModule.__file__ #This will give you the path to the .pyc file your program loaded
#or
import myModule
import os
print os.path.dirname(myModule.__file__)
try those out so you can be certain that you're actually using the file you're modifying. Hope that helps!