Exemplo n.º 1
0
class XLABaseTest(unittest.TestCase):
    """Provides the model and config of PolI"""
    def setUp(self, mPaths, cPath):
        mPath = xlinkanalyzer.__path__[0]
        xlaTestPath = path.join(path.split(mPath)[0], 'pytests/test_data')
        self.xlaTestMPaths = [
            path.join(xlaTestPath, _path) for _path in mPaths
        ]
        self.xlaTestCPath = path.join(xlaTestPath, cPath)

        self.config = Assembly()
        self.rManager = ResourceManager(self.config)
        self.rManager.loadAssembly(None, self.xlaTestCPath)

        [chimera.openModels.open(_path) for _path in self.xlaTestMPaths]
        self.models = chimera.openModels.list()
        # self.xla_models = [Model(chimeraModel, self.config) for chimeraModel in self.models]

    def _createTestWindow(self):
        self.testWindow = Toplevel()
        w = self.testWindow.winfo_screenwidth()
        h = self.testWindow.winfo_screenheight()
        x = w / 2
        y = h / 2
        self.testWindow.geometry("+%d+%d" % (x, y))
        self.testWindow.geometry("400x200")

    def tearDown(self):
        chimera.openModels.close(chimera.openModels.list())
Exemplo n.º 2
0
class XLABaseTest(unittest.TestCase):
    """Provides the model and config of PolI"""

    def setUp(self, mPaths, cPath):
        mPath = xlinkanalyzer.__path__[0]
        xlaTestPath = path.join(path.split(mPath)[0], 'pytests/test_data')
        self.xlaTestMPaths = [path.join(xlaTestPath, _path) for _path in mPaths]
        self.xlaTestCPath = path.join(xlaTestPath, cPath)

        self.config = Assembly()
        self.rManager = ResourceManager(self.config)
        self.rManager.loadAssembly(None, self.xlaTestCPath)

        [chimera.openModels.open(_path) for _path in self.xlaTestMPaths]
        self.models = chimera.openModels.list()
        # self.xla_models = [Model(chimeraModel, self.config) for chimeraModel in self.models]

    def _createTestWindow(self):
        self.testWindow = Toplevel()
        w = self.testWindow.winfo_screenwidth()
        h = self.testWindow.winfo_screenheight()
        x = w/2
        y = h/2
        self.testWindow.geometry("+%d+%d" % (x, y))
        self.testWindow.geometry("400x200")

    def tearDown(self):
        chimera.openModels.close(chimera.openModels.list())
Exemplo n.º 3
0
    def createUser(self, username, password, fname, lname):
        if self.gui.btd.database.newUser(username, password, fname, lname):
            popup = Toplevel()
            popup.title("Account created!")

            windowWidth = popup.winfo_screenwidth()
            windowHeight = popup.winfo_screenheight()

            width = .25 * windowWidth
            height = .1 * windowHeight
            x = (windowWidth - width) / 2
            y = (windowHeight - height) / 2

            popup.geometry("%dx%d+%d+%d" % (width, height, x, y))
            popup.update()

            Label(
                popup,
                text="Your new account has been successfully created!").pack()
            Button(popup, text="Dismiss", command=popup.destroy).pack()

            self.gui.screenChange(title.titlePage(self.root, self.gui))
        else:
            popup = Toplevel()
            popup.title("Username Exists!")

            windowWidth = popup.winfo_screenwidth()
            windowHeight = popup.winfo_screenheight()

            width = .25 * windowWidth
            height = .1 * windowHeight
            x = (windowWidth - width) / 2
            y = (windowHeight - height) / 2

            popup.geometry("%dx%d+%d+%d" % (width, height, x, y))
            popup.update()

            Label(popup,
                  text="A user account with that username already exists!"
                  ).pack()
            Button(popup, text="Dismiss", command=popup.destroy).pack()
