Exemple #1
0
    def execute(self, context):
        #add a textbox to display information.  attach it to this
        #add a persisetent callback on scene update
        #which monitors the status of the ODC

        #clear previous handlers
        clear_help_handlers()
        global implant_help_app_handle
        implant_help_app_handle = bpy.app.handlers.scene_update_pre.append(
            implant_help_parser)

        global help_display_box
        if help_display_box != None:
            del help_display_box
        help_text = 'Open Dental Implant Help Wizard \n'
        selections = odcutils.implant_selection(
            bpy.context)  #weird, how do I specify better arguments?
        sel_names = [item.name for item in selections]
        help_text += 'Selected Implants: ' + ', '.join(sel_names) + '\n'
        help_text += 'Next Step: ' + 'TBA'

        help_display_box = TextBox(context, 500, 500, 300, 100, 10, 20,
                                   help_text)
        help_display_box.snap_to_corner(context, corner=[0, 1])

        global implant_help_draw_handle
        implant_help_draw_handle = bpy.types.SpaceView3D.draw_handler_add(
            odc_help_draw, (self, context), 'WINDOW', 'POST_PIXEL')
        return {'FINISHED'}
Exemple #2
0
    def execute(self, context):
        #add a textbox to display information.  attach it to this
        #add a persisetent callback on scene update
        #which monitors the status of the ODC

        #clear previous handlers
        clear_help_handlers()
        global guide_help_app_handle
        guide_help_app_handle = bpy.app.handlers.scene_update_pre.append(
            guide_help_parser)

        global help_display_box
        if help_display_box != None:
            del help_display_box
        help_text = 'Open Dental Guide Help Wizard \n'
        help_text += 'Next Step: ' + 'TBA'

        help_display_box = TextBox(context, 500, 500, 300, 100, 10, 20,
                                   help_text)
        help_display_box.snap_to_corner(context, corner=[0, 1])

        global guide_help_draw_handle
        guide_help_draw_handle = bpy.types.SpaceView3D.draw_handler_add(
            odc_help_draw, (self, context), 'WINDOW', 'POST_PIXEL')
        return {'FINISHED'}
Exemple #3
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)

        self.tablegui = TableGUI(self)
        self.setCentralWidget(self.tablegui)    # Central Widget
        self.gui = GUILogic(self)
        self.sidepanel = SidePanel(self)
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.sidepanel)
        self.handgui = handGUI(self)
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.handgui)
        self.textbox  = TextBox(self)
        self.addDockWidget(QtCore.Qt.BottomDockWidgetArea, self.textbox)
        
        self.handgui.setStatusTip("Your hand.")
        self.tablegui.setStatusTip("Table")
        
        self.sidepanel.setFixedWidth(100)
        self.handgui.setFixedWidth(100)
        
        menubar = QtGui.QMenuBar(self)
        self.setMenuBar(menubar)
        self.menubar = self.create_menus(menubar)
        self.statusbar = self.statusBar()
        self.resize(850,680)
        self.setWindowTitle("Kasino")
        self.setMinimumSize(700, 500)
        
        text = "Welcome to play Kasino!"
        self.textbox.update_text(text)
Exemple #4
0
    def __init__(self, name, width, height):
        self.width = width
        self.height = height
        screen_size = (width, height)

        pygame.init()
        pygame.display.set_caption(name)

        self.screen = pygame.display.set_mode(screen_size)
        self.clock = pygame.time.Clock()
        self.running = False

        self.row = 10
        self.column = 10
        self.pad = 100
        self.maze_screen = 500

        self.cell_size = min(self.maze_screen / self.row,
                             self.maze_screen / self.column)
        self.maze = Maze(self.row, self.column)

        self.text_box = TextBox(675, 150, 250, 100, '10x10')
        self.generate_button = Button(gray, 675, 300, 250, 100, "Generate")
        self.solve_button = Button(gray, 675, 450, 250, 100, "Solve")

        self.player = Player(0, 0)
Exemple #5
0
    def invoke(self, context, event):

        sce = bpy.context.scene

        if context.object and context.object.type == 'MESH':
            self.bracket_manager = BracketDataManager(
                context,
                snap_type='OBJECT',
                snap_object=context.object,
                name='Bracket')
            self.bracket_slicer = BracektSlicer(context, self.bracket_manager)
        else:
            self.bracket_manager = BracketDataManager(context,
                                                      snap_type='SCENE',
                                                      snap_object=None,
                                                      name='Bracket')
            self.bracket_slicer = None

        help_txt = "DRAW MARGIN OUTLINE\n\nLeft Click on model to place bracket.\n G to grab  \n S to show slice \n ENTER to confirm \n ESC to cancel"
        self.help_box = TextBox(context, 500, 500, 300, 200, 10, 20, help_txt)
        self.help_box.snap_to_corner(context, corner=[1, 1])
        self.mode = 'main'
        self._handle = bpy.types.SpaceView3D.draw_handler_add(
            bracket_placement_draw_callback, (self, context), 'WINDOW',
            'POST_PIXEL')
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
Exemple #6
0
 def __init__(self):
     pg.init()
     pg.display.set_caption("Multiple Input Boxes")
     self.screen = pg.display.set_mode((1024, 700), pg.RESIZABLE)
     self.clock = pg.time.Clock()
     self.fps = 60.0
     self.done = False
     files = glob.glob('files/*[!.dat]')
     self.inputs = []
     print(files)
     for i, file in enumerate(files):
         box = TextBox(((100 * (i - 1)), 50, 75, 40),
                       command=self.change_color,
                       clear_on_enter=True,
                       inactive_on_enter=False,
                       active=False)
         self.inputs.append(box)
     screen_color = TextBox((100, 100, 150, 30),
                            command=self.change_color,
                            clear_on_enter=True,
                            inactive_on_enter=False)
     text_color = TextBox((100, 370, 150, 30),
                          command=self.change_text_color,
                          clear_on_enter=True,
                          inactive_on_enter=False,
                          active=False)
     self.prompts = self.make_prompts()
     self.color = (100, 100, 100)
     pg.key.set_repeat(*KEY_REPEAT_SETTING)
Exemple #7
0
def getUsername(screen, backgroundColor, settings):
    done = False
    clock = pygame.time.Clock()
    oldWidth = screen.get_rect().width
    oldHeight = screen.get_rect().height
    nameBox = TextBox(fontName = settings['fontName'])
    screen = pygame.display.set_mode((nameBox.width, nameBox.height), 0, 32)
    while not done:
        clock.tick(60)

        events = pygame.event.get()

        for event in events:
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_RETURN:
                    done = True

        nameBox.update(events)

        screen.fill(backgroundColor)

        nameBox.render(screen)

        pygame.display.flip()

    screen = pygame.display.set_mode((oldWidth, oldHeight), 0, 32)
    return nameBox.inputString
Exemple #8
0
    def __init__(self):
        # INITIALIZATION
        pygame.init()
        self.screen = pygame.display.set_mode((800, 550))
        self.start_button = Button((10, 10, 100, 50), self.screen, "Start", 33)
        self.restart_button = Button((120, 10, 100, 50), self.screen,
                                     "Restart", 33)

        size = self.screen.get_size()
        self.msg_box = TextBox((0, size[1] - 60, size[0], 50), self.screen, "",
                               33)
        self.msg_box2 = TextBox((size[0] - 250, 0, 250, 50), self.screen, "xD",
                                33)
        self.player_move = True
        self.player_map_pressed_flag = False
        self.cpu_map_pressed_flag = False
        self.state = GameState.SETTING
        self.win = False

        while True:
            self.restart()
            if self.main_loop():
                print("zwyciestwo")
            else:
                print("porażka")
Exemple #9
0
    def __init__(self):
        pygame.init()
        self.input = []
        pygame.display.set_caption("Hexon Sign Up")
        self.screen = pygame.display.set_mode((450, 800))
        self.clock = pygame.time.Clock()
        # Font Selection (Any_installed_font_on_PC, font_size)
        self.font = pygame.font.SysFont("01 Digitall", 35)
        self.fps = 60.0
        self.done = False
        # TextBoxes configurations:
        self.useremail_input = TextBox((85, 278, 305, 45),
                                       font=self.font,
                                       command=self.save_username,
                                       clear_on_enter=False,
                                       inactive_on_enter=True)
        username_input = TextBox((85, 364, 305, 45),
                                 font=self.font,
                                 command=self.save_email,
                                 clear_on_enter=False,
                                 inactive_on_enter=True,
                                 active=False)
        password_input = TextBox((85, 453, 305, 45),
                                 font=self.font,
                                 command=self.save_password,
                                 clear_on_enter=False,
                                 inactive_on_enter=True,
                                 active=False)

        self.prompts = self.make_labels()
        self.inputs = [useremail_input, username_input, password_input]
        self.input_data = {'Email': "", 'Username': "", 'Password': ""}
        self.color = (100, 100, 100)
        pygame.key.set_repeat(*KEY_REPEAT_SETTING)
Exemple #10
0
def build_textboxes():
    """Crear textboxes"""
    box_1 = TextBox((100, 430, 100, 20), id="name_con", active=True,
                        clear_on_enter=False, inactive_on_enter=True)
    box_2 = TextBox((100, 460, 100, 20), id="name_con", active=False,
                                clear_on_enter=False, inactive_on_enter=True)
    return box_1, box_2
class TextEntryDialog(Dialog):

    def __init__(self, parent, title="Enter some text", prompt="Enter some text",
     default="", cancel_button=1):
        self.prompt = prompt
        self.default = default
        Dialog.__init__(self, parent, title, cancel_button=cancel_button)

    def Body(self):
        label = Label(self, self.prompt)
        self.AddComponent(label, expand='h', border=7)

        self.text = TextBox(self, size=(100,25), process_enter=1)
        self.text.SetValue(self.default)
        self.text.OnChar = self.OnTextBoxChar
        self.AddComponent(self.text, expand='h', border=5)

    def OnTextBoxChar(self, event=None):
        # pressing Enter in the TextBox is the same as clicking OK
        if event.GetKeyCode() == keys.enter:
            self.OnClickOKButton(event)
        else:
            event.Skip()

    def GetValue(self):
        return self.text.GetValue()
Exemple #12
0
 def __init__(self, screen, text="", buttons=[], target=0, title=""):
     self.screen = screen
     # 枠線の色
     self.outline_color = (50, 50, 50)
     center_x, center_y = WIDTH // 2, HEIGHT // 2
     self.rect = Rect(center_x - 250, center_y - 150, 500, 300)
     # タイトルの作成
     self.title = None
     if title != "":
         self.title = TextBox(screen, self.rect.left, self.rect.top, 500, 32, title, \
                              font_size=25, outline_color=self.outline_color, outline_size=5)
     # メッセージの描画領域を作成
     x, y = WIDTH // 2 - 230, HEIGHT // 2 - 100
     self.textbox = TextBox(screen, x, y, 460, 155, text, outline_color=(255,)*3, \
                            font_size=25, align=('center', 'center'))
     # ボタンの作成
     self.buttons = []
     self.button_id = target
     self.button_size = len(buttons) or 1
     frame = 500 / self.button_size
     x = self.rect.left + frame / 2 - 50
     y = self.rect.bottom - 80
     for button in buttons:
         button = TextBox(screen,
                          x,
                          y,
                          100,
                          50,
                          button,
                          outline_color=(255, 255, 255),
                          align=('center', 'center'))
         x += frame
         self.buttons.append(button)
     # 時間管理
     self.clock = pygame.time.Clock()
