Skip to content

Commit

Permalink
add load button to analysis and generator
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed Jan 18, 2018
1 parent 9683986 commit bb9779c
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 28 deletions.
24 changes: 23 additions & 1 deletion data/ui/analysis.ui
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
<item row="0" column="16">
<widget class="QToolButton" name="btnSaveProto">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand All @@ -528,6 +528,9 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Save current protocol.</string>
</property>
<property name="text">
<string/>
</property>
Expand Down Expand Up @@ -780,6 +783,25 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
</property>
</widget>
</item>
<item row="0" column="17">
<widget class="QToolButton" name="btnLoadProto">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Load a protocol.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="document-open"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
30 changes: 26 additions & 4 deletions data/ui/generator.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1081</width>
<height>699</height>
<width>1287</width>
<height>774</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -42,8 +42,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1159</width>
<height>686</height>
<width>1287</width>
<height>774</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down Expand Up @@ -637,6 +637,9 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Save current fuzz profile.</string>
</property>
<property name="text">
<string>...</string>
</property>
Expand All @@ -646,6 +649,25 @@ image: url(:/icons/icons/splitter_handle_vertical.svg);
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="btnOpen">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>Load a fuzz profile.</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="document-open"/>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
Expand Down
7 changes: 7 additions & 0 deletions src/urh/controller/CompareFrameController.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CompareFrameController(QWidget):
files_dropped = pyqtSignal(list)
participant_changed = pyqtSignal()
show_config_field_types_triggered = pyqtSignal()
load_protocol_clicked = pyqtSignal()

def __init__(self, plugin_manager: PluginManager, project_manager: ProjectManager, parent):

Expand Down Expand Up @@ -263,6 +264,8 @@ def create_connects(self):
self.protocol_label_list_model.label_removed.connect(self.on_label_removed)

self.ui.btnSaveProto.clicked.connect(self.on_btn_save_protocol_clicked)
self.ui.btnLoadProto.clicked.connect(self.on_btn_load_proto_clicked)

self.ui.btnAnalyze.clicked.connect(self.on_btn_analyze_clicked)

self.ui.listViewLabelNames.editActionTriggered.connect(self.on_edit_label_action_triggered)
Expand Down Expand Up @@ -1047,6 +1050,10 @@ def on_btn_analyze_clicked(self):
def on_btn_save_protocol_clicked(self):
self.save_protocol()

@pyqtSlot()
def on_btn_load_proto_clicked(self):
self.load_protocol_clicked.emit()

@pyqtSlot()
def on_btn_next_search_clicked(self):
self.next_search_result()
Expand Down
8 changes: 8 additions & 0 deletions src/urh/controller/GeneratorTabController.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def create_connects(self, compare_frame_controller):
self.ui.cbViewType.currentIndexChanged.connect(self.on_view_type_changed)
self.ui.btnSend.clicked.connect(self.on_btn_send_clicked)
self.ui.btnSave.clicked.connect(self.on_btn_save_clicked)
self.ui.btnOpen.clicked.connect(self.on_btn_open_clicked)

self.project_manager.project_updated.connect(self.on_project_updated)

Expand Down Expand Up @@ -616,6 +617,13 @@ def on_btn_save_clicked(self):
if filename:
self.table_model.protocol.to_xml_file(filename)

@pyqtSlot()
def on_btn_open_clicked(self):
dialog = FileOperator.get_open_dialog(directory_mode=False, parent=self, name_filter="fuzz")
if dialog.exec_():
for filename in dialog.selectedFiles():
self.load_from_file(filename)

def load_from_file(self, filename: str):
try:
self.table_model.protocol.from_xml_file(filename)
Expand Down
30 changes: 12 additions & 18 deletions src/urh/controller/MainController.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def create_connects(self):
self.compare_frame_controller.show_config_field_types_triggered.connect(
self.on_show_field_types_config_action_triggered)

self.compare_frame_controller.load_protocol_clicked.connect(self.on_compare_frame_controller_load_protocol_clicked)

self.ui.lnEdtTreeFilter.textChanged.connect(self.on_file_tree_filter_text_changed)

self.ui.tabWidget.currentChanged.connect(self.on_selected_tab_changed)
Expand Down Expand Up @@ -713,25 +715,10 @@ def on_open_directory_action_triggered(self):
self.show_open_dialog(directory=True)

def show_open_dialog(self, directory=False):
fip = FileIconProvider()
self.dialog = QFileDialog(self)
self.dialog.setIconProvider(fip)
self.dialog.setDirectory(FileOperator.RECENT_PATH)
self.dialog.setWindowTitle("Open Folder")
if directory:
self.dialog.setFileMode(QFileDialog.Directory)
else:
self.dialog.setFileMode(QFileDialog.ExistingFiles)
self.dialog.setNameFilter(
"All files (*);;Complex (*.complex);;Complex16 unsigned (*.complex16u);;Complex16 signed (*.complex16s);;Wave (*.wav);;Protocols (*.proto.xml *.proto);;"
"Fuzzprofiles (*.fuzz.xml *.fuzz);;Plain bits (*.txt);;Tar Archives (*.tar *.tar.gz *.tar.bz2);;Zip Archives (*.zip)")

