Virgil Dupras avatar Virgil Dupras committed b6038e8

A couple of things at once:

- Added Button.bordered
- Pushed TextField.alignment down to Control
- Added MenuItem.state
- Added Segment.image

Comments (0)

Files changed (11)

docs/api/button.rst

         :ref:`Cocoa constant <literal-consts>`. The style of the button. Equivalent to
         ``[self bezelStyle]``. Use with ``NSBezelStyle`` constants.
     
+    .. attribute:: bordered
+    
+        *Boolean*. Whether the button has a border.
+    
     .. attribute:: title
         
         *String*. The text on the button. Equivalent to ``[self title]``.
     
     .. attribute:: state
         
-        :ref:`Cocoa constant <literal-consts>`. Equivalent to ``[self state]``.
+        :ref:`Cocoa constant <literal-consts>`. Use with ``NSCellStateValue`` constants.
     
     .. attribute:: shortcut
         

docs/api/control.rst

         
         :class:`Font`. The font of the control. Equivalent to ``[self font]``.
     
+    .. attribute:: alignment
+        
+        One of :ref:`text-alignment-constants`. Alignment of the text within the field.
+        Equivalent to ``[self alignment]``.
+    
     .. attribute:: controlSize
         
         :ref:`control-size-consts`. One of the 3 Regular, Small and Mini pre-defined

docs/api/menu.rst

     .. attribute:: tag
         
         Integer value corresponding to ``[self tag]``.
+    
+    .. attribute:: state
+        
+        :ref:`Cocoa constant <literal-consts>`. Use with ``NSCellStateValue`` constants.
+    
 
 MainMenu
 --------

docs/api/segment.rst

         
         Numeric. The width of the segment.
     
+    .. attribute:: image
+        
+        String. Name of the image resource to display in the segment.

docs/api/textfield.rst

         A string representing the "placeholder text", that is, a text displayed in light shade of
         grey when the text field contains no text. Equivalent to ``[[self cell] placeholderString]``.
     
-    .. attribute:: alignment
-        
-        One of :ref:`text-alignment-constants`. Alignment of the text within the field.
-        Equivalent to ``[self alignment]``.
-    
     .. attribute:: textColor
         
         :class:`Color`. Color of the text within the field. Equivalent to ``[self textColor]``.

xibless/button.py

 class Button(Control):
     OBJC_CLASS = 'NSButton'
     PROPERTIES = Control.PROPERTIES + ['imagePosition', ImageProperty('image'),
-        KeyShortcutProperty('shortcut')]
+        KeyShortcutProperty('shortcut'), 'bordered']
     
     def __init__(self, parent, title, action=None):
         self._bezelStyle = const.NSRoundedBezelStyle
             self.layoutDeltaY = -3
             self.layoutDeltaW = 4
             self.layoutDeltaH = 5
+        elif bezelStyle == const.NSShadowlessSquareBezelStyle:
+            self.layoutDeltaX = 0
+            self.layoutDeltaY = 0
+            self.layoutDeltaW = 0
+            self.layoutDeltaH = 0            
         else:
             self.layoutDeltaX = -6
             self.layoutDeltaY = -7

xibless/control.py

     Small = const.NSSmallControlSize
     Mini = const.NSMiniControlSize
 
+class TextAlignment(object):
+    Left = const.NSLeftTextAlignment
+    Right = const.NSRightTextAlignment
+    Center = const.NSCenterTextAlignment
+    Justified = const.NSJustifiedTextAlignment
+    Natural = const.NSNaturalTextAlignment
+    
 class Control(View):
     CONTROL_HEIGHTS = ControlHeights(20, 17, 14)
     PROPERTIES = View.PROPERTIES + [
         ActionProperty('action'), 'font', Property('controlSize', 'cell.controlSize'), 'formatter',
+        'alignment'
     ]
     
     def __init__(self, parent, width, height):
 from . import globalvars
 from .base import CodeTemplate, GeneratedItem, owner, NSApp, const, defaults
 from .types import Action, NLSTR
-from .control import ControlSize
+from .control import ControlSize, TextAlignment
 from .view import View, Box, Pack, Size, Rect
 from .font import Font, FontFamily, FontSize, FontTrait
 from .color import Color
 from .menu import Menu, MainMenu
 from .window import Window, Panel, PanelStyle
 from .button import Button, Checkbox
-from .textfield import TextField, Label, SearchField, TextAlignment
+from .textfield import TextField, Label, SearchField
 from .textview import TextView
 from .popup import Popup
 from .combo import Combobox
     OBJC_CLASS = 'NSMenuItem'
     PROPERTIES = GeneratedItem.PROPERTIES + [
         'tag', 'hidden', ImageProperty('image'), ActionProperty('action'),
-        KeyShortcutProperty('shortcut')
+        KeyShortcutProperty('shortcut'), 'state'
     ]
     
     def __init__(self, name, action=None, shortcut=None, tag=None):

xibless/segment.py

     def __init__(self, label, width):
         self.label = label
         self.width = width
+        self.image = None
     
 
 class SegmentedControl(Control):
                 convertValueToObjc(segment.label), convertValueToObjc(index))
             tmpl.setup += '[$varname$ setWidth:{} forSegment:{}];'.format(
                 convertValueToObjc(segment.width), convertValueToObjc(index))
+            if segment.image:
+                tmpl.setup += '[$varname$ setImage:[NSImage imageNamed:{}] forSegment:{}];'.format(
+                convertValueToObjc(segment.image), convertValueToObjc(index))
         return tmpl

xibless/textfield.py

 from .control import Control, ControlHeights
 from .font import Font, FontFamily, FontSize
 
-class TextAlignment(object):
-    Left = 1
-    Right = 2
-    Center = 3
-    Justified = 4
-    Natural = 5
-    
-    @staticmethod
-    def objcValue(value):
-        if value == TextAlignment.Left:
-            return const.NSLeftTextAlignment
-        elif value == TextAlignment.Right:
-            return const.NSRightTextAlignment
-        elif value == TextAlignment.Center:
-            return const.NSCenterTextAlignment
-        elif value == TextAlignment.Justified:
-            return const.NSJustifiedTextAlignment
-        elif value == TextAlignment.Natural:
-            return const.NSNaturalTextAlignment
-        else:
-            return value
-
 class TextField(Control):
     OBJC_CLASS = 'NSTextField'
     CONTROL_HEIGHTS = ControlHeights(22, 19, 16)
         Control.__init__(self, parent, 100, 22)
         self.text = text
         self.font = Font(FontFamily.Label, FontSize.RegularControl)
-        self.alignment = None
         self.textColor = None
     
     def dependencies(self):
         tmpl = Control.generateInit(self)
         self.properties['editable'] = True
         self.properties['selectable'] = True
-        self.properties['alignment'] = TextAlignment.objcValue(self.alignment)
         return tmpl
     
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.