changeset 169:5b880b8cff6d

Fixes to make PARPG compatible with changes made to fife.
author Beliar <KarstenBock@gmx.net>
date Sat, 25 Feb 2012 00:21:28 +0100
parents bfd3a4ef7f2b
children 0296f5f74a0f
files gui/inventorygui.py gui/slot.py gui/tabwidget.py
diffstat 3 files changed, 102 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/gui/inventorygui.py	Wed Feb 22 12:31:02 2012 +0100
+++ b/gui/inventorygui.py	Sat Feb 25 00:21:28 2012 +0100
@@ -17,6 +17,7 @@
 
 from fife.extensions.pychan.tools import callbackWithArguments as cbwa
 from fife.extensions import pychan
+from slot import Slot
 from fife.extensions.pychan.attrs import UnicodeAttr
 
 from parpg.gui import drag_drop_data as data_drag
@@ -34,7 +35,7 @@
         pychan.VBox.__init__(self, min_size=min_size, max_size=max_size,
                              **kwargs)
         self.background_image = 'gui/inv_images/inv_background.png'
-        icon = pychan.Icon(name="Icon")
+        icon = Slot(name="Icon")
         self.addChild(icon)
         self.adaptLayout()
         if self.parent is not None:
@@ -51,7 +52,9 @@
         icon.image = image        
 
 class InventoryGrid(pychan.VBox):
-    ATTRIBUTES = pychan.VBox.ATTRIBUTES + [pychan.attrs.PointAttr('grid_size')]
+    ATTRIBUTES = pychan.VBox.ATTRIBUTES + [pychan.attrs.PointAttr('grid_size'), 
+                                            pychan.attrs.PointAttr('cell_size')]
+    
     
     def _setNColumns(self, n_columns):
         n_rows = self.grid_size[1]
@@ -75,20 +78,24 @@
         n_columns, n_rows = grid_size
         self.removeAllChildren()
         for row_n in xrange(n_rows):
-            row_size = (n_columns * 50, 50)
+            row_size = (n_columns * self.cell_size[0], self.cell_size[1])
             row = pychan.HBox(min_size=row_size, max_size=row_size,
                               padding=self.padding)
             row.border_size = 1
             row.opaque = 0
             for column_n in xrange(n_columns):
                 index = (row_n * n_columns + column_n)
-                slot = pychan.Icon(min_size=(50, 50), max_size=(50, 50))
+                slot = Slot(min_size=(self.cell_size), 
+                                    max_size=(self.cell_size))
                 slot.border_size = 1
                 slot.name = "Slot_%d" % index
                 slot.index = index
+                slot.image = None
+                slot.size = self.cell_size
                 row.addChild(slot)
             self.addChild(row)
-        self.min_size = ((n_columns * 50) + 2, (n_rows * 50) + 2)
+        self.min_size = ((n_columns * self.cell_size[0]) + 2, 
+                        (n_rows * self.cell_size[1]) + 2)
         self.max_size = self.min_size
     
     def _getGridSize(self):
@@ -104,15 +111,60 @@
             index = row_or_index
         return self.findChildByName("Slot_%d" % index)
     
-    def __init__(self, grid_size=(2, 2), padding=0, **kwargs):
-        pychan.VBox.__init__(self, padding=padding, **kwargs)
-        self.opaque = 0
+    def __init__(self, 
+                grid_size=(2, 2), 
+                cell_size=(50, 50), 
+                parent = None, 
+                name = None,
+                size = None,
+                min_size = None, 
+                max_size = None, 
+                helptext = None, 
+                position = None, 
+                style = None, 
+                hexpand = None,
+                vexpand = None,
+                font = None,
+                base_color = None,
+                background_color = None,
+                foreground_color = None,
+                selection_color = None,
+                position_technique = None,
+                is_focusable = None,
+                comment = None,
+                background_image = None,
+                _real_widget = None):
+        pychan.VBox.__init__(self, 
+                            parent=parent, 
+                            name=name, 
+                            size=size, 
+                            min_size=min_size, 
+                            max_size=max_size,
+                            helptext=helptext, 
+                            position=position,
+                            style=style, 
+                            hexpand=hexpand, 
+                            vexpand=vexpand,
+                            font=font,
+                            base_color=base_color,
+                            background_color=background_color,
+                            foreground_color=foreground_color,
+                            selection_color=selection_color,
+                            border_size=1,
+                            position_technique=position_technique,
+                            is_focusable=is_focusable,
+                            comment=comment,
+                            padding=0,
+                            background_image=background_image,
+                            opaque=0,
+                            margins=None,
+                            _real_widget=_real_widget)
+        self.cell_size = cell_size
         self.grid_size = grid_size
-        self.border_size = 1
 
 
 class EquipmentGUI(ContainerGUIBase):
-    def __init__(self, controller, gui, equip, callbacks):
+    def __init__(self, controller, gui, equip, callbacks, slot_size = (50, 50)):
         ContainerGUIBase.__init__(self, controller, gui)
         self.equip = equip
         self.equip_to_gui = {
@@ -126,6 +178,7 @@
             "r_arm": "rightHandSlot",
         }
         self.setSlotEvents()
+        self.slot_size = slot_size
         
     def updateImages(self):
         for eq_slot, gui_slot in self.equip_to_gui.iteritems():
@@ -241,6 +294,7 @@
             events_to_map[slot_name + "/mouseReleased"] = self.showContextMenu
 
         self.grid.mapEvents(events_to_map)
+        self.updateImages()
 
     def updateImages(self):
         for index, child in enumerate(self.container.children):
@@ -252,9 +306,10 @@
             self.updateImage(slot)
             
     def updateImage(self, slot):
-        assert(isinstance(slot, pychan.Icon))
+        assert(isinstance(slot, Slot))
         if (slot.item):
             image = slot.item.containable.image
+
         else:
             image = None
         slot.image = image
@@ -388,4 +443,4 @@
     
     def closeInventory(self):
         self.gui.hide()
-        
\ No newline at end of file
+        
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/slot.py	Sat Feb 25 00:21:28 2012 +0100
@@ -0,0 +1,27 @@
+#   This file is part of PARPG.
+
+#   PARPG 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 3 of the License, or
+#   (at your option) any later version.
+
+#   PARPG 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 PARPG.  If not, see <http://www.gnu.org/licenses/>.
+
+from fife.extensions.pychan import Icon
+
+class Slot(Icon):
+
+    def _setImage(self, source):
+        self._image = source
+
+    def _getImage(self):
+        return self._image
+
+    image = property(_getImage, _setImage)
+    
--- a/gui/tabwidget.py	Wed Feb 22 12:31:02 2012 +0100
+++ b/gui/tabwidget.py	Sat Feb 25 00:21:28 2012 +0100
@@ -9,7 +9,10 @@
         def fset(self, min_size):
             self._min_size = min_size
             self.view.min_size = min_size
-            self.adaptLayout()
+            #HACK: This fixes a problem when the size is set before the Widget
+            #is created proper
+            if hasattr(self, '__parent'):   
+                 self.adaptLayout()
         
         return locals()
     min_size = property(**min_size())
@@ -21,7 +24,10 @@
         def fset(self, max_size):
             self._max_size = max_size
             self.view.max_size = max_size
-            self.adaptLayout()
+            #HACK: This fixes a problem when the size is set before the Widget
+            #is created proper
+            if hasattr(self, '__parent'):   
+                self.adaptLayout()
         
         return locals()
     max_size = property(**max_size())