self.dialog.setOptions(QFileDialog.DontResolveSymlinks)
self.dialog.setViewMode(QFileDialog.Detail)

if self.dialog.exec_():
dialog = FileOperator.get_open_dialog(directory_mode=directory, parent=self, name_filter="full")
if dialog.exec_():
try:
file_names = self.dialog.selectedFiles()
file_names = dialog.selectedFiles()
folders = [folder for folder in file_names if os.path.isdir(folder)]

if len(folders) > 0:
Expand Down Expand Up @@ -855,3 +842,10 @@ def on_project_loaded_status_changed(self, project_loaded: bool):
self.ui.actionSave_project.setVisible(project_loaded)
self.ui.actionConvert_Folder_to_Project.setDisabled(project_loaded)
self.__set_non_project_warning_visibility()

@pyqtSlot()
def on_compare_frame_controller_load_protocol_clicked(self):
dialog = FileOperator.get_open_dialog(directory_mode=False, parent=self, name_filter="proto")
if dialog.exec_():
for filename in dialog.selectedFiles():
self.add_protocol_file(filename)
15 changes: 14 additions & 1 deletion src/urh/ui/ui_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def setupUi(self, TabAnalysis):
self.gridLayout_2 = QtWidgets.QGridLayout()
self.gridLayout_2.setObjectName("gridLayout_2")
self.btnSaveProto = QtWidgets.QToolButton(self.layoutWidget1)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btnSaveProto.sizePolicy().hasHeightForWidth())
Expand Down Expand Up @@ -373,6 +373,16 @@ def setupUi(self, TabAnalysis):
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.gridLayout_2.addWidget(self.line, 0, 10, 1, 1)
self.btnLoadProto = QtWidgets.QToolButton(self.layoutWidget1)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btnLoadProto.sizePolicy().hasHeightForWidth())
self.btnLoadProto.setSizePolicy(sizePolicy)
icon = QtGui.QIcon.fromTheme("document-open")
self.btnLoadProto.setIcon(icon)
self.btnLoadProto.setObjectName("btnLoadProto")
self.gridLayout_2.addWidget(self.btnLoadProto, 0, 17, 1, 1)
self.verticalLayout.addLayout(self.gridLayout_2)
self.tblViewProtocol = ProtocolTableView(self.layoutWidget1)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
Expand Down Expand Up @@ -580,6 +590,7 @@ def retranslateUi(self, TabAnalysis):
self.chkBoxShowOnlyDiffs.setText(_translate("TabAnalysis", "Show only diffs in protocol"))
self.chkBoxOnlyShowLabelsInProtocol.setText(_translate("TabAnalysis", "Show only labels in protocol"))
self.btnAnalyze.setText(_translate("TabAnalysis", "Analyze"))
self.btnSaveProto.setToolTip(_translate("TabAnalysis", "Save current protocol."))
self.label_2.setToolTip(_translate("TabAnalysis", "<html><head/><body><p>The <span style=\" font-weight:600;\">Received Signal Strength Indicator</span> indicates the average signal power of the current message.</p></body></html>"))
self.label_2.setText(_translate("TabAnalysis", "RSSI:"))
self.lSlash.setText(_translate("TabAnalysis", "/"))
Expand All @@ -596,6 +607,8 @@ def retranslateUi(self, TabAnalysis):
self.label_3.setToolTip(_translate("TabAnalysis", "<html><head/><body><p>The <span style=\" font-weight:600;\">Message Start</span> is the point in time when a protocol message begins. Additionally the relative time (+ ...) from the previous message is shown.</p></body></html>"))
self.label_3.setText(_translate("TabAnalysis", "Timestamp:"))
self.btnSearchSelectFilter.setText(_translate("TabAnalysis", "Search"))
self.btnLoadProto.setToolTip(_translate("TabAnalysis", "Load a protocol."))
self.btnLoadProto.setText(_translate("TabAnalysis", "..."))
self.lBits.setText(_translate("TabAnalysis", "Bit:"))
self.lHex.setText(_translate("TabAnalysis", "Hex:"))
self.lDecimal.setText(_translate("TabAnalysis", "Decimal:"))
Expand Down
17 changes: 15 additions & 2 deletions src/urh/ui/ui_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Ui_GeneratorTab(object):
def setupUi(self, GeneratorTab):
GeneratorTab.setObjectName("GeneratorTab")
GeneratorTab.resize(1081, 699)
GeneratorTab.resize(1287, 774)
self.verticalLayout_3 = QtWidgets.QVBoxLayout(GeneratorTab)
self.verticalLayout_3.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_3.setSpacing(0)
Expand All @@ -19,7 +19,7 @@ def setupUi(self, GeneratorTab):
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 1159, 686))
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 1287, 774))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_2.setObjectName("verticalLayout_2")
Expand Down Expand Up @@ -301,6 +301,16 @@ def setupUi(self, GeneratorTab):
self.btnSave.setIcon(icon)
self.btnSave.setObjectName("btnSave")
self.horizontalLayout.addWidget(self.btnSave)
self.btnOpen = QtWidgets.QToolButton(self.layoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.btnOpen.sizePolicy().hasHeightForWidth())
self.btnOpen.setSizePolicy(sizePolicy)
icon = QtGui.QIcon.fromTheme("document-open")
self.btnOpen.setIcon(icon)
self.btnOpen.setObjectName("btnOpen")
self.horizontalLayout.addWidget(self.btnOpen)
self.gridLayout_2.addLayout(self.horizontalLayout, 0, 0, 1, 7)
self.btnNetworkSDRSend = QtWidgets.QPushButton(self.layoutWidget)
icon = QtGui.QIcon.fromTheme("network-wired")
Expand Down Expand Up @@ -372,7 +382,10 @@ def retranslateUi(self, GeneratorTab):
self.cbViewType.setItemText(2, _translate("GeneratorTab", "ASCII"))
self.lViewType.setText(_translate("GeneratorTab", "Viewtype:"))
self.labelGeneratedData.setText(_translate("GeneratorTab", "Generated data"))
self.btnSave.setToolTip(_translate("GeneratorTab", "Save current fuzz profile."))
self.btnSave.setText(_translate("GeneratorTab", "..."))
self.btnOpen.setToolTip(_translate("GeneratorTab", "Load a fuzz profile."))
self.btnOpen.setText(_translate("GeneratorTab", "..."))
self.btnNetworkSDRSend.setToolTip(_translate("GeneratorTab", "<html><head/><body><p><span style=\" font-weight:600;\">Send encoded data to your external application via TCP.</span></p></body></html>"))
self.btnNetworkSDRSend.setText(_translate("GeneratorTab", "Send via Network"))
self.btnRfCatSend.setToolTip(_translate("GeneratorTab", "<html><head/><body><p><span style=\" font-weight:600;\">Send encoded data via RfCat. </span></p><p><span style=\" font-style:italic;\">Hit again for stopping the sending process. Note that you can set the number of repetitions (from 1 to infinite) in:</span></p><p><span style=\" font-style:italic;\">Edit-&gt;Options-&gt;Device-&gt;\'Device sending repetitions\'</span></p></body></html>"))
Expand Down
40 changes: 38 additions & 2 deletions src/urh/util/FileOperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PyQt5.QtCore import QDir
from PyQt5.QtWidgets import QFileDialog, QMessageBox

