Skip to content

Commit

Permalink
Merge pull request #1221 from MuhammadMouradG/fix-accessing-to-impl-l…
Browse files Browse the repository at this point in the history
…ayer

Fix accessing to impl layer
  • Loading branch information
freakboy3742 authored May 23, 2021
2 parents 0447a36 + 8ddd94b commit 7926e28
Show file tree
Hide file tree
Showing 44 changed files with 80 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/android/toga_android/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, interface):
self.native = None
self._native_activity = _get_activity()
self.create()
self.native._impl = self
# Immediately re-apply styles. Some widgets may defer style application until
# they have been added to a container.
self.interface.style.reapply()
Expand Down
5 changes: 5 additions & 0 deletions src/android/toga_android/widgets/scrollcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def create(self):
if self.interface.content is not None:
self.set_content(self.interface.content)

# set _impl layer for other native layer versions
self.vScrollListener._impl = self
self.hScrollListener._impl = self
self.hScrollView._impl = self

def set_content(self, widget):
widget.viewport = AndroidViewport(widget.native)
content_view_params = android_widgets.LinearLayout__LayoutParams(
Expand Down
3 changes: 3 additions & 0 deletions src/android/toga_android/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def create(self):
# Create a mapping from text to numeric index to support `select_item()`.
self._indexByItem = {}

# set _impl layer for other native layer versions
self.adapter._impl = self

def add_item(self, item):
new_index = self.adapter.getCount()
self.adapter.add(str(item))
Expand Down
1 change: 0 additions & 1 deletion src/cocoa/toga_cocoa/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Document:
def __init__(self, interface):
self.native = TogaDocument.alloc()
self.native.interface = interface
self.native._impl = self

self.native.initWithContentsOfURL(
NSURL.URLWithString('file://{}'.format(quote(interface.filename))),
Expand Down
1 change: 1 addition & 0 deletions src/cocoa/toga_cocoa/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(self, interface):
self.constraints = None
self.native = None
self.create()
self.native._impl = self
self.interface.style.reapply()
self.set_enabled(self.interface.enabled)

Expand Down
1 change: 0 additions & 1 deletion src/cocoa/toga_cocoa/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class Canvas(Widget):
def create(self):
self.native = TogaCanvas.alloc().init()
self.native.interface = self.interface
self.native._impl = self

NSNotificationCenter.defaultCenter.addObserver(
self.native,
Expand Down
2 changes: 2 additions & 0 deletions src/cocoa/toga_cocoa/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def create(self):

# Create the actual text widget
self.text = TogaTextView.alloc().init()
self.text.interface = self.interface
self.text._impl = self
self.text.editable = True
self.text.selectable = True
self.text.verticallyResizable = True
Expand Down
1 change: 1 addition & 0 deletions src/cocoa/toga_cocoa/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def create(self):

self.input = NSTextField.new()
self.input.interface = self.interface
self.input._impl = self
self.input.bezeled = True
self.input.bezelStyle = NSTextFieldSquareBezel
self.input.translatesAutoresizingMaskIntoConstraints = False
Expand Down
1 change: 1 addition & 0 deletions src/gtk/toga_gtk/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def __init__(self, interface):
self.viewport = None
self.native = None
self.create()
self.native._impl = self
self.interface.style.reapply()

def set_app(self, app):
Expand Down
3 changes: 3 additions & 0 deletions src/gtk/toga_gtk/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def create(self):
self.native.set_min_content_width(self.interface.MIN_WIDTH)
self.native.set_min_content_height(self.interface.MIN_HEIGHT)

# set _impl layer for other native layer versions
self.treeview._impl = self

def change_source(self, source):
self.treeview.set_model(None)
self.store.change_source(source)
Expand Down
4 changes: 4 additions & 0 deletions src/gtk/toga_gtk/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def create(self):
self.textview.connect("focus-out-event", self.gtk_on_focus_out)
self.tag_placholder = self.buffer.create_tag("placeholder", foreground="gray")

# set _impl layer for other native layer versions
self.textview._impl = self
self.buffer._impl = self

def set_value(self, value):
self.buffer.set_text(value)

Expand Down
3 changes: 3 additions & 0 deletions src/gtk/toga_gtk/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ def create(self):

self.rehint()

# set _impl layer for other native layer versions
self.adjustment._impl = self

def gtk_on_change(self, widget):
value = widget.get_text().replace(",", ".") or 0
self.interface._value = Decimal(value).quantize(self.interface.step)
Expand Down
3 changes: 3 additions & 0 deletions src/gtk/toga_gtk/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ def create(self):
self.native.interface = self.interface
self.native.connect("value-changed", self.gtk_on_change)

# set _impl layer for other native layer versions
self.adj._impl = self

self.rehint()

def gtk_on_change(self, widget):
Expand Down
4 changes: 4 additions & 0 deletions src/gtk/toga_gtk/widgets/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ def create(self):
self.native.pack_start(self.switch, False, False, 0)
self.native.connect('show', lambda event: self.rehint())

# set _impl layer for other native layer versions
self.label._impl = self
self.switch._impl = self

def gtk_on_toggle(self, widget, state):
if self.interface.on_toggle:
self.interface.on_toggle(self.interface)
Expand Down
3 changes: 3 additions & 0 deletions src/gtk/toga_gtk/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def create(self):
self.native.set_min_content_width(200)
self.native.set_min_content_height(200)

# set _impl layer for other native layer versions
self.treeview._impl = self

def gtk_on_select(self, selection):
if self.interface.on_select:
if self.interface.multiple_select:
Expand Down
1 change: 1 addition & 0 deletions src/gtk/toga_gtk/widgets/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def create(self):

self.native = WebKit2.WebView()
self.native.interface = self.interface
self.native._impl = self

self.native.connect('key-press-event', self.gtk_on_key)
self._last_key_time = 0
Expand Down
1 change: 0 additions & 1 deletion src/gtk/toga_gtk/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self, interface):

def create(self):
self.native = self._IMPL_CLASS()
self.native._impl = self

self.native.connect("delete-event", self.gtk_on_close)
self.native.set_default_size(self.interface.size[0], self.interface.size[1])
Expand Down
1 change: 1 addition & 0 deletions src/iOS/toga_iOS/widgets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, interface):
self.constraints = None
self.native = None
self.create()
self.native._impl = self
self.interface.style.reapply()
self.set_enabled(self.interface.enabled)

Expand Down
1 change: 0 additions & 1 deletion src/iOS/toga_iOS/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class Canvas(Widget):
def create(self):
self.native = TogaCanvas.alloc().init()
self.native.interface = self.interface
self.native._impl = self
self.native.backgroundColor = UIColor.whiteColor

# Add the layout constraints
Expand Down
1 change: 1 addition & 0 deletions src/iOS/toga_iOS/widgets/detailedlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DetailedList(Widget):
def create(self):
self.controller = TogaTableViewController.alloc().init()
self.controller.interface = self.interface
self.controller._impl = self
self.native = self.controller.tableView

self.native.separatorStyle = UITableViewCellSeparatorStyleNone
Expand Down
3 changes: 1 addition & 2 deletions src/iOS/toga_iOS/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
class Label(Widget):
def create(self):
self.native = UILabel.new()
self.native.impl = self
self.native.interface = self
self.native.interface = self.interface

self.native.lineBreakMode = NSLineBreakByWordWrapping

Expand Down
1 change: 1 addition & 0 deletions src/iOS/toga_iOS/widgets/navigationview.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, title, content, on_action=None, style=None):
self._create()

