0

Im trying to reuse predefined regions but I get Nonetype error when assigning it to a new variable using sikuli.setW(). Here's my code:

import math
import sikuli

self.screen_reg = sikuli.Screen(0)
self.monitor_reg = self.screen_reg

self.leftreg = sikuli.Region(
    self.monitor_reg.x,
    self.monitor_reg.y,
    int(math.floor(self.monitor_reg.w/2)),
    self.monitor_reg.h)

self.rightreg = sikuli.Region(
    self.monitor_reg.x + int(math.floor(self.monitor_reg.w/2)),
    self.monitor_reg.y,
    int(math.floor(self.monitor_reg.w/2)),
    self.monitor_reg.h)

self.leftreg.highlight(3) <=== working

self.quarter = self.leftreg.setW(int(math.floor(self.leftreg.w/2)))

self.quarter.highlight(3) <====== didnt work; 

error: NoneType object has no attribute highlight

If I print type(quarter), it returns NoneType.

If I change it into these:

self.leftreg.highlight(3)
self.leftreg.setW(int(math.floor(self.leftreg.w/2)))
self.leftreg.highlight(3)

It works fine. What am I missing? Thanks for the help.

vpibano
  • 2,415
  • 1
  • 13
  • 26

1 Answers1

0

> What am I missing?

An object method may not have return type.

Here is excerpt from Sikuli source code

  public void setW(int W) {
    w = W > 1 ? W : 1;
    initScreen(null);
  }

Return type of setW is void. That is it returns nothing, while you expected that it returns a Region.

A correct way to do what you want would be:

self.quarter = Region(self.leftreg) # this constructs a new region
self.quarter.setW(int(math.floor(self.leftreg.w/2)))  # and this resizes it
RPWheeler
  • 86
  • 2
  • 5