Exemplo n.º 4
0
 def createUser(self, username, password, fname, lname):
     if self.gui.btd.database.newUser(username, password, fname, lname):
         popup = Toplevel()
         popup.title("Account created!")
         
         windowWidth = popup.winfo_screenwidth()
         windowHeight = popup.winfo_screenheight()
         
         width = .25 * windowWidth
         height = .1 * windowHeight
         x = (windowWidth - width) / 2
         y = (windowHeight - height) / 2
         
         popup.geometry("%dx%d+%d+%d" % (width, height, x, y))
         popup.update()
         
         Label(popup, text="Your new account has been successfully created!").pack()
         Button(popup, text="Dismiss", command=popup.destroy).pack()
         
         self.gui.screenChange(title.titlePage(self.root, self.gui))
     else:
         popup = Toplevel()
         popup.title("Username Exists!")
         
         windowWidth = popup.winfo_screenwidth()
         windowHeight = popup.winfo_screenheight()
         
         width = .25 * windowWidth
         height = .1 * windowHeight
         x = (windowWidth - width) / 2
         y = (windowHeight - height) / 2
         
         popup.geometry("%dx%d+%d+%d" % (width, height, x, y))
         popup.update()
         
         Label(popup, text="A user account with that username already exists!").pack()
         Button(popup, text="Dismiss", command=popup.destroy).pack()
Exemplo n.º 5
0
 def loginCommand(self, username, password):
     if self.gui.btd.database.login(username, password):
         self.gui.screenChange(welcomePage(self.root, self.gui))
     else:
         popup = Toplevel()
         popup.title("Incorrect")
         
         windowWidth = popup.winfo_screenwidth()
         windowHeight = popup.winfo_screenheight()
         
         width = .25 * windowWidth
         height = .1 * windowHeight
         x = (windowWidth - width) / 2
         y = (windowHeight - height) / 2
         
         popup.geometry("%dx%d+%d+%d" % (width, height, x, y))
         popup.update()
         
         Label(popup, text="Incorrect username or password!").pack()
         Button(popup, text="Dismiss", command=popup.destroy).pack()