def create(self):
# TODO: This need to be fix to follow `Toga` architecture
self._controller = TogaNavigationController.alloc().initWithRootViewController_(
self._config['content']._controller
)
Expand Down
1 change: 1 addition & 0 deletions src/iOS/toga_iOS/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def create(self):

self.picker = TogaPickerView.alloc().init()
self.picker.interface = self.interface
self.picker._impl = self
self.picker.native = self.native
self.picker.delegate = self.picker
self.picker.dataSource = self.picker
Expand Down
1 change: 1 addition & 0 deletions src/winforms/toga_winforms/widgets/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Box(Widget):
def create(self):
self.native = WinForms.Panel()
self.native.interface = self.interface
self.native._impl = self

def set_bounds(self, x, y, width, height):
if self.native:
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class Button(Widget):
def create(self):
self.native = WinForms.Button()
self.native.interface = self.interface
self.native._impl = self
self.native.Click += self.winforms_click
self.set_enabled(self.interface._enabled)

Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class Canvas(Box):
def create(self):
super(Canvas, self).create()
self.native.DoubleBuffered = True
self.native.interface = self.interface
self.native._impl = self
self.native.Paint += self.winforms_paint
self.native.Resize += self.winforms_resize
self.native.MouseDown += self.winforms_mouse_down
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/datepicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class DatePicker(Widget):
def create(self):
self.native = WinForms.DateTimePicker()
self.native.interface = self.interface
self.native._impl = self

def get_value(self):
date = datetime.datetime.strptime(self.native.Text, '%A, %B %d, %Y').date()
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/divider.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Divider(Widget):
def create(self):
self.native = WinForms.Label()
self.native.interface = self.interface
self.native._impl = self
self.native.BorderStyle = WinForms.BorderStyle.Fixed3D
self.native.AutoSize = False

