(widget=None, size=None, position=(20, 20),
                        autodestruct=None,
                        toolbar=False)
return BasicWindow
Create a basic QT window with a Galry widget inside.
    
    Arguments:
      * widget: a class or instance deriving from GalryWidget.
      * size=None: the size of the window as a tuple (width, height).
      * position=(100, 100): the initial position of the window on the screen,
        in pixels (x, y).
      * autodestruct=None: if not None, it is the time, in seconds, before the
        window closes itself.
Create a basic QT window with a Galry widget inside.
    
    Arguments:
      * widget: a class or instance deriving from GalryWidget.
      * size=None: the size of the window as a tuple (width, height).
      * position=(100, 100): the initial position of the window on the screen,
        in pixels (x, y).
      * autodestruct=None: if not None, it is the time, in seconds, before the
        window closes itself.
Create a basic QT window with a Galry widget inside . Arguments : * widget : a class or instance deriving from GalryWidget . * size = None : the size of the window as a tuple ( width height ) . * position = ( 100 100 ) : the initial position of the window on the screen in pixels ( x y ) . * autodestruct = None : if not None it is the time in seconds before the window closes itself .
def create_basic_window(widget=None, size=None, position=(20, 20),
                        autodestruct=None,
                        toolbar=False):
    """Create a basic QT window with a Galry widget inside.
    
    Arguments:
      * widget: a class or instance deriving from GalryWidget.
      * size=None: the size of the window as a tuple (width, height).
      * position=(100, 100): the initial position of the window on the screen,
        in pixels (x, y).
      * autodestruct=None: if not None, it is the time, in seconds, before the
        window closes itself.
    
    """
    class BasicWindow(AutodestructibleWindow):
        """Automatically-created QT window."""
        def initialize(self, widget=widget, size=size, position=position,
                       autodestruct=autodestruct):
            """Create a basic window to display a single widget.
            
            Arguments:
              * widget: a class or instance deriving from GalryWidget.
              * size=None: the size of the window as a tuple (width, height).
              * position=(100, 100): the initial position of the window on the screen,
                in pixels (x, y).
              * autodestruct=None: if not None, it is the time, in seconds, before the
                window closes itself.
              
            """
            self.set_autodestruct(autodestruct)
            # default widget
            if widget is None:
                widget = GalryWidget()
            # if widget is not an instance of GalryWidget, maybe it's a class,
            # then try to instanciate it
            if not isinstance(widget, GalryWidget):
                widget = widget()
            widget.window = self
            # create widget
            self.widget = widget
            if toolbar:
                self.add_toolbar()
            # if size is None:
                # size = self.widget.w, self.widget.h
            if size is not None:
                self.widget.w, self.widget.h = size
            self.setCentralWidget(self.widget)
            self.setWindowTitle("Galry")
            self.move(*position)
            # ensure the main window size is adjusted so that the widget size
            # is equal to the specified size
            self.resize(self.sizeHint())
            self.show()
            
        def toggle_toolbar(self):
            self.toolbar.setVisible(not self.toolbar.isVisible())#not )
            
        def add_toolbar(self):
            """Add navigation toolbar"""
            
            # reset
            reset_action = QtGui.QAction("Reset view (R)", self)
            reset_action.setIcon(get_icon('home'))
            self.widget.connect_events(reset_action.triggered, 'Reset')
            
            # show grid
            grid_action = QtGui.QAction("Show grid (G)", self)
            grid_action.setIcon(get_icon('grid'))
            self.widget.connect_events(grid_action.triggered, 'Grid')

            # fullscreen
            fullscreen_action = QtGui.QAction("Fullscreen (F)", self)
            fullscreen_action.setIcon(get_icon('fullscreen'))
            self.widget.connect_events(fullscreen_action.triggered, 'Fullscreen')

            # save image
            save_action = QtGui.QAction("Save image (S)", self)
            save_action.setIcon(get_icon('save'))
            save_action.setShortcut("S")
            save_action.triggered.connect(self.save)            
            
            toolbar_action = QtGui.QAction("Toggle toolbar visibility (T)", self)
            toolbar_action.setIcon(get_icon('toolbar'))
            toolbar_action.setShortcut("T")
            toolbar_action.triggered.connect(self.toggle_toolbar)
            # self.toolbar_action = toolbar_action
            
            # help
            help_action = QtGui.QAction("Show help (H)", self)
            help_action.setIcon(get_icon('help'))
            self.widget.connect_events(help_action.triggered, 'Help')
            
            # exit
            exit_action = QtGui.QAction("Exit (Q)", self)
            exit_action.setIcon(get_icon('exit'))
            exit_action.triggered.connect(self.close)
            
            # add toolbar
            mytoolbar = QtGui.QToolBar(self.widget)        
            mytoolbar.setIconSize(QtCore.QSize(32, 32))
            
            for action in [reset_action, grid_action, fullscreen_action,
                toolbar_action, save_action, help_action, exit_action]:
                self.addAction(action)
                mytoolbar.addAction(action)
            
            mytoolbar.setStyleSheet("""
            QToolBar, QToolButton
            {
                background: #000000;
                border-color: #000000;
                color: #ffffff;
            }
            QToolButton
            {
                margin-left: 5px;
            }
            QToolButton:hover
            {
                background: #2a2a2a;
            }
            """)
            mytoolbar.setMovable(False)
            mytoolbar.setFloatable(False)
            self.toolbar = mytoolbar
            self.addToolBar(mytoolbar)
            
        def save(self):
            """Open a file dialog and save the current image in the specified
            PNG file."""
            initial_filename = 'screen'
            existing = filter(lambda f: f.startswith(initial_filename), os.listdir('.'))
            i = 0
            if existing:
                for f in existing:
                    r = re.match('screen([0-9]*).png', f)
                    i = max(i, int(r.groups()[0]))
                i += 1
                # if last:
                    # last = int(last)
                    # i = last + 1
            filename, _ = QtGui.QFileDialog.getSaveFileName(self,
                "Save the current view in a PNG image",
                initial_filename + str(i) + '.png',
                # '*.png',
                # '*.png',
                # QtGui.QFileDialog.AnyFile,
                )
            if filename:
                self.widget.save_image(str(filename))
            
        def closeEvent(self, e):
            """Clean up memory upon closing."""
            self.widget.user_action_generator.close()
            self.widget.paint_manager.cleanup()
            super(BasicWindow, self).closeEvent(e)
            
        def contextMenuEvent(self, e):
            return
        
    return BasicWindow
