File chooser dialogs look like this:
But is it possible to have a fullscreen window and have this take up, say, half of that window instead of being its own window?
You can use GtkFileChooserWidget (Gtkmm 2.24).
It's the basic widget that GtkFileChooserDialog uses. As the description says:
GtkFileChooserWidget is a widget suitable for selecting files. It is
the main building block of a GtkFileChooserDialog. Most applications
will only need to use the latter; you can use GtkFileChooserWidget as
part of a larger window if you have special needs.
Note that GtkFileChooserWidget does not have any methods of its own.
Instead, you should use the functions that work on a GtkFileChooser.
Note that if what you want to add to the FileChooserDialog isn't too complicated, you could consider adding the extra functionality to the dialog itself, instead of creating a new window (with all the bureaucracy involved).
You can access the top part of the dialog (above the Ok/Cancel buttons) by calling get_content_area (). You'll get a reference to a VBox, to which you can then add more items, such as load or save options, formats, etc.
Here's a very simple example which adds a check button to the dialog:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# test_filechooser_extension.py
#
# Copyright 2017 John Coppens <john#jcoppens.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
from gi.repository import Gtk
class MainWindow(Gtk.Window):
def __init__(self):
super(MainWindow, self).__init__()
self.connect("destroy", lambda x: Gtk.main_quit())
btn = Gtk.Button("Click to activate file chooser")
btn.connect("clicked", self.button_clicked)
self.add(btn)
self.show_all()
def run(self):
Gtk.main()
def button_clicked(self, btn):
fc = Gtk.FileChooserDialog(
parent = self,
action = Gtk.FileChooserAction.OPEN,
buttons = ("Open", Gtk.ResponseType.OK,
"Cancel", Gtk.ResponseType.CANCEL))
area = fc.get_content_area()
option = Gtk.CheckButton("This could be an extra option")
area.pack_start(option, False, False, 0)
option.show()
fc.run()
fc.destroy()
def main(args):
mainwdw = MainWindow()
mainwdw.run()
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
Note that it is necessary to add .show() to the added widgets.
Related
After transfer zope2 app from ubuntu12 to centos7, i get some errors that indicate that the classes are not loaded.
How to check if all required libs of python are imported?
How to fix these errors:
WARNING OFS.Uninstalled Could not import class 'Photos' from module 'Products.Ezonus.projektai2.ezonus2.control.system.Photos'
------
WARNING OFS.Uninstalled Could not import class 'FailuArchyvas' from module 'Products.Ezonus.projektai2.ezonus2.control.system.FailuArchyvas'
You are getting some kind of exception when these Python modules are being imported. To debug, you can find ClassFactory.py which is part of Zope2 and modify it directly to display the exact error message:
##############################################################################
#
# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Zope Framework Class Finder
"""
import OFS.Uninstalled
def ClassFactory(jar, module, name,
_silly=('__doc__',), _globals={},
):
# Add the following code:
if module in [
'Products.Ezonus.projektai2.ezonus2.control.system.Photos',
'Products.Ezonus.projektai2.ezonus2.control.system.FailuArchyvas'
]:
m=__import__(module, _globals, _globals, _silly)
# ^^^
try:
m=__import__(module, _globals, _globals, _silly)
return getattr(m, name)
except:
return OFS.Uninstalled.Broken(jar, None, (module, name))
Where, for me, the exact file path was eggs/Zope2-2.13.22-py2.7.egg/Zope2/App/ClassFactory.py.
Most likely, you are missing some Ubuntu packages which need to be installed.
I would like to provide a user with different default file names based on the wildcard that they select.
It seems that pyface.FileDialog inherits from HasTraits so I should be above to observe it's wildcard_index trait to notice the change and update the default_filename trait.
Here are my versions,
import pyface, traits, traitsui
pyface.__version__, traits.__version__, traitsui.__version__
('6.1.2', '5.1.2', '6.1.3')
EDM python environment
import sys
sys.version
'2.7.15 |Enthought, Inc. (x86_64)| (default, Jun 21 2018, 22:10:16) [MSC v.1500 64 bit (AMD64)]'
Using the WX backend
import wx
wx.version()
'3.0.2.0 msw (classic)'
Here is the simplest possible demo. of the problem,
from pyface.api import FileDialog
from traits.api import on_trait_change
class MyFileDialog(FileDialog):
""" Subclass that allows the suggested file name to change based on the wildcard type.
"""
#on_trait_change('wildcard_index')
def on_wildcard_changed(self, idx):
# This is never called
self.default_filename = [
'filename_john',
'filename_paul',
'filename_george',
'filename_ringo'][idx]
if __name__ == '__main__':
types = ["*.a", "*.b", "*.c", "*.d"]
dialog = MyFileDialog(
action="save as",
wildcard="|".join(["%s|%s" % (t, t) for t in types]),
)
dialog.open()
I suggest that you post this question to the ets-users google group (For viewers not familiar with it, this is at: https://groups.google.com/forum/#!forum/ets-users).
I have a problem when using the ALDialog module on Python IDE and to load on Nao. I tried in different ways to load a dialogue but I always fall back on the same error.Runtimeerror LoadTopic::ALDialogIncorrect file myDialog.topIn the first case I write directly the text that I save in a. top file but at the time of LoadTopic () I have an error.In the second case I want to load the. top file by giving it the path. I come back to the same mistake again.Do you have a solution to my problem?Thank you very much.
import qi
import argparse
import os
import sys
from naoqi import ALProxy
def main(robot_ip, robot_port):
dialog = """
topic: ~myTopic() \n
language: enu \n
u:(test) hello \n """
file = open("myDialog.top","w")
file.write(dialog)
file.close()
# load topic
proxy = ALProxy("ALDialog",robot_ip,robot_port)
proxy.setLanguage("English")
self.topic = proxy.loadTopic("myDialog.top")
# start dialog
proxy.subscribe("myModule")
# activate dialog
proxy.activateTopic(self.topic)
if name == "main":
parser = argparse.ArgumentParser()
parser.add_argument("--ip", type=str,
default="169.254.245.164",help="Robot's IP address : '169.254.245.164'")
parser.add_argument("--port", type=int, default=9559,help="port number, the default value is OK in most cases")
args = parser.parse_args()
main(args.ip, args.port)
ALDialog.loadTopic expects an absolute filepath on the robot - it doesn't know anything about the context from which you're calling it (it could be from another computer, in which case of course it can't open that file). You need to be sure that your .top is indeed on the robot, and pass it's absolute path to ALDialog.
Once installed on the robot this path will be something like /home/nao/.local/share/PackageManager/apps/your-package-id/your-dialog-name/your-dialog-name_enu.top
On a vanilla Plone 4.3.3 site (Unified Installer on Ubuntu 14.04.1LTS), and after updating buildout.cfg with the zopeskel and paster boiler plate stuff and running buildout, I successfully created a dexterity package in my src folder:
$ cd src
$ ../bin/zopeskel dexterity my.package
After updating buildout.cfg (adding my.package to the eggs section and src/my.package to the develop section) and running buildout, I added content to my new package:
$ cd my.package
$ ../../bin/paster addcontent dexterity_content
I called the new content type mytype, resulting in mytype.py, a templates folder called mytype_templates, etc.
Restarting Plone and.... so far, so good....
Then I add templates to the mytype_templates folder:
add.pt
edit.pt
view.pt
In the mytype.py file I added all the necessary imports, schema definition
Class Imytype(form.Schema, IImageScaleTraversable):
....
....
, etc, etc, and obviously also the view, add and edit classes:
class View(dexterity.DisplayForm):
grok.context(Imytype)
grok.require('zope2.View')
# Disable turn fieldsets to tabs behavior
enable_form_tabbing = False
def update(self):
super(View, self).update()
class Add(dexterity.AddForm):
grok.name('my.package.mytype')
# Disable turn fieldsets to tabs behavior
enable_form_tabbing = False
def __init__(self, context, request):
super(Add, self).__init__(context, request)
......
......
class Edit(dexterity.EditForm):
grok.context(Imytype)
# Disable turn fieldsets to tabs behavior
enable_form_tabbing = False
def update(self):
super(Edit, self).update()
......
......
When I restart my Plone site in foreground mode, I get the following messages:
2015-02-06 12:52:41 INFO ZServer HTTP server started at Fri Feb 6 12:52:41 2015
Hostname: 0.0.0.0
Port: 8080
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/edit.pt
warnings.warn(msg, UserWarning, 1)
/home/Plone434_site/buildout-cache/eggs/grokcore.view-2.8-py2.7.egg/grokcore/view/templatereg.py:261: UserWarning: Found the following unassociated template after configuration: /home/Plone434_site/zinstance/src/my.package/my/package/mytype_templates/add.pt
warnings.warn(msg, UserWarning, 1)
2015-02-06 12:52:46 INFO Zope Ready to handle requests
Seemingly grok successfully picks up the view.pt, but not the add.pt and edit.pt
This is confirmed by customizing the templates. Changes to view.pt renders fine, changes to add.pt and edit.pt have no results. Plone falls back on the default dexterity templates, as the add.pt and edit.pt are not grokked.
I found a work-around by adding the following:
....
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
....
and to the Add class:
template = ViewPageTemplateFile('mytype_templates/add.pt')
and to the Edit class:
template = ViewPageTemplateFile('mytype_templates/edit.pt')
Obviously the error messages as listed above are still there, but at least it works and I can customize the add.pt and edit.pt.
Although I can live with this workaround, I am wondering why only the view.pt is grokked and not the add.pt and edit.pt.
Please notice that this (weird?) behavior was also duplicated using Plone 4.3.1, 4.3.2, 4.3.3 and 4.3.4
Any suggestions?
You have to declare the name, context, layer and schema of the views; use something like this (note the grok.layer method which maybe you're missing):
class AddForm(dexterity.AddForm):
grok.name('my.package.mytype')
grok.layer(Imylayer)
grok.context(Imytype)
schema = Imytype
def update(self):
super(AddForm, self).update()
...
class EditForm(dexterity.EditForm):
grok.context(Imytype)
grok.layer(Imylayer)
schema = Imytype
def update(self):
super(EditForm, self).update()
...
Alternatively you may skip the use of Grok at all and register everything via ZCML.
An example of this can be found in the collective.nitf package. There's a branch using Grok and a pull request removing it.
I have moved on to messing with Pygame recently, and I started following tutorials. Everything has ran fine up until I reached a program that looks like so:
"""
A python graphics introduction.
This simple program draws lines at a 45 degree angle from one side
of the screen to the other.
"""
# Import a library of functions called 'pygame'
import pygame
from pygame import font
# Initialize the game engine
pygame.init()
# Set the height and width of the screen
size = (400, 500)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Intro to Graphics")
#Loop until the user clicks the close button.
done = False
clock = pygame.time.Clock()
# Loop as long as done == False
while not done:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop
# All drawing code happens after the for loop and but
# inside the main while not done loop.
# Clear the screen and set the screen background
screen.fill(WHITE)
# Select the font to use, size, bold, italics
font = pygame.font.SysFont('Calibri', 25, True, False)
# Render the text. "True" means anti-aliased text.
# Black is the color. This creates an image of the
# letters, but does not put it on the screen
text = font.render("My text", True, BLACK)
# Put the image of the text on the screen at 250x250
screen.blit(text, [250, 250])
# Go ahead and update the screen with what we've drawn.
# This MUST happen after all the other drawing commands.
pygame.display.flip()
# This limits the while loop to a max of 60 times per second.
# Leave this out and we will use all CPU we can.
clock.tick(60)
# Be IDLE friendly
pygame.quit()
When ran I get an error at font = pygame.font.SysFont('Calibri', 25, True, False) that looks like:
RuntimeWarning: use font: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
Reason: image not found
(ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
Reason: image not found)
pygame.font.init()
Traceback (most recent call last):
File "IntroGraphics.py", line 15, in <module>
pygame.font.init()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/__init__.py", line 70, in __getattr__
raise NotImplementedError(MissingPygameModule)
NotImplementedError: font module not available
(ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pygame/font.so, 2): Library not loaded: /usr/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/SDL_ttf.framework/Versions/A/SDL_ttf
Reason: image not found)
I have looked on here for an answer, and the only other post about it involves 32-bit Pygame with 64-bit Python. I have made sure both of them are running 32-bit (Despite the fact it's a 64-bit machine. Pygame is only 32-bit.). I am running Python 2.7.9 Fresh Install
Other places say it's a problem with SDL, but I am inexperienced with SDL and I wouldn't know what to do.
Has anyone else had this problem?
The fonts that are available to pygame might be different on different computers. I suggest seeing if the font you want to use is included on your computer. You can see the all the available fonts with this command:
pygame.font.get_fonts()
# returns a list of available fonts
You can also get the system's default fort by using this command:
pygame.font.get_default_font()
# returnes the name of the default font
You can use this code to check your font:
if 'Calibri' in pygame.font.get_fonts():
font_name = 'Calibri'
else:
font_name = pygame.font.get_default_font()