Exemplo n.º 6
0
class ContinuousTMPViewer(object):
    def __init__(self,
                 suction_height,
                 regions,
                 tl_x=0,
                 tl_y=0,
                 width=500,
                 height=150,
                 title='Grid',
                 background='tan'):
        self.tk = Tk()
        # tk.geometry('%dx%d+%d+%d'%(width, height, 100, 0))
        self.tk.withdraw()
        self.top = Toplevel(self.tk)
        self.top.wm_title(title)
        self.top.protocol('WM_DELETE_WINDOW', self.top.destroy)

        self.suction_height = suction_height
        self.regions = regions
        self.tl_x = tl_x
        self.tl_y = tl_y
        self.width = width
        self.height = height
        self.canvas = Canvas(self.top,
                             width=self.width,
                             height=self.height,
                             background=background)
        self.canvas.pack()
        # self.center()
        self.move_frame(self.tl_x, self.tl_y)

        max_width = max(
            map(get_width,
                regions.values()))  # Really should take width of max minus min
        self.dist_to_pixel = (self.width - 2 * PIXEL_BUFFER
                              ) / max_width  # Maintains aspect ratio
        self.dist_width = self.width / self.dist_to_pixel
        self.dist_height = self.height / self.dist_to_pixel
        self.ground_height = self.height - self.dist_to_pixel * ENV_HEIGHT
        self.robot_dist = self.dist_height / 2.

        self.robot = []
        self.blocks = []
        self.holding = None
        self.environment = []
        self.draw_environment()

    def center(self):
        self.top.update_idletasks()
        w = self.top.winfo_screenwidth()
        h = self.top.winfo_screenheight()
        size = tuple(
            int(_) for _ in self.top.geometry().split('+')[0].split('x'))
        x = w / 2 - size[0] / 2
        y = h / 2 - size[1] / 2
        self.top.geometry("%dx%d+%d+%d" % (size + (x, y)))

    def move_frame(self, x, y):
        self.top.update_idletasks()
        size = tuple(
            int(_) for _ in self.top.geometry().split('+')[0].split('x'))
        self.top.geometry("%dx%d+%d+%d" % (size + (x, y)))

    def scale_x(self, x):  # x \in [-self.dist_width/2, self.dist_width/2]
        return self.dist_to_pixel * (x + self.dist_width / 2.)

    def scale_y(self, y):  # y \in [0, self.dist_height]
        return self.ground_height - self.dist_to_pixel * y

    def draw_block(self, x, y, width, height, name='', color='blue'):
        self.blocks.extend([
            self.canvas.create_rectangle(self.scale_x(x - width / 2.),
                                         self.scale_y(y),
                                         self.scale_x(x + width / 2.),
                                         self.scale_y(y + height),
                                         fill=color,
                                         outline='black',
                                         width=2),
            self.canvas.create_text(self.scale_x(x),
                                    self.scale_y(y + height / 2),
                                    text=name),
        ])

    # def draw_holding(self, x, width, height, color='blue'):
    #     self.holding = self.canvas.create_rectangle(self.scale_x(x - width / 2.),
    #                                                 self.scale_y(self.robot_dist - SUCTION_HEIGHT / 2 - height),
    #                                                 self.scale_x(x + width / 2.),
    #                                                 self.scale_y(self.robot_dist - SUCTION_HEIGHT / 2),
    #                                                 fill=color, outline='black', width=2)

    def draw_region(self, region, name='', color='red'):
        x1, x2 = map(self.scale_x, region)
        y1, y2 = self.ground_height, self.height
        self.environment.extend([
            self.canvas.create_rectangle(x1,
                                         y1,
                                         x2,
                                         y2,
                                         fill=color,
                                         outline='black',
                                         width=2),
            self.canvas.create_text((x1 + x2) / 2, (y1 + y2) / 2, text=name),
        ])

    def draw_environment(self):
        # TODO: automatically draw in order
        self.environment = []
        for name, region in sorted(self.regions.items(),
                                   key=lambda pair: get_width(pair[1]),
                                   reverse=True):
            self.draw_region(region, name=name, color=name)

    def draw_robot(
        self,
        x,
        y,
        color='yellow'
    ):  # TODO - could also visualize as top grasps instead of side grasps
        #y = self.robot_dist
        self.robot = [
            self.canvas.create_rectangle(
                self.scale_x(x - SUCTION_WIDTH / 2.),
                self.scale_y(y - self.suction_height / 2.),
                self.scale_x(x + SUCTION_WIDTH / 2.),
                self.scale_y(y + self.suction_height / 2.),
                fill=color,
                outline='black',
                width=2),
            self.canvas.create_rectangle(
                self.scale_x(x - STEM_WIDTH / 2.),
                self.scale_y(y + self.suction_height / 2.),
                self.scale_x(x + STEM_WIDTH / 2.),
                self.scale_y(y + self.suction_height / 2. + STEM_HEIGHT),
                fill=color,
                outline='black',
                width=2),
        ]

    def clear_state(self):
        for block in self.blocks:
            self.canvas.delete(block)
        for part in self.robot:
            self.canvas.delete(part)
        if self.holding is not None:
            self.canvas.delete(self.holding)

    def clear_all(self):
        self.canvas.delete('all')

    def save(self, filename):
        # TODO: screen recording based on location like I did before
        # TODO: only works on windows
        # self.canvas.postscript(file='%s.ps'%filename, colormode='color')
        #from PIL import ImageGrab
        try:
            import pyscreenshot as ImageGrab
        except ImportError:
            return None
        x, y = self.top.winfo_x(), 2 * self.top.winfo_y()
        width, height = self.top.winfo_width(), self.top.winfo_height(
        )  # winfo_width, winfo_reqheight
        path = filename + '.png'
        ImageGrab.grab((x, y, x + width, y + height)).save(path)
        return path
