commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9053 - in grc/trunk: . src/grc src/grc/gui/elements


From: jblum
Subject: [Commit-gnuradio] r9053 - in grc/trunk: . src/grc src/grc/gui/elements
Date: Tue, 29 Jul 2008 18:19:09 -0600 (MDT)

Author: jblum
Date: 2008-07-29 18:19:08 -0600 (Tue, 29 Jul 2008)
New Revision: 9053

Modified:
   grc/trunk/readme.txt
   grc/trunk/src/grc/ActionHandler.py
   grc/trunk/src/grc/Actions.py
   grc/trunk/src/grc/ParseXML.py
   grc/trunk/src/grc/gui/elements/Block.py
   grc/trunk/src/grc/gui/elements/Element.py
   grc/trunk/src/grc/gui/elements/FlowGraph.py
Log:
group rotate

Modified: grc/trunk/readme.txt
===================================================================
--- grc/trunk/readme.txt        2008-07-29 21:02:50 UTC (rev 9052)
+++ grc/trunk/readme.txt        2008-07-30 00:19:08 UTC (rev 9053)
@@ -1,9 +1,9 @@
 Hello!
 
 Thank you for downloading GNU Radio Companion.
-This program is free software. 
+This program is free software.
 A GPL license is distributed with this program.
-This license covers all the source code/python files. 
+This license covers all the source code/python files.
 You will also find a "creative commons license" for the grc icon.
 
 Intructions for GRC are available at:
@@ -12,14 +12,14 @@
 If you have questions, problems, suggestions, or want to contribute,
 please email me at josh at joshknows dot com
 
-   ---   Quickstart   ---   
+   ---   Quickstart   ---
 
-Install grc: 
+Install grc:
        "sudo make install"
-       
-Install the grc/gnuradio docs: 
+
+Install the grc/gnuradio docs:
        "sudo make docs_install"
-       
-Execute grc: 
+
+Execute grc:
        open a terminal and type "grc"
 

Modified: grc/trunk/src/grc/ActionHandler.py
===================================================================
--- grc/trunk/src/grc/ActionHandler.py  2008-07-29 21:02:50 UTC (rev 9052)
+++ grc/trunk/src/grc/ActionHandler.py  2008-07-30 00:19:08 UTC (rev 9053)
@@ -235,10 +235,12 @@
                        self.get_page().set_saved(False)
                elif state == BLOCK_ROTATE_LEFT:
                        if self.get_flow_graph().rotate_selected(DIR_LEFT):
+                               self.get_flow_graph().update()
                                
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
                                self.get_page().set_saved(False)
                elif state == BLOCK_ROTATE_RIGHT:
                        if self.get_flow_graph().rotate_selected(DIR_RIGHT):
+                               self.get_flow_graph().update()
                                
self.get_page().get_state_cache().save_new_state(self.get_flow_graph().export_data())
                                self.get_page().set_saved(False)
                elif state == ELEMENT_DELETE:

Modified: grc/trunk/src/grc/Actions.py
===================================================================
--- grc/trunk/src/grc/Actions.py        2008-07-29 21:02:50 UTC (rev 9052)
+++ grc/trunk/src/grc/Actions.py        2008-07-30 00:19:08 UTC (rev 9053)
@@ -26,7 +26,7 @@
 import gtk
 
 
######################################################################################################
-#      states
+# States
 
######################################################################################################
 
 APPLICATION_INITIALIZE = 'app init'
@@ -72,15 +72,15 @@
 PREFS_WINDOW_DISPLAY = 'prefs window display'
 
 
######################################################################################################
-#      actions
+# Actions
 
