Ignore:
Timestamp:
07/04/19 17:29:58 (5 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
python3
Phase:
public
Message:

Removed conditions on pygobject (re #347)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/delaycodes.py

    r965 r994  
    1111#------------------------------------------------------------------------------
    1212
    13 if pygobject:
    14 
    15 #------------------------------------------------------------------------------
    16 
    17     class Viewport(gtk.Viewport):
    18         """Viewport implementation that alleviates the problem with improper
    19         resizing by the VBox."""
    20         def __init__(self):
    21             """Construct the viewport."""
    22             gtk.Viewport.__init__(self)
    23             self._recursive = False
     13class Viewport(gtk.Viewport):
     14    """Viewport implementation that alleviates the problem with improper
     15    resizing by the VBox."""
     16    def __init__(self):
     17        """Construct the viewport."""
     18        gtk.Viewport.__init__(self)
     19        self._recursive = False
     20        self._vboxHeight = None
     21
     22    def setVBOXHeight(self, vboxHeight):
     23        """Set the height of the VBox which will be used to calculate the
     24        viewport's height."""
     25        self._vboxHeight = vboxHeight
     26
     27    def do_size_allocate(self, allocation):
     28        """Called when the viewport's size is allocated.
     29
     30        The height in the allocation object is modified so that it is only
     31        so high to fit into the VBox."""
     32        if self._vboxHeight is not None:
     33            allocation.y += 1
     34            allocation.height = self._vboxHeight - allocation.y
    2435            self._vboxHeight = None
    25 
    26         def setVBOXHeight(self, vboxHeight):
    27             """Set the height of the VBox which will be used to calculate the
    28             viewport's height."""
    29             self._vboxHeight = vboxHeight
    30 
    31         def do_size_allocate(self, allocation):
    32             """Called when the viewport's size is allocated.
    33 
    34             The height in the allocation object is modified so that it is only
    35             so high to fit into the VBox."""
    36             if self._vboxHeight is not None:
    37                 allocation.y += 1
    38                 allocation.height = self._vboxHeight - allocation.y
    39                 self._vboxHeight = None
    40             gtk.Viewport.do_size_allocate(self, allocation)
    41 
    42     class DelayCodeTableBase(gtk.VBox, gtk.Scrollable):
    43         """PyGObject-specific base class for the delay code table."""
    44         __gproperties__ = {
    45             "vscroll-policy" : ( gtk.ScrollablePolicy,
    46                                  "vscroll-policy",
    47                                  "The vertical scrolling policy",
    48                                  gtk.ScrollablePolicy.MINIMUM,
    49                                  gobject.PARAM_READWRITE ),
    50             "vadjustment" : ( gtk.Adjustment,
    51                               "vadjustment",
    52                               "The vertical adjustment",
    53                               gobject.PARAM_READWRITE ),
    54             "hscroll-policy" : ( gtk.ScrollablePolicy,
    55                                  "hscroll-policy",
    56                                  "The horizontal scrolling policy",
    57                                  gtk.ScrollablePolicy.MINIMUM,
    58                                  gobject.PARAM_READWRITE ),
    59             "hadjustment" : ( gtk.Adjustment,
    60                               "hadjustment",
    61                               "The horizontal adjustment",
    62                               gobject.PARAM_READWRITE )  }
    63 
    64 
    65         @staticmethod
    66         def _createViewport():
    67             """Create an instance of the viewport class used by this base class."""
    68             return Viewport()
    69 
    70         def __init__(self):
    71             """Construct the delay code table."""
    72             super(DelayCodeTableBase, self).__init__()
    73 
    74         def do_size_allocate(self, allocation):
    75             """Allocate the size for the table and its children.
    76 
    77             This sets up the VBox height in the viewport and then calls the
    78             do_size_allocate() function of VBox()."""
    79             self._viewport.setVBOXHeight(allocation.height)
    80             gtk.VBox.do_size_allocate(self, allocation)
    81             self.allocate_column_sizes(allocation)
    82 
    83         def do_get_property(self, prop):
    84             """Get the value of one of the properties defined above.
    85 
    86             The request is forwarded to the viewport."""
    87             if prop.name=="vscroll-policy":
    88                 return self._viewport.get_vscroll_policy()
    89             elif prop.name=="hscroll-policy":
    90                 return self._viewport.get_hscroll_policy()
    91             elif prop.name=="vadjustment":
    92                 return self._viewport.get_vadjustment()
    93             elif prop.name=="hadjustment":
    94                 return self._viewport.get_hadjustment()
    95             else:
    96                 raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_get_property" %
    97                                      (prop.name,))
    98 
    99         def do_set_property(self, prop, value):
    100             """Set the value of the adjustment properties defined above.
    101 
    102             The adjustments are forwarded to the viewport."""
    103             if prop.name=="vadjustment":
    104                 self._viewport.set_vadjustment(value)
    105             elif prop.name=="hadjustment":
    106                 self._viewport.set_hadjustment(value)
    107                 self._treeView.set_hadjustment(value)
    108             else:
    109                 raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_set_property" %
    110                                      (prop.name,))
    111 
    112         def setStyle(self):
    113             """Set the style of the event box from the treeview."""
    114 
    115     class Alignment(gtk.Alignment):
    116         """An alignment that remembers the width it was given."""
    117         def __init__(self, xalign = 0.0, yalign=0.0,
    118                      xscale = 0.0, yscale = 0.0 ):
    119             """Construct the alignment."""
    120             super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
    121                                             xscale = xscale, yscale = yscale)
    122             self.allocatedWidth = 0
    123 
    124         def do_size_allocate(self, allocation):
    125             """Called with the new size allocation."""
    126             self.allocatedWidth = allocation.width
    127             gtk.Alignment.do_size_allocate(self, allocation)
    128 
    129     class TreeView(gtk.TreeView):
    130         def do_size_allocate(self, allocation):
    131             allocation.height += 1
    132             gtk.TreeView.do_size_allocate(self, allocation)
    133 
    134 #------------------------------------------------------------------------------
    135 
    136 else: # pygobject
    137 
    138 #------------------------------------------------------------------------------
    139 
    140     class DelayCodeTableBase (gtk.VBox):
    141         """Base class of the delay code table for PyGtk."""
    142 
    143         __gsignals__ = {
    144             "set-scroll-adjustments": (
    145                 gobject.SIGNAL_RUN_LAST,
    146                 gobject.TYPE_NONE, (gtk.Adjustment, gtk.Adjustment))
    147                 }
    148 
    149         @staticmethod
    150         def _createViewport():
    151             """Create an instance of the viewport class used by this base class."""
    152             return gtk.Viewport()
    153 
    154         def __init__(self):
    155             """Construct the base class."""
    156             super(DelayCodeTableBase, self).__init__()
    157             self.set_set_scroll_adjustments_signal("set-scroll-adjustments")
    158             self.connect("size-allocate", self._do_size_allocate)
    159 
    160         def do_set_scroll_adjustments(self, hAdjustment, vAdjustment):
    161             """Set the adjustments on the viewport."""
    162             self._viewport.set_hadjustment(hAdjustment)
    163             self._viewport.set_vadjustment(vAdjustment)
    164             self._treeView.set_hadjustment(hAdjustment)
    165 
    166         def _do_size_allocate(self, widget, allocation):
    167             """Handler of the size-allocate signal.
    168 
    169             Calls allocate_column_sizes()."""
    170             self.allocate_column_sizes(allocation)
    171 
    172         def setStyle(self):
    173             """Set the style of the event box from the treeview."""
    174             if self._treeView is not None:
    175                 style = self._treeView.rc_get_style()
    176                 self._eventBox.modify_bg(0, style.bg[2])
    177                 self._eventBox.modify_fg(0, style.fg[2])
    178 
    179     class Alignment(gtk.Alignment):
    180         """An alignment that remembers the width it was given."""
    181         def __init__(self, xalign = 0.0, yalign=0.0,
    182                      xscale = 0.0, yscale = 0.0 ):
    183             """Construct the alignment."""
    184             super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
    185                                             xscale = xscale, yscale = yscale)
    186             self.allocatedWidth = 0
    187             self.connect("size-allocate", self._do_size_allocate)
    188 
    189         def _do_size_allocate(self, widget, allocation):
    190             """Called with the new size allocation."""
    191             self.allocatedWidth = allocation.width
     36        gtk.Viewport.do_size_allocate(self, allocation)
     37
     38class DelayCodeTableBase(gtk.VBox, gtk.Scrollable):
     39    """PyGObject-specific base class for the delay code table."""
     40    __gproperties__ = {
     41        "vscroll-policy" : ( gtk.ScrollablePolicy,
     42                             "vscroll-policy",
     43                             "The vertical scrolling policy",
     44                             gtk.ScrollablePolicy.MINIMUM,
     45                             gobject.PARAM_READWRITE ),
     46        "vadjustment" : ( gtk.Adjustment,
     47                          "vadjustment",
     48                          "The vertical adjustment",
     49                          gobject.PARAM_READWRITE ),
     50        "hscroll-policy" : ( gtk.ScrollablePolicy,
     51                             "hscroll-policy",
     52                             "The horizontal scrolling policy",
     53                             gtk.ScrollablePolicy.MINIMUM,
     54                             gobject.PARAM_READWRITE ),
     55        "hadjustment" : ( gtk.Adjustment,
     56                          "hadjustment",
     57                          "The horizontal adjustment",
     58                          gobject.PARAM_READWRITE )  }
     59
     60
     61    @staticmethod
     62    def _createViewport():
     63        """Create an instance of the viewport class used by this base class."""
     64        return Viewport()
     65
     66    def __init__(self):
     67        """Construct the delay code table."""
     68        super(DelayCodeTableBase, self).__init__()
     69
     70    def do_size_allocate(self, allocation):
     71        """Allocate the size for the table and its children.
     72
     73        This sets up the VBox height in the viewport and then calls the
     74        do_size_allocate() function of VBox()."""
     75        self._viewport.setVBOXHeight(allocation.height)
     76        gtk.VBox.do_size_allocate(self, allocation)
     77        self.allocate_column_sizes(allocation)
     78
     79    def do_get_property(self, prop):
     80        """Get the value of one of the properties defined above.
     81
     82        The request is forwarded to the viewport."""
     83        if prop.name=="vscroll-policy":
     84            return self._viewport.get_vscroll_policy()
     85        elif prop.name=="hscroll-policy":
     86            return self._viewport.get_hscroll_policy()
     87        elif prop.name=="vadjustment":
     88            return self._viewport.get_vadjustment()
     89        elif prop.name=="hadjustment":
     90            return self._viewport.get_hadjustment()
     91        else:
     92            raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_get_property" %
     93                                 (prop.name,))
     94
     95    def do_set_property(self, prop, value):
     96        """Set the value of the adjustment properties defined above.
     97
     98        The adjustments are forwarded to the viewport."""
     99        if prop.name=="vadjustment":
     100            self._viewport.set_vadjustment(value)
     101        elif prop.name=="hadjustment":
     102            self._viewport.set_hadjustment(value)
     103            self._treeView.set_hadjustment(value)
     104        else:
     105            raise AttributeError("mlx.gui.delaycodes.DelayCodeTableBase: property %s is not handled in do_set_property" %
     106                                 (prop.name,))
     107
     108    def setStyle(self):
     109        """Set the style of the event box from the treeview."""
     110
     111class Alignment(gtk.Alignment):
     112    """An alignment that remembers the width it was given."""
     113    def __init__(self, xalign = 0.0, yalign=0.0,
     114                 xscale = 0.0, yscale = 0.0 ):
     115        """Construct the alignment."""
     116        super(Alignment, self).__init__(xalign = xalign, yalign = yalign,
     117                                        xscale = xscale, yscale = yscale)
     118        self.allocatedWidth = 0
     119
     120    def do_size_allocate(self, allocation):
     121        """Called with the new size allocation."""
     122        self.allocatedWidth = allocation.width
     123        gtk.Alignment.do_size_allocate(self, allocation)
     124
     125class TreeView(gtk.TreeView):
     126    def do_size_allocate(self, allocation):
     127        allocation.height += 1
     128        gtk.TreeView.do_size_allocate(self, allocation)
    192129
    193130#------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.