Exemplo n.º 7
0
class ContinuousTMPViewer(object):
    def __init__(self,
                 regions,
                 tl_x=0,
                 tl_y=0,
                 width=500,
                 height=250,
                 title='Grid',
                 background='tan'):
        self.tk = Tk()
        # tk.geometry('%dx%d+%d+%d'%(width, height, 100, 0))
        self.tk.withdraw()
        self.top = Toplevel(self.tk)
        self.top.wm_title(title)
        self.top.protocol('WM_DELETE_WINDOW', self.top.destroy)

        self.regions = regions
        self.tl_x = tl_x
        self.tl_y = tl_y
        self.width = width
        self.height = height
        self.canvas = Canvas(self.top,
                             width=self.width,
                             height=self.height,
                             background=background)
        self.canvas.pack()
        # self.center()
        self.move_frame(self.tl_x, self.tl_y)

        self.dist_to_pixel = (self.width - 2 * PIXEL_BUFFER) / get_width(
            regions[GROUND])  # Maintains aspect ratio
        self.dist_width = self.width / self.dist_to_pixel
        self.dist_height = self.height / self.dist_to_pixel
        self.ground_height = self.height - self.dist_to_pixel * ENV_HEIGHT
        self.robot_dist = self.dist_height / 2.

        self.robot = []
        self.blocks = []
        self.holding = None
        self.environment = []
        self.draw_environment()

    def center(self):
        self.top.update_idletasks()
        w = self.top.winfo_screenwidth()
        h = self.top.winfo_screenheight()
        size = tuple(
            int(_) for _ in self.top.geometry().split('+')[0].split('x'))
        x = w / 2 - size[0] / 2
        y = h / 2 - size[1] / 2
        self.top.geometry("%dx%d+%d+%d" % (size + (x, y)))

    def move_frame(self, x, y):
        self.top.update_idletasks()
        size = tuple(
            int(_) for _ in self.top.geometry().split('+')[0].split('x'))
        self.top.geometry("%dx%d+%d+%d" % (size + (x, y)))

    def scale_x(self, x):  # x \in [-self.dist_width/2, self.dist_width/2]
        return self.dist_to_pixel * (x + self.dist_width / 2.)

    def scale_y(self, y):  # y \in [0, self.dist_height]
        return self.ground_height - self.dist_to_pixel * y

    def draw_block(self, x, width, height, color='blue'):
        self.blocks.append(
            self.canvas.create_rectangle(self.scale_x(x - width / 2.),
                                         self.scale_y(0),
                                         self.scale_x(x + width / 2.),
                                         self.scale_y(height),
                                         fill=color,
                                         outline='black',
                                         width=2))

    # def draw_holding(self, x, width, height, color='blue'):
    #     self.holding = self.canvas.create_rectangle(self.scale_x(x - width / 2.),
    #                                                 self.scale_y(self.robot_dist - SUCTION_HEIGHT / 2 - height),
    #                                                 self.scale_x(x + width / 2.),
    #                                                 self.scale_y(self.robot_dist - SUCTION_HEIGHT / 2),
    #                                                 fill=color, outline='black', width=2)

    def draw_region(self, region, color='red'):
        x1, x2 = map(self.scale_x, region)
        self.environment.append(
            self.canvas.create_rectangle(x1,
                                         self.ground_height,
                                         x2,
                                         self.height,
                                         fill=color,
                                         outline='black',
                                         width=2))

    def draw_environment(self, table_color='lightgrey'):
        self.environment = []
        self.draw_region(self.regions[GROUND], color=table_color)
        for name, region in self.regions.items():
            if name != GROUND:
                self.draw_region(region)

    def draw_robot(
        self,
        x,
        y,
        color='yellow'
    ):  # TODO - could also visualize as top grasps instead of side grasps
        #y = self.robot_dist
        self.robot = [
            self.canvas.create_rectangle(self.scale_x(x - SUCTION_WIDTH / 2.),
                                         self.scale_y(y - SUCTION_HEIGHT / 2.),
                                         self.scale_x(x + SUCTION_WIDTH / 2.),
                                         self.scale_y(y + SUCTION_HEIGHT / 2.),
                                         fill=color,
                                         outline='black',
                                         width=2),
            self.canvas.create_rectangle(self.scale_x(x - STEM_WIDTH / 2.),
                                         self.scale_y(y + SUCTION_HEIGHT / 2.),
                                         self.scale_x(x + STEM_WIDTH / 2.),
                                         self.scale_y(y + SUCTION_HEIGHT / 2. +
                                                      STEM_HEIGHT),
                                         fill=color,
                                         outline='black',
                                         width=2),
        ]

    def clear_state(self):
        for block in self.blocks:
            self.canvas.delete(block)
        for part in self.robot:
            self.canvas.delete(part)
        if self.holding is not None:
            self.canvas.delete(self.holding)

    def clear_all(self):
        self.canvas.delete('all')

    def save(self, filename):
        # self.canvas.postscript(file='%s.ps'%filename, colormode='color')
        from PIL import ImageGrab
        ImageGrab.grab((0, 0, self.width, self.height)).save(filename + '.jpg')