######################################################################################################
 
 ACTIONS_LIST = (
        gtk.Action(FLOW_GRAPH_NEW, '_New', 'Create a new flow graph', 
'gtk-new'),
-       gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open a flow graph from file', 
'gtk-open'),
-       gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save this flow graph', 
'gtk-save'),
-       gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the open flow graph 
as...', 'gtk-save-as'),
-       gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the open flow graph', 
'gtk-close'),
+       gtk.Action(FLOW_GRAPH_OPEN, '_Open', 'Open an existing flow graph', 
'gtk-open'),
+       gtk.Action(FLOW_GRAPH_SAVE, '_Save', 'Save the current flow graph', 
'gtk-save'),
+       gtk.Action(FLOW_GRAPH_SAVE_AS, 'Save _As', 'Save the current flow graph 
as...', 'gtk-save-as'),
+       gtk.Action(FLOW_GRAPH_CLOSE, '_Close', 'Close the current flow graph', 
'gtk-close'),
        gtk.Action(APPLICATION_QUIT, '_Quit', 'Quit program', 'gtk-quit'),
        gtk.Action(FLOW_GRAPH_UNDO, '_Undo', 'Undo a change to the flow graph', 
'gtk-undo'),
        gtk.Action(FLOW_GRAPH_REDO, '_Redo', 'Redo a change to the flow graph', 
'gtk-redo'),

Modified: grc/trunk/src/grc/ParseXML.py
===================================================================
--- grc/trunk/src/grc/ParseXML.py       2008-07-29 21:02:50 UTC (rev 9052)
+++ grc/trunk/src/grc/ParseXML.py       2008-07-30 00:19:08 UTC (rev 9053)
@@ -24,7 +24,7 @@
 from Utils import odict
 
 XMLSyntaxError = etree.XMLSyntaxError
-       
+
 def validate_dtd(xml_file, dtd_file=None):
        """!
        Validate an xml file against its dtd.
@@ -39,7 +39,7 @@
                        raise XMLSyntaxError, '\n'.join(map(str, 
dtd.error_log.filter_from_errors()))
        else:
                parser = etree.XMLParser(dtd_validation=True)
-               xml = etree.parse(xml_file, parser=parser)      
+               xml = etree.parse(xml_file, parser=parser)
                if parser.error_log:
                        raise XMLSyntaxError, '\n'.join(map(str, 
parser.error_log.filter_from_errors()))
 
@@ -51,15 +51,15 @@
        """
        xml = etree.parse(xml_file).getroot()
        return _from_file(xml)
-       
+
 def _from_file(xml):
        """!
-       Recursivly parse the xml tree into nested data format.  
+       Recursivly parse the xml tree into nested data format.
        @param xml the xml tree
        @return the nested data
-       """     
+       """
        tag = xml.tag
-       if not len(xml): 
+       if not len(xml):
                return odict({tag: xml.text or ''}) #store empty tags (text is 
None) as empty string
        nested_data = odict()
        for elem in xml:
@@ -70,7 +70,7 @@
        for key, values in nested_data.iteritems():
                if len(values) == 1: nested_data[key] = values[0]
        return odict({tag: nested_data})
-       
+
 def to_file(nested_data, xml_file):
        """!
        Write an xml file and use the to xml helper method to load it.
@@ -79,13 +79,13 @@
        """
        xml = _to_file(nested_data)[0]
        open(xml_file, 'w').write(etree.tostring(xml, xml_declaration=True, 
pretty_print=True))
-       
+
 def _to_file(nested_data):
        """!
        Recursivly parse the nested data into xml tree format.
        @param nested_data the nested data
        @return the xml tree filled with child nodes
-       """     
+       """
        nodes = list()
        for key,values in nested_data.iteritems():
                #listify the values if not a list
@@ -98,6 +98,6 @@
                        nodes.append(node)
        return nodes
 
-if __name__ == '__main__':     
+if __name__ == '__main__':
        """Use the main method to test parse xml's functions."""
-       pass    
+       pass

Modified: grc/trunk/src/grc/gui/elements/Block.py
===================================================================
--- grc/trunk/src/grc/gui/elements/Block.py     2008-07-29 21:02:50 UTC (rev 
9052)
+++ grc/trunk/src/grc/gui/elements/Block.py     2008-07-30 00:19:08 UTC (rev 
9053)
@@ -129,7 +129,7 @@
                else: layout.set_markup('<span 
foreground="red"><b>'+Utils.xml_encode(self.get_name())+'</b></span>')
                desc = pango.FontDescription(BLOCK_FONT)
                layout.set_font_description(desc)
-               self.label_width,self.label_height = layout.get_pixel_size()
+               self.label_width, self.label_height = layout.get_pixel_size()
                #display the params (except for the special params id and 
position)
                if Preferences.show_params():
                        for param in filter(lambda p: not 
(p.get_key().startswith('gui_') or p.get_key().startswith('_')), 
self.get_params()):
@@ -167,14 +167,16 @@
                Draw the signal block with label and inputs/outputs.
                @param window the gtk window to draw on
                """
+               x, y = self.get_coordinate()
+               #draw main block
                Element.draw(self, window, BG_color=self.bg_color)
+               #draw label image
                gc = self.get_gc()
-               gc.foreground = Colors.TXT_COLOR
-               X,Y = self.get_coordinate()
                if self.is_horizontal():
-                       window.draw_image(gc, self.horizontal_label, 0, 0, 
X+LABEL_PADDING_WIDTH, Y+(self.H-self.label_height)/2, -1, -1)
+                       window.draw_image(gc, self.horizontal_label, 0, 0, 
x+LABEL_PADDING_WIDTH, y+(self.H-self.label_height)/2, -1, -1)
                elif self.is_vertical():
-                       window.draw_image(gc, self.vertical_label, 0, 0, 
X+(self.H-self.label_height)/2, Y+LABEL_PADDING_WIDTH, -1, -1)
+                       window.draw_image(gc, self.vertical_label, 0, 0, 
x+(self.H-self.label_height)/2, y+LABEL_PADDING_WIDTH, -1, -1)
+               #draw ports
                map(lambda p: p.draw(window), self.get_ports())
 
        def what_is_selected(self, coor, coor_m=None):

Modified: grc/trunk/src/grc/gui/elements/Element.py
===================================================================
--- grc/trunk/src/grc/gui/elements/Element.py   2008-07-29 21:02:50 UTC (rev 
9052)
+++ grc/trunk/src/grc/gui/elements/Element.py   2008-07-30 00:19:08 UTC (rev 
9053)
@@ -90,12 +90,9 @@
        def rotate(self, direction):
                """!
                Rotate all of the areas by 90 degrees.
-               @param direction DIR_RIGHT or DIR_LEFT
+               @param direction 90 or 270 degrees
                """
-               if direction == DIR_LEFT: delta_rotation = 90
-               elif direction == DIR_RIGHT: delta_rotation = 270
-               self.set_rotation((self.get_rotation() + delta_rotation)%360)
-               self.update()
+               self.set_rotation((self.get_rotation() + direction)%360)
 
        def clear(self):
                """Empty the lines and areas."""

Modified: grc/trunk/src/grc/gui/elements/FlowGraph.py
===================================================================
--- grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-29 21:02:50 UTC (rev 
9052)
+++ grc/trunk/src/grc/gui/elements/FlowGraph.py 2008-07-30 00:19:08 UTC (rev 
9053)
@@ -261,11 +261,30 @@
                @param direction DIR_LEFT or DIR_RIGHT
                @return true if changed, otherwise false.
                """
-               changed = False
+               if not self.get_selected_blocks(): return False
+               #determine the number of degrees to rotate
+               direction = {DIR_LEFT: 90, DIR_RIGHT:270}[direction]
+               cos_r = {0: 1, 90: 0, 180: -1, 270: 0}[direction]
+               sin_r = {0: 0, 90: 1, 180: 0, 270: -1}[direction]
+               #initialize min and max coordinates
+               min_x, min_y = self.get_selected_block().get_coordinate()
+               max_x, max_y = self.get_selected_block().get_coordinate()
+               #rotate each selected block, and find min/max coordinate
                for selected_block in self.get_selected_blocks():
                        selected_block.rotate(direction)
-                       changed = True
-               return changed
+                       #update the min/max coordinate
+                       x, y = selected_block.get_coordinate()
+                       min_x, min_y = min(min_x, x), min(min_y, y)
+                       max_x, max_y = max(max_x, x), max(max_y, y)
+               #calculate center point of slected blocks
+               ctr_x, ctr_y = (max_x + min_x)/2, (max_y + min_y)/2
+               #rotate the blocks around the center point
+               for selected_block in self.get_selected_blocks():
+                       x, y = selected_block.get_coordinate()
+                       x, y = x - ctr_x, y - ctr_y
+                       x, y = (x*cos_r + y*sin_r + ctr_x, -x*sin_r + y*cos_r + 
ctr_y)
+                       selected_block.set_coordinate((x, y))
+               return True
 
        def remove_selected(self):
                """!





reply via email to

[Prev in Thread] Current Thread [Next in Thread]