[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9577 - gnuradio/trunk/grc/src/platforms/gui
From: |
jblum |
Subject: |
[Commit-gnuradio] r9577 - gnuradio/trunk/grc/src/platforms/gui |
Date: |
Sun, 14 Sep 2008 21:53:06 -0600 (MDT) |
Author: jblum
Date: 2008-09-14 21:53:04 -0600 (Sun, 14 Sep 2008)
New Revision: 9577
Modified:
gnuradio/trunk/grc/src/platforms/gui/Block.py
gnuradio/trunk/grc/src/platforms/gui/Constants.py
gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py
gnuradio/trunk/grc/src/platforms/gui/Port.py
Log:
port dimensions based on label text
Modified: gnuradio/trunk/grc/src/platforms/gui/Block.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Block.py 2008-09-14 18:37:08 UTC
(rev 9576)
+++ gnuradio/trunk/grc/src/platforms/gui/Block.py 2008-09-15 03:53:04 UTC
(rev 9577)
@@ -23,8 +23,7 @@
import Colors
from ... gui.Constants import BORDER_PROXIMITY_SENSITIVITY
from Constants import \
- BLOCK_FONT, LABEL_PADDING_WIDTH, \
- LABEL_PADDING_HEIGHT, PORT_HEIGHT, \
+ BLOCK_FONT, BLOCK_LABEL_PADDING, \
PORT_SEPARATION, LABEL_SEPARATION, \
PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS
import pygtk
@@ -116,12 +115,15 @@
self.bg_color = self.get_enabled() and Colors.BG_COLOR or
Colors.DISABLED_BG_COLOR
self.clear()
self._create_labels()
- self.W = self.label_width + 2*LABEL_PADDING_WIDTH
- max_ports = max(len(self.get_sinks()), len(self.get_sources()),
1)
- self.H = max(self.label_height+2*LABEL_PADDING_HEIGHT,
2*PORT_BORDER_SEPARATION + max_ports*PORT_HEIGHT +
(max_ports-1)*PORT_SEPARATION)
- if self.is_horizontal(): self.add_area((0,0),(self.W,self.H))
- elif self.is_vertical(): self.add_area((0,0),(self.H,self.W))
- map(lambda p: p.update(), self.get_sinks() + self.get_sources())
+ self.W = self.label_width + 2*BLOCK_LABEL_PADDING
+ self.H = max(*(
+ [self.label_height+2*BLOCK_LABEL_PADDING] +
[2*PORT_BORDER_SEPARATION + \
+ sum([port.H + PORT_SEPARATION for port in ports]) -
PORT_SEPARATION
+ for ports in (self.get_sources(), self.get_sinks())]
+ ))
+ if self.is_horizontal(): self.add_area((0, 0), (self.W, self.H))
+ elif self.is_vertical(): self.add_area((0, 0), (self.H, self.W))
+ map(lambda p: p.update(), self.get_ports())
def _create_labels(self):
"""Create the labels for the signal block."""
@@ -164,6 +166,7 @@
self.vertical_label = vimage =
gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), height, width)
for i in range(width):
for j in range(height): vimage.put_pixel(j,
width-i-1, image.get_pixel(i, j))
+ map(lambda p: p._create_labels(), self.get_ports())
def draw(self, window):
"""
@@ -176,9 +179,9 @@
#draw label image
gc = self.get_gc()
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+BLOCK_LABEL_PADDING, 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+BLOCK_LABEL_PADDING, -1, -1)
#draw ports
map(lambda p: p.draw(window), self.get_ports())
Modified: gnuradio/trunk/grc/src/platforms/gui/Constants.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Constants.py 2008-09-14 18:37:08 UTC
(rev 9576)
+++ gnuradio/trunk/grc/src/platforms/gui/Constants.py 2008-09-15 03:53:04 UTC
(rev 9577)
@@ -21,13 +21,12 @@
#label constraint dimensions
LABEL_SEPARATION = 3
-LABEL_PADDING_WIDTH = 9
-LABEL_PADDING_HEIGHT = 9
+BLOCK_LABEL_PADDING = 7
+PORT_LABEL_PADDING = 2
#port constraint dimensions
PORT_SEPARATION = 17
-PORT_HEIGHT = 15
-PORT_WIDTH = 25
PORT_BORDER_SEPARATION = 9
+PORT_MIN_WIDTH = 20
#fonts
PARAM_LABEL_FONT = 'Sans 9.5'
PARAM_FONT = 'Sans 7.5'
Modified: gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py 2008-09-14 18:37:08 UTC
(rev 9576)
+++ gnuradio/trunk/grc/src/platforms/gui/FlowGraph.py 2008-09-15 03:53:04 UTC
(rev 9577)
@@ -213,7 +213,7 @@
"""
changed = False
for selected_block in self.get_selected_blocks():
- for ports in selected_block.get_ports():
+ for ports in (selected_block.get_sinks(),
selected_block.get_sources()):
if ports and hasattr(ports[0], 'get_nports')
and ports[0].get_nports():
#find the param that controls port0
for param in
selected_block.get_params():
Modified: gnuradio/trunk/grc/src/platforms/gui/Port.py
===================================================================
--- gnuradio/trunk/grc/src/platforms/gui/Port.py 2008-09-14 18:37:08 UTC
(rev 9576)
+++ gnuradio/trunk/grc/src/platforms/gui/Port.py 2008-09-15 03:53:04 UTC
(rev 9577)
@@ -19,9 +19,9 @@
from Element import Element
from Constants import \
- PORT_HEIGHT, PORT_SEPARATION, \
- PORT_WIDTH, CONNECTOR_EXTENSION_MINIMAL, \
- CONNECTOR_EXTENSION_INCREMENT, PORT_FONT
+ PORT_SEPARATION, CONNECTOR_EXTENSION_MINIMAL, \
+ CONNECTOR_EXTENSION_INCREMENT, PORT_FONT, \
+ PORT_LABEL_PADDING, PORT_MIN_WIDTH
import Colors
import pygtk
pygtk.require('2.0')
@@ -42,63 +42,65 @@
def update(self):
"""Create new areas and labels for the port."""
self.clear()
- self.BG_color = Colors.get_color(self.get_color())
- self._create_labels()
#get current rotation
rotation = self.get_rotation()
#get all sibling ports
if self.is_source(): ports = self.get_parent().get_sources()
elif self.is_sink(): ports = self.get_parent().get_sinks()
+ #get the max width
+ self.W = max([port.W for port in ports] + [PORT_MIN_WIDTH])
#get a numeric index for this port relative to its sibling ports
index = ports.index(self)
length = len(ports)
#reverse the order of ports for these rotations
if rotation in (180, 270): index = length-index-1
- offset = (self.get_parent().H - length*PORT_HEIGHT -
(length-1)*PORT_SEPARATION)/2
+ offset = (self.get_parent().H - length*self.H -
(length-1)*PORT_SEPARATION)/2
#create areas and connector coordinates
if (self.is_sink() and rotation == 0) or (self.is_source() and
rotation == 180):
- x = -1*PORT_WIDTH
- y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
- self._connector_coordinate = (x-1, y+PORT_HEIGHT/2)
+ x = -1*self.W
+ y = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.W, self.H))
+ self._connector_coordinate = (x-1, y+self.H/2)
elif (self.is_source() and rotation == 0) or (self.is_sink()
and rotation == 180):
x = self.get_parent().W
- y = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_WIDTH, PORT_HEIGHT))
- self._connector_coordinate = (x+1+PORT_WIDTH,
y+PORT_HEIGHT/2)
+ y = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.W, self.H))
+ self._connector_coordinate = (x+1+self.W, y+self.H/2)
elif (self.is_source() and rotation == 90) or (self.is_sink()
and rotation == 270):
- y = -1*PORT_WIDTH
- x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
- self._connector_coordinate = (x+PORT_HEIGHT/2, y-1)
+ y = -1*self.W
+ x = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.H, self.W))
+ self._connector_coordinate = (x+self.H/2, y-1)
elif (self.is_sink() and rotation == 90) or (self.is_source()
and rotation == 270):
y = self.get_parent().W
- x = (PORT_SEPARATION+PORT_HEIGHT)*index+offset
- self.add_area((x, y), (PORT_HEIGHT, PORT_WIDTH))
- self._connector_coordinate = (x+PORT_HEIGHT/2,
y+1+PORT_WIDTH)
+ x = (PORT_SEPARATION+self.H)*index+offset
+ self.add_area((x, y), (self.H, self.W))
+ self._connector_coordinate = (x+self.H/2, y+1+self.W)
#the connector length
self._connector_length = CONNECTOR_EXTENSION_MINIMAL +
CONNECTOR_EXTENSION_INCREMENT*index
def _create_labels(self):
"""Create the labels for the socket."""
+ self.BG_color = Colors.get_color(self.get_color())
#create the layout
layout = gtk.DrawingArea().create_pango_layout(self.get_name())
desc = pango.FontDescription(PORT_FONT)
layout.set_font_description(desc)
- w,h = self.w,self.h = layout.get_pixel_size()
+ self.w, self.h = layout.get_pixel_size()
+ self.W, self.H = 2*PORT_LABEL_PADDING+self.w,
2*PORT_LABEL_PADDING+self.h
#create the pixmap
- pixmap =
gtk.gdk.Pixmap(self.get_parent().get_parent().get_window(), w, h, -1)
+ pixmap =
gtk.gdk.Pixmap(self.get_parent().get_parent().get_window(), self.w, self.h, -1)
gc = pixmap.new_gc()
gc.foreground = self.BG_color
- pixmap.draw_rectangle(gc, True, 0, 0, w, h)
+ pixmap.draw_rectangle(gc, True, 0, 0, self.w, self.h)
gc.foreground = Colors.TXT_COLOR
pixmap.draw_layout(gc, 0, 0, layout)
#create the images
- self.horizontal_label = image = pixmap.get_image(0, 0, w, h)
+ self.horizontal_label = image = pixmap.get_image(0, 0, self.w,
self.h)
if self.is_vertical():
- self.vertical_label = vimage =
gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), h, w)
- for i in range(w):
- for j in range(h): vimage.put_pixel(j, w-i-1,
image.get_pixel(i, j))
+ self.vertical_label = vimage =
gtk.gdk.Image(gtk.gdk.IMAGE_NORMAL, pixmap.get_visual(), self.h, self.w)
+ for i in range(self.w):
+ for j in range(self.h): vimage.put_pixel(j,
self.w-i-1, image.get_pixel(i, j))
def draw(self, window):
"""
@@ -111,9 +113,9 @@
X,Y = self.get_coordinate()
(x,y),(w,h) = self.areas_dict[self.get_rotation()][0] #use the
first area's sizes to place the labels
if self.is_horizontal():
- window.draw_image(gc, self.horizontal_label, 0, 0,
x+X+(PORT_WIDTH-self.w)/2, y+Y+(PORT_HEIGHT-self.h)/2, -1, -1)
+ window.draw_image(gc, self.horizontal_label, 0, 0,
x+X+(self.W-self.w)/2, y+Y+(self.H-self.h)/2, -1, -1)
elif self.is_vertical():
- window.draw_image(gc, self.vertical_label, 0, 0,
x+X+(PORT_HEIGHT-self.h)/2, y+Y+(PORT_WIDTH-self.w)/2, -1, -1)
+ window.draw_image(gc, self.vertical_label, 0, 0,
x+X+(self.H-self.h)/2, y+Y+(self.W-self.w)/2, -1, -1)
def get_connector_coordinate(self):
"""
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9577 - gnuradio/trunk/grc/src/platforms/gui,
jblum <=