Exemplo n.º 8
0
class ContinuousTMPViewer(object):
    def __init__(self,
                 env_region,
                 regions=[],
                 tl_x=0,
                 tl_y=0,
                 width=500,
                 height=250,
                 title='Grid',
                 background='tan'):
        self.tk = Tk()

        self.tk.withdraw()
        self.top = Toplevel(self.tk)
        self.top.wm_title(title)
        self.top.protocol('WM_DELETE_WINDOW', self.top.destroy)

        self.env_region = env_region
        self.regions = regions
        self.tl_x = tl_x
        self.tl_y = tl_y
        self.width = width
        self.height = height
        self.canvas = Canvas(self.top,
                             width=self.width,
                             height=self.height,
                             background=background)
        self.canvas.pack()

        self.move_frame(self.tl_x, self.tl_y)

        self.dist_to_pixel = (self.width -
                              2 * PIXEL_BUFFER) / (self.env_region.w)
        self.dist_width = self.width / self.dist_to_pixel
        self.dist_height = self.height / self.dist_to_pixel
        self.ground_height = self.height - self.dist_to_pixel * ENV_HEIGHT
        self.robot_dist = self.dist_height / 2.

        self.robot = []
        self.blocks = []
        self.holding = None
        self.draw_environment()

    def center(self):
        self.top.update_idletasks()
        w = self.top.winfo_screenwidth()
        h = self.top.winfo_screenheight()
        size = tuple(
            int(_) for _ in self.top.geometry().split('+')[0].split('x'))
        x = w / 2 - size[0] / 2
        y = h / 2 - size[1] / 2
        self.top.geometry("%dx%d+%d+%d" % (size + (x, y)))

    def move_frame(self, x, y):
        self.top.update_idletasks()
        size = tuple(
            int(_) for _ in self.top.geometry().split('+')[0].split('x'))
        self.top.geometry("%dx%d+%d+%d" % (size + (x, y)))

    def t_x(self, x):
        return self.dist_to_pixel * (x + self.dist_width / 2.)

    def t_y(self, y):
        return self.ground_height - self.dist_to_pixel * y

    def draw_block(self, block, x):
        self.blocks.append(
            self.canvas.create_rectangle(self.t_x(x - block.w / 2.),
                                         self.t_y(0),
                                         self.t_x(x + block.w / 2.),
                                         self.t_y(block.h),
                                         fill=block.color,
                                         outline='black',
                                         width=2))

    def draw_holding(self, block, x):
        self.holding = self.canvas.create_rectangle(
            self.t_x(x - block.w / 2.),
            self.t_y(self.robot_dist - SUCTION_HEIGHT / 2 - block.h),
            self.t_x(x + block.w / 2.),
            self.t_y(self.robot_dist - SUCTION_HEIGHT / 2),
            fill=block.color,
            outline='black',
            width=2)

    def draw_region(self, region):
        self.environment.append(
            self.canvas.create_rectangle(self.t_x(region.x - region.w / 2.),
                                         self.ground_height,
                                         self.t_x(region.x + region.w / 2.),
                                         self.height,
                                         fill='red',
                                         outline='black',
                                         width=2))

    def draw_environment(self, table_color='lightgrey', bin_color='grey'):
        self.environment = [
            self.canvas.create_rectangle(self.t_x(-self.env_region.w / 2),
                                         self.ground_height,
                                         self.t_x(self.env_region.w / 2),
                                         self.height,
                                         fill=table_color,
                                         outline='black',
                                         width=2)
        ]
        for region in self.regions:
            self.draw_region(region)

    def draw_robot(self, x, color='yellow'):
        self.robot = [
            self.canvas.create_rectangle(
                self.t_x(x - SUCTION_WIDTH / 2.),
                self.t_y(self.robot_dist - SUCTION_HEIGHT / 2.),
                self.t_x(x + SUCTION_WIDTH / 2.),
                self.t_y(self.robot_dist + SUCTION_HEIGHT / 2.),
                fill=color,
                outline='black',
                width=2),
            self.canvas.create_rectangle(
                self.t_x(x - STEM_WIDTH / 2.),
                self.t_y(self.robot_dist + SUCTION_HEIGHT / 2.),
                self.t_x(x + STEM_WIDTH / 2.),
                self.t_y(self.robot_dist + SUCTION_HEIGHT / 2. + STEM_HEIGHT),
                fill=color,
                outline='black',
                width=2),
        ]

    def clear_state(self):
        for block in self.blocks:
            self.canvas.delete(block)
        for part in self.robot:
            self.canvas.delete(part)
        if self.holding is not None:
            self.canvas.delete(self.holding)

    def clear_all(self):
        self.canvas.delete('all')

    def save(self, filename):

        from PIL import ImageGrab
        ImageGrab.grab((0, 0, self.width, self.height)).save(filename + '.jpg')