from urh.models.FileIconProvider import FileIconProvider
from urh.util.Errors import Errors

VIEW_TYPES = ["Bits", "Hex", "ASCII"]
Expand All @@ -20,6 +21,41 @@
RECENT_PATH = QDir.homePath()


def get_open_dialog(directory_mode=False, parent=None, name_filter="full") -> QFileDialog:
fip = FileIconProvider()
dialog = QFileDialog(parent)
dialog.setIconProvider(fip)
dialog.setDirectory(RECENT_PATH)

if directory_mode:
dialog.setFileMode(QFileDialog.Directory)
dialog.setWindowTitle("Open Folder")
else:
dialog.setFileMode(QFileDialog.ExistingFiles)
dialog.setWindowTitle("Open Files")
if name_filter == "full":
name_filter = "All files (*);;Complex (*.complex);;" \
"Complex16 unsigned (*.complex16u);;" \
"Complex16 signed (*.complex16s);;" \
"Wave (*.wav);;" \
"Protocols (*.proto.xml *.proto);;" \
"Fuzzprofiles (*.fuzz.xml *.fuzz);;" \
"Plain bits (*.txt);;" \
"Tar Archives (*.tar *.tar.gz *.tar.bz2);;" \
"Zip Archives (*.zip)"
elif name_filter == "proto":
name_filter = "Protocols (*.proto.xml *.proto);;"
elif name_filter == "fuzz":
name_filter = "Fuzzprofiles (*.fuzz.xml *.fuzz);;"

dialog.setNameFilter(name_filter)

dialog.setOptions(QFileDialog.DontResolveSymlinks)
dialog.setViewMode(QFileDialog.Detail)

return dialog


def uncompress_archives(file_names, temp_dir):
"""
Extract each archive from the list of filenames.
Expand Down Expand Up @@ -59,8 +95,8 @@ def get_save_file_name(initial_name: str, wav_only=False, caption="Save signal")
global RECENT_PATH
if caption == "Save signal":
name_filter = "Complex files (*.complex);;Complex16 files (2 unsigned int8) " \
"(*.complex16u);;Complex16 files (2 signed int8) (*.complex16s);;" \
"Compressed complex files (*.coco);;wav files (*.wav);;all files (*)"
"(*.complex16u);;Complex16 files (2 signed int8) (*.complex16s);;" \
"Compressed complex files (*.coco);;wav files (*.wav);;all files (*)"
if wav_only:
name_filter = "wav files (*.wav);;all files (*)"
elif caption == "Save fuzz profile":
Expand Down

0 comments on commit bb9779c

Please sign in to comment.