Exemple #13
0
 def output_maker(projects):
     dictionary = {}
     for row in projects:
         if row.company_name not in dictionary and row.maintenance_requested != "true":
             dictionary.setdefault(row.company_name, [])
             if row.maintenance_requested != "true":
                 dictionary[row.company_name].append(row.maintenance_requested)
                 dictionary[row.company_name].append(row.main_color)
         else:
             if row.maintenance_requested != "true":
                 dictionary.setdefault(row.company_name, []).append(row.maintenance_requested)
                 dictionary.setdefault([row.company_name].append(row.main_color))
     list = []
     for k, v in dictionary.items():
         if v != None:
             sublist = []
             dictionary[k] = v[0], TextBox.hex_to_rgb(v[1]), v[2:]
             sublist.append(k)
             sublist.append(TextBox.hex_to_rgb(v[1]))
             a = 0
             for i in v:
                 if "false" == i:
                     a += 1
             sublist.append(a*30)
             list.append(sublist)
     return list
Exemple #14
0
 def __init__(self, user, mode, password, museID=None):
     self.user = user
     self.password = password
     self.museID = museID
     pygame.init()
     self.width = 600
     self.height = 600
     pygame.display.set_caption(user + ' Prediction Session')
     self.screen = pygame.display.set_mode((self.width, self.height))
     self.mode = mode
     self.inputSize = (300, 60)
     self.inputPosition = (self.width / 2 - self.inputSize[0] / 2,
                           self.height / 2 - self.inputSize[1] / 2)
     font = pygame.font.Font(None, 50)
     inputRect = pygame.Rect(self.inputPosition[0], self.inputPosition[1],
                             self.inputSize[0], self.inputSize[1])
     self.input = TextBox(inputRect,
                          clear_on_enter=True,
                          inactive_on_enter=False,
                          font=font)
     self.gameRunning = False
     self.state = PredictionState.MUSE_DISCONNECTED  # 0 = Muse Disconnected, 1 = Session Running, 2 = Finished
     self.setup_marker_streaming()
     self.markers = [
         []
     ]  # Each item is array of 2 items - timestamp + the key which was pressed.
     self.eegData = [
         []
     ]  # Each item is array of timestamp + data for each channel.
     self.get_eeg_stream(0.5)
     self.startTime = time()  # Timestamp of experiment start.
     self.finishTime = 0  # Timestamp of experiment finish.
     self.lastEEGSampleTime = self.startTime
    def __init__(self, screen, game):
        ''' An example class to show how to creat custom GUI frames'''
        Frame.__init__(self, screen, (330, 110), (10, 10))

        self.game = game

        self.b1 = Button(self, "Toggle Constant", self.command)
        self.b2 = Button(self,
                         "Toggle Random",
                         self.command2,
                         position=(5, 40))
        self.b3 = Button(self, "Toggle Shape", self.command3, position=(5, 75))

        self.c_Label = Label(self, "False", position=(135, 10))
        self.r_Label = Label(self, "True", position=(135, 45))
        self.s_Label = Label(self, "Random", position=(135, 80))

        self.l1 = Label(self, "Size", position=(235, 10))
        self.tb1 = TextBox(self, (295, 10))

        self.l2 = Label(self, "Density", position=(235, 45))
        self.tb2 = TextBox(self, (295, 45))

        self.l3 = Label(self, "Speed", position=(235, 80))
        self.tb3 = TextBox(self, (295, 80))

        self.textboxes = {
            'size': self.tb1,
            'density': self.tb2,
            'speed': self.tb3
        }
        self.current = 'circle'
    def Body(self):
        label = Label(self, self.prompt)
        self.AddComponent(label, expand='h', border=7)

        self.text = TextBox(self, size=(100,25), process_enter=1)
        self.text.SetValue(self.default)
        self.text.OnChar = self.OnTextBoxChar
        self.AddComponent(self.text, expand='h', border=5)
Exemple #17
0
    def __init__(self, resources: Resources) -> None:
        self.ticks = -1
        self.last_finish = -1
        self.best_finish = -1

        font = FontManager(resources.get_path("DejaVuSans.ttf"), size=28)
        white = Color(r=255, g=255, b=255)
        self.timer_textbox = TextBox(font, 50, 100, white)
        self.best_time_textbox = TextBox(font, 50, 150, white)
Exemple #18
0
 def invoke(self,context, event):
      
     
     Model = context.object
     
            
     for ob in bpy.data.objects:
         if ob.name == 'Plane': continue
         ob.select = False
         ob.hide = True
     Model.select = True
     Model.hide = False
     
     #bpy.ops.view3d.view_selected()
     self.crv = LineDrawer(context,snap_type ='OBJECT', snap_object = Model)
     context.space_data.show_manipulator = False
     context.space_data.transform_manipulators = {'TRANSLATE'}
     v3d = bpy.context.space_data
     v3d.pivot_point = 'MEDIAN_POINT'
     
     
     #TODO, tweak the modifier as needed
     #help_txt = "Interactive Plane Cutting\n\nLeft click, move the mouse, and left click again.\nThen place your mouse on the side of the line to remove. \n Click on the model to isolate the cut to the line limits.\nClick off the model to cut beyond the end-points of the line."
     help_txt_open = "INTERACTIVE PLANE CUTTING OPEN\n\n-  LeftClick and move mouse to define a line across your model \n-  The line will stick to your mouse until you Left Click again\n-  LeftClick a 3rd time on the side of the line to be cut\n-  If you click on the model, the cut will be limited to the edges of the line \n-  If you click off of the model, the cut will extend into space\n\n\nEXTRUDING\n\n-  A dot will appear next to the most recent cut, you can click and move your mouse to extrude the new cut edge.\n-  LeftClick to confirm the position of the extrusion"
     help_txt_solid = "INTERACTIVE PLANE CUTTING SOLID\n\n-  LeftClick and move mouse to define a line across your model \n-  The line will stick to your mouse until you Left Click again\n-  A blue preview of the region to be deleted will present itself, everything behind the blue preview will be removed from the model\n-  LeftClick a 3rd time to confirm and the operator will end"
     
     if self.cut_method == 'SOLID':
         help_txt = help_txt_solid
     else:
         help_txt = help_txt_open
     self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
     self.help_box.snap_to_corner(context, corner = [1,1])
     self.mode = 'main'
     self._handle = bpy.types.SpaceView3D.draw_handler_add(plane_cut_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
     context.window_manager.modal_handler_add(self) 
     
     self.bme= bmesh.new()
     self.bme.from_mesh(Model.data)
     self.ob = Model
     self.cursor_updated = True
     
     
     self.new_geom = []
     self.new_geom_point = Vector((0,0,0))
     self.new_geom_draw_points = []
     
     self.extrude_verts = []
     self.extrude_origins = dict()
     self.extrude_geom_draw_points = []
     
     
     
     self.new_geom_color = (.8, .8, .1, 1)
     self.new_geom_point_color = (.1, .1, .8, 1)
     
     return {'RUNNING_MODAL'}
Exemple #19
0
    def prep_world(self):
        self.world_text = TextBox(self.settings, self.screen)
        self.world_text.update_text("WORLD")
        self.world_text.text_rect.centerx = self.settings.screen_width / 2
        self.world_text.text_rect.top = self.screen_rect.top + 5

        self.world_image = self.font.render(self.settings.world_level, True, self.text_color, self.settings.bg_color)
        self.world_rect = self.world_image.get_rect()
        self.world_rect.centerx = self.world_text.text_rect.centerx
        self.world_rect.top = self.world_text.text_rect.bottom
Exemple #20
0
 def __init__(self):
     self.screen = pygame.display.set_mode((1300,600))
     #self.screen_rect = self.screen.get_rect()
     self.bnum = 0
     
     self.clock = pygame.time.Clock()
     self.done = False
     self.fps = 60.0
     self.color = GREEN
     message, message2, message3, message4, message5, message6, message7, message8 = ("Host", "SensorNode 1",
                                     "SensorNode 2","SensorNode 3",
                                     "Communication", "Alarm", "Battery", "Change password")
     #button style
     self.button = Button((0,0,150,100),RED, self.button_click,
                          text=message, **BUTTON1_STYLE)
     #button move
     #self.button.rect.center = (self.screen_rect.centerx,100)
     
     self.button2 = Button((0,100,150,100),RED, self.button_click2,
                          text=message2, **BUTTON1_STYLE)
     self.button3 = Button((0,200,150,100),RED, self.button_click3,
                          text=message3, **BUTTON1_STYLE)
     self.button4 = Button((0,300,150,100),RED, self.button_click4,
                          text=message4, **BUTTON1_STYLE)
     self.button5 = Button((0,400,150,100),RED, self.button_click5,
                          text=message5, **BUTTON1_STYLE)
     self.button6 = Button((0,500,150,100),RED, self.button_click6,
                          text=message6, **BUTTON1_STYLE)
     self.button7 = Button((0,600,100,100),RED, self.button_click,
                          text=message7, **BUTTON1_STYLE)
     self.button8= Button((0,700,100,100),RED, self.button_click,
                          text=message8, **BUTTON1_STYLE)
     #input
     
     self.b2_input = TextBox((450,270,150,25),command=self.change_color2,
                           clear_on_enter=True,inactive_on_enter=False)
     
     pygame.key.set_repeat(*KEY_REPEAT_SETTING)
     
     #mesk
     
     self.pnum, self.pnum2, self.pnum3 = 0,0,0
     
     self.photo = pygame.image.load('p1.1.png').convert_alpha()
     self.photo_pos = (550, 55)
     self.mask = pygame.mask.from_surface(self.photo)
     
     self.photo2 = pygame.image.load('p1.3.png').convert_alpha()
     self.photo2_pos = (400, 200)
     self.mask2 = pygame.mask.from_surface(self.photo2)
     
     self.photo3 = pygame.image.load('p2.1.png').convert_alpha()
     self.photo3_pos = (410, 345)
     self.mask3 = pygame.mask.from_surface(self.photo3)
Exemple #21
0
 def __init__(self,
              x,
              y,
              w,
              h,
              text,
              handler=None,
              border_color=termbox.WHITE):
     TextBox.__init__(self, x, y, w, h, text, border_color)
     Selectable.__init__(self)
     self.handler = handler
Exemple #22
0
    def prep_coins(self):
        self.coin_text = TextBox(self.settings, self.screen)
        self.coin_text.update_text("COINS")
        self.coin_text.text_rect.centerx = self.lives_rect.centerx - 175
        self.coin_text.text_rect.top = self.screen_rect.top + 5

        coin_str = " {:,}".format(self.settings.coin_count)
        self.coin_image = self.font.render(coin_str, True, self.text_color, self.settings.bg_color)
        self.coin_rect = self.coin_image.get_rect()
        self.coin_rect.centerx = self.coin_text.text_rect.centerx
        self.coin_rect.top = self.coin_text.text_rect.bottom
Exemple #23
0
 def set_icon_text(self, text, font_size=20):
     textbox = TextBox(self.width, self.height)
     textbox.add_text(text, align="center", font_size=font_size, color=colors['black'])
     
     self.icon = textbox.image
     self.blurred_icon = self.icon.copy()
     image = pygame.Surface([self.width, self.height])
     image.fill(colors['gray'])
     image.set_alpha(240)
     self.blurred_icon.blit(image, (0,0))
     self.icon_pos = [self.rect.width/2 - self.width/2, self.rect.height/2 - self.height/2]
     self.image.blit(self.icon, self.icon_pos)
Exemple #24
0
 def __init__(self):
     pg.init()
     pg.display.set_caption("Input Box")
     self.screen = pg.display.set_mode((500,500))
     self.clock = pg.time.Clock()
     self.fps = 60.0
     self.done = False
     self.input = TextBox((100,100,150,30),command=self.change_color,
                           clear_on_enter=True,inactive_on_enter=False)
     self.color = (100,100,100)
     self.prompt = self.make_prompt()
     pg.key.set_repeat(*KEY_REPEAT_SETTING)
Exemple #25
0
    def prep_lives(self):
        """Turn level into a rendered image"""
        self.lives_text = TextBox(self.settings, self.screen)
        self.lives_text.update_text("LIVES")
        self.lives_text.text_rect.right = self.settings.screen_width - 50
        self.lives_text.text_rect.top = self.screen_rect.top + 5

        lives_str = " {:,}".format(self.settings.lives)
        self.lives_image = self.font.render(lives_str, True, self.text_color, self.settings.bg_color)
        self.lives_rect = self.lives_image.get_rect()
        self.lives_rect.centerx = self.lives_text.text_rect.centerx
        self.lives_rect.top = self.lives_text.text_rect.bottom
Exemple #26
0
    def prep_score(self):
        """Turn the score into a rendered image"""
        self.score_text = TextBox(self.settings, self.screen)
        self.score_text.update_text("SCORE")
        self.score_text.text_rect.top = self.screen_rect.top + 5
        self.score_text.text_rect.left = self.screen_rect.left + 50
        self.score_str = "{:,}".format(self.settings.score)
        self.score_image = self.font.render(self.score_str, True, self.text_color, self.settings.bg_color)

        #  Display the score at the top right of the screen
        self.score_rect = self.score_image.get_rect()
        self.score_rect.centerx = self.score_text.text_rect.centerx
        self.score_rect.top = self.score_text.text_rect.bottom
Exemple #27
0
    def prep_timer(self):
        timer_str = "{:,}".format(self.settings.timer)
        self.timer_image = self.font.render(timer_str, True, self.text_color, self.settings.bg_color)

        self.timer_text = TextBox(self.settings, self.screen)
        self.timer_text.update_text("TIMER")
        self.timer_text.text_rect.centerx = self.score_text.text_rect.centerx + 175
        self.timer_text.text_rect.top = self.screen_rect.top + 5

        #  Display the score at the top right of the screen
        self.timer_rect = self.timer_image.get_rect()
        self.timer_rect.centerx = self.score_text.text_rect.centerx + 175
        self.timer_rect.top = self.timer_text.text_rect.bottom
Exemple #28
0
 def __init__(self, window):
     self.player = Player()
     self.loop = True
     self.window = window
     width, height = self.window.get_size()
     self.background = pg.image.load(join(DATA_DIR,
                                          'floor-1256804.jpg')).convert()
     self.background = pg.transform.scale(self.background, (width, height))
     self.sheet = pg.Rect(100, 100, 800, 500)
     self.input = TextBox((110, 110, 150, 30),
                          command=self.player.set_name,
                          inactive_on_enter=False,
                          active_color=pg.Color('gray'))
Exemple #29
0
    def __init__(self):
        pg.init()
        pg.mixer.init()

        pg.display.set_caption("Dub_It")
        self.screen = pg.display.set_mode((780,220))
        self.clock = pg.time.Clock()
        self.fps = 60.0
        self.done = False
        self.input = TextBox((30,100,715,75),command=self.speech_to_speech,
                              clear_on_enter=True,inactive_on_enter=False)
        self.color = (100,100,100)
        self.prompt = self.make_prompt()
        pg.key.set_repeat(*KEY_REPEAT_SETTING)
Exemple #30
0
    def get_input(self, id, input):
        """ allows the user to search for cars by enterin a specific colour """
        try:
            input = input.lower()
            self.user_input = input
            self.colour = input
            if self.user_input == "red" or self.user_input == "blue" or self.user_input == "green" or self.user_input == "pink":
                self.prompt = self.make_prompt(
                    'Where do you want to start : e.g. NW')
                self.input = TextBox(
                    (900, 200, 200, 40),
                    command=self.robot_start,  # textbox position 
                    clear_on_enter=True,
                    inactive_on_enter=False)
            if input == "red":
                for coord in self.red:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, red, (x, y, 15, 15))
                    self.colourA = self.red

            elif input == "blue":
                for coord in self.blue:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, blue, (x, y, 15, 15))
                    self.colourA = self.blue

            elif input == "green":
                for coord in self.green:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, green, (x, y, 15, 15))
                    self.colourA = self.green

            elif input == "pink":
                for coord in self.pink:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, pink, (x, y, 15, 15))
                    self.colourA = self.pink

            else:
                self.prompt = self.make_prompt(
                    'Please enter the colour type given')
            self.screen = menuDisplay

        except ValueError:
            print("ERROR")
