示例#1
0
class Window(rox.Window, MenuWindow):
	drag_start = None

	def __init__(self, memo_list):
		rox.Window.__init__(self)
		MenuWindow.__init__(self)
		self.set_wmclass('Memo', 'Memo')
		self.set_title('Memo')
		self.set_resizable(False)
		if hasattr(self, 'set_deletable'):
			self.set_deletable(False)
		#self.set_type_hint(g.gdk.WINDOW_TYPE_HINT_DIALOG)

		self.tips = g.Tooltips()

		if main_sticky.int_value:
			self.stick()

		self.memo_list = memo_list
		self.last_day = None
		self.prime_in_progress = False

		vbox = g.VBox(FALSE, 0)
		self.add(vbox)

		hbox = g.HBox(False, 0)
		vbox.pack_start(hbox, expand = False)

		self.time_label = g.Label('')
		self.time_button = g.Button()
		self.time_button.add(self.time_label)
		self.time_button.unset_flags(g.CAN_FOCUS)
		hbox.pack_start(self.time_button, expand = True)

		hbox.pack_start(timer.TimerButton(), expand = False)

		self.list = g.TreeView(memo_list.visible)
		vbox.pack_start(self.list, expand = TRUE)
		self.list.unset_flags(g.CAN_FOCUS)

		cell = g.CellRendererText()
		column = g.TreeViewColumn('Time', cell, text = 0)
		cell.set_property('xalign', 1)
		self.list.append_column(column)

		cell = g.CellRendererText()
		column = g.TreeViewColumn('Message', cell, text = 1)
		self.list.append_column(column)

		self.list.set_headers_visible(FALSE)
		
		sel = self.list.get_selection()
		sel.set_mode(g.SELECTION_NONE)

		def activate(view, path, column):
			memo = memo_list.visible.get_memo_by_path(path)
			from EditBox import EditBox
			EditBox(memo).show()
		
		self.add_events(g.gdk.BUTTON_PRESS_MASK)
		self.list.connect('button-press-event', self.button_press)
		self.list.connect('row-activated', activate)
		self.time_button.add_events(g.gdk.BUTTON1_MOTION_MASK)
		self.time_button.connect('button-press-event', self.button_press)
		self.time_button.connect('motion-notify-event', self.button_motion)
		self.time_button.connect('clicked', self.time_button_clicked)

		self.update()
		gobject.timeout_add(10000, self.update)	# Update clock

		self.timeout = None	# For next alarm
		self.alert_box = None
		self.show_all_box = None
		self.save_box = None
		self.prime()

		# If we had more than one window, we'd need a remove too...
		memo_list.connect("MemoListChanged", self.prime)
		app_options.add_notify(self.options_changed)
		
		vbox.show_all()
	
	def time_button_clicked(self, widget):
		ev = g.get_current_event()
		if ev.type == g.gdk.MOTION_NOTIFY and self.drag_start:
			# Fake release from motion handler
			self.begin_move_drag(1, self.drag_start[0], self.drag_start[1], ev.time)
			self.drag_start = None
		else:
			self.new_memo()
	
	def options_changed(self):
		if time_format.has_changed:
			self.update()
			
		if main_sticky.int_value:
			self.stick()
		else:
			self.unstick()
	
	def update(self):
		if time_format.value == 'text':
			text = pretty_time.rough_time(time.time())
			self.tips.set_tip(self.time_button,
				time.strftime('%H:%M %a %Y-%m-%d'))
		else:
			# Note: importing gtk breaks strftime for am/pm
			text = time.strftime('%a %d-%b-%Y  ') + \
					pretty_time.str_time()
			self.tips.set_tip(self.time_button, None)
		self.time_label.set_text(text)
		
		t = time.localtime()
		year, month, day, hour, minute, second,	weekday, julian, dst = t
		if self.last_day != day:
			if self.last_day is not None:
				self.memo_list.new_day()
			self.last_day = day

		return TRUE
	
	def button_press(self, widget, event):
		if event.type != g.gdk.BUTTON_PRESS:
			return
		elif event.button == 2 or event.button == 3:
			self.popup_menu(event)
			return 1
		self.drag_start = map(int, (event.x_root, event.y_root))
		return 0
	
	def button_motion(self, widget, mev):
		if self.drag_start is None: return
		pos = map(int, (mev.x_root, mev.y_root))
		if self.time_button.drag_check_threshold(*(self.drag_start + pos)):
			self.time_button.released()
			if self.drag_start:
				# Release event was ignored (outside the button)
				self.time_button_clicked(widget)
	
	# Deal with any missed alarms
	# Set a timeout for the next alarm
	def prime(self, memo_list = None):
		if self.alert_box:
			return		# Don't do anything until closed

		if self.prime_in_progress:
			return		# Make this method atomic
		else:
			self.prime_in_progress = True
			
		missed, delay = self.memo_list.catch_up( alert_early.int_value )
		if missed:
			if dbus_notify.is_available():
				for m in missed:
					dbus_notify.notify(m)
			else:
				# Show the first one.
				self.alert_box = Alarm(missed[0])
				def destroyed(widget):
					self.alert_box = None
					self.prime()
				self.alert_box.connect('destroy', destroyed)
				g.gdk.beep()
				g.gdk.flush()
				time.sleep(0.3)
				g.gdk.beep()
				g.gdk.flush()
				time.sleep(1)
				self.alert_box.show()
		if delay:
			self.schedule(delay)
		self.prime_in_progress = False

	def timeout_cb(self):
		gobject.source_remove(self.timeout)
		self.timeout = 0
		self.prime()
		return 0
	
	def schedule(self, delay):
		if self.timeout:
			gobject.source_remove(self.timeout)

		# Avoid overflows - don't resched more than a day ahead
		if delay > 60 * 60 * 24:
			delay = 60 * 60 * 24

		self.timeout = gobject.timeout_add(int(1000 * delay), self.timeout_cb)