def create_basic_window ( widget = None , size = None , position = ( 20 , 20 ) , autodestruct = None , toolbar = False ) : class BasicWindow ( AutodestructibleWindow ) : """Automatically-created QT window.""" def initialize ( self , widget = widget , size = size , position = position , autodestruct = autodestruct ) : """Create a basic window to display a single widget.
            
            Arguments:
              * widget: a class or instance deriving from GalryWidget.
              * size=None: the size of the window as a tuple (width, height).
              * position=(100, 100): the initial position of the window on the screen,
                in pixels (x, y).
              * autodestruct=None: if not None, it is the time, in seconds, before the
                window closes itself.
              
            """ self . set_autodestruct ( autodestruct ) # default widget if widget is None : widget = GalryWidget ( ) # if widget is not an instance of GalryWidget, maybe it's a class, # then try to instanciate it if not isinstance ( widget , GalryWidget ) : widget = widget ( ) widget . window = self # create widget self . widget = widget if toolbar : self . add_toolbar ( ) # if size is None: # size = self.widget.w, self.widget.h if size is not None : self . widget . w , self . widget . h = size self . setCentralWidget ( self . widget ) self . setWindowTitle ( "Galry" ) self . move ( * position ) # ensure the main window size is adjusted so that the widget size # is equal to the specified size self . resize ( self . sizeHint ( ) ) self . show ( ) def toggle_toolbar ( self ) : self . toolbar . setVisible ( not self . toolbar . isVisible ( ) ) #not ) def add_toolbar ( self ) : """Add navigation toolbar""" # reset reset_action = QtGui . QAction ( "Reset view (R)" , self ) reset_action . setIcon ( get_icon ( 'home' ) ) self . widget . connect_events ( reset_action . triggered , 'Reset' ) # show grid grid_action = QtGui . QAction ( "Show grid (G)" , self ) grid_action . setIcon ( get_icon ( 'grid' ) ) self . widget . connect_events ( grid_action . triggered , 'Grid' ) # fullscreen fullscreen_action = QtGui . QAction ( "Fullscreen (F)" , self ) fullscreen_action . setIcon ( get_icon ( 'fullscreen' ) ) self . widget . connect_events ( fullscreen_action . triggered , 'Fullscreen' ) # save image save_action = QtGui . QAction ( "Save image (S)" , self ) save_action . setIcon ( get_icon ( 'save' ) ) save_action . setShortcut ( "S" ) save_action . triggered . connect ( self . save ) toolbar_action = QtGui . QAction ( "Toggle toolbar visibility (T)" , self ) toolbar_action . setIcon ( get_icon ( 'toolbar' ) ) toolbar_action . setShortcut ( "T" ) toolbar_action . triggered . connect ( self . toggle_toolbar ) # self.toolbar_action = toolbar_action # help help_action = QtGui . QAction ( "Show help (H)" , self ) help_action . setIcon ( get_icon ( 'help' ) ) self . widget . connect_events ( help_action . triggered , 'Help' ) # exit exit_action = QtGui . QAction ( "Exit (Q)" , self ) exit_action . setIcon ( get_icon ( 'exit' ) ) exit_action . triggered . connect ( self . close ) # add toolbar mytoolbar = QtGui . QToolBar ( self . widget ) mytoolbar . setIconSize ( QtCore . QSize ( 32 , 32 ) ) for action in [ reset_action , grid_action , fullscreen_action , toolbar_action , save_action , help_action , exit_action ] : self . addAction ( action ) mytoolbar . addAction ( action ) mytoolbar . setStyleSheet ( """
            QToolBar, QToolButton
            {
                background: #000000;
                border-color: #000000;
                color: #ffffff;
            }
            QToolButton
            {
                margin-left: 5px;
            }
            QToolButton:hover
            {
                background: #2a2a2a;
            }
            """ ) mytoolbar . setMovable ( False ) mytoolbar . setFloatable ( False ) self . toolbar = mytoolbar self . addToolBar ( mytoolbar ) def save ( self ) : """Open a file dialog and save the current image in the specified
            PNG file.""" initial_filename = 'screen' existing = filter ( lambda f : f . startswith ( initial_filename ) , os . listdir ( '.' ) ) i = 0 if existing : for f in existing : r = re . match ( 'screen([0-9]*).png' , f ) i = max ( i , int ( r . groups ( ) [ 0 ] ) ) i += 1 # if last: # last = int(last) # i = last + 1 filename , _ = QtGui . QFileDialog . getSaveFileName ( self , "Save the current view in a PNG image" , initial_filename + str ( i ) + '.png' , # '*.png', # '*.png', # QtGui.QFileDialog.AnyFile, ) if filename : self . widget . save_image ( str ( filename ) ) def closeEvent ( self , e ) : """Clean up memory upon closing.""" self . widget . user_action_generator . close ( ) self . widget . paint_manager . cleanup ( ) super ( BasicWindow , self ) . closeEvent ( e ) def contextMenuEvent ( self , e ) : return return BasicWindow