Exemple #31
0
 def construir(self):
     self.titulo = Titulo("KACH!", 320, 50, 70, 1, (126, 81, 9))
     self.titulo_terminado = Titulo("Juego Terminado!", 320, 100, 40, 3,
                                    (14, 98, 81))
     self.titulo_puntaje = Titulo("Su puntaje es:", 320, 150, 30, 4,
                                  (36, 32, 163))
     self.lblPuntuacion = Titulo("0", 300, 260, 180, 2, (0, 0, 0))
     self.lblinstrucciones = Titulo("Presione <Enter> para continuar", 320,
                                    440, 30, 4, (126, 81, 9))
     self.lblindicacion = Titulo("Ingrese Alias:", 320, 360, 25, 3,
                                 (14, 98, 81))
     self.input = TextBox((220, 380, 200, 30),
                          command=self.enviar_reporte,
                          clear_on_enter=True,
                          inactive_on_enter=False)
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.4'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)
        self.VSPACES    = {'h1': 10, 'h2': 8, 'h3': 6, 'h4': 4, 'h5': 4, 'h6': 4,
                           'p': 8, 'ul': 8, 'ol': 8, 'table': 8,
                           'li': 0, 'tr': 0}
        self.IGNORE_TAGS = ['title', 'style', 'script']

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.text_box  = TextBox(0, 0, self.width, self.height)

        FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../fonts/dejavu-fonts/ttf/')
        self.g.font = pygame.font.Font(os.path.join(FONT_DIR, 'DejaVuSansMono.ttf'), 16)

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        r = requests.get(url, headers={'user-agent': self.USER_AGENT})
        self.html_sourcecode = r.text

        html_parser = etree.HTMLParser(remove_blank_text=True)
        html_tree   = etree.fromstring(self.html_sourcecode, html_parser)
        self.parse_html(html_tree)

        self.text_box.layout(self.g)
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.2'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.text_box  = TextBox(0, 0, self.width, self.height)

        FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../fonts/dejavu-fonts/ttf/')
        self.g.font = pygame.font.Font(os.path.join(FONT_DIR, 'DejaVuSansMono.ttf'), 16)

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        r = requests.get(url, headers={'user-agent': self.USER_AGENT})
        self.html_sourcecode = r.text

        html_parser = etree.HTMLParser(remove_blank_text=True)
        html_tree   = etree.fromstring(self.html_sourcecode, html_parser)
        text        = etree.tostring(html_tree, encoding='unicode', method='text')

        self.text_box.set_text(text)
        self.text_box.layout(self.g)
Exemple #34
0
    def open_document(self, docid):
        self.frame.grid_remove()
        self.editor_frame = Frame(self.master, self.frame)
        #self.editor_windows = DocUI(self.editor_frame)
        self.editor_windows = TextBox(self.master, self.editor_frame)
        self.editor_windows.initialize(self.user, Document(docid))
        self.editor_windows.frame.grid(row=0, column=0, sticky=N+E+S+W)

        self.buttons_frame = Frame(self.master, self.editor_frame)
        self.buttons_frame.grid(row=0, column=1, sticky=N)
        self.buttons_windows = DocSideButtons(self.buttons_frame, self.editor_windows, self.user)
        self.buttons_windows.grid(row=0, column=0, sticky=N+E+S+W)

        self.search_frame = Frame(self.master, self.editor_frame)
        self.search_frame.grid(row=1, column=0, sticky=W+E)
        self.search_UI = DocSearchUI(self.master, self.search_frame, self.editor_windows)
        #self.search_UI.grid(row=0, column=0, sticky=W+E)

        self.search_box_f = Frame(self.master, self.editor_frame)
        self.search_box_f.grid(row=2, column=0, sticky=W+E)
        self.box_UI = DocSearchBox(self.master, self.search_box_f)
        #self.box_UI.grid(row=0, column=0, sticky=W+E)

        self.menubar.destroy()
        self.init_menus()

        return
 def __init__(self):
     """The initialisation function of key components of the main program"""
     pg.init()
     pg.display.set_caption("D5's Bargain Inspector")
     bg = pg.image.load('mainScreen.png')
     gameDisplay.blit(bg,(0,0))
     self.red = []
     self.blue = []
     self.green = []
     self.pink = []
     self.colourA =[]
     self.colour = ""
     self.num_items = 0
     self.finishedList =[]
     self.time = 0
     self.frame_count = 0
     self.frame_rate = 60
     self.start_time = 180
     self.screen = menuDisplay
     self.clock = pg.time.Clock()
     self.robot_loc = []
     self.fps = 60.0
     self.done = False
     self.input = TextBox((900,200,200,40),command=self.get_input,           #setting the size and position of the text box
                           clear_on_enter=True,inactive_on_enter=False)
     self.user_input = ""
     self.color = white
     self.prompt = self.make_prompt('Enter Red:BMW, Blue:Vauxhall, Green:Land Rover, Pink:Lexus')
     pg.key.set_repeat(*KEY_REPEAT_SETTING) #textbox to appear in the same position after action 
 def robot_start(self,id,input):
     """ Allows the user to choose the starting position of the robot"""
     input = input.upper()
     self.robot_loc = input
     if input == "N":
         pg.draw.rect(menuDisplay, red,(400,0,20,30))
         self.robot_loc = [400,0]
     elif input == "E":
         pg.draw.rect(menuDisplay, blue,(750,300,20,30))
         self.robot_loc = [750,300]
     elif input == "S":
         pg.draw.rect(menuDisplay, pink,(400,550,20,30))
         self.robot_loc = [400,550]
     elif input == "W":
         pg.draw.rect(menuDisplay, green,(10,300,20,30))
         self.robot_loc = [10,300]
     elif input == "NW":
         pg.draw.rect(menuDisplay, bright_green,(10,10,20,30))
         self.robot_loc = [10,10]
     elif input == "NE":
         pg.draw.rect(menuDisplay, bright_red,(750,10,20,30))
         self.robot_loc = [750,10]
     elif input == "SW":
         pg.draw.rect(menuDisplay, red,(10,550,20,30))
         self.robot_loc = [10,550]
     elif input == "SE":
         pg.draw.rect(menuDisplay, pink,(750,550,20,30))
         self.robot_loc = [750,550]
     else:
         self.prompt = self.make_prompt('Please enter a valid co-cordinate for the robot to search')
     if input == "N" or input == "E" or input == "S" or input == "W" or input == "NW" or input == "NE" or input == "SW" or input == "SE":
         self.prompt = self.make_prompt('Please enter the number of car types you will like to find?')
         self.input = TextBox((900,200,200,40),command=self.number_of_items, #textbox position
                     clear_on_enter=True,inactive_on_enter=False)