示例#2
0
class Bedroom(Room):
    """
    Bedroom window to pop up when player navigates to the Bedroom Location
    """
    def __init__(self):
        super().__init__("Bedroom")
        # Calling the user interface function
        self.setRoomButtons()
        self.setInteractionButtons()
        self.setEasterEggButtons()

    def setRoomButtons(self):
        # Setting up buttons and other room windows
        self.hw = None
        self.hallwayButton = QPushButton("Hallway", self)
        self.hallwayButton.setGeometry(self.width / 2 - self.button_width / 2,
                                       self.image_height - self.button_height,
                                       self.button_width, self.button_height)
        self.hallwayButton.clicked.connect(self.toHallway)

    def setInteractionButtons(self):
        # setting evening buttons
        if config.game_time.isDay() == False:
            # Alarm
            self.alarm_window = None
            self.alarmButton = QPushButton("", self)
            self.alarmButton.setIcon(
                QIcon("../images/icons/magnifying_glass.png"))
            self.alarmButton.setGeometry(502, 460, self.bw, self.bh)
            self.alarmButton.setStyleSheet(
                "background-color: rgba(0, 255, 255, 0);")
            self.alarmButton.clicked.connect(self.toAlarm)

            # Bedside books
            self.booksButton = QPushButton("", self)
            self.booksButton.setIcon(
                QIcon("../images/icons/magnifying_glass.png"))
            self.booksButton.setGeometry(210, 430, self.bw, self.bh)
            self.booksButton.setStyleSheet(
                "background-color: rgba(0, 255, 255, 0);")
            self.booksButton.clicked.connect(self.toBooks)

            # Bedside Lights - Right
            self.rightLightsButton = QPushButton("", self)
            self.rightLightsButton.setIcon(
                QIcon("../images/icons/magnifying_glass.png"))
            self.rightLightsButton.setGeometry(532, 225, self.bw, self.bh)
            self.rightLightsButton.setStyleSheet(
                "background-color: rgba(0, 255, 255, 0);")
            self.rightLightsButton.clicked.connect(self.toLightsOff)

            # Bedside Lights - Left
            self.leftLightsButton = QPushButton("", self)
            self.leftLightsButton.setIcon(
                QIcon("../images/icons/magnifying_glass.png"))
            self.leftLightsButton.setGeometry(160, 263, self.bw, self.bh)
            self.leftLightsButton.setStyleSheet(
                "background-color: rgba(0, 255, 255, 0);")
            self.leftLightsButton.clicked.connect(self.toLightsOff)
        else:
            # Alarm
            self.alarm_window = None
            self.alarmButton = QPushButton("", self)
            self.alarmButton.setIcon(
                QIcon("../images/icons/magnifying_glass.png"))
            self.alarmButton.setGeometry(475, 535, self.bw, self.bh)
            self.alarmButton.setStyleSheet(
                "background-color: rgba(0, 255, 255, 0);")
            self.alarmButton.clicked.connect(self.toAlarm)

            # Candle
            self.booksButton = QPushButton("", self)
            self.booksButton.setIcon(
                QIcon("../images/icons/magnifying_glass.png"))
            self.booksButton.setGeometry(105, 525, self.bw, self.bh)
            self.booksButton.setStyleSheet(
                "background-color: rgba(0, 255, 255, 0);")
            self.booksButton.clicked.connect(self.toBooks)

    def setEasterEggButtons(self):
        pass

    def toHallway(self, checked):
        config.progress.rooms_visited += 1
        if self.hw is None:
            self.hw = Hallway.Hallway()
            self.hw.show()
        else:
            self.hw.close()
            self.hw = None
        self.close()

    def toBooks(self, checked):
        self.playAudio("hmm", nancy=True)

    def toAlarm(self, checked):
        if config.progress.data.loc["met_ingman", "complete"] == True:
            if self.alarm_window is None:
                self.alarm_window = Alarm()
                self.alarm_window.show()
            else:
                self.alarm_window.close()
                self.alarm_window = None

            self.close()
        else:
            self.playAudio("cant_do", nancy=True)