Expand Down
1 change: 1 addition & 0 deletions src/winforms/toga_winforms/widgets/imageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ImageView(Widget):
def create(self):
self.native = WinForms.PictureBox()
self.native.interface = self.interface
self.native._impl = self
self.native.SizeMode = WinForms.PictureBoxSizeMode.StretchImage

def set_image(self, image):
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class Label(Widget):
def create(self):
self.native = WinForms.Label()
self.native.interface = self.interface
self.native._impl = self

def set_alignment(self, value):
self.native.TextAlign = TextAlignment(value)
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/multilinetextinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class MultilineTextInput(Widget):
def create(self):
# because https://stackoverflow.com/a/612234
self.native = WinForms.RichTextBox()
self.native.interface = self.interface
self.native._impl = self
self.native.Multiline = True
self.native.TextChanged += self.winforms_text_changed
self.native.Enter += self.winforms_enter
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/numberinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class NumberInput(Widget):
def create(self):
self.native = WinForms.NumericUpDown()
self.native.interface = self.interface
self.native._impl = self
self.native.Value = Convert.ToDecimal(0.0)
self.native.ValueChanged += self.winforms_value_changed

Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class OptionContainer(Widget):
def create(self):
self.native = WinForms.TabControl()
self.native.interface = self.interface
self.native._impl = self
self.native.Selected += self.winforms_selected

def add_content(self, label, widget):
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class ProgressBar(Widget):
def create(self):
self.native = WinForms.ProgressBar()
self.native.interface = self.interface
self.native._impl = self

def start(self):
self.set_running_style()
Expand Down
1 change: 1 addition & 0 deletions src/winforms/toga_winforms/widgets/scrollcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class ScrollContainer(Widget):
def create(self):
self.native = WinForms.Panel()
self.native.interface = self.interface
self.native._impl = self
self.native.AutoScroll = True
self.native.Scroll += self.winforms_scroll
self.native.MouseWheel += self.winforms_scroll
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def winforms_selected_index_changed(self, sender, event):
class Selection(Widget):
def create(self):
self.native = TogaComboBox(self.interface)
self.native.interface = self.interface
self.native._impl = self

def remove_all_items(self):
self.native.Items.Clear()
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Slider(Widget):
"""
def create(self):
self.native = WinForms.TrackBar()
self.native.interface = self.interface
self.native._impl = self
self.native.Scroll += self.winforms_scroll
self.native.MouseDown += self.winforms_mouse_down
self.native.MouseUp += self.winforms_mouse_up
Expand Down
1 change: 1 addition & 0 deletions src/winforms/toga_winforms/widgets/splitcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SplitContainer(Widget):
def create(self):
self.native = WinForms.SplitContainer()
self.native.interface = self.interface
self.native._impl = self
self.native.Resize += self.winforms_resize
self.native.SplitterMoved += self.winforms_resize
self.ratio = None
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Switch(Widget):
def create(self):
self.native = WinForms.CheckBox()
self.native.interface = self.interface
self.native._impl = self
self.native.CheckedChanged += self.winforms_checked_changed

def winforms_checked_changed(self, sender, event):
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
class Table(Widget):
def create(self):
self.native = WinForms.ListView()
self.native.interface = self.interface
self.native._impl = self
self.native.View = WinForms.View.Details
self._cache = []
self._first_item = 0
Expand Down
4 changes: 4 additions & 0 deletions src/winforms/toga_winforms/widgets/textinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class TextInput(Widget):
def create(self):
self.native = WinForms.TextBox()
self.native.interface = self.interface
self.native._impl = self
self.native.Multiline = False
self.native.DoubleClick += self.winforms_double_click
self.native.TextChanged += self.winforms_text_changed
Expand All @@ -19,6 +21,8 @@ def create(self):
self.native.LostFocus += self.winforms_lost_focus

self.error_provider = WinForms.ErrorProvider()
self.error_provider.interface = self.interface
self.error_provider._impl = self
self.error_provider.SetIconAlignment(
self.native, WinForms.ErrorIconAlignment.MiddleRight
)
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/timepicker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class TimePicker(Widget):
def create(self):
self.native = WinForms.DateTimePicker()
self.native.interface = self.interface
self.native._impl = self
self.native.ValueChanged += self.winforms_value_changed
self.native.Format = WinForms.DateTimePickerFormat.Time
self.native.ShowUpDown = True
Expand Down
2 changes: 2 additions & 0 deletions src/winforms/toga_winforms/widgets/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
class Tree(Widget):
def create(self):
self.native = WinForms.TreeView()
self.native.interface = self.interface
self.native._impl = self

def row_data(self, item):
self.interface.factory.not_implemented('Tree.row_data()')
Expand Down
Loading

0 comments on commit 7926e28

Please sign in to comment.