Exemple #37
0
 def invoke(self,context, event):
     
     if len(context.scene.odc_splints) == 0 and context.object:
         #This is a hidden cheat, allowing quick starting of a splint
         my_item = context.scene.odc_splints.add()        
         my_item.name = context.object.name + '_Splint'
         my_item.model = context.object.name
         self.report({'WARNING'}, "Assumed you wanted to start a new splint on the active object!  If not, then UNDO")
         
         for ob in bpy.data.objects:
             ob.select = False
             
         context.object.select = True
         bpy.ops.view3d.view_selected()
         self.splint = my_item
         
     else:
         self.splint = odcutils.splint_selction(context)[0]
         
     self.crv = None
     margin = self.splint.name + '_outline'
     
     if (self.splint.model == '' or self.splint.model not in bpy.data.objects) and not context.object:
         self.report({'WARNING'}, "There is no model, the curve will snap to anything in the scene!")
         self.crv = CurveDataManager(context,snap_type ='SCENE', snap_object = None, shrink_mod = False, name = margin)
         
     elif self.splint.model != '' and self.splint.model in bpy.data.objects:
         Model = bpy.data.objects[self.splint.model]
         for ob in bpy.data.objects:
             ob.select = False
         Model.select = True
         Model.hide = False
         context.scene.objects.active = Model
         bpy.ops.view3d.view_selected()
         self.crv = CurveDataManager(context,snap_type ='OBJECT', snap_object = Model, shrink_mod = True, name = margin)
         self.crv.crv_obj.parent = Model
         
     if self.crv == None:
         self.report({'ERROR'}, "Not sure what you want, you may need to select an object or plan a splint")
         return {'CANCELLED'}
     
     self.splint.margin = self.crv.crv_obj.name
     
     if 'Wrap' in self.crv.crv_obj.modifiers:
         mod = self.crv.crv_obj.modifiers['Wrap']
         mod.offset = .75
         mod.use_keep_above_surface = True
     
         mod = self.crv.crv_obj.modifiers.new('Smooth','SMOOTH')
         mod.iterations = 10
         
     #TODO, tweak the modifier as needed
     help_txt = "DRAW MARGIN OUTLINE\n\nLeft Click on model to draw outline \nRight click to delete a point \nLeft Click last point to make loop \n G to grab  \n ENTER to confirm \n ESC to cancel"
     self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
     self.help_box.snap_to_corner(context, corner = [1,1])
     self.mode = 'main'
     self._handle = bpy.types.SpaceView3D.draw_handler_add(ispltmgn_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
     context.window_manager.modal_handler_add(self) 
     return {'RUNNING_MODAL'}
Exemple #38
0
    def __init__(self, font_name=None, desc_font_size=25, desc_font_color=(255,255,255),
                 exit_pos=(540,500), bg_img=None, textbox_pos=(0, 530), textbox_size=(500, 50)
                 ):
        """Select from 6 tiled pictures of locations where a date can take place. \
        Displays gold cost under each tile. Deducts gold and initiates dating sequence when \
        player clicks on a valid tile."""
        self.bg_img = bg_img or None
        self.font_name = font_name
        self.desc_font_size = desc_font_size
        self.desc_font_color = desc_font_color
        self.desc_font = pygame.font.Font(font_name, desc_font_size)

        self.tiles = pygame.sprite.Group()
        tileStartX, tileStartY = 10, 0
        positions = ([[tileStartX + i*Tile.SIZE_X, tileStartY] for i in range(3)] +
            [[tileStartX + i*Tile.SIZE_X, tileStartY + Tile.SIZE_Y] for i in range(3)])
        def make_tile(name, cost, img_key, loc_key):
            pos = positions.pop(0)
            tile = Tile(name, cost, img_key, loc_key, pos)
            self.tiles.add(tile)
            def on_click():
                print("You clicked on {}".format(tile.name))
                self.done = True
                self.success = True
                self.loc_name = tile.name
                self.cost = tile.cost
                self.loc_key = tile.loc_key
            def on_hover():
                self.changeText("{} -- cost: {} gold".format(name, cost))
            def on_unhover():
                self.changeText("")
            tile.on_click = on_click
            tile.on_hover = on_hover
            tile.on_unhover = on_unhover
        make_tile("Beach of the East", 500, "TILE_beach_east", "beach_east")
        make_tile("Beach of the West", 500, "TILE_beach_west", "beach_west")
        make_tile("Arcade", 1000, "TILE_arcade", "arcade")
        make_tile("Hot Springs", 2000, "TILE_springs", "springs")

        def on_click():
            self.done = True
        self.exit_btn = BlockButton(on_click, datingsim.COLOR_D, (110, 50), exit_pos,
                            "Back")

        self.textbox = TextBox("", textbox_pos, textbox_size, frame_color=(230, 40, 0))
        # TODO: note that frame_color here isn't doing anything.

        self.buttons = pygame.sprite.Group()
        self.buttons.add(self.exit_btn)

        self.all_sprites = pygame.sprite.Group()
        self.all_sprites.add(self.tiles)
        self.all_sprites.add(self.textbox)
        self.all_sprites.add(self.buttons)

        self.main_surface = pygame.display.get_surface()
        self.done = False
        self.curr_tile = None
        self.success = False  # whether a choice was made
    def number_of_items(self,id,input):
        """ This will allow the user to enter the number of chosen car models they want to find"""

        if input.isdigit() and (int(input) <= len(self.colourA)):
            self.num_items = int(input)
            self.prompt = self.make_prompt('Enter the minutes you want the robot to search for?')
            self.input = TextBox((900,200,200,40),command=self.input_time, #textbox pisition
                                clear_on_enter=True,inactive_on_enter=False)

        else:
           self.prompt = self.make_prompt('Please enter how many chosen car models to find?')
Exemple #40
0
 def invoke(self, context, event):
     layers_copy = [layer for layer in context.scene.layers]
     context.scene.layers[0] = True
     
     tooth = odcutils.tooth_selection(context)[0]
     self.tooth = tooth
     sce=bpy.context.scene
     a = tooth.name
     prep = tooth.prep_model
     margin = str(a + "_Margin")
     self.crv = None
     self.margin_manager = None
     if margin in bpy.data.objects:
         self.report({'WARNING'}, "you have already made a margin for this tooth, hit esc and then undo if you didn't want to replace it")
     
     if prep and prep in bpy.data.objects:
         Prep = bpy.data.objects[prep]
         Prep.hide = False
         L = Prep.location
         ###Keep a list of unhidden objects
         for o in sce.objects:
             if o.name != prep and not o.hide:
                 o.hide = True
                 
         self.crv = CurveDataManager(context,snap_type ='OBJECT', snap_object = Prep, shrink_mod = True, name = margin)
         
         self.margin_manager = MarginSlicer(tooth, context, self.crv)
     else:
         self.report({'WARNING'}, "There is no prep for this tooth, your margin will snap to the master model or all objects in scene")
     
     master=sce.odc_props.master
     if master and master in bpy.data.objects:
         Master = bpy.data.objects[master]
         if prep not in bpy.data.objects:
             self.crv = CurveDataManager(context,snap_type ='OBJECT', snap_object = Master, shrink_mod = True, name = margin)
             self.margin_manager = MarginSlicer(tooth, context, self.crv)
     else:
         self.report({'WARNING'}, "No master model...there are risks!")
     
     if not self.crv:
         self.crv = CurveDataManager(context,snap_type ='SCENE', snap_object = None, shrink_mod = False, name = margin)
     
     tooth.margin = self.crv.crv_obj.name
     
     help_txt = "DRAW MARGIN OUTLINE\n\nLeft Click on model to draw outline \nRight click to delete a point \nLeft Click last point to make loop \n G to grab  \n S to show slice \n ENTER to confirm \n ESC to cancel"
     self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
     self.help_box.snap_to_corner(context, corner = [1,1])
     self.mode = 'main'
     self._handle = bpy.types.SpaceView3D.draw_handler_add(icrnmgn_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
     context.window_manager.modal_handler_add(self)
     return {'RUNNING_MODAL'}
Exemple #41
0
    def invoke(self,context,event):
        self.mode = 'main'
        help_txt = "DRAW CUT OUTLINE\n\nLeft Click on model to draw outline outline \nRight click to delete \nLeft Click last point to close loop\n C to preview cut n\ Adjustt red segements and re-cut \n S and then click in region to split to make cut and split mesh \n ENTER to confirm"
        
        self.stroke_smoothing = .4
        self.sketch = []
        
        self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
        self.help_box.snap_to_corner(context, corner = [1,1])
        self.knife = PolyLineKnife(context,context.object)
        self._handle = bpy.types.SpaceView3D.draw_handler_add(plyknife_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
        context.window_manager.modal_handler_add(self)

        return {'RUNNING_MODAL'}
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.6'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)
        self.VSPACES    = {'h1': 10, 'h2': 8, 'h3': 6, 'h4': 4, 'h5': 4, 'h6': 4,
                           'p': 8, 'pre': 8, 'ul': 8, 'ol': 8, 'table': 8,
                           'li': 0, 'tr': 0}
        self.IGNORE_TAGS = ['title', 'style', 'script']

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.top    = 20
        self.left   = 0
        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.do_redraw = True

        self.address_bar   = TextField(0,  0, self.width, 20, on_action_handler=self)
        self.text_box      = TextBox  (0, 20, self.width, self.height - 20)
        self.active_widget = self

        self.fonts = Fonts()
        self.g.font = self.fonts.normal

        self.ATTR = {'default': AttributeWidget(font=self.fonts.normal,fg=(0, 0, 0, 255),bg=(255, 255, 255, 255)),

                     'h1': AttributeWidget(font=self.fonts.h1),
                     'h2': AttributeWidget(font=self.fonts.h2),
                     'h3': AttributeWidget(font=self.fonts.h3),
                     'h4': AttributeWidget(font=self.fonts.h4),
                     'h5': AttributeWidget(font=self.fonts.h5),
                     'h6': AttributeWidget(font=self.fonts.h6),

                     'pre' : AttributeWidget(font=self.fonts.monospace),
                     'code': AttributeWidget(font=self.fonts.monospace)
                     }
        self.attr_stack   = []
        self.attr_current = self.ATTR['default']

        self.links        = []
        self.link_current = None
        self.link_active  = ''

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        self.load(url)
Exemple #43
0
 def invoke(self,context, event):
     
     if context.object:
         ob = context.object
         L = odcutils.get_bbox_center(ob, world=True)
         context.scene.cursor_location = L
     
     self.crv = CurveDataManager(context,snap_type ='SCENE', snap_object = None, shrink_mod = False, name = 'Plan Curve')
      
     #TODO, tweak the modifier as needed
     help_txt = "DRAW ARCH OUTLINE\n\nLeft Click in scene to draw a curve \nPoints will snap to objects under mouse \nNot clicking on object will make points at same depth as 3D cursor \n Right click to delete a point n\ G to grab  \n ENTER to confirm \n ESC to cancel"
     self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
     self.help_box.snap_to_corner(context, corner = [1,1])
     self.mode = 'main'
     self._handle = bpy.types.SpaceView3D.draw_handler_add(arch_crv_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
     context.window_manager.modal_handler_add(self) 
     return {'RUNNING_MODAL'}
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.4'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)
        self.VSPACES    = {'h1': 10, 'h2': 8, 'h3': 6, 'h4': 4, 'h5': 4, 'h6': 4,
                           'p': 8, 'pre': 8, 'ul': 8, 'ol': 8, 'table': 8,
                           'li': 0, 'tr': 0}
        self.IGNORE_TAGS = ['title', 'style', 'script']

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.text_box  = TextBox(0, 0, self.width, self.height)

        self.fonts = Fonts()
        self.g.font = self.fonts.normal

        self.ATTR = {'default': AttributeWidget(font=self.fonts.normal,fg=(0, 0, 0, 255),bg=(255, 255, 255, 255)),

                     'h1': AttributeWidget(font=self.fonts.h1),
                     'h2': AttributeWidget(font=self.fonts.h2),
                     'h3': AttributeWidget(font=self.fonts.h3),
                     'h4': AttributeWidget(font=self.fonts.h4),
                     'h5': AttributeWidget(font=self.fonts.h5),
                     'h6': AttributeWidget(font=self.fonts.h6),

                     'pre' : AttributeWidget(font=self.fonts.monospace),
                     'code': AttributeWidget(font=self.fonts.monospace)
                     }
        self.attr_stack   = []
        self.attr_current = self.ATTR['default']

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        r = requests.get(url, headers={'user-agent': self.USER_AGENT})
        self.html_sourcecode = r.text

        html_parser = etree.HTMLParser(remove_blank_text=True)
        html_tree   = etree.fromstring(self.html_sourcecode, html_parser)
        self.parse_html(html_tree)

        self.text_box.layout(self.g)
    def get_input(self,id,input):
        """ allows the user to search for cars by enterin a specific colour """
        try:
            input = input.lower()
            self.user_input = input
            self.colour = input
            if self.user_input == "red" or self.user_input == "blue" or self.user_input == "green" or self.user_input == "pink":
                self.prompt = self.make_prompt('Where do you want to start : e.g. NW')
                self.input = TextBox((900,200,200,40),command=self.robot_start, # textbox position 
                              clear_on_enter=True,inactive_on_enter=False)
            if input == "red":
                for coord in self.red:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, red,(x,y,15,15))
                    self.colourA = self.red

            elif input == "blue":
                for coord in self.blue:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, blue,(x,y,15,15))
                    self.colourA = self.blue

            elif input == "green":
                for coord in self.green:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, green,(x,y,15,15))
                    self.colourA = self.green

            elif input == "pink":
                for coord in self.pink:
                    x = coord[0]
                    y = coord[1]
                    pg.draw.rect(menuDisplay, pink,(x,y,15,15))
                    self.colourA = self.pink
                    
            else:
                self.prompt = self.make_prompt('Please enter the colour type given')
            self.screen = menuDisplay

        except ValueError:
            print("ERROR")
Exemple #46
0
    def __init__(self, gurl, bg_img=None, gurl_img_pos=(300, 300), textPos=(0,400),
                 textSize=(180,280), use_default_buttons=True):
        self.gurl = gurl
        self.bg_img = bg_img
        self.gurl_img_pos = gurl_img_pos
        self.mood = "default"
        self.meet_advisor = MeetAdvisor(gurl)


        self.gurl_textbox = TextBox("filler", textPos, textSize)
        self.all_sprites = pygame.sprite.Group(self.meet_advisor,
                            self.gurl_textbox)

        self.buttons = pygame.sprite.Group()
        prevx, prevy = None, 300
        def make_button(name, on_click, size=(110, 50), color=datingsim.COLOR_A,
                        dx=20):
            nonlocal prevx
            if prevx == None:
                x = dx
            else:
                x = prevx + dx + size[0]
            y = prevy
            b = BlockButton(on_click, color, pos=(x,y), size=size, text=name)
            prevx = x
            self.buttons.add(b)
            self.all_sprites.add(b)
        self.add_button = make_button
        if use_default_buttons:
            self.add_default_buttons()

        # make an exit button
        def on_exit_click():
            import kitchen
            kitchen.remove_scene(self)
            print("exit click")
            self.done = True
        self.exit_button = BlockButton(on_exit_click, datingsim.COLOR_A, pos=(680,500),
                                        size=(110, 50), text="go back")
        self.buttons.add(self.exit_button)
        self.all_sprites.add(self.exit_button)

        self.done = False;
        self.main_surface = pygame.display.get_surface()
    def invoke(self, context, event):

        sce=bpy.context.scene

        if context.object and context.object.type == 'MESH':
            self.bracket_manager = BracketDataManager(context,snap_type ='OBJECT', snap_object = context.object, name = 'Bracket')
            self.bracket_slicer = BracektSlicer(context, self.bracket_manager)
        else:
            self.bracket_manager = BracketDataManager(context,snap_type ='SCENE', snap_object = None, name = 'Bracket')
            self.bracket_slicer = None
        
        
        help_txt = "DRAW MARGIN OUTLINE\n\nLeft Click on model to place bracket.\n G to grab  \n S to show slice \n ENTER to confirm \n ESC to cancel"
        self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
        self.help_box.snap_to_corner(context, corner = [1,1])
        self.mode = 'main'
        self._handle = bpy.types.SpaceView3D.draw_handler_add(bracket_placement_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}
Exemple #48
0
 def __init__(self, text, popup_pos, popup_bg_surf, text_box_pos, text_box_size,
              okay_pos, okay_size, okay_color=(120,230,120),
              okay_font_color=(255,255,255), font=None, font_size=25,
              font_color=(255,255,255), snapshot=None,
              text_box_bg_color=None, **text_box_style):
     self.text = text
     self.popup_pos = popup_pos
     self.popup_bg_surf = popup_bg_surf
     self.popup_surf = pygame.Surface(popup_bg_surf.get_rect().size)
     self.done = False
     def on_click():
         self.done = True
     self.okay_btn = BlockButton(on_click, okay_color, okay_size, okay_pos,
                                 text="okay", font_color=okay_font_color)
     self.text_box = TextBox(text, text_box_pos, text_box_size, font=font,
                             font_color=font_color, font_size=font_size,
                             bg_color=text_box_bg_color,
                             **text_box_style)
     self.snapshot = snapshot
     self.main_surface = pygame.display.get_surface()
     self.popup_group = pygame.sprite.Group(self.okay_btn, self.text_box)
Exemple #49
0
    def __init__(self, master, user):
        self.user = user
        self.user.manage.manage_DB.check()
        self.manage_Docs = DocumentManager(self.user.manage.manage_DB)

        # Child Windows:
        self.window_login = Login_Window(master, self, self.user)
        self.window_editor = TextBox(master, self)
        self.window_invitations = Invitation_Viewer_Window(
            master, self, self.user)
        self.window_applications = App_Viewer_Window(master, self, self.user)

        self.directory = {'name': '', 'parent_dir': '1'}
        self.directory_contents = []

        self.font = ("Helvetica", "20", "normal")

        self.top = master.winfo_toplevel()
        self.init_frame(master)
        self.init_menus()
        return
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.1'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.text_box  = TextBox(0, 0, self.width, self.height)

        FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../fonts/dejavu-fonts/ttf/')
        self.g.font = pygame.freetype.Font(os.path.join(FONT_DIR, 'DejaVuSansMono.ttf'), ptsize=16, style=pygame.freetype.STYLE_STRONG)

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        r = requests.get(url, headers={'user-agent': self.USER_AGENT})
        self.text_box.set_text(r.text)
        self.text_box.layout(self.g)
class Control(object):
    def __init__(self):
        pg.init()
        pg.display.set_caption("Input Box")
        self.screen = pg.display.set_mode((500,500))
        self.clock = pg.time.Clock()
        self.fps = 60.0
        self.done = False
        self.input = TextBox((100,100,150,30),command=self.change_color,
                              clear_on_enter=True,inactive_on_enter=False)
        self.color = (100,100,100)
        self.prompt = self.make_prompt()
        pg.key.set_repeat(*KEY_REPEAT_SETTING)

    def make_prompt(self):
        font = pg.font.SysFont("arial", 20)
        message = 'Please type a color name for background (ex. "red"):'
        rend = font.render(message, True, pg.Color("white"))
        return (rend, rend.get_rect(topleft=(10,35)))

    def event_loop(self):
        for event in pg.event.get():
            if event.type == pg.QUIT:
                self.done = True
            self.input.get_event(event)

    def change_color(self,id,color):
        try:
            self.color = pg.Color(str(color))
        except ValueError:
            print("Please input a valid color name.")

    def main_loop(self):
        while not self.done:
            self.event_loop()
            self.input.update()
            self.screen.fill(self.color)
            self.input.draw(self.screen)
            self.screen.blit(*self.prompt)
            pg.display.update()
            self.clock.tick(self.fps)
from window import Window, Container, AppWindow, ChildWindow
from point import Point
from dialogbox import DialogBox
from textbox import TextBox, isaNumber, isaFloat, isaURL
from button import Button, OK, Cancel, RadioButtonGroup, RadioButton

sampleContainer = Container(None, "Test Window", Point(10, 10), 20, 20)

textChild = TextBox(sampleContainer, "Hello", Point(10, 10), 10, 10)
sampleContainer.addChildWindow(textChild)
iterChild = sampleContainer.childIterator()

def sampleValidator():
    return True

for i in iterChild:
    print i


try:
    sampleContainer.setFocus()
    sampleContainer.hasFocus()
    sampleContainer.minimize()
    sampleContainer.maximize()
    textChild.setText("")
    textChild.getText()
    textChild.validate(sampleValidator)
except NotImplementedError:
    print "You need to implement this"

sampleAppWindow = AppWindow("Sample App Window")
class SimpleWebbrowser:
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.4'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)
        self.VSPACES    = {'h1': 10, 'h2': 8, 'h3': 6, 'h4': 4, 'h5': 4, 'h6': 4,
                           'p': 8, 'pre': 8, 'ul': 8, 'ol': 8, 'table': 8,
                           'li': 0, 'tr': 0}
        self.IGNORE_TAGS = ['title', 'style', 'script']

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.text_box  = TextBox(0, 0, self.width, self.height)

        self.fonts = Fonts()
        self.g.font = self.fonts.normal

        self.ATTR = {'default': AttributeWidget(font=self.fonts.normal,fg=(0, 0, 0, 255),bg=(255, 255, 255, 255)),

                     'h1': AttributeWidget(font=self.fonts.h1),
                     'h2': AttributeWidget(font=self.fonts.h2),
                     'h3': AttributeWidget(font=self.fonts.h3),
                     'h4': AttributeWidget(font=self.fonts.h4),
                     'h5': AttributeWidget(font=self.fonts.h5),
                     'h6': AttributeWidget(font=self.fonts.h6),

                     'pre' : AttributeWidget(font=self.fonts.monospace),
                     'code': AttributeWidget(font=self.fonts.monospace)
                     }
        self.attr_stack   = []
        self.attr_current = self.ATTR['default']

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        r = requests.get(url, headers={'user-agent': self.USER_AGENT})
        self.html_sourcecode = r.text

        html_parser = etree.HTMLParser(remove_blank_text=True)
        html_tree   = etree.fromstring(self.html_sourcecode, html_parser)
        self.parse_html(html_tree)

        self.text_box.layout(self.g)

    def parse_html(self, element):
        if element.tag in self.IGNORE_TAGS:
            return

        if element.tag in self.VSPACES:
            self.text_box.widgets.append(VSpaceWidget(self.VSPACES[element.tag]))

        if element.tag in self.ATTR:
            self.attr_stack.append(self.attr_current)
            self.attr_current = self.ATTR[element.tag]
            self.text_box.widgets.append(self.attr_current)

        if element.text != None:
            for word in element.text.split():
                self.text_box.widgets.append(TextWidget(word))

        for child in element:
            self.parse_html(child)

        if element.tag in self.ATTR:
            self.attr_current = self.attr_stack.pop()
            self.text_box.widgets.append(self.attr_current)

        if element.tail != None:
            for word in element.tail.split():
                self.text_box.widgets.append(TextWidget(word))

    def set_size(self, size):
        self.width     = size[0]
        self.height    = size[1]
        self.g.surface = pygame.display.set_mode(size, pygame.RESIZABLE)

        self.text_box.set_size(self.width, self.height)
        self.text_box.layout(self.g)

    def draw(self, g):
        g.fg = (  0,   0,   0, 255)
        g.bg = (255, 255, 255, 255)
        g.font = self.fonts.normal

        g.surface.fill((255, 255, 255))
        self.text_box.draw(g)

    def run(self):
        while True:
            self.draw(self.g)
            pygame.display.flip()

            event = pygame.event.wait()

            if event.type == pygame.QUIT:
                break

            if event.type == pygame.VIDEORESIZE:
                self.set_size(event.size)

            if event.type == pygame.MOUSEMOTION:
                continue

            if event.type == pygame.MOUSEBUTTONUP:
                continue

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    break


                elif event.key == pygame.K_UP   : self.text_box.scroll(  0, -5)
                elif event.key == pygame.K_DOWN : self.text_box.scroll(  0,  5)
                elif event.key == pygame.K_LEFT : self.text_box.scroll(-20,  0)
                elif event.key == pygame.K_RIGHT: self.text_box.scroll( 20,  0)

                elif event.key == pygame.K_PAGEUP  : self.text_box.scroll_page_up()
                elif event.key == pygame.K_PAGEDOWN: self.text_box.scroll_page_down()


                elif event.key == pygame.K_HOME:
                    if event.mod & pygame.KMOD_SHIFT:
                        self.text_box.scroll_x_home()
                    else:
                        self.text_box.scroll_y_home()

                elif event.key == pygame.K_END:
                    if event.mod & pygame.KMOD_SHIFT:
                        self.text_box.scroll_x_end()
                    else:
                        self.text_box.scroll_y_end()

    def quit(self):
        pygame.quit()
class SimpleWebbrowser:
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.2'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.text_box  = TextBox(0, 0, self.width, self.height)

        FONT_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../fonts/dejavu-fonts/ttf/')
        self.g.font = pygame.font.Font(os.path.join(FONT_DIR, 'DejaVuSansMono.ttf'), 16)

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        r = requests.get(url, headers={'user-agent': self.USER_AGENT})
        self.html_sourcecode = r.text

        html_parser = etree.HTMLParser(remove_blank_text=True)
        html_tree   = etree.fromstring(self.html_sourcecode, html_parser)
        text        = etree.tostring(html_tree, encoding='unicode', method='text')

        self.text_box.set_text(text)
        self.text_box.layout(self.g)

    def set_size(self, size):
        self.width     = size[0]
        self.height    = size[1]
        self.g.surface = pygame.display.set_mode(size, pygame.RESIZABLE)

        self.text_box.set_size(self.width, self.height)
        self.text_box.layout(self.g)

    def draw(self, g):
        g.surface.fill((255, 255, 255))
        self.text_box.draw(g)

    def run(self):
        while True:
            self.draw(self.g)
            pygame.display.flip()

            event = pygame.event.wait()

            if event.type == pygame.QUIT:
                break

            if event.type == pygame.VIDEORESIZE:
                self.set_size(event.size)

            if event.type == pygame.MOUSEMOTION:
                continue

            if event.type == pygame.MOUSEBUTTONUP:
                continue

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    break


                elif event.key == pygame.K_UP   : self.text_box.scroll(  0, -5)
                elif event.key == pygame.K_DOWN : self.text_box.scroll(  0,  5)
                elif event.key == pygame.K_LEFT : self.text_box.scroll(-20,  0)
                elif event.key == pygame.K_RIGHT: self.text_box.scroll( 20,  0)

                elif event.key == pygame.K_PAGEUP  : self.text_box.scroll_page_up()
                elif event.key == pygame.K_PAGEDOWN: self.text_box.scroll_page_down()


                elif event.key == pygame.K_HOME:
                    if event.mod & pygame.KMOD_SHIFT:
                        self.text_box.scroll_x_home()
                    else:
                        self.text_box.scroll_y_home()

                elif event.key == pygame.K_END:
                    if event.mod & pygame.KMOD_SHIFT:
                        self.text_box.scroll_x_end()
                    else:
                        self.text_box.scroll_y_end()

    def quit(self):
        pygame.quit()
Exemple #55
0
class Dialogue:

    debug = False

    def __init__(self, text, popup_pos, popup_bg_surf, text_box_pos, text_box_size,
                 okay_pos, okay_size, okay_color=(120,230,120),
                 okay_font_color=(255,255,255), font=None, font_size=25,
                 font_color=(255,255,255), snapshot=None,
                 text_box_bg_color=None, **text_box_style):
        self.text = text
        self.popup_pos = popup_pos
        self.popup_bg_surf = popup_bg_surf
        self.popup_surf = pygame.Surface(popup_bg_surf.get_rect().size)
        self.done = False
        def on_click():
            self.done = True
        self.okay_btn = BlockButton(on_click, okay_color, okay_size, okay_pos,
                                    text="okay", font_color=okay_font_color)
        self.text_box = TextBox(text, text_box_pos, text_box_size, font=font,
                                font_color=font_color, font_size=font_size,
                                bg_color=text_box_bg_color,
                                **text_box_style)
        self.snapshot = snapshot
        self.main_surface = pygame.display.get_surface()
        self.popup_group = pygame.sprite.Group(self.okay_btn, self.text_box)

    def ath(self):
        self.okay_btn.kill()
        self.text_box.kill()

    def main_loop(self):
        while not self.done:
            for e in pygame.event.get():
                if e.type is pygame.QUIT:
                    pygame.quit()
                    quit()
                if e.type is pygame.MOUSEBUTTONDOWN:
                    rect = self.okay_btn.rect.move(self.popup_pos)
                    if rect.collidepoint(e.pos):
                        self.okay_btn.on_click()
            if self.snapshot:
                self.main_surface.blit(self.snapshot, [0,0])
            self.popup_surf.blit(self.popup_bg_surf, [0,0])
            self.popup_group.update()
            self.popup_group.draw(self.popup_surf)
            self.main_surface.blit(self.popup_surf, self.popup_pos)
            pygame.display.flip()
            pygame.time.wait(1000//20)
        self.ath()

    @staticmethod
    def test():
        pygame.init()
        pygame.display.set_caption("Dialogue")
        GAME_SIZE = GAME_WIDTH, GAME_HEIGHT = (800, 600)
        screen = pygame.display.set_mode(GAME_SIZE)

        popup_w, popup_h = popup_size = (400,300)
        popup_bg_surf = pygame.Surface(popup_size)
        popup_bg_surf.fill([10,60,80])
        popup_pos = (GAME_WIDTH - popup_w)/2, (GAME_HEIGHT - popup_h)/2
        text_box_w, text_box_h = text_box_size = (370, 200)
        text_box_pos = (popup_w - text_box_w)/2, (popup_h - text_box_h)/2
        text = ("Lorem ipsum lumpus rumpus fruity patootie. In the beginning "
            "there was dark. What is?")
        okay_w, okay_h = okay_size = (80, 50)
        okay_pos = (popup_w - okay_w)/2, (popup_h - okay_h - 3)
        snapshot = pygame.image.load('new-zealand.jpg').convert()

        d = Dialogue(text, popup_pos, popup_bg_surf, text_box_pos, text_box_size,
                     okay_pos, okay_size, snapshot=snapshot)
        d.main_loop()
        pygame.quit()
Exemple #56
0
class DateChoose():

    def __init__(self, font_name=None, desc_font_size=25, desc_font_color=(255,255,255),
                 exit_pos=(540,500), bg_img=None, textbox_pos=(0, 530), textbox_size=(500, 50)
                 ):
        """Select from 6 tiled pictures of locations where a date can take place. \
        Displays gold cost under each tile. Deducts gold and initiates dating sequence when \
        player clicks on a valid tile."""
        self.bg_img = bg_img or None
        self.font_name = font_name
        self.desc_font_size = desc_font_size
        self.desc_font_color = desc_font_color
        self.desc_font = pygame.font.Font(font_name, desc_font_size)

        self.tiles = pygame.sprite.Group()
        tileStartX, tileStartY = 10, 0
        positions = ([[tileStartX + i*Tile.SIZE_X, tileStartY] for i in range(3)] +
            [[tileStartX + i*Tile.SIZE_X, tileStartY + Tile.SIZE_Y] for i in range(3)])
        def make_tile(name, cost, img_key, loc_key):
            pos = positions.pop(0)
            tile = Tile(name, cost, img_key, loc_key, pos)
            self.tiles.add(tile)
            def on_click():
                print("You clicked on {}".format(tile.name))
                self.done = True
                self.success = True
                self.loc_name = tile.name
                self.cost = tile.cost
                self.loc_key = tile.loc_key
            def on_hover():
                self.changeText("{} -- cost: {} gold".format(name, cost))
            def on_unhover():
                self.changeText("")
            tile.on_click = on_click
            tile.on_hover = on_hover
            tile.on_unhover = on_unhover
        make_tile("Beach of the East", 500, "TILE_beach_east", "beach_east")
        make_tile("Beach of the West", 500, "TILE_beach_west", "beach_west")
        make_tile("Arcade", 1000, "TILE_arcade", "arcade")
        make_tile("Hot Springs", 2000, "TILE_springs", "springs")

        def on_click():
            self.done = True
        self.exit_btn = BlockButton(on_click, datingsim.COLOR_D, (110, 50), exit_pos,
                            "Back")

        self.textbox = TextBox("", textbox_pos, textbox_size, frame_color=(230, 40, 0))
        # TODO: note that frame_color here isn't doing anything.

        self.buttons = pygame.sprite.Group()
        self.buttons.add(self.exit_btn)

        self.all_sprites = pygame.sprite.Group()
        self.all_sprites.add(self.tiles)
        self.all_sprites.add(self.textbox)
        self.all_sprites.add(self.buttons)

        self.main_surface = pygame.display.get_surface()
        self.done = False
        self.curr_tile = None
        self.success = False  # whether a choice was made

    def changeText(self, text):
        """render changed text if necessary"""
        self.textbox.text = text
        self.textbox.render()
        print("Text changed to {}.".format(text))

    def main_loop(self):
        while not self.done:
            for e in pygame.event.get():
                if e.type is pygame.QUIT:
                    pygame.quit()
                    datingsim.quit()
                    quit()
                elif e.type is pygame.MOUSEMOTION:
                    for tile in self.tiles:
                        if tile.rect.collidepoint(e.pos):
                            if (tile != self.curr_tile):
                                tile.on_hover()
                            self.curr_tile = tile
                        elif tile == self.curr_tile: # didn't collide with curr_tile
                            tile.on_unhover()
                            self.curr_tile = None
                elif e.type is pygame.MOUSEBUTTONDOWN:
                    if self.curr_tile != None:
                        self.curr_tile.on_click()
                    for button in self.buttons:
                        if button.rect.collidepoint(e.pos):
                            button.on_click()

            if self.bg_img:
                self.main_surface.blit(self.bg_img, [0,0])
            else:
                self.main_surface.fill((0, 0, 0))
            self.all_sprites.update()
            self.all_sprites.draw(self.main_surface)
            pygame.display.flip()
            pygame.time.wait(1000//20)
        self.ath()

    def ath(self):
        pass

    @staticmethod
    def test():
        instance = DateChoose()
        instance.main_loop()
        if instance.success:
            print("You chose {}.".format(instance.loc_name))
            print("The location key of your choice is {}.".format(instance.loc_key))
            print("The cost of this location is {}.".format(instance.cost))
        else:
            print("No choice of location was made.")
Exemple #57
0
class OPENDENTAL_OT_mesh_trim_polyline(bpy.types.Operator):
    """Draw a line with the mouse to cut mesh into pieces"""
    bl_idname = "opendental.trim_mesh"
    bl_label = "Polyline Trim Mesh"
    bl_options = {'REGISTER', 'UNDO'}
    
    def sketch_confirm(self, context, event):
        print('sketch confirmed')
        if len(self.sketch) < 5 and self.knife.ui_type == 'DENSE_POLY':
            print('sketch too short, cant confirm')
            return
        x, y = event.mouse_region_x, event.mouse_region_y
        last_hovered = self.knife.hovered[1] #guaranteed to be a point by criteria to enter sketch mode
        self.knife.hover(context,x,y)
        print('last hovered %i' % last_hovered)
        
        sketch_3d = common_utilities.ray_cast_path(context, self.knife.cut_ob,self.sketch)
        
        if self.knife.hovered[0] == None:
            #add the points in
            if last_hovered == len(self.knife.pts) - 1:
                self.knife.pts += sketch_3d[0::5]
                print('add on to the tail')

                
            else:
                self.knife.pts = self.knife.pts[:last_hovered] + sketch_3d[0::5]
                print('snipped off and added on to the tail')
        
        else:
            print('inserted new segment')
            print('now hovered %i' % self.knife.hovered[1])
            new_pts = sketch_3d[0::5]
            if last_hovered > self.knife.hovered[1]:
                new_pts.reverse()
                self.knife.pts = self.knife.pts[:self.knife.hovered[1]] + new_pts + self.knife.pts[last_hovered:]
            else:
                self.knife.pts = self.knife.pts[:last_hovered] + new_pts + self.knife.pts[self.knife.hovered[1]:]
        self.knife.snap_poly_line()
        
    def modal_nav(self, event):
        events_nav = {'MIDDLEMOUSE', 'WHEELINMOUSE','WHEELOUTMOUSE', 'WHEELUPMOUSE','WHEELDOWNMOUSE'} #TODO, better navigation, another tutorial
        handle_nav = False
        handle_nav |= event.type in events_nav

        if handle_nav: 
            return 'nav'
        return ''
    
    def modal_main(self,context,event):
        # general navigation
        nmode = self.modal_nav(event)
        if nmode != '':
            return nmode  #stop here and tell parent modal to 'PASS_THROUGH'

        #after navigation filter, these are relevant events in this state
        if event.type == 'G' and event.value == 'PRESS':
            if self.knife.grab_initiate():
                return 'grab'
            else:
                #need to select a point
                return 'main'
        
        if event.type == 'MOUSEMOVE':
            self.knife.hover(context, event.mouse_region_x, event.mouse_region_y)    
            return 'main'
        
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            
            x, y = event.mouse_region_x, event.mouse_region_y
            self.knife.click_add_point(context, x,y)  #takes care of selection too
            if self.knife.ui_type == 'DENSE_POLY' and self.knife.hovered[0] == 'POINT':
                self.sketch = [(x,y)]
                return 'sketch'
            return 'main'
        
        if event.type == 'RIGHTMOUSE' and event.value == 'PRESS':
            self.knife.click_delete_point(mode = 'mouse')
            return 'main'
        
        if event.type == 'X' and event.value == 'PRESS':
            self.knife.delete_selected(mode = 'selected')
            return 'main'
        
        if event.type == 'C' and event.value == 'PRESS':
            self.knife.make_cut()
            return 'main' 
        if event.type == 'D' and event.value == 'PRESS':
            print('confirm cut')
            if len(self.knife.new_cos) and len(self.knife.bad_segments) == 0 and not self.knife.split:
                print('actuall confirm cut')
                self.knife.confirm_cut_to_mesh()
                return 'main' 
            
        if event.type == 'E' and event.value == 'PRESS':     
            if self.knife.split and self.knife.face_seed and len(self.knife.ed_map):
                self.knife.split_geometry()
                return 'finish' 
            
        if event.type == 'S' and event.value == 'PRESS':
            return 'inner'
          
        if event.type == 'RET' and event.value == 'PRESS':
            self.knife.confirm_cut_to_mesh()
            return 'finish'
            
        elif event.type == 'ESC' and event.value == 'PRESS':
            return 'cancel' 

        return 'main'
    
    def modal_grab(self,context,event):
        # no navigation in grab mode
        
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            #confirm location
            self.knife.grab_confirm()
            return 'main'
        
        elif event.type in {'RIGHTMOUSE', 'ESC'} and event.value == 'PRESS':
            #put it back!
            self.knife.grab_cancel()
            return 'main'
        
        elif event.type == 'MOUSEMOVE':
            #update the b_pt location
            self.knife.grab_mouse_move(context,event.mouse_region_x, event.mouse_region_y)
            return 'grab'
    
    def modal_sketch(self,context,event):
        if event.type == 'MOUSEMOVE':
            x, y = event.mouse_region_x, event.mouse_region_y
            if not len(self.sketch):
                return 'main'
            (lx, ly) = self.sketch[-1]
            ss0,ss1 = self.stroke_smoothing ,1-self.stroke_smoothing
            self.sketch += [(lx*ss0+x*ss1, ly*ss0+y*ss1)]
            return 'sketch'
        
        elif event.type == 'LEFTMOUSE' and event.value == 'RELEASE':
            self.sketch_confirm(context, event)
            self.sketch = []
            return 'main'
        
    def modal_inner(self,context,event):
        
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            print('left click modal inner')
            x, y = event.mouse_region_x, event.mouse_region_y
            if self.knife.click_seed_select(context, x,y):
                print('seed set')
                return 'main'
            else:
                return 'inner'
        
        if event.type in {'RET', 'ESC'}:
            return 'main'
            
    def modal(self, context, event):
        context.area.tag_redraw()
        
        FSM = {}    
        FSM['main']    = self.modal_main
        FSM['sketch']  = self.modal_sketch
        FSM['grab']    = self.modal_grab
        FSM['nav']     = self.modal_nav
        FSM['inner']   = self.modal_inner
        
        nmode = FSM[self.mode](context, event)
        
        if nmode == 'nav': 
            return {'PASS_THROUGH'}
        
        if nmode in {'finish','cancel'}:
            #clean up callbacks
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'FINISHED'} if nmode == 'finish' else {'CANCELLED'}
        
        if nmode: self.mode = nmode
        
        return {'RUNNING_MODAL'}
    
    def invoke(self,context,event):
        self.mode = 'main'
        help_txt = "DRAW CUT OUTLINE\n\nLeft Click on model to draw outline outline \nRight click to delete \nLeft Click last point to close loop\n C to preview cut n\ Adjustt red segements and re-cut \n S and then click in region to split to make cut and split mesh \n ENTER to confirm"
        
        self.stroke_smoothing = .4
        self.sketch = []
        
        self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
        self.help_box.snap_to_corner(context, corner = [1,1])
        self.knife = PolyLineKnife(context,context.object)
        self._handle = bpy.types.SpaceView3D.draw_handler_add(plyknife_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
        context.window_manager.modal_handler_add(self)

        return {'RUNNING_MODAL'}
class SimpleWebbrowser:
    def __init__(self, width=800, height=600, url='http://localhost/'):
        self.VERSION = '0.6'
        self.USER_AGENT = 'SimpleWebBrowser/{version}'.format(version=self.VERSION)
        self.VSPACES    = {'h1': 10, 'h2': 8, 'h3': 6, 'h4': 4, 'h5': 4, 'h6': 4,
                           'p': 8, 'pre': 8, 'ul': 8, 'ol': 8, 'table': 8,
                           'li': 0, 'tr': 0}
        self.IGNORE_TAGS = ['title', 'style', 'script']

        pygame.init()
        pygame.key.set_repeat(100, 1000 // 25)

        self.top    = 20
        self.left   = 0
        self.width  = width
        self.height = height

        self.g         = Graphics()
        self.g.surface = pygame.display.set_mode((self.width, self.height), pygame.RESIZABLE)
        self.do_redraw = True

        self.address_bar   = TextField(0,  0, self.width, 20, on_action_handler=self)
        self.text_box      = TextBox  (0, 20, self.width, self.height - 20)
        self.active_widget = self

        self.fonts = Fonts()
        self.g.font = self.fonts.normal

        self.ATTR = {'default': AttributeWidget(font=self.fonts.normal,fg=(0, 0, 0, 255),bg=(255, 255, 255, 255)),

                     'h1': AttributeWidget(font=self.fonts.h1),
                     'h2': AttributeWidget(font=self.fonts.h2),
                     'h3': AttributeWidget(font=self.fonts.h3),
                     'h4': AttributeWidget(font=self.fonts.h4),
                     'h5': AttributeWidget(font=self.fonts.h5),
                     'h6': AttributeWidget(font=self.fonts.h6),

                     'pre' : AttributeWidget(font=self.fonts.monospace),
                     'code': AttributeWidget(font=self.fonts.monospace)
                     }
        self.attr_stack   = []
        self.attr_current = self.ATTR['default']

        self.links        = []
        self.link_current = None
        self.link_active  = ''

        pygame.display.set_caption('SimpleWebBrowser V{version}'.format(version=self.VERSION))

        self.load(url)


    def load(self, uri):
        """ Load new web page."""
        self.link_active = urljoin(self.link_active, uri)
        self.address_bar.set_text(self.link_active)
        self.address_bar.draw(self.g)

        r = requests.get(self.link_active, headers={'user-agent': self.USER_AGENT})
        self.html_sourcecode = r.text

        self.attr_stack       = []
        self.attr_current     = self.ATTR['default']
        self.links            = []

        self.text_box.scroll_left = 0
        self.text_box.scroll_top  = 0
        self.text_box.widgets     = []

        html_parser = etree.HTMLParser(remove_blank_text=True)
        html_tree   = etree.fromstring(self.html_sourcecode, html_parser)
        self.parse_html(html_tree)

        self.text_box.layout(self.g)

    def parse_html(self, element):
        if element.tag in self.IGNORE_TAGS:
            return

        if element.tag in self.VSPACES:
            self.text_box.widgets.append(VSpaceWidget(self.VSPACES[element.tag]))

        if element.tag in self.ATTR:
            self.attr_stack.append(self.attr_current)
            self.attr_current = self.ATTR[element.tag]
            self.text_box.widgets.append(self.attr_current)

        if element.tag == 'a':
            self.link_current = Link(href=element.get('href'))
            self.links.append(self.link_current)

            self.attr_stack.append(self.attr_current)
            self.attr_current = AttributeWidget(fg=(0,0,255,255), bg=(255,255,255,255))
            self.text_box.widgets.append(self.attr_current)

        if element.tag in ['ul', 'ol']:
            self.text_box.widgets.append(IndentWidget(32))

        if element.text != None:
            for word in element.text.split():
                text_widget = TextWidget(word)
                self.text_box.widgets.append(text_widget)

                if self.link_current != None:
                    self.link_current.widgets.append(text_widget)

        for child in element:
            self.parse_html(child)

        if element.tag in self.ATTR:
            self.attr_current = self.attr_stack.pop()
            self.text_box.widgets.append(self.attr_current)

        if element.tag == 'a':
            self.link_current = None

            self.attr_current = self.attr_stack.pop()
            self.text_box.widgets.append(self.attr_current)

        if element.tag in ['ul', 'ol']:
            self.text_box.widgets.append(IndentWidget(-32))

        if element.tail != None:
            for word in element.tail.split():
                text_widget = TextWidget(word)
                self.text_box.widgets.append(text_widget)

                if self.link_current != None:
                    self.link_current.widgets.append(text_widget)

    def set_size(self, size):
        self.width     = size[0]
        self.height    = size[1]
        self.g.surface = pygame.display.set_mode(size, pygame.RESIZABLE)

        self.address_bar.set_size(self.width, 20)
        self.address_bar.layout(self.g)

        self.text_box.set_size(self.width, self.height - 20)
        self.text_box.layout(self.g)

        self.draw(self.g)

    def draw(self, g):
        g.fg = (  0,   0,   0, 255)
        g.bg = (255, 255, 255, 255)
        g.font = self.fonts.normal

        self.g.surface.set_clip(None)
        g.surface.fill(g.bg)
        self.address_bar.draw(g)
        self.text_box.draw(g)

    def on_action(self, widget):
        self.load(self.address_bar.text)
        self.draw(self.g)
        pygame.display.flip()

    def on_focus(self):
        pass

    def on_blur(self):
        pass

    def on_mouse_down(self, event):
        pass

    def on_mouse_up(self, event):
        for link in self.links:
            if link.is_point_in(event.pos[0] - self.text_box.left + self.text_box.scroll_left,
                                event.pos[1] - self.text_box.top  + self.text_box.scroll_top):
                self.load(link.href)
                break

    def on_key_down(self, event):
        if   event.key == pygame.K_UP   : self.text_box.scroll(  0, -5)
        elif event.key == pygame.K_DOWN : self.text_box.scroll(  0,  5)
        elif event.key == pygame.K_LEFT : self.text_box.scroll(-20,  0)
        elif event.key == pygame.K_RIGHT: self.text_box.scroll( 20,  0)

        elif event.key == pygame.K_PAGEUP  : self.text_box.scroll_page_up()
        elif event.key == pygame.K_PAGEDOWN: self.text_box.scroll_page_down()

        elif event.key == pygame.K_HOME:
            if event.mod & pygame.KMOD_SHIFT:
                self.text_box.scroll_x_home()
            else:
                self.text_box.scroll_y_home()

        elif event.key == pygame.K_END:
            if event.mod & pygame.KMOD_SHIFT:
                self.text_box.scroll_x_end()
            else:
                self.text_box.scroll_y_end()

    def run(self):
        while True:
            if self.active_widget.do_redraw:
                self.active_widget.draw(self.g)
                pygame.display.flip()

            if self.active_widget == self:
                self.do_redraw = True
            else:
                self.do_redraw = False

            event = pygame.event.wait()

            if event.type == pygame.QUIT:
                break

            if event.type == pygame.VIDEORESIZE:
                self.set_size(event.size)

            if event.type == pygame.MOUSEMOTION:
                self.do_redraw = False

            if event.type == pygame.MOUSEBUTTONDOWN:
                if self.address_bar.is_point_in(event.pos[0], event.pos[1]):
                    new_active_widget = self.address_bar
                else:
                    new_active_widget = self

                if new_active_widget != self.active_widget:
                    self.active_widget.on_blur()
                    self.active_widget.draw(self.g)

                    self.active_widget = new_active_widget

                    self.active_widget.on_focus()
                    self.active_widget.draw(self.g)

                    pygame.display.flip()

                self.active_widget.on_mouse_down(event)

            if event.type == pygame.MOUSEBUTTONUP:
                self.active_widget.on_mouse_up(event)

            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    break

                self.active_widget.on_key_down(event)

    def quit(self):
        pygame.quit()
Exemple #59
0
class OPENDENTAL_OT_mark_crown_margin(bpy.types.Operator):
    """Mark Margin.  Draw a line with the mouse to extrude bezier curves"""
    bl_idname = "opendental.mark_crown_margin"
    bl_label = "Mark Crown Margin"
    bl_options = {'REGISTER', 'UNDO'}
    
    @classmethod
    def poll(cls, context):
        #restoration exists and is in scene
        teeth = odcutils.tooth_selection(context)
        
        if teeth != []:#This can only happen one tooth at a time
            #tooth = teeth[0]
            #return tooth.prep_model in bpy.data.objects
            return True
        else:
            return False   
    def modal_nav(self, event):
        events_nav = {'MIDDLEMOUSE', 'WHEELINMOUSE','WHEELOUTMOUSE', 'WHEELUPMOUSE','WHEELDOWNMOUSE'} #TODO, better navigation, another tutorial
        handle_nav = False
        handle_nav |= event.type in events_nav

        if handle_nav: 
            return 'nav'
        return ''
    
    def modal_main(self,context,event):
        # general navigation
        nmode = self.modal_nav(event)
        if nmode != '':
            return nmode  #stop here and tell parent modal to 'PASS_THROUGH'

        #after navigation filter, these are relevant events in this state
        if event.type == 'G' and event.value == 'PRESS':
            if self.crv.grab_initiate():
                return 'grab'
            else:
                #error, need to select a point
                return 'main'
        
        if event.type == 'MOUSEMOVE':
            self.crv.hover(context, event.mouse_region_x, event.mouse_region_y)    
            return 'main'
        
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            x, y = event.mouse_region_x, event.mouse_region_y
            self.crv.click_add_point(context, x,y)
            return 'main'
        
        if event.type == 'RIGHTMOUSE' and event.value == 'PRESS':
            self.crv.click_delete_point(mode = 'mouse')
            return 'main'
        
        if event.type == 'X' and event.value == 'PRESS':
            self.crv.delete_selected(mode = 'selected')
            return 'main'
        
        if event.type == 'S' and event.value == 'PRESS' and self.margin_manager:
            self.margin_manager.prepare_slice()
            return 'slice'
            
        if event.type == 'RET' and event.value == 'PRESS':
            return 'finish'
            
        elif event.type == 'ESC' and event.value == 'PRESS':
            del_obj = self.crv.crv_obj
            context.scene.objects.unlink(del_obj)
            bpy.data.objects.remove(del_obj)
            self.tooth.margin = ''
            return 'cancel' 

        return 'main'
    
    def modal_grab(self,context,event):
        # no navigation in grab mode
        
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            #confirm location
            self.crv.grab_confirm()
            return 'main'
        
        elif event.type in {'RIGHTMOUSE', 'ESC'} and event.value == 'PRESS':
            #put it back!
            self.crv.grab_cancel()
            return 'main'
        
        elif event.type == 'MOUSEMOVE':
            #update the b_pt location
            self.crv.grab_mouse_move(context,event.mouse_region_x, event.mouse_region_y)
            return 'grab'
    
    def modal_slice(self,context,event):
        # no navigation in grab mode
        
        if event.type == 'LEFTMOUSE' and event.value == 'PRESS':
            #confirm location
            self.margin_manager.slice_confirm()
            return 'main'
        
        elif event.type in {'RIGHTMOUSE', 'ESC'} and event.value == 'PRESS':
            #put it back!
            self.margin_manager.slice_cancel()
            return 'main'
        
        elif event.type == 'MOUSEMOVE':
            #update the b_pt location
            self.margin_manager.slice_mouse_move(context,event.mouse_region_x, event.mouse_region_y)
            return 'slice'
         
    def modal(self, context, event):
        context.area.tag_redraw()
        
        FSM = {}    
        FSM['main']    = self.modal_main
        FSM['grab']    = self.modal_grab
        FSM['slice']   = self.modal_slice
        FSM['nav']     = self.modal_nav
        
        nmode = FSM[self.mode](context, event)
        
        if nmode == 'nav': 
            return {'PASS_THROUGH'}
        
        if nmode in {'finish','cancel'}:
            #clean up callbacks
            bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW')
            return {'FINISHED'} if nmode == 'finish' else {'CANCELLED'}
        
        if nmode: self.mode = nmode
        
        return {'RUNNING_MODAL'}
    
    def invoke(self, context, event):
        layers_copy = [layer for layer in context.scene.layers]
        context.scene.layers[0] = True
        
        tooth = odcutils.tooth_selection(context)[0]
        self.tooth = tooth
        sce=bpy.context.scene
        a = tooth.name
        prep = tooth.prep_model
        margin = str(a + "_Margin")
        self.crv = None
        self.margin_manager = None
        if margin in bpy.data.objects:
            self.report({'WARNING'}, "you have already made a margin for this tooth, hit esc and then undo if you didn't want to replace it")
        
        if prep and prep in bpy.data.objects:
            Prep = bpy.data.objects[prep]
            Prep.hide = False
            L = Prep.location
            ###Keep a list of unhidden objects
            for o in sce.objects:
                if o.name != prep and not o.hide:
                    o.hide = True
                    
            self.crv = CurveDataManager(context,snap_type ='OBJECT', snap_object = Prep, shrink_mod = True, name = margin)
            
            self.margin_manager = MarginSlicer(tooth, context, self.crv)
        else:
            self.report({'WARNING'}, "There is no prep for this tooth, your margin will snap to the master model or all objects in scene")
        
        master=sce.odc_props.master
        if master and master in bpy.data.objects:
            Master = bpy.data.objects[master]
            if prep not in bpy.data.objects:
                self.crv = CurveDataManager(context,snap_type ='OBJECT', snap_object = Master, shrink_mod = True, name = margin)
                self.margin_manager = MarginSlicer(tooth, context, self.crv)
        else:
            self.report({'WARNING'}, "No master model...there are risks!")
        
        if not self.crv:
            self.crv = CurveDataManager(context,snap_type ='SCENE', snap_object = None, shrink_mod = False, name = margin)
        
        tooth.margin = self.crv.crv_obj.name
        
        help_txt = "DRAW MARGIN OUTLINE\n\nLeft Click on model to draw outline \nRight click to delete a point \nLeft Click last point to make loop \n G to grab  \n S to show slice \n ENTER to confirm \n ESC to cancel"
        self.help_box = TextBox(context,500,500,300,200,10,20,help_txt)
        self.help_box.snap_to_corner(context, corner = [1,1])
        self.mode = 'main'
        self._handle = bpy.types.SpaceView3D.draw_handler_add(icrnmgn_draw_callback, (self, context), 'WINDOW', 'POST_PIXEL')
        context.window_manager.modal_handler_add(self)
        return {'RUNNING_MODAL'}