Skip to content

Commit

Permalink
Added cancel button to the LoadingDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
korcankaraokcu committed Feb 21, 2017
1 parent b5c6b6f commit 425713e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 13 deletions.
24 changes: 19 additions & 5 deletions GUI/LoadingDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'LoadingDialog.ui'
#
# Created: Wed Dec 7 19:30:07 2016
# Created: Tue Feb 21 22:38:30 2017
# by: PyQt5 UI code generator 5.2.1
#
# WARNING! All changes made in this file will be lost!
Expand All @@ -12,9 +12,9 @@
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(195, 40)
self.gridLayout = QtWidgets.QGridLayout(Dialog)
self.gridLayout.setObjectName("gridLayout")
Dialog.resize(208, 89)
self.gridLayout_2 = QtWidgets.QGridLayout(Dialog)
self.gridLayout_2.setObjectName("gridLayout_2")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setObjectName("horizontalLayout")
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
Expand All @@ -34,7 +34,20 @@ def setupUi(self, Dialog):
self.horizontalLayout.addWidget(self.label_StatusText)
spacerItem1 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem1)
self.gridLayout.addLayout(self.horizontalLayout, 0, 0, 1, 1)
self.gridLayout_2.addLayout(self.horizontalLayout, 0, 0, 1, 1)
self.widget_Cancel = QtWidgets.QWidget(Dialog)
self.widget_Cancel.setObjectName("widget_Cancel")
self.gridLayout = QtWidgets.QGridLayout(self.widget_Cancel)
self.gridLayout.setContentsMargins(0, 0, 0, 0)
self.gridLayout.setObjectName("gridLayout")
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem2, 0, 0, 1, 1)
self.pushButton_Cancel = QtWidgets.QPushButton(self.widget_Cancel)
self.pushButton_Cancel.setObjectName("pushButton_Cancel")
self.gridLayout.addWidget(self.pushButton_Cancel, 0, 1, 1, 1)
spacerItem3 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.gridLayout.addItem(spacerItem3, 0, 2, 1, 1)
self.gridLayout_2.addWidget(self.widget_Cancel, 1, 0, 1, 1)

self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
Expand All @@ -43,4 +56,5 @@ def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
self.label_StatusText.setText(_translate("Dialog", "Processing"))
self.pushButton_Cancel.setText(_translate("Dialog", "Cancel"))

45 changes: 42 additions & 3 deletions GUI/LoadingDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>195</width>
<height>40</height>
<width>208</width>
<height>89</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down Expand Up @@ -67,6 +67,45 @@
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QWidget" name="widget_Cancel" native="true">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButton_Cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down
6 changes: 6 additions & 0 deletions PINCE.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ def __init__(self, parent=None):
# Check refresh_table method of FunctionsInfoWidgetForm for exemplary usage
self.background_thread = self.BackgroundThread()
self.background_thread.output_ready.connect(self.accept)
self.pushButton_Cancel.clicked.connect(self.cancel_thread)
pince_directory = SysUtils.get_current_script_directory()
self.movie = QMovie(pince_directory + "/media/LoadingDialog/ajax-loader.gif", QByteArray())
self.label_Animated.setMovie(self.movie)
Expand All @@ -853,6 +854,11 @@ def __init__(self, parent=None):
self.movie.setSpeed(100)
self.movie.start()

# This function only cancels the last command sent
# Override this if you want to do dangerous stuff like, God forbid, background_thread.terminate()
def cancel_thread(self):
GDB_Engine.cancel_last_command()

def exec_(self):
self.background_thread.start()
super(LoadingDialogForm, self).exec_()
Expand Down
31 changes: 26 additions & 5 deletions libPINCE/GDB_Engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@
# See gdb_async_condition's docstrings
gdb_async_output = ""

#:doc:cancel_send_command
# A boolean value. Used to cancel the last gdb command sent
# Use the function cancel_last_command to make use of this variable
# Return value of the current send_command call will be an empty string
cancel_send_command = False


# The comments next to the regular expressions shows the expected gdb output, hope it helps to the future developers

def cancel_last_command():
"""Cancels the last gdb command sent"""
global cancel_send_command
cancel_send_command = True


def send_command(command, control=False, cli_output=False, send_with_file=False, file_contents_send=None,
recv_with_file=False):
"""Issues the command sent, raises an exception if the inferior is running or no inferior has been selected
Expand Down Expand Up @@ -147,6 +159,7 @@ def send_command(command, control=False, cli_output=False, send_with_file=False,
"""
global child
global gdb_output
global cancel_send_command
with lock_send_command:
time0 = time()
if not gdb_initialized:
Expand Down Expand Up @@ -178,11 +191,17 @@ def send_command(command, control=False, cli_output=False, send_with_file=False,
if not control:
while gdb_output is "":
sleep(type_defs.CONST_TIME.GDB_INPUT_SLEEP)
if not control:
if recv_with_file or cli_output:
output = pickle.load(open(recv_file, "rb"))
if cancel_send_command:
break
if not cancel_send_command:
if recv_with_file or cli_output:
output = pickle.load(open(recv_file, "rb"))
else:
output = gdb_output
else:
output = gdb_output
output = ""
child.sendcontrol("c")
cancel_send_command = False
else:
output = ""
if type(output) == str:
Expand Down Expand Up @@ -302,7 +321,7 @@ def wait_for_stop(timeout=1):


def interrupt_inferior(interrupt_reason=type_defs.STOP_REASON.DEBUG):
"""Interrupt the inferior, can be also used to cancel the current gdb command
"""Interrupt the inferior
Args:
interrupt_reason (int): Just changes the global variable stop_reason. Can be a member of type_defs.STOP_REASON
Expand Down Expand Up @@ -348,6 +367,7 @@ def init_gdb(gdb_path=type_defs.PATHS.GDB_PATH):
global referenced_jumps_dict
global referenced_calls_dict
global gdb_output
global cancel_send_command
detach()

# Temporary IPC_PATH, this little hack is needed because send_command requires a valid IPC_PATH
Expand All @@ -360,6 +380,7 @@ def init_gdb(gdb_path=type_defs.PATHS.GDB_PATH):
referenced_jumps_dict.clear()
referenced_calls_dict.clear()
gdb_output = ""
cancel_send_command = False

libpince_dir = SysUtils.get_libpince_directory()
child = pexpect.spawn('sudo LC_NUMERIC=C ' + gdb_path + ' --interpreter=mi', cwd=libpince_dir,
Expand Down

0 comments on commit 425713e

Please sign in to comment.